From 8e8bd67cddd093a7de690bfd869f40cd7d5b48ee Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Wed, 13 Jul 2011 15:43:09 -0700 Subject: [PATCH] testrados: fix Change testrados back to a simple single-threaded test. The multi-threaded tests need to be properly designed to run multi-threaded. Signed-off-by: Colin McCabe --- src/testrados.c | 169 +++++++++++++++++------------------------------- 1 file changed, 61 insertions(+), 108 deletions(-) diff --git a/src/testrados.c b/src/testrados.c index dc4087cb810be..acaa9a75a4f00 100644 --- a/src/testrados.c +++ b/src/testrados.c @@ -21,29 +21,19 @@ #include #include -/* Print out a line, but prefix the thread number. */ -static void tprintf(int tnum, const char *fmt, ...) -{ - va_list ap; - printf("%d :", tnum); - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -static int do_rados_setxattr(int tnum, rados_ioctx_t io_ctx, const char *oid, +static int do_rados_setxattr(rados_ioctx_t io_ctx, const char *oid, const char *key, const char *val) { int ret = rados_setxattr(io_ctx, oid, key, val, strlen(val) + 1); if (ret < 0) { - tprintf(tnum, "rados_setxattr failed with error %d\n", ret); + printf("rados_setxattr failed with error %d\n", ret); return 1; } - tprintf(tnum, "rados_setxattr %s=%s\n", key, val); + printf("rados_setxattr %s=%s\n", key, val); return 0; } -static int do_rados_getxattr(int tnum, rados_ioctx_t io_ctx, const char *oid, +static int do_rados_getxattr(rados_ioctx_t io_ctx, const char *oid, const char *key, const char *expected) { size_t blen = strlen(expected) + 1; @@ -51,19 +41,19 @@ static int do_rados_getxattr(int tnum, rados_ioctx_t io_ctx, const char *oid, memset(buf, 0, sizeof(buf)); int r = rados_getxattr(io_ctx, oid, key, buf, blen); if (r < 0) { - tprintf(tnum, "rados_getxattr(%s) failed with error %d\n", key, r); + printf("rados_getxattr(%s) failed with error %d\n", key, r); return 1; } if (strcmp(buf, expected) != 0) { - tprintf(tnum, "rados_getxattr(%s) got wrong result! " + printf("rados_getxattr(%s) got wrong result! " "expected: '%s'. got '%s'\n", key, expected, buf); return 1; } - tprintf(tnum, "rados_getxattr %s=%s\n", key, buf); + printf("rados_getxattr %s=%s\n", key, buf); return 0; } -static int do_rados_getxattrs(int tnum, rados_ioctx_t io_ctx, const char *oid, +static int do_rados_getxattrs(rados_ioctx_t io_ctx, const char *oid, const char **exkeys, const char **exvals) { rados_xattrs_iter_t iter; @@ -74,7 +64,7 @@ static int do_rados_getxattrs(int tnum, rados_ioctx_t io_ctx, const char *oid, } ret = rados_getxattrs(io_ctx, oid, &iter); if (ret) { - tprintf(tnum, "rados_getxattrs(%s) failed with error %d\n", oid, ret); + printf("rados_getxattrs(%s) failed with error %d\n", oid, ret); return 1; } while (1) { @@ -82,7 +72,7 @@ static int do_rados_getxattrs(int tnum, rados_ioctx_t io_ctx, const char *oid, const char *key, *val; ret = rados_getxattrs_next(iter, &key, &val, &len); if (ret) { - tprintf(tnum, "rados_getxattrs(%s): rados_getxattrs_next " + printf("rados_getxattrs(%s): rados_getxattrs_next " "returned error %d\n", oid, ret); return 1; } @@ -95,35 +85,35 @@ static int do_rados_getxattrs(int tnum, rados_ioctx_t io_ctx, const char *oid, nfound++; break; } - tprintf(tnum, "rados_getxattrs(%s): got key %s, but the " + printf("rados_getxattrs(%s): got key %s, but the " "value was %s rather than %s.\n", oid, key, val, exvals[i]); return 1; } } if (nfound != nval) { - tprintf(tnum, "rados_getxattrs(%s): only found %d extended attributes. " + printf("rados_getxattrs(%s): only found %d extended attributes. " "Expected %d\n", oid, nfound, nval); return 1; } rados_getxattrs_end(iter); - tprintf(tnum, "rados_getxattrs(%s)\n", oid); + printf("rados_getxattrs(%s)\n", oid); return 0; } -static int testrados(int tnum) +static int testrados(void) { char tmp[32]; int i, r; rados_t cl; if (rados_create(&cl, NULL) < 0) { - tprintf(tnum, "error initializing\n"); + printf("error initializing\n"); return 1; } if (rados_conf_read_file(cl, NULL)) { - tprintf(tnum, "error reading configuration file\n"); + printf("error reading configuration file\n"); return 1; } @@ -131,89 +121,89 @@ static int testrados(int tnum) // This should fail. if (!rados_conf_set(cl, "config option that doesn't exist", "some random value")) { - tprintf(tnum, "error: succeeded in setting nonexistent config option\n"); + printf("error: succeeded in setting nonexistent config option\n"); return 1; } if (rados_conf_get(cl, "log to stderr", tmp, sizeof(tmp))) { - tprintf(tnum, "error: failed to read log_to_stderr from config\n"); + printf("error: failed to read log_to_stderr from config\n"); return 1; } // Can we change it? if (rados_conf_set(cl, "log to stderr", "2")) { - tprintf(tnum, "error: error setting log_to_stderr\n"); + printf("error: error setting log_to_stderr\n"); return 1; } if (rados_conf_get(cl, "log to stderr", tmp, sizeof(tmp))) { - tprintf(tnum, "error: failed to read log_to_stderr from config\n"); + printf("error: failed to read log_to_stderr from config\n"); return 1; } if (tmp[0] != '2') { - tprintf(tnum, "error: new setting for log_to_stderr failed to take effect.\n"); + printf("error: new setting for log_to_stderr failed to take effect.\n"); return 1; } if (rados_connect(cl)) { - tprintf(tnum, "error connecting\n"); + printf("error connecting\n"); return 1; } if (rados_connect(cl) == 0) { - tprintf(tnum, "second connect attempt didn't return an error\n"); + printf("second connect attempt didn't return an error\n"); return 1; } /* create an io_ctx */ r = rados_pool_create(cl, "foo"); - tprintf(tnum, "rados_pool_create = %d\n", r); + printf("rados_pool_create = %d\n", r); rados_ioctx_t io_ctx; r = rados_ioctx_create(cl, "foo", &io_ctx); - tprintf(tnum, "rados_ioctx_create = %d, io_ctx = %p\n", r, io_ctx); + printf("rados_ioctx_create = %d, io_ctx = %p\n", r, io_ctx); /* list all pools */ { int buf_sz = rados_pool_list(cl, NULL, 0); - tprintf(tnum, "need buffer size of %d\n", buf_sz); + printf("need buffer size of %d\n", buf_sz); char buf[buf_sz]; int r = rados_pool_list(cl, buf, buf_sz); if (r != buf_sz) { - tprintf(tnum, "buffer size mismatch: got %d the first time, but %d " + printf("buffer size mismatch: got %d the first time, but %d " "the second.\n", buf_sz, r); return 1; } const char *b = buf; - tprintf(tnum, "begin pools.\n"); + printf("begin pools.\n"); while (1) { if (b[0] == '\0') break; - tprintf(tnum, " pool: '%s'\n", b); + printf(" pool: '%s'\n", b); b += strlen(b) + 1; }; - tprintf(tnum, "end pools.\n"); + printf("end pools.\n"); } /* stat */ struct rados_pool_stat_t st; r = rados_ioctx_pool_stat(io_ctx, &st); - tprintf(tnum, "rados_ioctx_pool_stat = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects); + printf("rados_ioctx_pool_stat = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects); /* snapshots */ r = rados_ioctx_snap_create(io_ctx, "snap1"); - tprintf(tnum, "rados_ioctx_snap_create snap1 = %d\n", r); + printf("rados_ioctx_snap_create snap1 = %d\n", r); rados_snap_t snaps[10]; r = rados_ioctx_snap_list(io_ctx, snaps, 10); for (i=0; i