예제 #1
0
int main(int argc, char *argv[])
{
  ih_core_bitarray_t *bitarray;

  bitarray = ih_core_bitarray_create(4);
  if (!bitarray) {
    ih_core_trace_exit("ih_core_bitarray_create");
  }

  ih_core_bitarray_unset_all(bitarray);
  ih_core_bitarray_print(bitarray);
  while (ih_core_bitarray_increment(bitarray)) {
    ih_core_bitarray_print(bitarray);
  }

  ih_core_bitarray_destroy(bitarray);

  test_get_functions();
  test_set_functions();
  test_from_char();
  test_from_double();
  test_from_long();
  test_from_short();
  test_from_string();

  return 0;
}
예제 #2
0
int
main(int ac, char *av[]) {
  char **ia = av + 1, **a_end = av + ac, *ep;
  const char *fname = NULL;

  for (; ia < a_end; ++ia) {
    if (!strcmp("--fp-len", *ia))               s_fp_len = atoi(*++ia);
    else if (!strcmp("--offset", *ia))          s_offset = atoi(*++ia);
    else if (!strcmp("--times", *ia))           s_times = atoi(*++ia);
    else if (!strcmp("--hash", *ia))            s_show_hash = 1;
    else if (!strcmp("--b1", *ia))              s_b1 = atoi(*++ia);
    else if (!strcmp("--b2", *ia))              s_b2 = atoi(*++ia);
    else if (!strcmp("--m", *ia))               s_m = strtol(*++ia, &ep, 0);
    else if (!strcmp("--m1", *ia))              s_m1 = strtol(*++ia, &ep, 0);
    else if (!strcmp("--m2", *ia))              s_m2 = strtol(*++ia, &ep, 0);
    else if (!strcmp("--file", *ia))            fname = *++ia;
    else if (!strcmp("--no-mmap", *ia))         s_no_mmap = 1;
    else if (!strcmp("--verbose", *ia))         s_verbosity = 1;
    else if (!strncmp("--verbose=", *ia, 10))   s_verbosity = atoi(*ia + 10);
    else if (!strcmp("--bm-dump", *ia))         s_bm_dump = 1;
    else if (!strcmp("--bench-hash", *ia))      s_options |= O_BENCH_HASH;
    else if (!strcmp("--check-hash", *ia))      s_options |= O_CHECK_HASH;
    else if (!strcmp("--bench-lut", *ia))       s_options |= O_BENCH_LUT;
    else if (!strcmp("--hash-mod", *ia))        s_options |= O_HASH_MOD;
    else if (!strcmp("--hash-mod16x2", *ia))    s_options |= O_HASH_MOD16X2;
    else if (!strcmp("--hash-mask16x2", *ia))   s_options |= O_HASH_MASK16X2;
    else if (!strcmp("--hash-mask", *ia))       s_options |= O_HASH_MASK;
    else if (!strcmp("--hash-mask32x2", *ia))   s_options |= O_HASH_MASK32X2;
    else if (!strcmp("--help", *ia))            show_usage();
    else if (!strcmp("--", *ia)) {
      ++ia;
      break;
    }
    else if ('-' == **ia) {
      DIE("unknown option: %s\n", *ia);
    }
    else break;
  }
  bmz_set_verbosity(s_verbosity);

  if (!s_options) s_options = O_DEFAULT;
  else if (!(s_options & O_HASHES)) s_options |= O_HASHES;

  if (fname)
    test_from_file(fname);
  else if (ia >= a_end)
    test_from_stdin();
  else for (; ia < a_end; ++ia)
    test_from_string(*ia, strlen(*ia));

  return 0;
}
예제 #3
0
static void
test_from_file(const char *fname) {
  int fd = open(fname, O_RDONLY, 0);
  char *data = NULL;
  struct stat st;
  long len;

  if (fd == -1) DIE("cannot open '%s'", fname);

  if (fstat(fd, &st) != 0) DIE("stat failed on '%s'", fname);

  len = st.st_size;

  if (!s_no_mmap) {
#ifndef HT_NO_MMAP
    LOG(1, "mmaping %ld bytes in to memory...", len);
    data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);

    if ((char *)-1 == data) {
      LOG(0, "mmap failed on '%s', trying alternative...", fname);
      errno = 0;
      data = NULL;
    }
#endif
  }

  if (!data) {
    LOG(1, "reading %ld bytes in to memory...", len);

    data = malloc(len);

    if (!data) DIE("error alloc'ing %ld bytes", len);

    if ((len = read(fd, data, len)) != st.st_size)
      DIE("error reading %s (expecting %ld bytes, got %ld",
          fname, (long)st.st_size, len);
  }
  else {
  }

  test_from_string(data, st.st_size);
}
예제 #4
0
static void
test_from_stdin() {
  size_t len;
  char *data = read_from_fp(stdin, &len);
  test_from_string(data, len);
}