Exemple #1
0
double longrunning_rotation() {
  // We're going to be doing a bunch of rotations; we probably shouldn't
  // let the user see all the verbose output.
  test_verbose = false;

  // There's probably some great reason why this exact size was chosen for
  // the test bit array; however, if there is, it's been lost to
  // history.
  // const size_t bit_sz = 10000 * 1024 * 8 + 471;
  const size_t bit_sz = 12 * 1024 * 8 + 471;
  testutil_newrand(bit_sz, 0);

  const clockmark_t start_time = ktiming_getmark();
  testutil_rotate(0, bit_sz, -bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 2);
  const clockmark_t end_time = ktiming_getmark();

  // Arguably, we should set test_verbose back to whatever it was before
  // we started.  However, since we're never going to be running more than
  // one performance test at a time (or performance tests at the same time
  // as functional tests), we can just let it be.

  return ktiming_diff_usec(&start_time, &end_time) / 1000000000.0;
}
Exemple #2
0
static void test_headerexamples(void) {
  /* Verify the examples given in bitarray.h. */
  testutil_frmstr("10010110");
  testutil_expect("10010110", 5);
  testutil_rotate(0, 8, -1);
  testutil_expect("00101101", 5);
  testutil_frmstr("10010110");
  testutil_rotate(2, 5, 2);
  testutil_expect("10110100", 5);
}
Exemple #3
0
static void test_12bit(void) {
  testutil_frmstr("010000101000");
  testutil_rotate(0, 12, 1);
  testutil_expect("001000010100", 6);
  
  testutil_frmstr("010000101000");
  testutil_rotate(0, 12, -1);
  testutil_expect("100001010000", 5);
  testutil_rotate(0, 12, -1);
  testutil_expect("000010100001", 5);
  testutil_rotate(0, 12, -1);
  testutil_expect("000101000010", 6);
  
  testutil_frmstr("010000101000");
  testutil_rotate(0, 12, 0);
  testutil_expect("010000101000", 6);
  testutil_rotate(0, 12, 1);
  testutil_expect("001000010100", 6);
  testutil_rotate(0, 12, -1);
  testutil_expect("010000101000", 6);
  testutil_rotate(0, 12, -1);
  testutil_expect("100001010000", 5);
  testutil_rotate(0, 12, -(3 + 12));
  testutil_expect("001010000100", 6);
}
Exemple #4
0
/* A sample long-running set of rotation operations. */
double longrunning_rotation(void) {
  test_verbose = false;
  size_t bit_sz = 12 * 1024 * 8 + 471;
  testutil_newrand(bit_sz, 0);
  clockmark_t time1 = ktiming_getmark();
  testutil_rotate(0, bit_sz, (ssize_t) -bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 2);
  clockmark_t time2 = ktiming_getmark();
  
  return ktiming_diff_usec(&time1, &time2) / 1000000000.0;
}
Exemple #5
0
static void test_8bit(void) {
  testutil_frmstr("10000101");
  testutil_rotate(0, 8, 0);
  testutil_expect("10000101", 4);
  testutil_rotate(0, 8, 1);
  testutil_expect("11000010", 3);
  testutil_rotate(0, 8, -1);
  testutil_expect("10000101", 4);
  testutil_rotate(0, 8, -1);
  testutil_expect("00001011", 3);
  testutil_rotate(0, 8, -(3 + 8));
  testutil_expect("01011000", 4);
}
Exemple #6
0
static void test_lotsmore(void) {
  testutil_frmstr("00101");
  testutil_rotate(0, 5, 0);
  testutil_expect("00101", 3);
  testutil_rotate(0, 5, 1);
  testutil_expect("10010", 3);
  testutil_rotate(0, 5, -1);
  testutil_expect("00101", 3);
  testutil_rotate(0, 5, -1);
  testutil_expect("01010", 4);
  testutil_rotate(0, 5, -(3 + 5));
  testutil_expect("10010", 3);
  
  testutil_frmstr("11000101");
  testutil_rotate(3, 5, 0);
  testutil_expect("11000101", 4);
  testutil_rotate(3, 5, 1);
  testutil_expect("11010010", 5);
  testutil_rotate(3, 5, -1);
  testutil_expect("11000101", 4);
  testutil_rotate(3, 5, -1);
  testutil_expect("11001010", 5);
  testutil_rotate(3, 5, -(3 + 5));
  testutil_expect("11010010", 5);
  
  testutil_frmstr("11000101000010");
  testutil_rotate(3, 5, 0);
  testutil_expect("11000101000010", 7);
  testutil_rotate(3, 5, 1);
  testutil_expect("11010010000010", 7);
  testutil_rotate(3, 5, -1);
  testutil_expect("11000101000010", 7);
  testutil_rotate(3, 5, -1);
  testutil_expect("11001010000010", 7);
  testutil_rotate(3, 5, -(3 + 5 * 99));
  testutil_expect("11010010000010", 7);
  
  testutil_frmstr("");
  testutil_rotate(0, 0, -5);
  testutil_expect("", 0);
  testutil_frmstr("1");
  testutil_rotate(0, 0, -5);
  testutil_expect("1", 0);
  testutil_rotate(0, 1, -5);
  testutil_expect("1", 0);
  
  testutil_frmstr("11000101000010010100100101000110010101101001010010000100010"); /* 59 bits */
  testutil_rotate(0, 0, -5);
  testutil_expect("11000101000010010100100101000110010101101001010010000100010", 37);
  testutil_rotate(0, 59, 15);
  testutil_expect("01001000010001011000101000010010100100101000110010101101001", 37);
  testutil_rotate(14, 27, 3);
  /*           ..............***************************..................*/
  testutil_expect("01001000010001101011000101000010010100100000110010101101001", 35);
  testutil_rotate(57, 2, -3);
  testutil_expect("01001000010001101011000101000010010100100000110010101101010", 36);

  testutil_frmstr("11000101000010010100100101000110010101101001010010000100010110011001"); /* 68 bits */
  testutil_rotate(0, 0, -5);
  testutil_expect("11000101000010010100100101000110010101101001010010000100010110011001", 42);
  testutil_rotate(0, 68, 15);
  testutil_expect("10001011001100111000101000010010100100101000110010101101001010010000", 41);
  testutil_rotate(14, 27, 3);
  /*           ..............***************************...........................*/
  testutil_expect("10001011001100101111000101000010010100100000110010101101001010010000", 39);
  testutil_rotate(57, 2, -3);
  testutil_expect("10001011001100101111000101000010010100100000110010101101010010010000", 39);
}
Exemple #7
0
void parse_and_run_tests(const char *filename, int selected_test) {
  test_verbose = false;
  fprintf(stderr, "Testing file %s.\n", filename);
  FILE *f = fopen(filename, "r");

  char buf[BUF_SIZE];
  int test = -1;
  int line = 0;
  bool ready_to_run = false;
  if (f == NULL) {
    fprintf(stderr, "Error opening file.\n");
    return;
  }
  while (fgets(buf, BUF_SIZE, f) != NULL) {
    line++;
    char* token = strtok(buf, " ");
    switch (token[0]) {
     case '\n':
     case '#':
      continue;
     case 't':
      test = NEXT_ARG_INT();
      ready_to_run = (test == selected_test || selected_test == -1);
      if (!ready_to_run) {
        continue;
      }

      fprintf(stderr, "\nRunning test #%d...\n", test);
      break;
     case 'n':
      if (!ready_to_run) {
        continue;
      }
      testutil_frmstr(next_arg_char());
      break;
     case 'e':
      if (!ready_to_run) {
        continue;
      }
      {
        char *expected = next_arg_char();
        testutil_expect_internal(expected, filename, line);
      }
      break;
     case 'r':
      if (!ready_to_run) {
        continue;
      }
      {
        size_t offset = NEXT_ARG_INT();
        size_t length = NEXT_ARG_INT();
        ssize_t amount = NEXT_ARG_INT();
        testutil_require_valid_input(offset, length, amount, filename, line);
        testutil_rotate(offset, length, amount);
      }
      break;
     default:
      fprintf(stderr, "Unknown command %s", buf);
    }
  }

  fprintf(stderr, "Done testing file %s.\n", filename);
}