Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
    int optind = 0;
    int i;
    struct fhb_handle *handles;


    if (agetarg(args, argc, argv, &optind, AARG_GNUSTYLE))
	usage(1);

    if (help_flag)
	usage(0);

    if (num_files <= 0)
	usage(1);

    if (write_file < 0)
	usage(1);

#ifdef KERBEROS
    if (!k_hasafs())
#endif
	errx(1, "no afs kernel module");

    handles = emalloc(num_files * sizeof(*handles));

    starttesting("creating files");
    for (i = 0; i < num_files; i++)
	create_file(i, &handles[i]);
    endtesting();

    for (i = 0; i < num_runs; i++)
	open_bench(i, handles);

    printf("==================\n");
    starttesting("unlink files");
    for (i = 0; i < num_files; i++)
	unlink_file(i);
    endtesting();

    printf("==================\n");
    starttesting("nop call");
    for (i = 0; i < num_files; i++)
	nop_call();
    endtesting();

    return 0;
}
Ejemplo n.º 2
0
static void
open_bench(int i, struct fhb_handle *handles)
{
    printf("====== test run %d\n" "==================\n", i);

    starttesting("fhopening files");
    for (i = 0; i < num_files; i++)
	fhopen_file(i, &handles[i]);
    endtesting();

    starttesting("opening files");
    for (i = 0; i < num_files; i++)
	open_file(i);
    endtesting();
}
Ejemplo n.º 3
0
static int
test_hash(void)
{
    Hashtab *h;

    starttesting("hashtab");

    h = hashtabnew(100, hash_cmp, hash_hash);
    if (!h)
	return endtesting(1);

    if (!hashtabadd(h, "one")||
	!hashtabadd(h, "two")||
	!hashtabadd(h, "three")||
	!hashtabadd(h, "four"))
	return endtesting(1);

    printf("foreach ----\n");
    hashtabforeach(h, hash_print, NULL);

    printf("search ----\none == %s\ntwo == %s\nthree == %s\nfour == %s\n", 
	   (char *)hashtabsearch(h, "one"),
	   (char *)hashtabsearch(h, "two"),
	   (char *)hashtabsearch(h, "three"),
	   (char *)hashtabsearch(h, "four"));

    hashtabrelease(h);

    return endtesting(0);
}
Ejemplo n.º 4
0
static int
test_math (void)
{
    starttesting ("math");

    if (arlautil_findprime(17) != 17)
	return endtesting (1);
    if (arlautil_findprime(18) != 19)
	return endtesting (1);
    if (arlautil_findprime(11412) != 11423)
	return endtesting (1);

    if (arlautil_findprime(11412) != 11423)
	return endtesting (1);

    if (arlautil_isprime(20897) == 0)
	return endtesting (1);
    if (arlautil_isprime(49037) == 0)
	return endtesting (1);

    return endtesting (0);
}
Ejemplo n.º 5
0
static int
test_log (void)
{
    Log_method *m;
    Log_unit *u1, *u2;
    char buf[1024];

    starttesting ("log");

    m = log_open ("util-tester", "/dev/stderr:notime");
    if (m == NULL)
	return endtesting(1);

    u1 = log_unit_init (m, "u1", u1_units, 0x3);
    if (u1 == NULL)
	return endtesting(1);

    u2 = log_unit_init (m, "u2", u2_units, 0x0);
    if (u2 == NULL)
	return endtesting(1);

    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);
    log_log (u1, 0x1, "1.  this should show");
    log_log (u2, 0x1, "X.  this should NOT show");

    log_set_mask_str (m, NULL, "u1:-debug;u2:+debug");
    log_log (u1, 0x1, "X.  now this should NOT show");
    log_log (u2, 0x1, "2.  now this should show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask_str (m, NULL, "u1:-debug;u2:-debug");
    log_log (u1, 0x1, "X.  now this should NOT show");
    log_log (u2, 0x1, "X.  now this should NOT show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask_str (m, NULL, "+debug");
    log_log (u1, 0x1, "3.  now this should show");
    log_log (u2, 0x1, "4.  now this should show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask_str (m, NULL, "-debug");
    log_log (u1, 0x1, "X.  now this should NOT show");
    log_log (u2, 0x1, "X.  now this should NOT show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask_str (m, NULL, "+debug,+warning");
    log_log (u1, 0x1, "5.  now this should show");
    log_log (u2, 0x1, "6.  now this should show");
    log_log (u1, 0x2, "7.  now this should show");
    log_log (u2, 0x2, "8.  now this should show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask_str (m, u1, "-debug,-warning");
    log_log (u1, 0x1, "X. now this should NOT show");
    log_log (u2, 0x1, "9. now this should show");
    log_log (u1, 0x2, "X. now this should NOT show");
    log_log (u2, 0x2, "10. now this should show");

    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask (u1, 0x4 + 0x2 + 0x1);
    log_set_mask (u2, 0x8 + 0x4 + 0x2 + 0x1);

    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("%s\n", buf); fflush (stdout);
    log_set_mask_str (m, NULL, buf);

    log_set_mask_str (m, NULL, "all");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("all: %s\n", buf); fflush (stdout);

    log_set_mask_str (m, NULL, "-all");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("none: %s\n", buf); fflush (stdout);


    log_close (m);
    return endtesting (0);
}