diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-10-16 13:06:41 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:21:12 -0500 |
commit | 8773e743c518578584d07d35ffdafdd598af88b0 (patch) | |
tree | 89726232dd6ae9eca1c219e21729a9b2336ddaa9 /source4/torture/basic | |
parent | 0f2347e417dec4a50f95d64353b260cd53a44a2b (diff) | |
download | samba-8773e743c518578584d07d35ffdafdd598af88b0.tar.gz samba-8773e743c518578584d07d35ffdafdd598af88b0.tar.bz2 samba-8773e743c518578584d07d35ffdafdd598af88b0.zip |
r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained
output in the testsuite rather than just True or False for a
set of tests.
The aim is to use this for:
* known failure lists (run all tests and detect tests that
started working or started failing). This
would allow us to get rid of the RPC-SAMBA3-* tests
* nicer torture output
* simplification of the testsuite system
* compatibility with other unit testing systems
* easier usage of smbtorture (being able to run one test
and automatically set up the environment for that)
This is still a work-in-progress; expect more updates over the next couple of
days.
(This used to be commit 0eb6097305776325c75081356309115f445a7218)
Diffstat (limited to 'source4/torture/basic')
-rw-r--r-- | source4/torture/basic/aliases.c | 197 | ||||
-rw-r--r-- | source4/torture/basic/attr.c | 66 | ||||
-rw-r--r-- | source4/torture/basic/base.c | 923 | ||||
-rw-r--r-- | source4/torture/basic/charset.c | 58 | ||||
-rw-r--r-- | source4/torture/basic/delaywrite.c | 209 | ||||
-rw-r--r-- | source4/torture/basic/delete.c | 1118 | ||||
-rw-r--r-- | source4/torture/basic/denytest.c | 157 | ||||
-rw-r--r-- | source4/torture/basic/dir.c | 56 | ||||
-rw-r--r-- | source4/torture/basic/disconnect.c | 3 | ||||
-rw-r--r-- | source4/torture/basic/locking.c | 751 | ||||
-rw-r--r-- | source4/torture/basic/mangle_test.c | 13 | ||||
-rw-r--r-- | source4/torture/basic/misc.c | 855 | ||||
-rw-r--r-- | source4/torture/basic/properties.c | 16 | ||||
-rw-r--r-- | source4/torture/basic/rename.c | 96 | ||||
-rw-r--r-- | source4/torture/basic/scanner.c | 23 | ||||
-rw-r--r-- | source4/torture/basic/secleak.c | 9 | ||||
-rw-r--r-- | source4/torture/basic/unlink.c | 60 | ||||
-rw-r--r-- | source4/torture/basic/utable.c | 72 |
18 files changed, 2262 insertions, 2420 deletions
diff --git a/source4/torture/basic/aliases.c b/source4/torture/basic/aliases.c index 3643d098ba..01ca33359d 100644 --- a/source4/torture/basic/aliases.c +++ b/source4/torture/basic/aliases.c @@ -34,62 +34,62 @@ struct trans2_blobs { }; /* look for aliases for a query */ -static void gen_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int level_offset) +static bool gen_aliases(struct torture_context *tctx, + struct smbcli_state *cli, struct smb_trans2 *t2, + int level_offset) { - TALLOC_CTX *mem_ctx; uint16_t level; struct trans2_blobs *alias_blobs = NULL; struct trans2_blobs *t2b, *t2b2; int count=0, alias_count=0; - mem_ctx = talloc_init("aliases"); - for (level=0;level<2000;level++) { NTSTATUS status; SSVAL(t2->in.params.data, level_offset, level); - status = smb_raw_trans2(cli->tree, mem_ctx, t2); + status = smb_raw_trans2(cli->tree, tctx, t2); if (!NT_STATUS_IS_OK(status)) continue; - t2b = talloc(mem_ctx, struct trans2_blobs); + t2b = talloc(tctx, struct trans2_blobs); t2b->level = level; t2b->params = t2->out.params; t2b->data = t2->out.data; DLIST_ADD(alias_blobs, t2b); - d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", + torture_comment(tctx, + "\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", level, level, (int)t2b->data.length, (int)t2b->data.length); count++; } - d_printf("Found %d levels with success status\n", count); + torture_comment(tctx, "Found %d levels with success status\n", count); for (t2b=alias_blobs; t2b; t2b=t2b->next) { for (t2b2=alias_blobs; t2b2; t2b2=t2b2->next) { if (t2b->level >= t2b2->level) continue; if (data_blob_equal(&t2b->params, &t2b2->params) && data_blob_equal(&t2b->data, &t2b2->data)) { - printf("\tLevel %u (0x%x) and level %u (0x%x) are possible aliases\n", + torture_comment(tctx, + "\tLevel %u (0x%x) and level %u (0x%x) are possible aliases\n", t2b->level, t2b->level, t2b2->level, t2b2->level); alias_count++; } } } - d_printf("Found %d aliased levels\n", alias_count); - - talloc_free(mem_ctx); + torture_comment(tctx, "Found %d aliased levels\n", alias_count); + + return true; } /* look for qfsinfo aliases */ -static void qfsinfo_aliases(struct smbcli_state *cli) +static bool qfsinfo_aliases(struct torture_context *tctx, + struct smbcli_state *cli) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_QFSINFO; - d_printf("\nChecking for QFSINFO aliases\n"); - t2.in.max_param = 0; t2.in.max_data = smb_raw_max_trans_data(cli->tree, 0); t2.in.max_setup = 0; @@ -100,19 +100,18 @@ static void qfsinfo_aliases(struct smbcli_state *cli) t2.in.params = data_blob(NULL, 2); t2.in.data = data_blob(NULL, 0); - gen_aliases(cli, &t2, 0); + return gen_aliases(tctx, cli, &t2, 0); } /* look for qfileinfo aliases */ -static void qfileinfo_aliases(struct smbcli_state *cli) +static bool qfileinfo_aliases(struct torture_context *tctx, + struct smbcli_state *cli) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_QFILEINFO; const char *fname = "\\qfileinfo_aliases.txt"; int fnum; - d_printf("\nChecking for QFILEINFO aliases\n"); - t2.in.max_param = 2; t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2); t2.in.max_setup = 0; @@ -125,33 +124,32 @@ static void qfileinfo_aliases(struct smbcli_state *cli) smbcli_unlink(cli->tree, fname); fnum = create_complex_file(cli, cli, fname); - if (fnum == -1) { - printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - } + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, + "open of %s failed (%s)", fname, + smbcli_errstr(cli->tree))); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); SSVAL(t2.in.params.data, 0, fnum); - gen_aliases(cli, &t2, 2); + if (!gen_aliases(tctx, cli, &t2, 2)) + return false; smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname); + + return true; } /* look for qpathinfo aliases */ -static void qpathinfo_aliases(struct smbcli_state *cli) +static bool qpathinfo_aliases(struct torture_context *tctx, + struct smbcli_state *cli) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_QPATHINFO; const char *fname = "\\qpathinfo_aliases.txt"; int fnum; - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init("qpathinfo"); - - d_printf("\nChecking for QPATHINFO aliases\n"); t2.in.max_param = 2; t2.in.max_data = smb_raw_max_trans_data(cli->tree, 2); @@ -160,42 +158,40 @@ static void qpathinfo_aliases(struct smbcli_state *cli) t2.in.timeout = 0; t2.in.setup_count = 1; t2.in.setup = &setup; - t2.in.params = data_blob_talloc(mem_ctx, NULL, 6); + t2.in.params = data_blob_talloc(tctx, NULL, 6); t2.in.data = data_blob(NULL, 0); smbcli_unlink(cli->tree, fname); fnum = create_complex_file(cli, cli, fname); - if (fnum == -1) { - printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - } + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, + "open of %s failed (%s)", fname, + smbcli_errstr(cli->tree))); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_close(cli->tree, fnum); SIVAL(t2.in.params.data, 2, 0); - smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params, + smbcli_blob_append_string(cli->session, tctx, &t2.in.params, fname, STR_TERMINATE); - gen_aliases(cli, &t2, 0); + if (!gen_aliases(tctx, cli, &t2, 0)) + return false; smbcli_unlink(cli->tree, fname); - talloc_free(mem_ctx); + + return true; } /* look for trans2 findfirst aliases */ -static void findfirst_aliases(struct smbcli_state *cli) +static bool findfirst_aliases(struct torture_context *tctx, + struct smbcli_state *cli) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_FINDFIRST; const char *fname = "\\findfirst_aliases.txt"; int fnum; - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init("findfirst"); - - d_printf("\nChecking for FINDFIRST aliases\n"); t2.in.max_param = 16; t2.in.max_data = smb_raw_max_trans_data(cli->tree, 16); @@ -204,14 +200,14 @@ static void findfirst_aliases(struct smbcli_state *cli) t2.in.timeout = 0; t2.in.setup_count = 1; t2.in.setup = &setup; - t2.in.params = data_blob_talloc(mem_ctx, NULL, 12); + t2.in.params = data_blob_talloc(tctx, NULL, 12); t2.in.data = data_blob(NULL, 0); smbcli_unlink(cli->tree, fname); fnum = create_complex_file(cli, cli, fname); - if (fnum == -1) { - printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - } + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, + "open of %s failed (%s)", fname, + smbcli_errstr(cli->tree))); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_close(cli->tree, fnum); @@ -222,28 +218,29 @@ static void findfirst_aliases(struct smbcli_state *cli) SSVAL(t2.in.params.data, 6, 0); SIVAL(t2.in.params.data, 8, 0); - smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params, + smbcli_blob_append_string(cli->session, tctx, &t2.in.params, fname, STR_TERMINATE); - gen_aliases(cli, &t2, 6); + if (!gen_aliases(tctx, cli, &t2, 6)) + return false; smbcli_unlink(cli->tree, fname); - talloc_free(mem_ctx); + + return true; } /* look for aliases for a set function */ -static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int level_offset) +static bool gen_set_aliases(struct torture_context *tctx, + struct smbcli_state *cli, + struct smb_trans2 *t2, int level_offset) { - TALLOC_CTX *mem_ctx; uint16_t level; struct trans2_blobs *alias_blobs = NULL; struct trans2_blobs *t2b; int count=0, dsize; - mem_ctx = talloc_init("aliases"); - for (level=1;level<1100;level++) { NTSTATUS status, status1; SSVAL(t2->in.params.data, level_offset, level); @@ -254,7 +251,7 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int data_blob_free(&t2->in.data); t2->in.data = data_blob(NULL, dsize); data_blob_clear(&t2->in.data); - status = smb_raw_trans2(cli->tree, mem_ctx, t2); + status = smb_raw_trans2(cli->tree, tctx, t2); /* some error codes mean that this whole level doesn't exist */ if (NT_STATUS_EQUAL(NT_STATUS_INVALID_LEVEL, status) || NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS, status) || @@ -274,7 +271,7 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int } if (!NT_STATUS_EQUAL(status, status1)) { - printf("level=%d size=%d %s\n", level, dsize, nt_errstr(status)); + torture_comment(tctx, "level=%d size=%d %s\n", level, dsize, nt_errstr(status)); } status1 = status; } @@ -282,33 +279,34 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue; - t2b = talloc(mem_ctx, struct trans2_blobs); + t2b = talloc(tctx, struct trans2_blobs); t2b->level = level; t2b->params = t2->out.params; t2b->data = t2->out.data; DLIST_ADD(alias_blobs, t2b); - d_printf("\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", + torture_comment(tctx, + "\tFound level %4u (0x%03x) of size %3d (0x%02x)\n", level, level, (int)t2->in.data.length, (int)t2->in.data.length); count++; } - d_printf("Found %d valid levels\n", count); - talloc_free(mem_ctx); + torture_comment(tctx, "Found %d valid levels\n", count); + + return true; } /* look for setfileinfo aliases */ -static void setfileinfo_aliases(struct smbcli_state *cli) +static bool setfileinfo_aliases(struct torture_context *tctx, + struct smbcli_state *cli) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_SETFILEINFO; const char *fname = "\\setfileinfo_aliases.txt"; int fnum; - d_printf("\nChecking for SETFILEINFO aliases\n"); - t2.in.max_param = 2; t2.in.max_data = 0; t2.in.max_setup = 0; @@ -321,33 +319,31 @@ static void setfileinfo_aliases(struct smbcli_state *cli) smbcli_unlink(cli->tree, fname); fnum = create_complex_file(cli, cli, fname); - if (fnum == -1) { - printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - } + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, + "open of %s failed (%s)", fname, + smbcli_errstr(cli->tree))); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); SSVAL(t2.in.params.data, 0, fnum); SSVAL(t2.in.params.data, 4, 0); - gen_set_aliases(cli, &t2, 2); + gen_set_aliases(tctx, cli, &t2, 2); smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname); + + return true; } /* look for setpathinfo aliases */ -static void setpathinfo_aliases(struct smbcli_state *cli) +static bool setpathinfo_aliases(struct torture_context *tctx, + struct smbcli_state *cli) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_SETPATHINFO; const char *fname = "\\setpathinfo_aliases.txt"; int fnum; - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init("findfirst"); - - d_printf("\nChecking for SETPATHINFO aliases\n"); t2.in.max_param = 32; t2.in.max_data = smb_raw_max_trans_data(cli->tree, 32); @@ -356,53 +352,50 @@ static void setpathinfo_aliases(struct smbcli_state *cli) t2.in.timeout = 0; t2.in.setup_count = 1; t2.in.setup = &setup; - t2.in.params = data_blob_talloc(mem_ctx, NULL, 4); + t2.in.params = data_blob_talloc(tctx, NULL, 4); t2.in.data = data_blob(NULL, 0); smbcli_unlink(cli->tree, fname); fnum = create_complex_file(cli, cli, fname); - if (fnum == -1) { - printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - } + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, + "open of %s failed (%s)", fname, + smbcli_errstr(cli->tree))); smbcli_write(cli->tree, fnum, 0, &t2, 0, sizeof(t2)); smbcli_close(cli->tree, fnum); SSVAL(t2.in.params.data, 2, 0); - smbcli_blob_append_string(cli->session, mem_ctx, &t2.in.params, + smbcli_blob_append_string(cli->session, tctx, &t2.in.params, fname, STR_TERMINATE); - gen_set_aliases(cli, &t2, 0); + if (!gen_set_aliases(tctx, cli, &t2, 0)) + return false; - if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { - printf("unlink: %s\n", smbcli_errstr(cli->tree)); - } - talloc_free(mem_ctx); + torture_assert_ntstatus_ok(tctx, smbcli_unlink(cli->tree, fname), + talloc_asprintf(tctx, "unlink: %s", smbcli_errstr(cli->tree))); + + return true; } /* look for aliased info levels in trans2 calls */ -BOOL torture_trans2_aliases(struct torture_context *torture) +struct torture_suite *torture_trans2_aliases(void) { - struct smbcli_state *cli; - - if (!torture_open_connection(&cli, 0)) { - return False; - } - - - qfsinfo_aliases(cli); - qfileinfo_aliases(cli); - qpathinfo_aliases(cli); - findfirst_aliases(cli); - setfileinfo_aliases(cli); - setpathinfo_aliases(cli); - - if (!torture_close_connection(cli)) { - return False; - } - - return True; + struct torture_suite *suite = torture_suite_create( + talloc_autofree_context(), + "ALIASES"); + + torture_suite_add_1smb_test(suite, "QFILEINFO aliases", + qfsinfo_aliases); + torture_suite_add_1smb_test(suite, "QFSINFO aliases", qfileinfo_aliases); + torture_suite_add_1smb_test(suite, "QPATHINFO aliases", qpathinfo_aliases); + torture_suite_add_1smb_test(suite, "FINDFIRST aliases", findfirst_aliases); + torture_suite_add_1smb_test(suite, "setfileinfo_aliases", + setfileinfo_aliases); + torture_suite_add_1smb_test(suite, "setpathinfo_aliases", + setpathinfo_aliases); + + return suite; } diff --git a/source4/torture/basic/attr.c b/source4/torture/basic/attr.c index a98f815a92..8e1a53d7c0 100644 --- a/source4/torture/basic/attr.c +++ b/source4/torture/basic/attr.c @@ -87,22 +87,15 @@ static const struct trunc_open_results attr_results[] = { }; -BOOL torture_openattrtest(struct torture_context *torture) +BOOL torture_openattrtest(struct torture_context *tctx, + struct smbcli_state *cli1) { - struct smbcli_state *cli1; const char *fname = "\\openattr.file"; int fnum1; - BOOL correct = True; uint16_t attr; uint_t i, j, k, l; int failures = 0; - printf("starting open attr test\n"); - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) { smbcli_setatr(cli1->tree, fname, 0, 0); smbcli_unlink(cli1->tree, fname); @@ -111,15 +104,13 @@ BOOL torture_openattrtest(struct torture_context *torture) open_attrs_table[i], NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("open %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open %d (1) of %s failed (%s)", i, + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close %d (1) of %s failed (%s)", i, fname, + smbcli_errstr(cli1->tree))); for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) { fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, @@ -132,40 +123,37 @@ BOOL torture_openattrtest(struct torture_context *torture) if (fnum1 == -1) { for (l = 0; l < ARRAY_SIZE(attr_results); l++) { if (attr_results[l].num == k) { - printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)\n", + torture_comment(tctx, "[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)\n", k, open_attrs_table[i], open_attrs_table[j], fname, smbcli_errstr(cli1->tree)); - correct = False; CHECK_MAX_FAILURES(error_exit); } } - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_ACCESS_DENIED)) { - printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n", + torture_assert_ntstatus_equal(tctx, + smbcli_nt_error(cli1->tree), NT_STATUS_ACCESS_DENIED, + talloc_asprintf(tctx, "[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s", k, open_attrs_table[i], open_attrs_table[j], - smbcli_errstr(cli1->tree)); - correct = False; + smbcli_errstr(cli1->tree))); CHECK_MAX_FAILURES(error_exit); - } #if 0 - printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]); + torture_comment(tctx, "[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]); #endif k++; continue; } - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close %d (2) of %s failed (%s)\n", j, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close %d (2) of %s failed (%s)", j, + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL))) { - printf("getatr(2) failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL), + talloc_asprintf(tctx, "getatr(2) failed (%s)", smbcli_errstr(cli1->tree))); #if 0 - printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n", + torture_comment(tctx, "[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n", k, open_attrs_table[i], open_attrs_table[j], attr ); #endif @@ -174,12 +162,11 @@ BOOL torture_openattrtest(struct torture_context *torture) if (attr != attr_results[l].result_attr || open_attrs_table[i] != attr_results[l].init_attr || open_attrs_table[j] != attr_results[l].trunc_attr) { - printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n", + torture_comment(tctx, "[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n", k, open_attrs_table[i], open_attrs_table[j], (uint_t)attr, attr_results[l].result_attr); - correct = False; CHECK_MAX_FAILURES(error_exit); } break; @@ -192,11 +179,6 @@ error_exit: smbcli_setatr(cli1->tree, fname, 0, 0); smbcli_unlink(cli1->tree, fname); - printf("open attr test %s.\n", correct ? "passed" : "failed"); - - if (!torture_close_connection(cli1)) { - correct = False; - } - return correct; + return true; } diff --git a/source4/torture/basic/base.c b/source4/torture/basic/base.c index 27bafa3a75..1c2b835aa8 100644 --- a/source4/torture/basic/base.c +++ b/source4/torture/basic/base.c @@ -35,11 +35,11 @@ #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0) -static struct smbcli_state *open_nbt_connection(void) +static struct smbcli_state *open_nbt_connection(struct torture_context *tctx) { struct nbt_name called, calling; struct smbcli_state *cli; - const char *host = lp_parm_string(-1, "torture", "host"); + const char *host = torture_setting_string(tctx, "host", NULL); make_nbt_name_client(&calling, lp_netbios_name()); @@ -47,17 +47,17 @@ static struct smbcli_state *open_nbt_connection(void) cli = smbcli_state_init(NULL); if (!cli) { - printf("Failed initialize smbcli_struct to connect with %s\n", host); + torture_comment(tctx, "Failed initialize smbcli_struct to connect with %s\n", host); goto failed; } if (!smbcli_socket_connect(cli, host)) { - printf("Failed to connect with %s\n", host); + torture_comment(tctx, "Failed to connect with %s\n", host); goto failed; } if (!smbcli_transport_establish(cli, &calling, &called)) { - printf("%s rejected the session\n",host); + torture_comment(tctx, "%s rejected the session\n",host); goto failed; } @@ -68,46 +68,42 @@ failed: return NULL; } -static BOOL tcon_devtest(struct smbcli_state *cli, - const char *myshare, const char *devtype, - NTSTATUS expected_error) +static BOOL tcon_devtest(struct torture_context *tctx, + struct smbcli_state *cli, + const char *myshare, const char *devtype, + NTSTATUS expected_error) { BOOL status; - BOOL ret; - const char *password = lp_parm_string(-1, "torture", "password"); + const char *password = torture_setting_string(tctx, "password", NULL); status = NT_STATUS_IS_OK(smbcli_tconX(cli, myshare, devtype, password)); - printf("Trying share %s with devtype %s\n", myshare, devtype); + torture_comment(tctx, "Trying share %s with devtype %s\n", myshare, devtype); if (NT_STATUS_IS_OK(expected_error)) { - if (status) { - ret = True; - } else { - printf("tconX to share %s with type %s " - "should have succeeded but failed\n", - myshare, devtype); - ret = False; + if (!status) { + torture_fail(tctx, talloc_asprintf(tctx, + "tconX to share %s with type %s " + "should have succeeded but failed", + myshare, devtype)); } smbcli_tdis(cli); } else { if (status) { - printf("tconx to share %s with type %s " + torture_fail(tctx, talloc_asprintf(tctx, + "tconx to share %s with type %s " "should have failed but succeeded\n", - myshare, devtype); - ret = False; + myshare, devtype)); } else { if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree), expected_error)) { - ret = True; } else { - printf("Returned unexpected error\n"); - ret = False; + torture_fail(tctx, "Returned unexpected error"); } } } - return ret; + return true; } @@ -116,93 +112,74 @@ static BOOL tcon_devtest(struct smbcli_state *cli, test whether fnums and tids open on one VC are available on another (a major security hole) */ -static BOOL run_fdpasstest(struct torture_context *torture) +static bool run_fdpasstest(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = "\\fdpass.tst"; int fnum1, oldtid; uint8_t buf[1024]; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting fdpasstest\n"); - smbcli_unlink(cli1->tree, fname); - printf("Opening a file on connection 1\n"); + torture_comment(tctx, "Opening a file on connection 1\n"); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, + "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); - printf("writing to file on connection 1\n"); + torture_comment(tctx, "writing to file on connection 1\n"); - if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) { - printf("write failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, + smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) == 13, + talloc_asprintf(tctx, + "write failed (%s)\n", smbcli_errstr(cli1->tree))); oldtid = cli2->tree->tid; cli2->session->vuid = cli1->session->vuid; cli2->tree->tid = cli1->tree->tid; cli2->session->pid = cli1->session->pid; - printf("reading from file on connection 2\n"); + torture_comment(tctx, "reading from file on connection 2\n"); - if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) { - printf("read succeeded! nasty security hole [%s]\n", - buf); - return False; - } + torture_assert(tctx, smbcli_read(cli2->tree, fnum1, buf, 0, 13) != 13, + talloc_asprintf(tctx, + "read succeeded! nasty security hole [%s]\n", buf)); smbcli_close(cli1->tree, fnum1); smbcli_unlink(cli1->tree, fname); cli2->tree->tid = oldtid; - torture_close_connection(cli1); - torture_close_connection(cli2); - - printf("finished fdpasstest\n"); - return True; + return true; } /** This checks how the getatr calls works */ -static BOOL run_attrtest(struct torture_context *torture) +static BOOL run_attrtest(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; int fnum; time_t t, t2; const char *fname = "\\attrib123456789.tst"; BOOL correct = True; - printf("starting attrib test\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - smbcli_unlink(cli->tree, fname); fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); smbcli_close(cli->tree, fnum); if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) { - printf("getatr failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "getatr failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } - printf("New file time is %s", ctime(&t)); + torture_comment(tctx, "New file time is %s", ctime(&t)); if (abs(t - time(NULL)) > 60*60*24*10) { - printf("ERROR: SMBgetatr bug. time is %s", + torture_comment(tctx, "ERROR: SMBgetatr bug. time is %s", ctime(&t)); t = time(NULL); correct = False; @@ -210,44 +187,38 @@ static BOOL run_attrtest(struct torture_context *torture) t2 = t-60*60*24; /* 1 day ago */ - printf("Setting file time to %s", ctime(&t2)); + torture_comment(tctx, "Setting file time to %s", ctime(&t2)); if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) { - printf("setatr failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "setatr failed (%s)\n", smbcli_errstr(cli->tree)); correct = True; } if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) { - printf("getatr failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "getatr failed (%s)\n", smbcli_errstr(cli->tree)); correct = True; } - printf("Retrieved file time as %s", ctime(&t)); + torture_comment(tctx, "Retrieved file time as %s", ctime(&t)); if (t != t2) { - printf("ERROR: getatr/setatr bug. times are\n%s", + torture_comment(tctx, "ERROR: getatr/setatr bug. times are\n%s", ctime(&t)); - printf("%s", ctime(&t2)); + torture_comment(tctx, "%s", ctime(&t2)); correct = True; } smbcli_unlink(cli->tree, fname); - if (!torture_close_connection(cli)) { - correct = False; - } - - printf("attrib test finished\n"); - return correct; } /** This checks a couple of trans2 calls */ -static BOOL run_trans2test(struct torture_context *torture) +static BOOL run_trans2test(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; int fnum; size_t size; time_t c_time, a_time, m_time, w_time, m_time2; @@ -257,33 +228,27 @@ static BOOL run_trans2test(struct torture_context *torture) const char *pname; BOOL correct = True; - printf("starting trans2 test\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - smbcli_unlink(cli->tree, fname); - printf("Testing qfileinfo\n"); + torture_comment(tctx, "Testing qfileinfo\n"); fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time, NULL, NULL))) { - printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } - printf("Testing NAME_INFO\n"); + torture_comment(tctx, "Testing NAME_INFO\n"); if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) { - printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } if (!pname || strcmp(pname, fname)) { - printf("qfilename gave different name? [%s] [%s]\n", + torture_comment(tctx, "qfilename gave different name? [%s] [%s]\n", fname, pname); correct = False; } @@ -294,30 +259,30 @@ static BOOL run_trans2test(struct torture_context *torture) fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (fnum == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); return False; } smbcli_close(cli->tree, fnum); - printf("Checking for sticky create times\n"); + torture_comment(tctx, "Checking for sticky create times\n"); if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) { - printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } else { if (c_time != m_time) { - printf("create time=%s", ctime(&c_time)); - printf("modify time=%s", ctime(&m_time)); - printf("This system appears to have sticky create times\n"); + torture_comment(tctx, "create time=%s", ctime(&c_time)); + torture_comment(tctx, "modify time=%s", ctime(&m_time)); + torture_comment(tctx, "This system appears to have sticky create times\n"); } if (a_time % (60*60) == 0) { - printf("access time=%s", ctime(&a_time)); - printf("This system appears to set a midnight access time\n"); + torture_comment(tctx, "access time=%s", ctime(&a_time)); + torture_comment(tctx, "This system appears to set a midnight access time\n"); correct = False; } if (abs(m_time - time(NULL)) > 60*60*24*7) { - printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time)); + torture_comment(tctx, "ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time)); correct = False; } } @@ -328,12 +293,12 @@ static BOOL run_trans2test(struct torture_context *torture) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); smbcli_close(cli->tree, fnum); if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) { - printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } else { if (w_time < 60*60*24*2) { - printf("write time=%s", ctime(&w_time)); - printf("This system appears to set a initial 0 write time\n"); + torture_comment(tctx, "write time=%s", ctime(&w_time)); + torture_comment(tctx, "This system appears to set a initial 0 write time\n"); correct = False; } } @@ -344,12 +309,12 @@ static BOOL run_trans2test(struct torture_context *torture) /* check if the server updates the directory modification time when creating a new file */ if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) { - printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } sleep(3); if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) { - printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } @@ -358,41 +323,35 @@ static BOOL run_trans2test(struct torture_context *torture) smbcli_write(cli->tree, fnum, 0, &fnum, 0, sizeof(fnum)); smbcli_close(cli->tree, fnum); if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) { - printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree)); correct = False; } else { if (m_time2 == m_time) { - printf("This system does not update directory modification times\n"); + torture_comment(tctx, "This system does not update directory modification times\n"); correct = False; } } smbcli_unlink(cli->tree, fname2); smbcli_rmdir(cli->tree, dname); - if (!torture_close_connection(cli)) { - correct = False; - } - - printf("trans2 test finished\n"); - return correct; } /* send smb negprot commands, not reading the response */ -static BOOL run_negprot_nowait(struct torture_context *torture) +static BOOL run_negprot_nowait(struct torture_context *tctx) { int i; struct smbcli_state *cli, *cli2; BOOL correct = True; - printf("starting negprot nowait test\n"); + torture_comment(tctx, "starting negprot nowait test\n"); - cli = open_nbt_connection(); + cli = open_nbt_connection(tctx); if (!cli) { return False; } - printf("Filling send buffer\n"); + torture_comment(tctx, "Filling send buffer\n"); for (i=0;i<100;i++) { struct smbcli_request *req; @@ -400,30 +359,30 @@ static BOOL run_negprot_nowait(struct torture_context *torture) event_loop_once(cli->transport->socket->event.ctx); if (req->state == SMBCLI_REQUEST_ERROR) { if (i > 0) { - printf("Failed to fill pipe packet[%d] - %s (ignored)\n", i+1, nt_errstr(req->status)); + torture_comment(tctx, "Failed to fill pipe packet[%d] - %s (ignored)\n", i+1, nt_errstr(req->status)); break; } else { - printf("Failed to fill pipe - %s \n", nt_errstr(req->status)); + torture_comment(tctx, "Failed to fill pipe - %s \n", nt_errstr(req->status)); torture_close_connection(cli); return False; } } } - printf("Opening secondary connection\n"); + torture_comment(tctx, "Opening secondary connection\n"); if (!torture_open_connection(&cli2, 1)) { - printf("Failed to open secondary connection\n"); + torture_comment(tctx, "Failed to open secondary connection\n"); correct = False; } if (!torture_close_connection(cli2)) { - printf("Failed to close secondary connection\n"); + torture_comment(tctx, "Failed to close secondary connection\n"); correct = False; } torture_close_connection(cli); - printf("finished negprot nowait test\n"); + torture_comment(tctx, "finished negprot nowait test\n"); return correct; } @@ -432,9 +391,8 @@ static BOOL run_negprot_nowait(struct torture_context *torture) this checks to see if a secondary tconx can use open files from an earlier tconx */ -static BOOL run_tcon_test(struct torture_context *torture) +static BOOL run_tcon_test(struct torture_context *tctx, struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname = "\\tcontest.tmp"; int fnum1; uint16_t cnum1, cnum2, cnum3; @@ -442,23 +400,17 @@ static BOOL run_tcon_test(struct torture_context *torture) uint8_t buf[4]; BOOL ret = True; struct smbcli_tree *tree1; - const char *host = lp_parm_string(-1, "torture", "host"); - const char *share = lp_parm_string(-1, "torture", "share"); - const char *password = lp_parm_string(-1, "torture", "password"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("starting tcontest\n"); + const char *host = torture_setting_string(tctx, "host", NULL); + const char *share = torture_setting_string(tctx, "share", NULL); + const char *password = torture_setting_string(tctx, "password", NULL); if (smbcli_deltree(cli->tree, fname) == -1) { - printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + torture_comment(tctx, "unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); return False; } @@ -467,13 +419,13 @@ static BOOL run_tcon_test(struct torture_context *torture) memset(&buf, 0, 4); /* init buf so valgrind won't complain */ if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("initial write failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "initial write failed (%s)\n", smbcli_errstr(cli->tree)); return False; } tree1 = cli->tree; /* save old tree connection */ if (NT_STATUS_IS_ERR(smbcli_tconX(cli, share, "?????", password))) { - printf("%s refused 2nd tree connect (%s)\n", host, + torture_comment(tctx, "%s refused 2nd tree connect (%s)\n", host, smbcli_errstr(cli->tree)); talloc_free(cli); return False; @@ -487,10 +439,10 @@ static BOOL run_tcon_test(struct torture_context *torture) cli->tree->tid = cnum2; if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) { - printf("* server allows write with wrong TID\n"); + torture_comment(tctx, "* server allows write with wrong TID\n"); ret = False; } else { - printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree)); } @@ -498,10 +450,10 @@ static BOOL run_tcon_test(struct torture_context *torture) cli->tree->tid = cnum3; if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) { - printf("* server allows write with invalid TID\n"); + torture_comment(tctx, "* server allows write with invalid TID\n"); ret = False; } else { - printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree)); } /* try a write with an invalid vuid */ @@ -509,24 +461,24 @@ static BOOL run_tcon_test(struct torture_context *torture) cli->tree->tid = cnum1; if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) { - printf("* server allows write with invalid VUID\n"); + torture_comment(tctx, "* server allows write with invalid VUID\n"); ret = False; } else { - printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree)); } cli->session->vuid = vuid1; cli->tree->tid = cnum1; if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) { - printf("close failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(cli->tree)); return False; } cli->tree->tid = cnum2; if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) { - printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "secondary tdis failed (%s)\n", smbcli_errstr(cli->tree)); return False; } @@ -535,73 +487,52 @@ static BOOL run_tcon_test(struct torture_context *torture) smbcli_unlink(tree1, fname); - if (!torture_close_connection(cli)) { - return False; - } - return ret; } /** checks for correct tconX support */ -static BOOL run_tcon_devtype_test(struct torture_context *torture) +static BOOL run_tcon_devtype_test(struct torture_context *tctx, + struct smbcli_state *cli1) { - struct smbcli_state *cli1 = NULL; - NTSTATUS status; - BOOL ret = True; - const char *host = lp_parm_string(-1, "torture", "host"); - const char *share = lp_parm_string(-1, "torture", "share"); - - status = smbcli_full_connection(NULL, - &cli1, host, - share, NULL, - cmdline_credentials, NULL); + const char *share = torture_setting_string(tctx, "share", NULL); - if (!NT_STATUS_IS_OK(status)) { - printf("could not open connection\n"); - return False; - } + if (!tcon_devtest(tctx, cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE)) + return false; - if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE)) - ret = False; + if (!tcon_devtest(tctx, cli1, "IPC$", "?????", NT_STATUS_OK)) + return false; - if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK)) - ret = False; - - if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE)) - ret = False; + if (!tcon_devtest(tctx, cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE)) + return false; - if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK)) - ret = False; + if (!tcon_devtest(tctx, cli1, "IPC$", "IPC", NT_STATUS_OK)) + return false; - if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE)) - ret = False; + if (!tcon_devtest(tctx, cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE)) + return false; - if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK)) - ret = False; + if (!tcon_devtest(tctx, cli1, share, "A:", NT_STATUS_OK)) + return false; - if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK)) - ret = False; + if (!tcon_devtest(tctx, cli1, share, "?????", NT_STATUS_OK)) + return false; - if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE)) - ret = False; + if (!tcon_devtest(tctx, cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE)) + return false; - if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE)) - ret = False; + if (!tcon_devtest(tctx, cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE)) + return false; - if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE)) - ret = False; + if (!tcon_devtest(tctx, cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE)) + return false; - talloc_free(cli1); - - if (ret) - printf("Passed tcondevtest\n"); - - return ret; + return true; } -static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2) +static BOOL rw_torture2(struct torture_context *tctx, + struct smbcli_state *c1, struct smbcli_state *c2) { const char *lockfname = "\\torture2.lck"; int fnum1; @@ -612,119 +543,86 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2) BOOL correct = True; ssize_t bytes_read, bytes_written; - if (smbcli_deltree(c1->tree, lockfname) == -1) { - printf("unlink failed (%s)\n", smbcli_errstr(c1->tree)); - } + torture_assert(tctx, smbcli_deltree(c1->tree, lockfname) != -1, + talloc_asprintf(tctx, + "unlink failed (%s)", smbcli_errstr(c1->tree))); fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("first open read/write of %s failed (%s)\n", - lockfname, smbcli_errstr(c1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, + "first open read/write of %s failed (%s)", + lockfname, smbcli_errstr(c1->tree))); fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY, DENY_NONE); - if (fnum2 == -1) { - printf("second open read-only of %s failed (%s)\n", - lockfname, smbcli_errstr(c2->tree)); - smbcli_close(c1->tree, fnum1); - return False; - } + torture_assert(tctx, fnum2 != -1, + talloc_asprintf(tctx, + "second open read-only of %s failed (%s)", + lockfname, smbcli_errstr(c2->tree))); - printf("Checking data integrity over %d ops\n", torture_numops); + torture_comment(tctx, "Checking data integrity over %d ops\n", + torture_numops); for (i=0;i<torture_numops;i++) { size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1; if (i % 10 == 0) { - printf("%d\r", i); fflush(stdout); + torture_comment(tctx, "%d\r", i); fflush(stdout); } generate_random_buffer(buf, buf_size); if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) { - printf("write failed (%s)\n", smbcli_errstr(c1->tree)); - printf("wrote %d, expected %d\n", (int)bytes_written, (int)buf_size); + torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c1->tree)); + torture_comment(tctx, "wrote %d, expected %d\n", (int)bytes_written, (int)buf_size); correct = False; break; } if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) { - printf("read failed (%s)\n", smbcli_errstr(c2->tree)); - printf("read %d, expected %d\n", (int)bytes_read, (int)buf_size); + torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c2->tree)); + torture_comment(tctx, "read %d, expected %d\n", (int)bytes_read, (int)buf_size); correct = False; break; } - if (memcmp(buf_rd, buf, buf_size) != 0) - { - printf("read/write compare failed\n"); - correct = False; - break; - } + torture_assert(tctx, memcmp(buf_rd, buf, buf_size) == 0, + "read/write compare failed\n"); } - if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) { - printf("close failed (%s)\n", smbcli_errstr(c2->tree)); - correct = False; - } - if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) { - printf("close failed (%s)\n", smbcli_errstr(c1->tree)); - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(c2->tree, fnum2), + talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(c2->tree))); + torture_assert_ntstatus_ok(tctx, smbcli_close(c1->tree, fnum1), + talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(c1->tree))); - if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) { - printf("unlink failed (%s)\n", smbcli_errstr(c1->tree)); - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_unlink(c1->tree, lockfname), + talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(c1->tree))); return correct; } -#define BOOLSTR(b) ((b) ? "Yes" : "No") - -static BOOL run_readwritetest(struct torture_context *torture) +static bool run_readwritetest(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; - BOOL test1, test2 = True; - - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting readwritetest\n"); - - test1 = rw_torture2(cli1, cli2); - printf("Passed readwritetest v1: %s\n", BOOLSTR(test1)); + torture_comment(tctx, "Running readwritetest v1\n"); + if (!rw_torture2(tctx, cli1, cli2)) + return false; - if (test1) { - test2 = rw_torture2(cli1, cli1); - printf("Passed readwritetest v2: %s\n", BOOLSTR(test2)); - } - - if (!torture_close_connection(cli1)) { - test1 = False; - } + torture_comment(tctx, "Running readwritetest v2\n"); - if (!torture_close_connection(cli2)) { - test2 = False; - } + if (!rw_torture2(tctx, cli1, cli1)) + return false; - return (test1 && test2); + return true; } - - - - /* test the timing of deferred open requests */ -static BOOL run_deferopen(struct smbcli_state *cli, int dummy) +static BOOL run_deferopen(struct torture_context *tctx, struct smbcli_state *cli, int dummy) { const char *fname = "\\defer_open_test.dat"; int retries=4; @@ -732,11 +630,11 @@ static BOOL run_deferopen(struct smbcli_state *cli, int dummy) BOOL correct = True; if (retries <= 0) { - printf("failed to connect\n"); + torture_comment(tctx, "failed to connect\n"); return False; } - printf("Testing deferred open requests.\n"); + torture_comment(tctx, "Testing deferred open requests.\n"); while (i < 4) { int fnum = -1; @@ -755,23 +653,23 @@ static BOOL run_deferopen(struct smbcli_state *cli, int dummy) if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) { double e = timeval_elapsed(&tv); if (e < 0.5 || e > 1.5) { - fprintf(stderr,"Timing incorrect %.2f violation\n", + torture_comment(tctx,"Timing incorrect %.2f violation\n", e); } } } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)); if (fnum == -1) { - fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree)); + torture_comment(tctx,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree)); return False; } - printf("pid %u open %d\n", (unsigned)getpid(), i); + torture_comment(tctx, "pid %u open %d\n", (unsigned)getpid(), i); sleep(10); i++; if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) { - fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree)); + torture_comment(tctx,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree)); return False; } sleep(2); @@ -780,15 +678,12 @@ static BOOL run_deferopen(struct smbcli_state *cli, int dummy) if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { /* All until the last unlink will fail with sharing violation. */ if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) { - printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + torture_comment(tctx, "unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); correct = False; } } - printf("deferred test finished\n"); - if (!torture_close_connection(cli)) { - correct = False; - } + torture_comment(tctx, "deferred test finished\n"); return correct; } @@ -796,24 +691,17 @@ static BOOL run_deferopen(struct smbcli_state *cli, int dummy) Try with a wrong vuid and check error message. */ -static BOOL run_vuidtest(struct torture_context *torture) +static BOOL run_vuidtest(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname = "\\vuid.tst"; int fnum; size_t size; time_t c_time, a_time, m_time; - BOOL correct = True; uint16_t orig_vuid; NTSTATUS result; - printf("starting vuid test\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - smbcli_unlink(cli->tree, fname); fnum = smbcli_open(cli->tree, fname, @@ -823,50 +711,40 @@ static BOOL run_vuidtest(struct torture_context *torture) cli->session->vuid += 1234; - printf("Testing qfileinfo with wrong vuid\n"); + torture_comment(tctx, "Testing qfileinfo with wrong vuid\n"); if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time, NULL, NULL))) { - printf("ERROR: qfileinfo passed with wrong vuid\n"); - correct = False; + torture_fail(tctx, "qfileinfo passed with wrong vuid"); } if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status, NT_STATUS_DOS(ERRSRV, ERRbaduid)) && !NT_STATUS_EQUAL(cli->transport->error.e.nt_status, NT_STATUS_INVALID_HANDLE)) { - printf("ERROR: qfileinfo should have returned DOS error " + torture_fail(tctx, talloc_asprintf(tctx, + "qfileinfo should have returned DOS error " "ERRSRV:ERRbaduid\n but returned %s\n", - smbcli_errstr(cli->tree)); - correct = False; + smbcli_errstr(cli->tree))); } cli->session->vuid -= 1234; - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) { - printf("close failed (%s)\n", smbcli_errstr(cli->tree)); - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum), + talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(cli->tree))); smbcli_unlink(cli->tree, fname); - if (!torture_close_connection(cli)) { - correct = False; - } - - printf("vuid test finished\n"); - - return correct; + return true; } /* Test open mode returns on read-only files. */ - static BOOL run_opentest(struct torture_context *torture) + static BOOL run_opentest(struct torture_context *tctx, struct smbcli_state *cli1, + struct smbcli_state *cli2) { - static struct smbcli_state *cli1; - static struct smbcli_state *cli2; const char *fname = "\\readonly.file"; char *control_char_fname; int fnum1, fnum2; @@ -877,12 +755,6 @@ static BOOL run_vuidtest(struct torture_context *torture) int failures = 0; int i; - printf("starting open test\n"); - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - asprintf(&control_char_fname, "\\readonly.afile"); for (i = 1; i <= 0x1f; i++) { control_char_fname[10] = i; @@ -891,7 +763,7 @@ static BOOL run_vuidtest(struct torture_context *torture) if (!check_error(__location__, cli1, ERRDOS, ERRinvalidname, NT_STATUS_OBJECT_NAME_INVALID)) { - printf("Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n", + torture_comment(tctx, "Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n", smbcli_errstr(cli1->tree), i); failures++; } @@ -905,31 +777,31 @@ static BOOL run_vuidtest(struct torture_context *torture) free(control_char_fname); if (!failures) - printf("Create file with control char names passed.\n"); + torture_comment(tctx, "Create file with control char names passed.\n"); smbcli_setatr(cli1->tree, fname, 0, 0); smbcli_unlink(cli1->tree, fname); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) { - printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test1); return False; } fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE); if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test1); return False; } @@ -939,10 +811,10 @@ static BOOL run_vuidtest(struct torture_context *torture) if (check_error(__location__, cli1, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED)) { - printf("correct error code ERRDOS/ERRnoaccess returned\n"); + torture_comment(tctx, "correct error code ERRDOS/ERRnoaccess returned\n"); } - printf("finished open test 1\n"); + torture_comment(tctx, "finished open test 1\n"); error_test1: smbcli_close(cli1->tree, fnum1); @@ -952,7 +824,7 @@ error_test1: fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE); if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } @@ -961,23 +833,23 @@ error_test1: if (check_error(__location__, cli1, ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION)) { - printf("correct error code ERRDOS/ERRbadshare returned\n"); + torture_comment(tctx, "correct error code ERRDOS/ERRbadshare returned\n"); } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree)); return False; } smbcli_unlink(cli1->tree, fname); - printf("finished open test 2\n"); + torture_comment(tctx, "finished open test 2\n"); /* Test truncate open disposition on file opened for read. */ fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum1 == -1) { - printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } @@ -986,24 +858,24 @@ error_test1: memset(buf, '\0', 20); if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) { - printf("write failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(cli1->tree)); correct = False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree)); return False; } /* Ensure size == 20. */ if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) { - printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test3); return False; } if (fsize != 20) { - printf("(3) file size != 20\n"); + torture_comment(tctx, "(3) file size != 20\n"); CHECK_MAX_FAILURES(error_test3); return False; } @@ -1012,64 +884,60 @@ error_test1: fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE); if (fnum1 == -1) { - printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test3); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree)); return False; } /* Ensure size == 0. */ if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) { - printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test3); return False; } if (fsize != 0) { - printf("(3) file size != 0\n"); + torture_comment(tctx, "(3) file size != 0\n"); CHECK_MAX_FAILURES(error_test3); return False; } - printf("finished open test 3\n"); + torture_comment(tctx, "finished open test 3\n"); error_test3: smbcli_unlink(cli1->tree, fname); - printf("testing ctemp\n"); + torture_comment(tctx, "testing ctemp\n"); fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path); if (fnum1 == -1) { - printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "ctemp failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test4); return False; } - printf("ctemp gave path %s\n", tmp_path); + torture_comment(tctx, "ctemp gave path %s\n", tmp_path); if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "close of temp failed (%s)\n", smbcli_errstr(cli1->tree)); } if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) { - printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree)); } error_test4: /* Test the non-io opens... */ - if (!torture_open_connection(&cli2, 1)) { - return False; - } - smbcli_setatr(cli2->tree, fname, 0, 0); smbcli_unlink(cli2->tree, fname); - printf("TEST #1 testing 2 non-io opens (no delete)\n"); + torture_comment(tctx, "TEST #1 testing 2 non-io opens (no delete)\n"); fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test10); return False; } @@ -1077,31 +945,31 @@ error_test4: fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 == -1) { - printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test10); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); return False; } - printf("non-io open test #1 passed.\n"); + torture_comment(tctx, "non-io open test #1 passed.\n"); error_test10: smbcli_unlink(cli1->tree, fname); - printf("TEST #2 testing 2 non-io opens (first with delete)\n"); + torture_comment(tctx, "TEST #2 testing 2 non-io opens (first with delete)\n"); fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test20); return False; } @@ -1110,31 +978,31 @@ error_test10: NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 == -1) { - printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test20); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } - printf("non-io open test #2 passed.\n"); + torture_comment(tctx, "non-io open test #2 passed.\n"); error_test20: smbcli_unlink(cli1->tree, fname); - printf("TEST #3 testing 2 non-io opens (second with delete)\n"); + torture_comment(tctx, "TEST #3 testing 2 non-io opens (second with delete)\n"); fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test30); return False; } @@ -1143,31 +1011,31 @@ error_test20: NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 == -1) { - printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test30); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); return False; } - printf("non-io open test #3 passed.\n"); + torture_comment(tctx, "non-io open test #3 passed.\n"); error_test30: smbcli_unlink(cli1->tree, fname); - printf("TEST #4 testing 2 non-io opens (both with delete)\n"); + torture_comment(tctx, "TEST #4 testing 2 non-io opens (both with delete)\n"); fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test40); return False; } @@ -1176,29 +1044,29 @@ error_test30: NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 != -1) { - printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test40); return False; } - printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation"); + torture_comment(tctx, "test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation"); if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } - printf("non-io open test #4 passed.\n"); + torture_comment(tctx, "non-io open test #4 passed.\n"); error_test40: smbcli_unlink(cli1->tree, fname); - printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n"); + torture_comment(tctx, "TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n"); fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test50); return False; } @@ -1207,24 +1075,24 @@ error_test40: NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 == -1) { - printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test50); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); return False; } - printf("non-io open test #5 passed.\n"); + torture_comment(tctx, "non-io open test #5 passed.\n"); error_test50: - printf("TEST #6 testing 1 non-io open, one io open\n"); + torture_comment(tctx, "TEST #6 testing 1 non-io open, one io open\n"); smbcli_unlink(cli1->tree, fname); @@ -1232,7 +1100,7 @@ error_test50: NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test60); return False; } @@ -1241,24 +1109,24 @@ error_test50: NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 == -1) { - printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test60); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); return False; } - printf("non-io open test #6 passed.\n"); + torture_comment(tctx, "non-io open test #6 passed.\n"); error_test60: - printf("TEST #7 testing 1 non-io open, one io open with delete\n"); + torture_comment(tctx, "TEST #7 testing 1 non-io open, one io open with delete\n"); smbcli_unlink(cli1->tree, fname); @@ -1266,7 +1134,7 @@ error_test60: NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); if (fnum1 == -1) { - printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test70); return False; } @@ -1275,29 +1143,29 @@ error_test60: NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0); if (fnum2 != -1) { - printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree)); + torture_comment(tctx, "test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree)); CHECK_MAX_FAILURES(error_test70); return False; } - printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation"); + torture_comment(tctx, "test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation"); if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } - printf("non-io open test #7 passed.\n"); + torture_comment(tctx, "non-io open test #7 passed.\n"); error_test70: - printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n"); + torture_comment(tctx, "TEST #8 testing one normal open, followed by lock, followed by open with truncate\n"); smbcli_unlink(cli1->tree, fname); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { - printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } @@ -1306,72 +1174,65 @@ error_test70: memset(buf, '\0', 20); if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) { - printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) write failed (%s)\n", smbcli_errstr(cli1->tree)); correct = False; } /* Ensure size == 20. */ if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) { - printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test80); return False; } if (fsize != 20) { - printf("(8) file size != 20\n"); + torture_comment(tctx, "(8) file size != 20\n"); CHECK_MAX_FAILURES(error_test80); return False; } /* Get an exclusive lock on the open file. */ if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test80); return False; } fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); if (fnum1 == -1) { - printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree)); return False; } /* Ensure size == 0. */ if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) { - printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree)); CHECK_MAX_FAILURES(error_test80); return False; } if (fsize != 0) { - printf("(8) file size != 0\n"); + torture_comment(tctx, "(8) file size != 0\n"); CHECK_MAX_FAILURES(error_test80); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) { - printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree)); return False; } error_test80: - printf("open test #8 passed.\n"); + torture_comment(tctx, "open test #8 passed.\n"); smbcli_unlink(cli1->tree, fname); - if (!torture_close_connection(cli1)) { - correct = False; - } - if (!torture_close_connection(cli2)) { - correct = False; - } - return correct; } @@ -1399,19 +1260,12 @@ error_test80: /** Test ntcreate calls made by xcopy */ -static BOOL run_xcopy(struct torture_context *torture) +static bool run_xcopy(struct torture_context *tctx, + struct smbcli_state *cli1) { - struct smbcli_state *cli1; const char *fname = "\\test.txt"; - BOOL correct = True; int fnum1, fnum2; - printf("starting xcopy test\n"); - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE, @@ -1419,62 +1273,43 @@ static BOOL run_xcopy(struct torture_context *torture) NTCREATEX_DISP_OVERWRITE_IF, 0x4044, 0); - if (fnum1 == -1) { - printf("First open failed - %s\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, + "First open failed - %s", smbcli_errstr(cli1->tree))); fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, SECOND_DESIRED_ACCESS, 0, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0x200000, 0); - if (fnum2 == -1) { - printf("second open failed - %s\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, + "second open failed - %s", smbcli_errstr(cli1->tree))); - if (!torture_close_connection(cli1)) { - correct = False; - } - - return correct; + return true; } -static BOOL run_iometer(struct torture_context *torture) +static bool run_iometer(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname = "\\iobw.tst"; int fnum; size_t filesize; NTSTATUS status; char buf[2048]; int ops; - BOOL result = False; - - printf("Starting iometer test\n"); memset(buf, 0, sizeof(buf)); - if (!torture_open_connection(&cli, 0)) { - return False; - } - status = smbcli_getatr(cli->tree, fname, NULL, &filesize, NULL); - if (!NT_STATUS_IS_OK(status)) { - printf("smbcli_getatr failed: %s\n", nt_errstr(status)); - goto done; - } + torture_assert_ntstatus_ok(tctx, status, + talloc_asprintf(tctx, "smbcli_getatr failed: %s", nt_errstr(status))); - printf("size: %d\n", (int)filesize); + torture_comment(tctx, "size: %d\n", (int)filesize); filesize -= (sizeof(buf) - 1); fnum = smbcli_nt_create_full(cli->tree, fname, 0x16, 0x2019f, 0, 0x3, 3, 0x42, 0x3); - if (fnum == -1) { - printf("open failed: %s\n", smbcli_errstr(cli->tree)); - goto done; - } + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, "open failed: %s", + smbcli_errstr(cli->tree))); ops = 0; @@ -1487,61 +1322,40 @@ static BOOL run_iometer(struct torture_context *torture) for (i=0; i<num_reads; i++) { ssize_t res; if (ops++ > torture_numops) { - result = True; - goto done; + return true; } res = smbcli_read(cli->tree, fnum, buf, random() % filesize, sizeof(buf)); - if (res != sizeof(buf)) { - printf("read failed: %s\n", - smbcli_errstr(cli->tree)); - goto done; - } + torture_assert(tctx, res == sizeof(buf), + talloc_asprintf(tctx, "read failed: %s", + smbcli_errstr(cli->tree))); } for (i=0; i<num_writes; i++) { ssize_t res; if (ops++ > torture_numops) { - result = True; - goto done; + return true; } res = smbcli_write(cli->tree, fnum, 0, buf, random() % filesize, sizeof(buf)); - if (res != sizeof(buf)) { - printf("read failed: %s\n", - smbcli_errstr(cli->tree)); - goto done; - } + torture_assert(tctx, res == sizeof(buf), + talloc_asprintf(tctx, "read failed: %s", + smbcli_errstr(cli->tree))); } } - result = True; - done: - - if (!torture_close_connection(cli)) { - printf("close_connection failed: %s\n", - smbcli_errstr(cli->tree)); - return False; - } - - return result; + return true; } /** tries variants of chkpath */ -static BOOL torture_chkpath_test(struct torture_context *torture) +static BOOL torture_chkpath_test(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; int fnum; BOOL ret; - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("starting chkpath test\n"); - - printf("Testing valid and invalid paths\n"); + torture_comment(tctx, "Testing valid and invalid paths\n"); /* cleanup from an old run */ smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2"); @@ -1549,29 +1363,29 @@ static BOOL torture_chkpath_test(struct torture_context *torture) smbcli_rmdir(cli->tree, "\\chkpath.dir"); if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) { - printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "mkdir1 failed : %s\n", smbcli_errstr(cli->tree)); return False; } if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) { - printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "mkdir2 failed : %s\n", smbcli_errstr(cli->tree)); return False; } fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE); if (fnum == -1) { - printf("open1 failed (%s)\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "open1 failed (%s)\n", smbcli_errstr(cli->tree)); return False; } smbcli_close(cli->tree, fnum); if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) { - printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "chkpath1 failed: %s\n", smbcli_errstr(cli->tree)); ret = False; } if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) { - printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree)); + torture_comment(tctx, "chkpath2 failed: %s\n", smbcli_errstr(cli->tree)); ret = False; } @@ -1579,7 +1393,7 @@ static BOOL torture_chkpath_test(struct torture_context *torture) ret = check_error(__location__, cli, ERRDOS, ERRbadpath, NT_STATUS_NOT_A_DIRECTORY); } else { - printf("* chkpath on a file should fail\n"); + torture_comment(tctx, "* chkpath on a file should fail\n"); ret = False; } @@ -1587,7 +1401,7 @@ static BOOL torture_chkpath_test(struct torture_context *torture) ret = check_error(__location__, cli, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_NAME_NOT_FOUND); } else { - printf("* chkpath on a non existent file should fail\n"); + torture_comment(tctx, "* chkpath on a non existent file should fail\n"); ret = False; } @@ -1595,7 +1409,7 @@ static BOOL torture_chkpath_test(struct torture_context *torture) ret = check_error(__location__, cli, ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND); } else { - printf("* chkpath on a non existent component should fail\n"); + torture_comment(tctx, "* chkpath on a non existent component should fail\n"); ret = False; } @@ -1603,10 +1417,6 @@ static BOOL torture_chkpath_test(struct torture_context *torture) smbcli_unlink(cli->tree, "\\chkpath.dir\\*"); smbcli_rmdir(cli->tree, "\\chkpath.dir"); - if (!torture_close_connection(cli)) { - return False; - } - return ret; } @@ -1614,7 +1424,7 @@ static BOOL torture_chkpath_test(struct torture_context *torture) * This is a test to excercise some weird Samba3 error paths. */ -static BOOL torture_samba3_errorpaths(struct torture_context *torture) +static BOOL torture_samba3_errorpaths(struct torture_context *tctx) { BOOL nt_status_support; struct smbcli_state *cli_nt = NULL, *cli_dos = NULL; @@ -1627,14 +1437,14 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) NTSTATUS status; if (mem_ctx == NULL) { - printf("talloc_init failed\n"); + torture_comment(tctx, "talloc_init failed\n"); return False; } nt_status_support = lp_nt_status_support(); if (!lp_set_cmdline("nt status support", "yes")) { - printf("Could not set 'nt status support = yes'\n"); + torture_comment(tctx, "Could not set 'nt status support = yes'\n"); goto fail; } @@ -1643,7 +1453,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) } if (!lp_set_cmdline("nt status support", "no")) { - printf("Could not set 'nt status support = yes'\n"); + torture_comment(tctx, "Could not set 'nt status support = yes'\n"); goto fail; } @@ -1653,7 +1463,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) if (!lp_set_cmdline("nt status support", nt_status_support ? "yes":"no")) { - printf("Could not reset 'nt status support = yes'"); + torture_comment(tctx, "Could not reset 'nt status support = yes'"); goto fail; } @@ -1661,7 +1471,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) smbcli_rmdir(cli_nt->tree, dname); if (!NT_STATUS_IS_OK(smbcli_mkdir(cli_nt->tree, dname))) { - printf("smbcli_mkdir(%s) failed: %s\n", dname, + torture_comment(tctx, "smbcli_mkdir(%s) failed: %s\n", dname, smbcli_errstr(cli_nt->tree)); goto fail; } @@ -1681,14 +1491,14 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) status = smb_raw_open(cli_nt->tree, mem_ctx, &io); if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) { - printf("(%s) incorrect status %s should be %s\n", + torture_comment(tctx, "(%s) incorrect status %s should be %s\n", __location__, nt_errstr(status), nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION)); goto fail; } status = smb_raw_open(cli_dos->tree, mem_ctx, &io); if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) { - printf("(%s) incorrect status %s should be %s\n", + torture_comment(tctx, "(%s) incorrect status %s should be %s\n", __location__, nt_errstr(status), nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists))); goto fail; @@ -1696,14 +1506,14 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) status = smbcli_mkdir(cli_nt->tree, dname); if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) { - printf("(%s) incorrect status %s should be %s\n", + torture_comment(tctx, "(%s) incorrect status %s should be %s\n", __location__, nt_errstr(status), nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION)); goto fail; } status = smbcli_mkdir(cli_dos->tree, dname); if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRnoaccess))) { - printf("(%s) incorrect status %s should be %s\n", + torture_comment(tctx, "(%s) incorrect status %s should be %s\n", __location__, nt_errstr(status), nt_errstr(NT_STATUS_DOS(ERRDOS, ERRnoaccess))); goto fail; @@ -1712,7 +1522,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; status = smb_raw_open(cli_nt->tree, mem_ctx, &io); if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) { - printf("(%s) incorrect status %s should be %s\n", + torture_comment(tctx, "(%s) incorrect status %s should be %s\n", __location__, nt_errstr(status), nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION)); goto fail; @@ -1720,7 +1530,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) status = smb_raw_open(cli_dos->tree, mem_ctx, &io); if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) { - printf("(%s) incorrect status %s should be %s\n", + torture_comment(tctx, "(%s) incorrect status %s should be %s\n", __location__, nt_errstr(status), nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists))); goto fail; @@ -1732,28 +1542,28 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) fnum = smbcli_open(cli_nt->tree, fname, O_RDWR | O_CREAT, 5); if (fnum != -1) { - printf("Open(%s) with invalid deny mode succeeded -- " + torture_comment(tctx, "Open(%s) with invalid deny mode succeeded -- " "expected failure\n", fname); smbcli_close(cli_nt->tree, fnum); goto fail; } if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree), NT_STATUS_DOS(ERRDOS,ERRbadaccess))) { - printf("Expected DOS error ERRDOS/ERRbadaccess, " + torture_comment(tctx, "Expected DOS error ERRDOS/ERRbadaccess, " "got %s\n", smbcli_errstr(cli_nt->tree)); goto fail; } fnum = smbcli_open(cli_dos->tree, fname, O_RDWR | O_CREAT, 5); if (fnum != -1) { - printf("Open(%s) with invalid deny mode succeeded -- " + torture_comment(tctx, "Open(%s) with invalid deny mode succeeded -- " "expected failure\n", fname); smbcli_close(cli_nt->tree, fnum); goto fail; } if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree), NT_STATUS_DOS(ERRDOS,ERRbadaccess))) { - printf("Expected DOS error ERRDOS:ERRbadaccess, " + torture_comment(tctx, "Expected DOS error ERRDOS:ERRbadaccess, " "got %s\n", smbcli_errstr(cli_nt->tree)); goto fail; } @@ -1767,7 +1577,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (fnum != -1) { - printf("Open(%s) succeeded -- expected failure\n", + torture_comment(tctx, "Open(%s) succeeded -- expected failure\n", os2_fname); smbcli_close(cli_dos->tree, fnum); goto fail; @@ -1775,7 +1585,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_dos->tree), NT_STATUS_DOS(ERRDOS, ERRcannotopen))) { - printf("Expected DOS error ERRDOS/ERRcannotopen, got %s\n", + torture_comment(tctx, "Expected DOS error ERRDOS/ERRcannotopen, got %s\n", smbcli_errstr(cli_dos->tree)); goto fail; } @@ -1784,7 +1594,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (fnum != -1) { - printf("Open(%s) succeeded -- expected failure\n", + torture_comment(tctx, "Open(%s) succeeded -- expected failure\n", os2_fname); smbcli_close(cli_nt->tree, fnum); goto fail; @@ -1792,7 +1602,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree), NT_STATUS_OBJECT_NAME_NOT_FOUND)) { - printf("Expected error NT_STATUS_OBJECT_NAME_NOT_FOUND, " + torture_comment(tctx, "Expected error NT_STATUS_OBJECT_NAME_NOT_FOUND, " "got %s\n", smbcli_errstr(cli_nt->tree)); goto fail; } @@ -1814,52 +1624,61 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture) NTSTATUS torture_base_init(void) { - register_torture_op("BASE-FDPASS", run_fdpasstest); - register_torture_op("BASE-LOCK1", torture_locktest1); - register_torture_op("BASE-LOCK2", torture_locktest2); - register_torture_op("BASE-LOCK3", torture_locktest3); - register_torture_op("BASE-LOCK4", torture_locktest4); - register_torture_op("BASE-LOCK5", torture_locktest5); - register_torture_op("BASE-LOCK6", torture_locktest6); - register_torture_op("BASE-LOCK7", torture_locktest7); - register_torture_op("BASE-UNLINK", torture_unlinktest); - register_torture_op("BASE-ATTR", run_attrtest); - register_torture_op("BASE-TRANS2", run_trans2test); - register_torture_op("BASE-NEGNOWAIT", run_negprot_nowait); - register_torture_op("BASE-DIR1", torture_dirtest1); - register_torture_op("BASE-DIR2", torture_dirtest2); - register_torture_op("BASE-DENY1", torture_denytest1); - register_torture_op("BASE-DENY2", torture_denytest2); - register_torture_op("BASE-DENY3", torture_denytest3); - register_torture_op("BASE-DENYDOS", torture_denydos_sharing); - register_torture_multi_op("BASE-NTDENY1", torture_ntdenytest1); - register_torture_op("BASE-NTDENY2", torture_ntdenytest2); - register_torture_op("BASE-TCON", run_tcon_test); - register_torture_op("BASE-TCONDEV", run_tcon_devtype_test); - register_torture_op("BASE-VUID", run_vuidtest); - register_torture_op("BASE-RW1", run_readwritetest); - register_torture_op("BASE-OPEN", run_opentest); - register_torture_multi_op("BASE-DEFER_OPEN", run_deferopen); - register_torture_op("BASE-XCOPY", run_xcopy); - register_torture_op("BASE-IOMETER", run_iometer); - register_torture_op("BASE-RENAME", torture_test_rename); - register_torture_op("BASE-DELETE", torture_test_delete); - register_torture_op("BASE-PROPERTIES", torture_test_properties); - register_torture_op("BASE-MANGLE", torture_mangle); - register_torture_op("BASE-OPENATTR", torture_openattrtest); - register_torture_op("BASE-CHARSET", torture_charset); - register_torture_op("BASE-CHKPATH", torture_chkpath_test); - register_torture_op("BASE-SECLEAK", torture_sec_leak); - register_torture_op("BASE-DISCONNECT", torture_disconnect); - register_torture_op("BASE-DELAYWRITE", torture_delay_write); - register_torture_op("BASE-SAMBA3ERROR", torture_samba3_errorpaths); - - register_torture_op("SCAN-CASETABLE", torture_casetable); - register_torture_op("SCAN-UTABLE", torture_utable); - register_torture_op("SCAN-SMB", torture_smb_scan); - register_torture_op("SCAN-ALIASES", torture_trans2_aliases); - register_torture_op("SCAN-TRANS2", torture_trans2_scan); - register_torture_op("SCAN-NTTRANS", torture_nttrans_scan); + struct torture_suite *suite = torture_suite_create( + talloc_autofree_context(), "BASE"); + + torture_suite_add_2smb_test(suite, "FDPASS", run_fdpasstest); + torture_suite_add_suite(suite, torture_base_locktest()); + torture_suite_add_1smb_test(suite, "UNLINK", torture_unlinktest); + torture_suite_add_1smb_test(suite, "ATTR", run_attrtest); + torture_suite_add_1smb_test(suite, "TRANS2", run_trans2test); + torture_suite_add_simple_test(suite, "NEGNOWAIT", run_negprot_nowait); + torture_suite_add_1smb_test(suite, "DIR1", torture_dirtest1); + torture_suite_add_1smb_test(suite, "DIR2", torture_dirtest2); + torture_suite_add_1smb_test(suite, "DENY1", torture_denytest1); + torture_suite_add_2smb_test(suite, "DENY2", torture_denytest2); + torture_suite_add_2smb_test(suite, "DENY3", torture_denytest3); + torture_suite_add_1smb_test(suite, "DENYDOS", torture_denydos_sharing); + torture_suite_add_smb_multi_test(suite, "NTDENY1", torture_ntdenytest1); + torture_suite_add_2smb_test(suite, "NTDENY2", torture_ntdenytest2); + torture_suite_add_1smb_test(suite, "TCON", run_tcon_test); + torture_suite_add_1smb_test(suite, "TCONDEV", run_tcon_devtype_test); + torture_suite_add_1smb_test(suite, "VUID", run_vuidtest); + torture_suite_add_2smb_test(suite, "RW1", run_readwritetest); + torture_suite_add_2smb_test(suite, "OPEN", run_opentest); + torture_suite_add_smb_multi_test(suite, "DEFER_OPEN", run_deferopen); + torture_suite_add_1smb_test(suite, "XCOPY", run_xcopy); + torture_suite_add_1smb_test(suite, "IOMETER", run_iometer); + torture_suite_add_1smb_test(suite, "RENAME", torture_test_rename); + torture_suite_add_suite(suite, torture_test_delete()); + torture_suite_add_1smb_test(suite, "PROPERTIES", torture_test_properties); + torture_suite_add_1smb_test(suite, "MANGLE", torture_mangle); + torture_suite_add_1smb_test(suite, "OPENATTR", torture_openattrtest); + torture_suite_add_1smb_test(suite, "CHARSET", torture_charset); + torture_suite_add_1smb_test(suite, "CHKPATH", torture_chkpath_test); + torture_suite_add_1smb_test(suite, "SECLEAK", torture_sec_leak); + torture_suite_add_simple_test(suite, "DISCONNECT", torture_disconnect); + torture_suite_add_suite(suite, torture_delay_write()); + torture_suite_add_simple_test(suite, "SAMBA3ERROR", torture_samba3_errorpaths); + + torture_suite_add_1smb_test(suite, "CASETABLE", torture_casetable); + torture_suite_add_1smb_test(suite, "UTABLE", torture_utable); + torture_suite_add_simple_test(suite, "SMB", torture_smb_scan); + torture_suite_add_suite(suite, torture_trans2_aliases()); + torture_suite_add_1smb_test(suite, "TRANS2", torture_trans2_scan); + torture_suite_add_1smb_test(suite, "NTTRANS", torture_nttrans_scan); + + torture_suite_add_simple_test(suite, "BENCH-HOLDCON", torture_holdcon); + torture_suite_add_simple_test(suite, "BENCH-READWRITE", run_benchrw); + torture_suite_add_smb_multi_test(suite, "BENCH-TORTURE", run_torture); + torture_suite_add_1smb_test(suite, "SCAN-PIPE_NUMBER", run_pipe_number); + torture_suite_add_1smb_test(suite, "SCAN-IOCTL", torture_ioctl_test); + torture_suite_add_smb_multi_test(suite, "SCAN-MAXFID", run_maxfidtest); + + suite->description = talloc_strdup(suite, + "Basic SMB tests (imported from the original smbtorture)"); + + torture_register_suite(suite); return NT_STATUS_OK; } diff --git a/source4/torture/basic/charset.c b/source4/torture/basic/charset.c index d7e53ae92a..d7172e9cec 100644 --- a/source4/torture/basic/charset.c +++ b/source4/torture/basic/charset.c @@ -26,14 +26,15 @@ #include "libcli/libcli.h" #include "torture/util.h" -#define BASEDIR "\\chartest" +#define BASEDIR "\\chartest\\" /* open a file using a set of unicode code points for the name the prefix BASEDIR is added before the name */ -static NTSTATUS unicode_open(struct smbcli_tree *tree, +static NTSTATUS unicode_open(struct torture_context *tctx, + struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, uint32_t open_disposition, const uint32_t *u_name, @@ -57,12 +58,12 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree, i = convert_string_talloc(ucs_name, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname); if (i == -1) { - printf("Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n"); + torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n"); talloc_free(ucs_name); return NT_STATUS_NO_MEMORY; } - fname2 = talloc_asprintf(ucs_name, "%s\\%s", BASEDIR, fname); + fname2 = talloc_asprintf(ucs_name, "%s%s", BASEDIR, fname); if (!fname2) { talloc_free(ucs_name); return NT_STATUS_NO_MEMORY; @@ -93,7 +94,8 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree, /* see if the server recognises composed characters */ -static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_composed(struct torture_context *tctx, + struct smbcli_state *cli, TALLOC_CTX *mem_ctx) { const uint32_t name1[] = {0x61, 0x308}; const uint32_t name2[] = {0xe4}; @@ -101,14 +103,14 @@ static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) printf("Testing composite character (a umlaut)\n"); - status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 2); + status1 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 2); if (!NT_STATUS_IS_OK(status1)) { printf("Failed to create composed name - %s\n", nt_errstr(status1)); return False; } - status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); + status2 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); if (!NT_STATUS_IS_OK(status2)) { printf("Failed to create accented character - %s\n", @@ -122,7 +124,8 @@ static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) /* see if the server recognises a naked diacritical */ -static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_diacritical(struct torture_context *tctx, + struct smbcli_state *cli, TALLOC_CTX *mem_ctx) { const uint32_t name1[] = {0x308}; const uint32_t name2[] = {0x308, 0x308}; @@ -130,7 +133,7 @@ static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) printf("Testing naked diacritical (umlaut)\n"); - status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); + status1 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); if (!NT_STATUS_IS_OK(status1)) { printf("Failed to create naked diacritical - %s\n", @@ -139,7 +142,7 @@ static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) } /* try a double diacritical */ - status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 2); + status2 = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 2); if (!NT_STATUS_IS_OK(status2)) { printf("Failed to create double naked diacritical - %s\n", @@ -153,7 +156,8 @@ static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) /* see if the server recognises a partial surrogate pair */ -static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_surrogate(struct torture_context *tctx, + struct smbcli_state *cli, TALLOC_CTX *mem_ctx) { const uint32_t name1[] = {0xd800}; const uint32_t name2[] = {0xdc00}; @@ -162,7 +166,7 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) printf("Testing partial surrogate\n"); - status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); + status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); if (!NT_STATUS_IS_OK(status)) { printf("Failed to create partial surrogate 1 - %s\n", @@ -170,7 +174,7 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) return False; } - status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); + status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); if (!NT_STATUS_IS_OK(status)) { printf("Failed to create partial surrogate 2 - %s\n", @@ -178,7 +182,7 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) return False; } - status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 2); + status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 2); if (!NT_STATUS_IS_OK(status)) { printf("Failed to create full surrogate - %s\n", @@ -192,7 +196,8 @@ static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) /* see if the server recognises wide-a characters */ -static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_widea(struct torture_context *tctx, + struct smbcli_state *cli, TALLOC_CTX *mem_ctx) { const uint32_t name1[] = {'a'}; const uint32_t name2[] = {0xff41}; @@ -201,7 +206,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) printf("Testing wide-a\n"); - status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); + status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1); if (!NT_STATUS_IS_OK(status)) { printf("Failed to create 'a' - %s\n", @@ -209,7 +214,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) return False; } - status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); + status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1); if (!NT_STATUS_IS_OK(status)) { printf("Failed to create wide-a - %s\n", @@ -217,7 +222,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) return False; } - status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 1); + status = unicode_open(tctx, cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 1); if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) { printf("Expected %s creating wide-A - %s\n", @@ -229,37 +234,30 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) return True; } -BOOL torture_charset(struct torture_context *torture) +BOOL torture_charset(struct torture_context *tctx, struct smbcli_state *cli) { - static struct smbcli_state *cli; BOOL ret = True; TALLOC_CTX *mem_ctx; mem_ctx = talloc_init("torture_charset"); - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("Starting charset tests\n"); - if (!torture_setup_dir(cli, BASEDIR)) { return False; } - if (!test_composed(cli, mem_ctx)) { + if (!test_composed(tctx, cli, mem_ctx)) { ret = False; } - if (!test_diacritical(cli, mem_ctx)) { + if (!test_diacritical(tctx, cli, mem_ctx)) { ret = False; } - if (!test_surrogate(cli, mem_ctx)) { + if (!test_surrogate(tctx, cli, mem_ctx)) { ret = False; } - if (!test_widea(cli, mem_ctx)) { + if (!test_widea(tctx, cli, mem_ctx)) { ret = False; } diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index e42ca1239d..4c2a511721 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -32,7 +32,7 @@ #define BASEDIR "\\delaywrite" -static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli) { union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; @@ -42,15 +42,13 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ ssize_t written; time_t t; - printf("Testing delayed update of write time\n"); - if (!torture_setup_dir(cli, BASEDIR)) { return False; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } @@ -58,15 +56,15 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Initial write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); /* 3 second delay to ensure we get past any 2 second time granularity (older systems may have that) */ @@ -75,7 +73,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); if (written != 1) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -83,17 +81,17 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ t = time(NULL); while (time(NULL) < t+120) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -102,7 +100,7 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time?!\n"); + torture_comment(tctx, "Server did not update write time?!\n"); ret = False; } @@ -119,9 +117,9 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ * Do as above, but using 2 connections. */ -static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli, + struct smbcli_state *cli2) { - struct smbcli_state *cli2=NULL; union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; NTSTATUS status; @@ -132,19 +130,13 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem time_t t; union smb_flush flsh; - printf("Testing delayed update of write time using 2 connections\n"); - - if (!torture_open_connection(&cli2, 1)) { - return False; - } - if (!torture_setup_dir(cli, BASEDIR)) { return False; } fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum1 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } @@ -152,15 +144,15 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Initial write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Initial write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); /* 3 second delay to ensure we get past any 2 second time granularity (older systems may have that) */ @@ -198,17 +190,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem while (time(NULL) < t+120) { finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -217,7 +209,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time?!\n"); + torture_comment(tctx, "Server did not update write time?!\n"); ret = False; } @@ -227,23 +219,23 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Modified write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Modified write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); - printf("Doing a 10 byte write to extend the file and see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -251,7 +243,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem /* Just to prove to tridge that the an smbflush has no effect on the write time :-). The setfileinfo IS STICKY. JRA. */ - printf("Doing flush after write\n"); + torture_comment(tctx, "Doing flush after write\n"); flsh.flush.level = RAW_FLUSH_FLUSH; flsh.flush.in.file.fnum = fnum1; @@ -267,17 +259,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem don't have any effect. But make sure. */ while (time(NULL) < t+15) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -286,47 +278,47 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time\n"); } fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } - printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time\n"); } - printf("Closing the first fd to see if write time updated.\n"); + torture_comment(tctx, "Closing the first fd to see if write time updated.\n"); smbcli_close(cli->tree, fnum1); fnum1 = -1; - printf("Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -334,16 +326,16 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.in.file.fnum = fnum2; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time\n"); } t = time(NULL); @@ -352,17 +344,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem don't have any effect. But make sure. */ while (time(NULL) < t+15) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -371,17 +363,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time\n"); } - printf("Closing both fd's to see if write time updated.\n"); + torture_comment(tctx, "Closing both fd's to see if write time updated.\n"); smbcli_close(cli->tree, fnum2); fnum2 = -1; fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); if (fnum1 == -1) { - printf("Failed to open %s\n", fname); + torture_comment(tctx, "Failed to open %s\n", fname); return False; } @@ -389,23 +381,23 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("Second open initial write time %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + torture_comment(tctx, "Second open initial write time %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time)); sleep(10); - printf("Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); + torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n"); written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10); if (written != 10) { - printf("write failed - wrote %d bytes (%s)\n", + torture_comment(tctx, "write failed - wrote %d bytes (%s)\n", (int)written, __location__); return False; } @@ -413,16 +405,16 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.in.file.fnum = fnum1; finfo2 = finfo1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); return False; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time\n"); + torture_comment(tctx, "Server updated write_time\n"); } t = time(NULL); @@ -431,17 +423,17 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem don't have any effect. But make sure. */ while (time(NULL) < t+15) { - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); ret = False; break; } - printf("write time %s\n", - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "write time %s\n", + nt_time_string(tctx, finfo2.basic_info.out.write_time)); if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("Server updated write_time after %d seconds\n", + torture_comment(tctx, "Server updated write_time after %d seconds\n", (int)(time(NULL) - t)); break; } @@ -450,7 +442,7 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem } if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { - printf("Server did not update write time\n"); + torture_comment(tctx, "Server did not update write time\n"); } @@ -458,9 +450,6 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem second connection to ensure it's the same. This is very easy for a Windows server but a bastard to get right on a POSIX server. JRA. */ - if (cli2 != NULL) { - torture_close_connection(cli2); - } if (fnum1 != -1) smbcli_close(cli->tree, fnum1); smbcli_unlink(cli->tree, fname); @@ -480,7 +469,8 @@ static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem * nasty.... */ -static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +static BOOL test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli, + struct smbcli_state *cli2) { union smb_fileinfo finfo1, finfo2; const char *fname = BASEDIR "\\torture_file.txt"; @@ -489,9 +479,6 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx int fnum2; BOOL ret = True; ssize_t written; - struct smbcli_state *cli2=NULL; - - printf("Testing finfo update on close\n"); if (!torture_setup_dir(cli, BASEDIR)) { return False; @@ -506,7 +493,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo1.basic_info.in.file.fnum = fnum1; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo1); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); @@ -519,19 +506,15 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); if (written != 1) { - printf("(%s) written gave %d - should have been 1\n", + torture_comment(tctx, "(%s) written gave %d - should have been 1\n", __location__, (int)written); ret = False; goto done; } - if (!torture_open_connection(&cli2, 1)) { - return False; - } - fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); if (fnum2 == -1) { - printf("(%s) failed to open 2nd time - %s\n", + torture_comment(tctx, "(%s) failed to open 2nd time - %s\n", __location__, smbcli_errstr(cli2->tree)); ret = False; goto done; @@ -540,7 +523,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1); if (written != 1) { - printf("(%s) written gave %d - should have been 1\n", + torture_comment(tctx, "(%s) written gave %d - should have been 1\n", __location__, (int)written); ret = False; goto done; @@ -549,7 +532,7 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("(%s) fileinfo failed: %s\n", @@ -560,31 +543,31 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx if (finfo1.basic_info.out.create_time != finfo2.basic_info.out.create_time) { - printf("(%s) create_time changed\n", __location__); + torture_comment(tctx, "(%s) create_time changed\n", __location__); ret = False; goto done; } if (finfo1.basic_info.out.access_time != finfo2.basic_info.out.access_time) { - printf("(%s) access_time changed\n", __location__); + torture_comment(tctx, "(%s) access_time changed\n", __location__); ret = False; goto done; } if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { - printf("(%s) write_time changed\n", __location__); - printf("write time conn 1 = %s, conn 2 = %s\n", - nt_time_string(mem_ctx, finfo1.basic_info.out.write_time), - nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + torture_comment(tctx, "(%s) write_time changed\n", __location__); + torture_comment(tctx, "write time conn 1 = %s, conn 2 = %s\n", + nt_time_string(tctx, finfo1.basic_info.out.write_time), + nt_time_string(tctx, finfo2.basic_info.out.write_time)); ret = False; goto done; } if (finfo1.basic_info.out.change_time != finfo2.basic_info.out.change_time) { - printf("(%s) change_time changed\n", __location__); + torture_comment(tctx, "(%s) change_time changed\n", __location__); ret = False; goto done; } @@ -595,14 +578,13 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx * *not* have updated the stat on disk */ smbcli_close(cli2->tree, fnum2); - torture_close_connection(cli2); cli2 = NULL; /* This call is only for the people looking at ethereal :-) */ finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO; finfo2.basic_info.in.file.path = fname; - status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); + status = smb_raw_pathinfo(cli->tree, tctx, &finfo2); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); @@ -615,9 +597,6 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx smbcli_close(cli->tree, fnum1); smbcli_unlink(cli->tree, fname); smbcli_deltree(cli->tree, BASEDIR); - if (cli2 != NULL) { - torture_close_connection(cli2); - } return ret; } @@ -626,23 +605,13 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx /* testing of delayed update of write_time */ -BOOL torture_delay_write(struct torture_context *torture) +struct torture_suite *torture_delay_write(void) { - struct smbcli_state *cli; - BOOL ret = True; - TALLOC_CTX *mem_ctx; - - if (!torture_open_connection(&cli, 0)) { - return False; - } + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE"); - mem_ctx = talloc_init("torture_delay_write"); + torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write); + torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update); + torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2); - ret &= test_finfo_after_write(cli, mem_ctx); - ret &= test_delayed_write_update(cli, mem_ctx); - ret &= test_delayed_write_update2(cli, mem_ctx); - - torture_close_connection(cli); - talloc_free(mem_ctx); - return ret; + return suite; } diff --git a/source4/torture/basic/delete.c b/source4/torture/basic/delete.c index 445333ca6f..4f787ebb65 100644 --- a/source4/torture/basic/delete.c +++ b/source4/torture/basic/delete.c @@ -29,11 +29,11 @@ #include "torture/raw/proto.h" -static BOOL check_delete_on_close(struct smbcli_state *cli, int fnum, - const char *fname, BOOL expect_it, - const char *where) +static bool check_delete_on_close(struct torture_context *tctx, + struct smbcli_state *cli, int fnum, + const char *fname, bool expect_it, + const char *where) { - TALLOC_CTX *mem_ctx = talloc_init("single_search"); union smb_search_data data; NTSTATUS status; @@ -41,20 +41,14 @@ static BOOL check_delete_on_close(struct smbcli_state *cli, int fnum, size_t size; uint16_t mode; - BOOL res = True; - - status = torture_single_search(cli, mem_ctx, + status = torture_single_search(cli, tctx, fname, RAW_SEARCH_TRANS2, RAW_SEARCH_DATA_FULL_DIRECTORY_INFO, FILE_ATTRIBUTE_DIRECTORY, &data); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) single_search failed (%s)\n", - where, nt_errstr(status)); - res = False; - goto done; - } + torture_assert_ntstatus_ok(tctx, status, + talloc_asprintf(tctx, "single_search failed (%s)", where)); if (fnum != -1) { union smb_fileinfo io; @@ -63,53 +57,33 @@ static BOOL check_delete_on_close(struct smbcli_state *cli, int fnum, io.all_info.level = RAW_FILEINFO_ALL_INFO; io.all_info.in.file.fnum = fnum; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &io); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) qfileinfo failed (%s)\n", where, - nt_errstr(status)); - res = False; - goto done; - } + status = smb_raw_fileinfo(cli->tree, tctx, &io); + torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, + "qfileinfo failed (%s)", where)); - if (expect_it != io.all_info.out.delete_pending) { - printf("%s - Expected del_on_close flag %d, qfileinfo/all_info gave %d\n", - where, expect_it, io.all_info.out.delete_pending); - res = False; - goto done; - } + torture_assert(tctx, expect_it == io.all_info.out.delete_pending, + talloc_asprintf(tctx, + "%s - Expected del_on_close flag %d, qfileinfo/all_info gave %d", + where, expect_it, io.all_info.out.delete_pending)); - if (nlink != io.all_info.out.nlink) { - printf("%s - Expected nlink %d, qfileinfo/all_info gave %d\n", - where, nlink, io.all_info.out.nlink); - res = False; - goto done; - } + torture_assert(tctx, nlink == io.all_info.out.nlink, + talloc_asprintf(tctx, + "%s - Expected nlink %d, qfileinfo/all_info gave %d", + where, nlink, io.all_info.out.nlink)); io.standard_info.level = RAW_FILEINFO_STANDARD_INFO; io.standard_info.in.file.fnum = fnum; - status = smb_raw_fileinfo(cli->tree, mem_ctx, &io); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) qpathinfo failed (%s)\n", where, - nt_errstr(status)); - res = False; - goto done; - } - - if (expect_it != io.standard_info.out.delete_pending) { - printf("%s - Expected del_on_close flag %d, qfileinfo/standard_info gave %d\n", - where, expect_it, io.standard_info.out.delete_pending); - res = False; - goto done; - } + status = smb_raw_fileinfo(cli->tree, tctx, &io); + torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "qpathinfo failed (%s)", where)); - if (nlink != io.standard_info.out.nlink) { - printf("%s - Expected nlink %d, qfileinfo/standard_info gave %d\n", - where, nlink, io.all_info.out.nlink); - res = False; - goto done; - } + torture_assert(tctx, expect_it == io.standard_info.out.delete_pending, + talloc_asprintf(tctx, "%s - Expected del_on_close flag %d, qfileinfo/standard_info gave %d\n", + where, expect_it, io.standard_info.out.delete_pending)); + torture_assert(tctx, nlink == io.standard_info.out.nlink, + talloc_asprintf(tctx, "%s - Expected nlink %d, qfileinfo/standard_info gave %d", + where, nlink, io.all_info.out.nlink)); } status = smbcli_qpathinfo(cli->tree, fname, @@ -117,35 +91,19 @@ static BOOL check_delete_on_close(struct smbcli_state *cli, int fnum, &size, &mode); if (expect_it) { - if (!NT_STATUS_EQUAL(status, NT_STATUS_DELETE_PENDING)) { - printf("(%s) qpathinfo did not give correct error " - "code (%s) -- NT_STATUS_DELETE_PENDING " - "expected\n", where, - nt_errstr(status)); - res = False; - goto done; - } + torture_assert_ntstatus_equal(tctx, status, NT_STATUS_DELETE_PENDING, + "qpathinfo did not give correct error code"); } else { - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) qpathinfo failed (%s)\n", where, - nt_errstr(status)); - res = False; - goto done; - } + torture_assert_ntstatus_ok(tctx, status, + talloc_asprintf(tctx, "qpathinfo failed (%s)", where)); } - done: - talloc_free(mem_ctx); - return res; + return true; } -#define CHECK_STATUS(_cli, _expected) do { \ - if (!NT_STATUS_EQUAL(_cli->tree->session->transport->error.e.nt_status, _expected)) { \ - printf("(%d) Incorrect status %s - should be %s\n", \ - __LINE__, nt_errstr(_cli->tree->session->transport->error.e.nt_status), nt_errstr(_expected)); \ - correct = False; \ - goto fail; \ - }} while (0) +#define CHECK_STATUS(_cli, _expected) \ + torture_assert_ntstatus_equal(tctx, _cli->tree->session->transport->error.e.nt_status, _expected, \ + "Incorrect status") static const char *fname = "\\delete.file"; static const char *fname_new = "\\delete.new"; @@ -153,19 +111,19 @@ static const char *dname = "\\delete.dir"; static void del_clean_area(struct smbcli_state *cli1, struct smbcli_state *cli2) { + smb_raw_exit(cli1->session); + smb_raw_exit(cli2->session); + smbcli_deltree(cli1->tree, dname); smbcli_setatr(cli1->tree, fname, 0, 0); smbcli_unlink(cli1->tree, fname); smbcli_setatr(cli1->tree, fname_new, 0, 0); smbcli_unlink(cli1->tree, fname_new); - - smb_raw_exit(cli1->session); - smb_raw_exit(cli2->session); } /* Test 1 - this should delete the file on close. */ -static BOOL deltest1(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest1(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; @@ -177,31 +135,21 @@ static BOOL deltest1(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(cli1->tree))); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded (should fail)\n", - __location__, fname); - return False; - } + torture_assert(tctx, fnum1 == -1, talloc_asprintf(tctx, "open of %s succeeded (should fail)", + fname)); - printf("first delete on close test succeeded.\n"); return True; } /* Test 2 - this should delete the file on close. */ -static BOOL deltest2(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest2(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; @@ -212,23 +160,17 @@ static BOOL deltest2(struct smbcli_state *cli1, struct smbcli_state *cli2) FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_nt_delete_on_close(cli1->tree, fnum1, True), + talloc_asprintf(tctx, "setting delete_on_close failed (%s)", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close failed (%s)", + smbcli_errstr(cli1->tree))); fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE); if (fnum1 != -1) { @@ -240,14 +182,12 @@ static BOOL deltest2(struct smbcli_state *cli1, struct smbcli_state *cli2) return False; } smbcli_unlink(cli1->tree, fname); - } else { - printf("second delete on close test succeeded.\n"); } - return True; + return true; } /* Test 3 - ... */ -static BOOL deltest3(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest3(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; @@ -260,11 +200,8 @@ static BOOL deltest3(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* This should fail with a sharing violation - open for delete is only compatible with SHARE_DELETE. */ @@ -275,11 +212,9 @@ static BOOL deltest3(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN, 0, 0); - if (fnum2 != -1) { - printf("(%s) open - 2 of %s succeeded - should have failed.\n", - __location__, fname); - return False; - } + torture_assert(tctx, fnum2 == -1, + talloc_asprintf(tctx, "open - 2 of %s succeeded - should have failed.", + fname)); /* This should succeed. */ @@ -289,29 +224,21 @@ static BOOL deltest3(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); - if (fnum2 == -1) { - printf("(%s) open - 2 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 2 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_nt_delete_on_close(cli1->tree, fnum1, True), + talloc_asprintf(tctx, "setting delete_on_close failed (%s)", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close 1 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close 1 failed (%s)", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) { - printf("(%s) close 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum2), + talloc_asprintf(tctx, "close 2 failed (%s)", + smbcli_errstr(cli1->tree))); /* This should fail - file should no longer be there. */ @@ -325,18 +252,16 @@ static BOOL deltest3(struct smbcli_state *cli1, struct smbcli_state *cli2) } smbcli_unlink(cli1->tree, fname); return False; - } else { - printf("third delete on close test succeeded.\n"); } return True; } /* Test 4 ... */ -static BOOL deltest4(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest4(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -348,11 +273,8 @@ static BOOL deltest4(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* This should succeed. */ fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, @@ -362,23 +284,18 @@ static BOOL deltest4(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); - if (fnum2 == -1) { - printf("(%s) open - 2 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 2 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) { - printf("(%s) close - 1 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_close(cli1->tree, fnum2), + talloc_asprintf(tctx, "close - 1 failed (%s)", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_nt_delete_on_close(cli1->tree, fnum1, True), + talloc_asprintf(tctx, "setting delete_on_close failed (%s)", + smbcli_errstr(cli1->tree))); /* This should fail - no more opens once delete on close set. */ fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, @@ -386,60 +303,43 @@ static BOOL deltest4(struct smbcli_state *cli1, struct smbcli_state *cli2) FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); - if (fnum2 != -1) { - printf("(%s) open - 3 of %s succeeded ! Should have failed.\n", - __location__, fname ); - return False; - } + torture_assert(tctx, fnum2 == -1, + talloc_asprintf(tctx, "open - 3 of %s succeeded ! Should have failed.", + fname )); + CHECK_STATUS(cli1, NT_STATUS_DELETE_PENDING); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 2 failed (%s)", + smbcli_errstr(cli1->tree))); - printf("fourth delete on close test succeeded.\n"); - - fail: - return correct; } /* Test 5 ... */ -static BOOL deltest5(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest5(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; del_clean_area(cli1, cli2); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } - + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); + /* This should fail - only allowed on NT opens with DELETE access. */ - if (NT_STATUS_IS_OK(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close on OpenX file succeeded - should fail !\n", - __location__); - return False; - } + torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_nt_delete_on_close(cli1->tree, fnum1, True)), + "setting delete_on_close on OpenX file succeeded - should fail !"); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 2 failed (%s)", smbcli_errstr(cli1->tree))); - printf("fifth delete on close test succeeded.\n"); return True; } /* Test 6 ... */ -static BOOL deltest6(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest6(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; @@ -453,35 +353,28 @@ static BOOL deltest6(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* This should fail - only allowed on NT opens with DELETE access. */ - if (NT_STATUS_IS_OK(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close on file with no delete access succeeded - should fail !\n", - __location__); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_nt_delete_on_close(cli1->tree, fnum1, True)), + "setting delete_on_close on file with no delete access succeeded - should fail !"); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 2 failed (%s)", + smbcli_errstr(cli1->tree))); - printf("sixth delete on close test succeeded.\n"); return True; } /* Test 7 ... */ -static BOOL deltest7(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest7(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -492,68 +385,42 @@ static BOOL deltest7(struct smbcli_state *cli1, struct smbcli_state *cli2) FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_nt_delete_on_close(cli1->tree, fnum1, True), + "setting delete_on_close on file failed !"); - correct &= check_delete_on_close(cli1, fnum1, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, True, __location__); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, False))) { - printf("(%s) unsetting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, + smbcli_nt_delete_on_close(cli1->tree, fnum1, False), + "unsetting delete_on_close on file failed !"); - correct &= check_delete_on_close(cli1, fnum1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, False, __location__); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 2 failed (%s)", smbcli_errstr(cli1->tree))); /* This next open should succeed - we reset the flag. */ fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } - - printf("seventh delete on close test succeeded.\n"); - - fail: + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 2 failed (%s)", + smbcli_errstr(cli1->tree))); return correct; } /* Test 8 ... */ -static BOOL deltest8(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest8(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -565,12 +432,9 @@ static BOOL deltest8(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_DATA| @@ -580,57 +444,36 @@ static BOOL deltest8(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); - if (fnum2 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, + smbcli_nt_delete_on_close(cli1->tree, fnum1, True), + "setting delete_on_close on file failed !"); - correct &= check_delete_on_close(cli1, fnum1, fname, True, __location__); - correct &= check_delete_on_close(cli2, fnum2, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, True, __location__); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 1 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 1 failed (%s)", + smbcli_errstr(cli1->tree))); - correct &= check_delete_on_close(cli1, -1, fname, True, __location__); - correct &= check_delete_on_close(cli2, fnum2, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, -1, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, True, __location__); - if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli2->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli2->tree, fnum2), + talloc_asprintf(tctx, "close - 2 failed (%s)", smbcli_errstr(cli2->tree))); /* This should fail.. */ fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded should have been deleted on close !\n", - __location__, fname); - correct = False; - } else { - printf("eighth delete on close test succeeded.\n"); - } - - fail: + torture_assert(tctx, fnum1 == -1, + talloc_asprintf(tctx, "open of %s succeeded should have been deleted on close !\n", fname)); return correct; } /* Test 9 ... */ -static BOOL deltest9(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest9(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; @@ -644,21 +487,17 @@ static BOOL deltest9(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded should have failed!\n", - __location__, fname); - return False; - } + torture_assert(tctx, fnum1 == -1, + talloc_asprintf(tctx, "open of %s succeeded should have failed!", + fname)); - printf("ninth delete on close test succeeded.\n"); return True; } /* Test 10 ... */ -static BOOL deltest10(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest10(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; - BOOL correct = True; del_clean_area(cli1, cli2); @@ -670,39 +509,25 @@ static BOOL deltest10(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* This should delete the file. */ - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close failed (%s)", + smbcli_errstr(cli1->tree))); /* This should fail.. */ fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded should have been deleted on close !\n", - __location__, fname); - correct = False; - goto fail; - } else { - printf("tenth delete on close test succeeded.\n"); - } - - fail: - - return correct; + torture_assert(tctx, fnum1 == -1, + talloc_asprintf(tctx, "open of %s succeeded should have been deleted on close !", + fname)); + return true; } /* Test 11 ... */ -static BOOL deltest11(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest11(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; NTSTATUS status; @@ -717,32 +542,23 @@ static BOOL deltest11(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); status = smbcli_nt_delete_on_close(cli1->tree, fnum1, True); - if (!NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) { - printf("(%s) setting delete_on_close should fail with NT_STATUS_CANNOT_DELETE. Got %s instead)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_equal(tctx, status, NT_STATUS_CANNOT_DELETE, + talloc_asprintf(tctx, "setting delete_on_close should fail with NT_STATUS_CANNOT_DELETE. Got %s instead)", smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close failed (%s)", + smbcli_errstr(cli1->tree))); - printf("eleventh delete on close test succeeded.\n"); return True; } /* Test 12 ... */ -static BOOL deltest12(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest12(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; NTSTATUS status; @@ -759,32 +575,26 @@ static BOOL deltest12(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded. Should fail with " - "NT_STATUS_CANNOT_DELETE.\n", __location__, fname); - smbcli_close(cli1->tree, fnum1); - return False; - } else { - status = smbcli_nt_error(cli1->tree); - if (!NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) { - printf("(%s) setting delete_on_close on open should " + torture_assert(tctx, fnum1 == -1, + talloc_asprintf(tctx, "open of %s succeeded. Should fail with " + "NT_STATUS_CANNOT_DELETE.\n", fname)); + + status = smbcli_nt_error(cli1->tree); + torture_assert_ntstatus_equal(tctx, status, NT_STATUS_CANNOT_DELETE, + talloc_asprintf(tctx, "setting delete_on_close on open should " "fail with NT_STATUS_CANNOT_DELETE. Got %s " - "instead)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } - } + "instead)", + smbcli_errstr(cli1->tree))); - printf("twelvth delete on close test succeeded.\n"); - return True; + return true; } /* Test 13 ... */ -static BOOL deltest13(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest13(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -802,12 +612,9 @@ static BOOL deltest13(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_DATA| @@ -819,70 +626,48 @@ static BOOL deltest13(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); - if (fnum2 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli2->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, + "open of %s failed (%s)", + fname, smbcli_errstr(cli2->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, - True))) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, + smbcli_nt_delete_on_close(cli1->tree, fnum1, + True), + "setting delete_on_close on file failed !"); - correct &= check_delete_on_close(cli1, fnum1, fname, True, __location__); - correct &= check_delete_on_close(cli2, fnum2, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, True, __location__); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli2->tree, fnum2, - False))) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_nt_delete_on_close(cli2->tree, fnum2, + False), + "setting delete_on_close on file failed !"); - correct &= check_delete_on_close(cli1, fnum1, fname, False, __location__); - correct &= check_delete_on_close(cli2, fnum2, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, False, __location__); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 1 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 1 failed (%s)", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli2->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli2->tree, fnum2), + talloc_asprintf(tctx, "close - 2 failed (%s)", + smbcli_errstr(cli2->tree))); fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE); - if (fnum1 == -1) { - printf("(%s) open of %s failed!\n", - __location__, fname); - correct = False; - goto fail; - } - - printf("thirteenth delete on close test succeeded.\n"); + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed!", + fname)); - fail: + smbcli_close(cli1->tree, fnum1); return correct; } /* Test 14 ... */ -static BOOL deltest14(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest14(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int dnum1 = -1; - BOOL correct = True; + bool correct = true; del_clean_area(cli1, cli2); @@ -897,21 +682,13 @@ static BOOL deltest14(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_WRITE| NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_CREATE, 0, 0); - if (dnum1 == -1) { - printf("(%s) open of %s failed: %s!\n", - __location__, dname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, dnum1 != -1, talloc_asprintf(tctx, "open of %s failed: %s!", + dname, smbcli_errstr(cli1->tree))); - correct &= check_delete_on_close(cli1, dnum1, dname, False, __location__); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, dnum1, True))) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } - correct &= check_delete_on_close(cli1, dnum1, dname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, dnum1, dname, False, __location__); + torture_assert_ntstatus_ok(tctx, smbcli_nt_delete_on_close(cli1->tree, dnum1, True), + "setting delete_on_close on file failed !"); + correct &= check_delete_on_close(tctx, cli1, dnum1, dname, True, __location__); smbcli_close(cli1->tree, dnum1); /* Now it should be gone... */ @@ -925,26 +702,17 @@ static BOOL deltest14(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_WRITE| NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0); - if (dnum1 != -1) { - printf("(%s) setting delete_on_close on file succeeded !\n", - __location__); - correct = False; - goto fail; - } - - printf("fourteenth delete on close test succeeded.\n"); - - fail: + torture_assert(tctx, dnum1 == -1, "setting delete_on_close on file succeeded !"); return correct; } /* Test 15 ... */ -static BOOL deltest15(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest15(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; + bool correct = true; int fnum2 = -1; - BOOL correct = True; NTSTATUS status; del_clean_area(cli1, cli2); @@ -964,21 +732,12 @@ static BOOL deltest15(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open - 1 of %s failed (%s)", fname, smbcli_errstr(cli1->tree))); status = smbcli_rename(cli2->tree, fname, fname_new); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) renaming failed: %s !\n", - __location__, nt_errstr(status)); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, status, "renaming failed!"); fnum2 = smbcli_nt_create_full(cli2->tree, fname_new, 0, SEC_GENERIC_ALL, @@ -989,28 +748,21 @@ static BOOL deltest15(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum2 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname_new, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, + talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname_new, smbcli_errstr(cli1->tree))); status = smbcli_nt_delete_on_close(cli2->tree, fnum2, True); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, status, + "setting delete_on_close on file failed !"); smbcli_close(cli2->tree, fnum2); /* The file should be around under the new name, there's a second * handle open */ - correct &= check_delete_on_close(cli1, fnum1, fname_new, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname_new, True, __location__); fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_GENERIC_ALL, @@ -1021,14 +773,10 @@ static BOOL deltest15(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum2 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - correct &= check_delete_on_close(cli2, fnum2, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, False, __location__); smbcli_close(cli2->tree, fnum2); smbcli_close(cli1->tree, fnum1); @@ -1042,12 +790,8 @@ static BOOL deltest15(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OPEN, 0, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); smbcli_close(cli1->tree, fnum1); @@ -1060,27 +804,19 @@ static BOOL deltest15(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OPEN, 0, 0); - if (fnum1 != -1) { - printf("(%s) smbcli_open succeeded, should have " - "failed\n", __location__); - smbcli_close(cli1->tree, fnum1); - correct = False; - goto fail; - } - - printf("fifteenth delete on close test succeeded.\n"); - - fail: + torture_assert(tctx, fnum1 == -1, + "smbcli_open succeeded, should have " + "failed"); return correct; } /* Test 16 ... */ -static BOOL deltest16(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest16(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = true; del_clean_area(cli1, cli2); @@ -1102,19 +838,14 @@ static BOOL deltest16(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_CREATE, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert (tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", fname, smbcli_errstr(cli1->tree))); /* The delete on close bit is *not* reported as being set. */ - correct &= check_delete_on_close(cli1, fnum1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, False, __location__); /* The delete on close bit is *not* reported as being set. */ - correct &= check_delete_on_close(cli1, -1, fname, False, __location__); - correct &= check_delete_on_close(cli2, -1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, -1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli2, -1, fname, False, __location__); /* Now try opening again for read-only. */ fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, @@ -1126,49 +857,36 @@ static BOOL deltest16(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OPEN, 0, 0); - /* Should work. */ - if (fnum2 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - correct &= check_delete_on_close(cli1, fnum1, fname, False, __location__); - correct &= check_delete_on_close(cli1, -1, fname, False, __location__); - correct &= check_delete_on_close(cli2, fnum2, fname, False, __location__); - correct &= check_delete_on_close(cli2, -1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, -1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli2, -1, fname, False, __location__); smbcli_close(cli1->tree, fnum1); - correct &= check_delete_on_close(cli2, fnum2, fname, True, __location__); - correct &= check_delete_on_close(cli2, -1, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli2, fnum2, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli2, -1, fname, True, __location__); smbcli_close(cli2->tree, fnum2); /* And the file should be deleted ! */ fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded (should fail)\n", - __location__, fname); - correct = False; - goto fail; - } - - printf("sixteenth delete on close test succeeded.\n"); - - fail: + torture_assert(tctx, fnum1 == -1, talloc_asprintf(tctx, "open of %s succeeded (should fail)", + fname)); return correct; } /* Test 17 ... */ -static BOOL deltest17(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest17(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -1189,12 +907,8 @@ static BOOL deltest17(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_CREATE, 0, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* And close - just to create the file. */ smbcli_close(cli1->tree, fnum1); @@ -1209,15 +923,11 @@ static BOOL deltest17(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OPEN, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* The delete on close bit is *not* reported as being set. */ - correct &= check_delete_on_close(cli1, fnum1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, False, __location__); /* Now try opening again for read-only. */ fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, @@ -1231,45 +941,33 @@ static BOOL deltest17(struct smbcli_state *cli1, struct smbcli_state *cli2) 0, 0); /* Should work. */ - if (fnum2 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); /* still not reported as being set on either */ - correct &= check_delete_on_close(cli1, fnum1, fname, False, __location__); - correct &= check_delete_on_close(cli1, fnum2, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum2, fname, False, __location__); smbcli_close(cli1->tree, fnum1); - correct &= check_delete_on_close(cli1, fnum2, fname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum2, fname, False, __location__); smbcli_close(cli1->tree, fnum2); /* See if the file is deleted - shouldn't be.... */ fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); - if (fnum1 == -1) { - printf("(%s) open of %s failed (should succeed) - %s\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } - - printf("seventeenth delete on close test succeeded.\n"); - - fail: + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (should succeed) - %s", + fname, smbcli_errstr(cli1->tree))); return correct; } /* Test 18 ... */ -static BOOL deltest18(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest18(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -1293,15 +991,11 @@ static BOOL deltest18(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_CREATE, NTCREATEX_OPTIONS_DIRECTORY|NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, dname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + dname, smbcli_errstr(cli1->tree))); /* The delete on close bit is *not* reported as being set. */ - correct &= check_delete_on_close(cli1, fnum1, dname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, dname, False, __location__); /* Now try opening again for read-only. */ fnum2 = smbcli_nt_create_full(cli1->tree, dname, 0, @@ -1315,19 +1009,15 @@ static BOOL deltest18(struct smbcli_state *cli1, struct smbcli_state *cli2) /* Should work. */ - if (fnum2 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, dname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + dname, smbcli_errstr(cli1->tree))); - correct &= check_delete_on_close(cli1, fnum1, dname, False, __location__); - correct &= check_delete_on_close(cli1, fnum2, dname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, dname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum2, dname, False, __location__); smbcli_close(cli1->tree, fnum1); - correct &= check_delete_on_close(cli1, fnum2, dname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum2, dname, True, __location__); smbcli_close(cli1->tree, fnum2); @@ -1340,26 +1030,18 @@ static BOOL deltest18(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, NTCREATEX_OPTIONS_DIRECTORY, 0); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded (should fail)\n", - __location__, dname); - correct = False; - goto fail; - } - - printf("eighteenth delete on close test succeeded.\n"); - - fail: + torture_assert(tctx, fnum1 == -1, talloc_asprintf(tctx, "open of %s succeeded (should fail)", + dname)); return correct; } /* Test 19 ... */ -static BOOL deltest19(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest19(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int fnum2 = -1; - BOOL correct = True; + bool correct = True; del_clean_area(cli1, cli2); @@ -1379,12 +1061,8 @@ static BOOL deltest19(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_CREATE, NTCREATEX_OPTIONS_DIRECTORY, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, dname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + dname, smbcli_errstr(cli1->tree))); /* And close - just to create the directory. */ smbcli_close(cli1->tree, fnum1); @@ -1401,15 +1079,11 @@ static BOOL deltest19(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_DISP_OPEN, NTCREATEX_OPTIONS_DIRECTORY|NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0); - if (fnum1 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open - 1 of %s failed (%s)", fname, smbcli_errstr(cli1->tree))); /* The delete on close bit is *not* reported as being set. */ - correct &= check_delete_on_close(cli1, fnum1, dname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, dname, False, __location__); /* Now try opening again for read-only. */ fnum2 = smbcli_nt_create_full(cli1->tree, dname, 0, @@ -1422,16 +1096,12 @@ static BOOL deltest19(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_OPTIONS_DIRECTORY, 0); /* Should work. */ - if (fnum2 == -1) { - printf("(%s) open - 1 of %s failed (%s)\n", - __location__, dname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, "open - 1 of %s failed (%s)", + dname, smbcli_errstr(cli1->tree))); smbcli_close(cli1->tree, fnum1); - correct &= check_delete_on_close(cli1, fnum2, dname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum2, dname, True, __location__); smbcli_close(cli1->tree, fnum2); @@ -1447,26 +1117,18 @@ static BOOL deltest19(struct smbcli_state *cli1, struct smbcli_state *cli2) CHECK_STATUS(cli1, NT_STATUS_OBJECT_NAME_NOT_FOUND); - if (fnum1 != -1) { - printf("(%s) open of %s succeeded (should fail)\n", - __location__, dname); - correct = False; - goto fail; - } - - printf("nineteenth delete on close test succeeded.\n"); - - fail: + torture_assert(tctx, fnum1 == -1, + talloc_asprintf(tctx, "open of %s succeeded (should fail)", dname)); return correct; } /* Test 20 ... */ -static BOOL deltest20(struct smbcli_state *cli1, struct smbcli_state *cli2) +static bool deltest20(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2) { int fnum1 = -1; int dnum1 = -1; - BOOL correct = True; + bool correct = True; NTSTATUS status; del_clean_area(cli1, cli2); @@ -1485,14 +1147,10 @@ static BOOL deltest20(struct smbcli_state *cli1, struct smbcli_state *cli2) NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_CREATE, NTCREATEX_OPTIONS_DIRECTORY, 0); - if (dnum1 == -1) { - printf("(%s) open of %s failed: %s!\n", - __location__, dname, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, dnum1 != -1, talloc_asprintf(tctx, "open of %s failed: %s!", + dname, smbcli_errstr(cli1->tree))); - correct &= check_delete_on_close(cli1, dnum1, dname, False, __location__); + correct &= check_delete_on_close(tctx, cli1, dnum1, dname, False, __location__); status = smbcli_nt_delete_on_close(cli1->tree, dnum1, True); { @@ -1500,72 +1158,54 @@ static BOOL deltest20(struct smbcli_state *cli1, struct smbcli_state *cli2) asprintf(&fullname, "\\%s%s", dname, fname); fnum1 = smbcli_open(cli1->tree, fullname, O_CREAT|O_RDWR, DENY_NONE); - if (fnum1 != -1) { - printf("(%s) smbcli_open succeeded, should have " - "failed with NT_STATUS_DELETE_PENDING\n", - __location__); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 == -1, + "smbcli_open succeeded, should have " + "failed with NT_STATUS_DELETE_PENDING" + ); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), - NT_STATUS_DELETE_PENDING)) { - printf("(%s) smbcli_open returned %s, expected " - "NT_STATUS_DELETE_PENDING\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert_ntstatus_equal(tctx, + smbcli_nt_error(cli1->tree), + NT_STATUS_DELETE_PENDING, + "smbcli_open failed"); } status = smbcli_nt_delete_on_close(cli1->tree, dnum1, False); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) setting delete_on_close on file failed !\n", - __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, status, + "setting delete_on_close on file failed !"); { char *fullname; asprintf(&fullname, "\\%s%s", dname, fname); fnum1 = smbcli_open(cli1->tree, fullname, O_CREAT|O_RDWR, DENY_NONE); - if (fnum1 == -1) { - printf("(%s) smbcli_open failed: %s\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "smbcli_open failed: %s\n", + smbcli_errstr(cli1->tree))); smbcli_close(cli1->tree, fnum1); } status = smbcli_nt_delete_on_close(cli1->tree, dnum1, True); - if (!NT_STATUS_EQUAL(status, NT_STATUS_DIRECTORY_NOT_EMPTY)) { - printf("(%s) setting delete_on_close returned %s, expected " - "NT_STATUS_DIRECTORY_NOT_EMPTY\n", __location__, - smbcli_errstr(cli1->tree)); - correct = False; - goto fail; - } - + torture_assert_ntstatus_equal(tctx, status, NT_STATUS_DIRECTORY_NOT_EMPTY, + "setting delete_on_close failed"); smbcli_close(cli1->tree, dnum1); - printf("twentieth delete on close test succeeded.\n"); - - fail: - return correct; } /* Test 21 ... */ -static BOOL deltest21(struct smbcli_state **ppcli1, struct smbcli_state **ppcli2) +static bool deltest21(struct torture_context *tctx) { int fnum1 = -1; - struct smbcli_state *cli1 = *ppcli1; - struct smbcli_state *cli2 = *ppcli2; - BOOL correct = True; + struct smbcli_state *cli1; + struct smbcli_state *cli2; + bool correct = True; + + if (!torture_open_connection(&cli1, 0)) + return False; + + if (!torture_open_connection(&cli2, 1)) + return False; del_clean_area(cli1, cli2); @@ -1576,32 +1216,26 @@ static BOOL deltest21(struct smbcli_state **ppcli1, struct smbcli_state **ppcli2 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) open of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open of %s failed (%s)", + fname, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) { - printf("(%s) setting delete_on_close failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_nt_delete_on_close(cli1->tree, fnum1, True), + talloc_asprintf(tctx, "setting delete_on_close failed (%s)", + smbcli_errstr(cli1->tree))); /* Ensure delete on close is set. */ - correct &= check_delete_on_close(cli1, fnum1, fname, True, __location__); + correct &= check_delete_on_close(tctx, cli1, fnum1, fname, True, __location__); /* Now yank the rug from under cli1. */ smbcli_transport_dead(cli1->transport, NT_STATUS_LOCAL_DISCONNECT); fnum1 = -1; - if (!torture_open_connection(ppcli1, 0)) { + if (!torture_open_connection(&cli1, 0)) { return False; } - cli1 = *ppcli1; - /* On slow build farm machines it might happen that they are not fast * enogh to delete the file for this test */ msleep(200); @@ -1618,73 +1252,41 @@ static BOOL deltest21(struct smbcli_state **ppcli1, struct smbcli_state **ppcli2 CHECK_STATUS(cli1, NT_STATUS_OBJECT_NAME_NOT_FOUND); - printf("twenty-first delete on close test succeeded.\n"); - - fail: - return correct; } /* Test delete on close semantics. */ -BOOL torture_test_delete(struct torture_context *torture) +struct torture_suite *torture_test_delete(void) { - struct smbcli_state *cli1 = NULL; - struct smbcli_state *cli2 = NULL; - BOOL correct = True; - - printf("starting delete test\n"); - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - - if (!torture_open_connection(&cli2, 1)) { - printf("(%s) failed to open second connection.\n", - __location__); - correct = False; - goto fail; - } - - correct &= deltest1(cli1, cli2); - correct &= deltest2(cli1, cli2); - correct &= deltest3(cli1, cli2); - correct &= deltest4(cli1, cli2); - correct &= deltest5(cli1, cli2); - correct &= deltest6(cli1, cli2); - correct &= deltest7(cli1, cli2); - correct &= deltest8(cli1, cli2); - correct &= deltest9(cli1, cli2); - correct &= deltest10(cli1, cli2); - correct &= deltest11(cli1, cli2); - correct &= deltest12(cli1, cli2); - correct &= deltest13(cli1, cli2); - correct &= deltest14(cli1, cli2); - correct &= deltest15(cli1, cli2); + struct torture_suite *suite = torture_suite_create( + talloc_autofree_context(), + "DELETE"); + + torture_suite_add_2smb_test(suite, "deltest1", deltest1); + torture_suite_add_2smb_test(suite, "deltest2", deltest2); + torture_suite_add_2smb_test(suite, "deltest3", deltest3); + torture_suite_add_2smb_test(suite, "deltest4", deltest4); + torture_suite_add_2smb_test(suite, "deltest5", deltest5); + torture_suite_add_2smb_test(suite, "deltest6", deltest6); + torture_suite_add_2smb_test(suite, "deltest7", deltest7); + torture_suite_add_2smb_test(suite, "deltest8", deltest8); + torture_suite_add_2smb_test(suite, "deltest9", deltest9); + torture_suite_add_2smb_test(suite, "deltest10", deltest10); + torture_suite_add_2smb_test(suite, "deltest11", deltest11); + torture_suite_add_2smb_test(suite, "deltest12", deltest12); + torture_suite_add_2smb_test(suite, "deltest13", deltest13); + torture_suite_add_2smb_test(suite, "deltest14", deltest14); + torture_suite_add_2smb_test(suite, "deltest15", deltest15); if (!lp_parm_bool(-1, "target", "samba3", False)) { - correct &= deltest16(cli1, cli2); - correct &= deltest17(cli1, cli2); - correct &= deltest18(cli1, cli2); - correct &= deltest19(cli1, cli2); - correct &= deltest20(cli1, cli2); + torture_suite_add_2smb_test(suite, "deltest16", deltest16); + torture_suite_add_2smb_test(suite, "deltest17", deltest17); + torture_suite_add_2smb_test(suite, "deltest18", deltest18); + torture_suite_add_2smb_test(suite, "deltest19", deltest19); + torture_suite_add_2smb_test(suite, "deltest20", deltest20); } - correct &= deltest21(&cli1, &cli2); + torture_suite_add_simple_test(suite, "deltest21", deltest21); - if (!correct) { - printf("Failed delete test\n"); - } else { - printf("delete test ok !\n"); - } - - fail: - del_clean_area(cli1, cli2); - - if (!torture_close_connection(cli1)) { - correct = False; - } - if (!torture_close_connection(cli2)) { - correct = False; - } - return correct; + return suite; } diff --git a/source4/torture/basic/denytest.c b/source4/torture/basic/denytest.c index 86186c5667..cd724b1d4e 100644 --- a/source4/torture/basic/denytest.c +++ b/source4/torture/basic/denytest.c @@ -25,7 +25,6 @@ #include "libcli/libcli.h" #include "torture/util.h" -extern BOOL torture_showall; extern int torture_failures; #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0) @@ -1401,18 +1400,18 @@ static const struct { }; -static void progress_bar(uint_t i, uint_t total) +static void progress_bar(struct torture_context *tctx, uint_t i, uint_t total) { - printf("%5d/%5d\r", i, total); + torture_comment(tctx, "%5d/%5d\r", i, total); fflush(stdout); } /* this produces a matrix of deny mode behaviour for 1 connection */ -BOOL torture_denytest1(struct torture_context *torture) +BOOL torture_denytest1(struct torture_context *tctx, + struct smbcli_state *cli1) { - static struct smbcli_state *cli1; int fnum1, fnum2; int i; BOOL correct = True; @@ -1420,13 +1419,7 @@ BOOL torture_denytest1(struct torture_context *torture) const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"}; int failures=0; - if (!torture_open_connection(&cli1, 0)) { - return False; - } - - printf("starting denytest1\n"); - - printf("Testing deny modes with 1 connection\n"); + torture_comment(tctx, "Testing deny modes with 1 connection\n"); for (i=0;i<2;i++) { smbcli_unlink(cli1->tree, fnames[i]); @@ -1435,7 +1428,7 @@ BOOL torture_denytest1(struct torture_context *torture) smbcli_close(cli1->tree, fnum1); } - printf("testing %d entries\n", (int)ARRAY_SIZE(denytable1)); + torture_comment(tctx, "testing %d entries\n", (int)ARRAY_SIZE(denytable1)); GetTimeOfDay(&tv_start); @@ -1443,7 +1436,7 @@ BOOL torture_denytest1(struct torture_context *torture) enum deny_result res; const char *fname = fnames[denytable1[i].isexe]; - progress_bar(i, ARRAY_SIZE(denytable1)); + progress_bar(tctx, i, ARRAY_SIZE(denytable1)); fnum1 = smbcli_open(cli1->tree, fname, denytable1[i].mode1, @@ -1467,12 +1460,13 @@ BOOL torture_denytest1(struct torture_context *torture) } } - if (torture_showall || res != denytable1[i].result) { + if (lp_parm_bool(-1, "torture", "showall", False) || + res != denytable1[i].result) { int64_t tdif; GetTimeOfDay(&tv); tdif = usec_time_diff(&tv, &tv_start); tdif /= 1000; - printf("%lld: %s %8s %10s %8s %10s %s (correct=%s)\n", + torture_comment(tctx, "%lld: %s %8s %10s %8s %10s %s (correct=%s)\n", (long long)tdif, fname, denystr(denytable1[i].deny1), @@ -1497,11 +1491,7 @@ failed: smbcli_unlink(cli1->tree, fnames[i]); } - if (!torture_close_connection(cli1)) { - correct = False; - } - - printf("finshed denytest1 (%d failures)\n", failures); + torture_comment(tctx, "finshed denytest1 (%d failures)\n", failures); return correct; } @@ -1509,9 +1499,10 @@ failed: /* this produces a matrix of deny mode behaviour with 2 connections */ -BOOL torture_denytest2(struct torture_context *torture) +BOOL torture_denytest2(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - static struct smbcli_state *cli1, *cli2; int fnum1, fnum2; int i; BOOL correct = True; @@ -1519,15 +1510,6 @@ BOOL torture_denytest2(struct torture_context *torture) struct timeval tv, tv_start; int failures=0; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting denytest2\n"); - - printf("Testing deny modes with 2 connections\n"); - for (i=0;i<2;i++) { smbcli_unlink(cli1->tree, fnames[i]); fnum1 = smbcli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE); @@ -1541,7 +1523,7 @@ BOOL torture_denytest2(struct torture_context *torture) enum deny_result res; const char *fname = fnames[denytable2[i].isexe]; - progress_bar(i, ARRAY_SIZE(denytable1)); + progress_bar(tctx, i, ARRAY_SIZE(denytable1)); fnum1 = smbcli_open(cli1->tree, fname, denytable2[i].mode1, @@ -1565,12 +1547,13 @@ BOOL torture_denytest2(struct torture_context *torture) } } - if (torture_showall || res != denytable2[i].result) { + if (lp_parm_bool(-1, "torture", "showall", False) || + res != denytable2[i].result) { int64_t tdif; GetTimeOfDay(&tv); tdif = usec_time_diff(&tv, &tv_start); tdif /= 1000; - printf("%lld: %s %8s %10s %8s %10s %s (correct=%s)\n", + torture_comment(tctx, "%lld: %s %8s %10s %8s %10s %s (correct=%s)\n", (long long)tdif, fname, denystr(denytable2[i].deny1), @@ -1595,14 +1578,7 @@ failed: smbcli_unlink(cli1->tree, fnames[i]); } - if (!torture_close_connection(cli1)) { - correct = False; - } - if (!torture_close_connection(cli2)) { - correct = False; - } - - printf("finshed denytest2 (%d failures)\n", failures); + torture_comment(tctx, "finshed denytest2 (%d failures)\n", failures); return correct; } @@ -1611,23 +1587,13 @@ failed: /* simple test harness for playing with deny modes */ -BOOL torture_denytest3(struct torture_context *torture) +BOOL torture_denytest3(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; int fnum1, fnum2; const char *fname; - printf("starting deny3 test\n"); - - printf("Testing simple deny modes\n"); - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - if (!torture_open_connection(&cli2, 1)) { - return False; - } - fname = "\\deny_dos1.dat"; smbcli_unlink(cli1->tree, fname); @@ -1636,7 +1602,7 @@ BOOL torture_denytest3(struct torture_context *torture) if (fnum1 != -1) smbcli_close(cli1->tree, fnum1); if (fnum2 != -1) smbcli_close(cli1->tree, fnum2); smbcli_unlink(cli1->tree, fname); - printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); + torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2); fname = "\\deny_dos2.dat"; @@ -1647,11 +1613,7 @@ BOOL torture_denytest3(struct torture_context *torture) if (fnum1 != -1) smbcli_close(cli1->tree, fnum1); if (fnum2 != -1) smbcli_close(cli2->tree, fnum2); smbcli_unlink(cli1->tree, fname); - printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); - - - torture_close_connection(cli1); - torture_close_connection(cli2); + torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2); return True; } @@ -1758,7 +1720,8 @@ static NTSTATUS predict_share_conflict(uint32_t sa1, uint32_t am1, uint32_t sa2, /* a denytest for ntcreatex */ -static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *cli2, int client) +static BOOL torture_ntdenytest(struct torture_context *tctx, + struct smbcli_state *cli1, struct smbcli_state *cli2, int client) { const struct bit_value share_access_bits[] = { { NTCREATEX_SHARE_ACCESS_READ, "S_R" }, @@ -1787,7 +1750,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c int failures = 0; uint8_t buf[1]; - printf("format: server correct\n"); + torture_comment(tctx, "format: server correct\n"); ZERO_STRUCT(buf); @@ -1812,7 +1775,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c io1.ntcreatex.in.fname = fname; io2 = io1; - printf("testing %d entries on %s\n", torture_numops, fname); + torture_comment(tctx, "testing %d entries on %s\n", torture_numops, fname); for (i=0;i<torture_numops;i++) { NTSTATUS status1, status2, status2_p; @@ -1825,7 +1788,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c int b_am2 = random() & ((1<<nbits2)-1); BOOL read_for_execute; - progress_bar(i, torture_numops); + progress_bar(tctx, i, torture_numops); io1.ntcreatex.in.share_access = map_bits(share_access_bits, b_sa1, nbits1); io1.ntcreatex.in.access_mask = map_bits(access_mask_bits, b_am1, nbits2); @@ -1889,10 +1852,10 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c GetTimeOfDay(&tv); tdif = usec_time_diff(&tv, &tv_start); tdif /= 1000; - if (torture_showall || + if (lp_parm_bool(-1, "torture", "showall", False) || !NT_STATUS_EQUAL(status2, status2_p) || res != res2) { - printf("\n%-20s %-70s\n%-20s %-70s %4s %4s %s/%s\n", + torture_comment(tctx, "\n%-20s %-70s\n%-20s %-70s %4s %4s %s/%s\n", bit_string(mem_ctx, share_access_bits, b_sa1, nbits1), bit_string(mem_ctx, access_mask_bits, b_am1, nbits2), bit_string(mem_ctx, share_access_bits, b_sa2, nbits1), @@ -1916,7 +1879,7 @@ static BOOL torture_ntdenytest(struct smbcli_state *cli1, struct smbcli_state *c failed: smbcli_unlink(cli1->tree, fname); - printf("finshed ntdenytest (%d failures)\n", failures); + torture_comment(tctx, "finshed ntdenytest (%d failures)\n", failures); return correct; } @@ -1925,47 +1888,31 @@ failed: /* a denytest for ntcreatex */ -BOOL torture_ntdenytest1(struct smbcli_state *cli, int client) +BOOL torture_ntdenytest1(struct torture_context *tctx, struct smbcli_state *cli, int client) { extern int torture_seed; srandom(torture_seed + client); - printf("starting ntdenytest1 client %d\n", client); + torture_comment(tctx, "starting ntdenytest1 client %d\n", client); - return torture_ntdenytest(cli, cli, client); + return torture_ntdenytest(tctx, cli, cli, client); } /* a denytest for ntcreatex */ -BOOL torture_ntdenytest2(struct torture_context *torture) +BOOL torture_ntdenytest2(struct torture_context *torture, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; - BOOL ret; - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - - if (!torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting ntdenytest2\n"); - - ret = torture_ntdenytest(cli1, cli2, 0); - - torture_close_connection(cli1); - torture_close_connection(cli2); - - return ret; + return torture_ntdenytest(torture, cli1, cli2, 0); } #define CHECK_STATUS(status, correct) do { \ if (!NT_STATUS_EQUAL(status, correct)) { \ - printf("(%s) Incorrect status %s - should be %s\n", \ + torture_comment(tctx, "(%s) Incorrect status %s - should be %s\n", \ __location__, nt_errstr(status), nt_errstr(correct)); \ ret = False; \ goto done; \ @@ -1973,7 +1920,7 @@ BOOL torture_ntdenytest2(struct torture_context *torture) #define CHECK_VAL(v, correct) do { \ if ((v) != (correct)) { \ - printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \ + torture_comment(tctx, "(%s) wrong value for %s 0x%x - should be 0x%x\n", \ __location__, #v, (int)(v), (int)correct); \ ret = False; \ }} while (0) @@ -1981,9 +1928,9 @@ BOOL torture_ntdenytest2(struct torture_context *torture) /* test sharing of handles with DENY_DOS on a single connection */ -BOOL torture_denydos_sharing(struct torture_context *torture) +BOOL torture_denydos_sharing(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; union smb_open io; union smb_fileinfo finfo; const char *fname = "\\torture_denydos.txt"; @@ -1993,13 +1940,9 @@ BOOL torture_denydos_sharing(struct torture_context *torture) union smb_setfileinfo sfinfo; TALLOC_CTX *mem_ctx; - if (!torture_open_connection(&cli, 0)) { - return False; - } - mem_ctx = talloc_new(cli); - printf("Checking DENY_DOS shared handle semantics\n"); + torture_comment(tctx, "Checking DENY_DOS shared handle semantics\n"); smbcli_unlink(cli->tree, fname); io.openx.level = RAW_OPEN_OPENX; @@ -2013,7 +1956,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture) io.openx.in.size = 0; io.openx.in.timeout = 0; - printf("openx twice with RDWR/DENY_DOS\n"); + torture_comment(tctx, "openx twice with RDWR/DENY_DOS\n"); status = smb_raw_open(cli->tree, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum1 = io.openx.out.file.fnum; @@ -2022,7 +1965,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture) CHECK_STATUS(status, NT_STATUS_OK); fnum2 = io.openx.out.file.fnum; - printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); + torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2); sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION; sfinfo.position_information.in.file.fnum = fnum1; @@ -2030,7 +1973,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture) status = smb_raw_setfileinfo(cli->tree, &sfinfo); CHECK_STATUS(status, NT_STATUS_OK); - printf("two handles should be same file handle\n"); + torture_comment(tctx, "two handles should be same file handle\n"); finfo.position_information.level = RAW_FILEINFO_POSITION_INFORMATION; finfo.position_information.in.file.fnum = fnum1; status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo); @@ -2046,7 +1989,7 @@ BOOL torture_denydos_sharing(struct torture_context *torture) smbcli_close(cli->tree, fnum1); smbcli_close(cli->tree, fnum2); - printf("openx twice with RDWR/DENY_NONE\n"); + torture_comment(tctx, "openx twice with RDWR/DENY_NONE\n"); io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE; status = smb_raw_open(cli->tree, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_OK); @@ -2057,9 +2000,9 @@ BOOL torture_denydos_sharing(struct torture_context *torture) CHECK_STATUS(status, NT_STATUS_OK); fnum2 = io.openx.out.file.fnum; - printf("fnum1=%d fnum2=%d\n", fnum1, fnum2); + torture_comment(tctx, "fnum1=%d fnum2=%d\n", fnum1, fnum2); - printf("two handles should be separate\n"); + torture_comment(tctx, "two handles should be separate\n"); sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION; sfinfo.position_information.in.file.fnum = fnum1; sfinfo.position_information.in.position = 1000; diff --git a/source4/torture/basic/dir.c b/source4/torture/basic/dir.c index 01d25e5d4a..c86f134c32 100644 --- a/source4/torture/basic/dir.c +++ b/source4/torture/basic/dir.c @@ -34,22 +34,16 @@ static void list_fn(struct clilist_file_info *finfo, const char *name, void *sta /* test directory listing speed */ -BOOL torture_dirtest1(struct torture_context *torture) +BOOL torture_dirtest1(struct torture_context *tctx, + struct smbcli_state *cli) { int i; - struct smbcli_state *cli; int fnum; BOOL correct = True; extern int torture_numops; struct timeval tv; - printf("starting dirtest1\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("Creating %d random filenames\n", torture_numops); + torture_comment(tctx, "Creating %d random filenames\n", torture_numops); srandom(0); tv = timeval_current(); @@ -66,11 +60,11 @@ BOOL torture_dirtest1(struct torture_context *torture) free(fname); } - printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); - printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); - printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); + torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); + torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); + torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); - printf("dirtest core %g seconds\n", timeval_elapsed(&tv)); + torture_comment(tctx, "dirtest core %g seconds\n", timeval_elapsed(&tv)); srandom(0); for (i=0;i<torture_numops;i++) { @@ -80,34 +74,22 @@ BOOL torture_dirtest1(struct torture_context *torture) free(fname); } - if (!torture_close_connection(cli)) { - correct = False; - } - - printf("finished dirtest1\n"); - return correct; } -BOOL torture_dirtest2(struct torture_context *torture) +BOOL torture_dirtest2(struct torture_context *tctx, + struct smbcli_state *cli) { int i; - struct smbcli_state *cli; int fnum, num_seen; BOOL correct = True; extern int torture_entries; - printf("starting dirtest2\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - if (!torture_setup_dir(cli, "\\LISTDIR")) { return False; } - printf("Creating %d files\n", torture_entries); + torture_comment(tctx, "Creating %d files\n", torture_entries); /* Create torture_entries files and torture_entries directories. */ for (i=0;i<torture_entries;i++) { @@ -139,7 +121,7 @@ BOOL torture_dirtest2(struct torture_context *torture) /* Now ensure that doing an old list sees both files and directories. */ num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); - printf("num_seen = %d\n", num_seen ); + torture_comment(tctx, "num_seen = %d\n", num_seen ); /* We should see (torture_entries) each of files & directories + . and .. */ if (num_seen != (2*torture_entries)+2) { correct = False; @@ -152,7 +134,7 @@ BOOL torture_dirtest2(struct torture_context *torture) * relevant entries. */ num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); - printf("num_seen = %d\n", num_seen ); + torture_comment(tctx, "num_seen = %d\n", num_seen ); if (num_seen != torture_entries+2) { correct = False; fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", @@ -160,7 +142,7 @@ BOOL torture_dirtest2(struct torture_context *torture) } num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); - printf("num_seen = %d\n", num_seen ); + torture_comment(tctx, "num_seen = %d\n", num_seen ); if (num_seen != torture_entries) { correct = False; fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", @@ -175,16 +157,10 @@ BOOL torture_dirtest2(struct torture_context *torture) } #if 0 - printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); - printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); - printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); + torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); + torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); + torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); #endif - if (!torture_close_connection(cli)) { - correct = False; - } - - printf("finished dirtest1\n"); - return correct; } diff --git a/source4/torture/basic/disconnect.c b/source4/torture/basic/disconnect.c index 92cb828606..348f59d057 100644 --- a/source4/torture/basic/disconnect.c +++ b/source4/torture/basic/disconnect.c @@ -129,11 +129,11 @@ static BOOL test_disconnect_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) */ BOOL torture_disconnect(struct torture_context *torture) { - struct smbcli_state *cli; BOOL ret = True; TALLOC_CTX *mem_ctx; int i; extern int torture_numops; + struct smbcli_state *cli; mem_ctx = talloc_init("torture_raw_mux"); @@ -169,7 +169,6 @@ BOOL torture_disconnect(struct torture_context *torture) smb_raw_exit(cli->session); smbcli_deltree(cli->tree, BASEDIR); - torture_close_connection(cli); talloc_free(mem_ctx); return ret; } diff --git a/source4/torture/basic/locking.c b/source4/torture/basic/locking.c index c4aae64ca8..c966c667e6 100644 --- a/source4/torture/basic/locking.c +++ b/source4/torture/basic/locking.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/libcli.h" +#include "torture/ui.h" #include "torture/util.h" #include "torture/torture.h" #include "system/time.h" @@ -38,150 +39,113 @@ must not use posix semantics) 2) support for lock timeouts */ -BOOL torture_locktest1(struct torture_context *torture) +bool torture_locktest1(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt1.lck"; int fnum1, fnum2, fnum3; time_t t1, t2; uint_t lock_timeout; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest1\n"); - if (!torture_setup_dir(cli1, BASEDIR)) { return False; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, + "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("(%s) open2 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx, + "open2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); fnum3 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); - if (fnum3 == -1) { - printf("open3 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); - return False; - } + torture_assert(tctx, fnum3 != -1, talloc_asprintf(tctx, + "open3 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree))); - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, "lock1 failed (%s)", smbcli_errstr(cli1->tree))); + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug\n"); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug\n"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 5, 9, 0, WRITE_LOCK))) { - printf("lock1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli1->tree, fnum1, 5, 9, 0, WRITE_LOCK), + talloc_asprintf(tctx, + "lock1 failed (%s)", smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 5, 9, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 5, 9, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - } - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - } - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock2 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; lock_timeout = (6 + (random() % 20)); - printf("Testing lock timeout with timeout=%u\n", lock_timeout); + torture_comment(tctx, "Testing lock timeout with timeout=%u\n", + lock_timeout); t1 = time(NULL); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK))) { - printf("lock3 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)), + "lock3 succeeded! This is a locking bug\n"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } t2 = time(NULL); if (t2 - t1 < 5) { - printf("error: This server appears not to support timed lock requests\n"); + torture_fail(tctx, + "error: This server appears not to support timed lock requests"); } - printf("server slept for %u seconds for a %u second timeout\n", + torture_comment(tctx, "server slept for %u seconds for a %u second timeout\n", (uint_t)(t2-t1), lock_timeout); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) { - printf("close1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum2), + talloc_asprintf(tctx, "close1 failed (%s)", smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock4 succeeded! This is a locking bug\n"); - return False; - } else { - if (!check_error(__location__, cli2, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum3))) { - printf("close3 failed (%s)\n", smbcli_errstr(cli2->tree)); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock4 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli2, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; - if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, fname))) { - printf("unlink failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli1->tree))); + torture_assert_ntstatus_ok(tctx, smbcli_close(cli2->tree, fnum3), + talloc_asprintf(tctx, "close3 failed (%s)", smbcli_errstr(cli2->tree))); - if (!torture_close_connection(cli1)) { - return False; - } - - if (!torture_close_connection(cli2)) { - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_unlink(cli1->tree, fname), + talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(cli1->tree))); - printf("Passed locktest1\n"); - return True; + return true; } @@ -196,139 +160,110 @@ BOOL torture_locktest1(struct torture_context *torture) 3) the server denies unlock requests by an incorrect client PID */ -BOOL torture_locktest2(struct torture_context *torture) +bool torture_locktest2(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname = BASEDIR "\\lockt2.lck"; int fnum1, fnum2, fnum3; - BOOL correct = True; - - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("starting locktest2\n"); if (!torture_setup_dir(cli, BASEDIR)) { return False; } - printf("Testing pid context\n"); + torture_comment(tctx, "Testing pid context\n"); cli->session->pid = 1; fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, + "open of %s failed (%s)", fname, smbcli_errstr(cli->tree))); fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("(%s) open2 of %s failed (%s)\n", - __location__, fname, smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, + talloc_asprintf(tctx, "open2 of %s failed (%s)", + fname, smbcli_errstr(cli->tree))); cli->session->pid = 2; fnum3 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE); - if (fnum3 == -1) { - printf("open3 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, fnum3 != -1, + talloc_asprintf(tctx, + "open3 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree))); cli->session->pid = 1; - if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("lock1 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, + "lock1 failed (%s)", smbcli_errstr(cli->tree))); - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { - printf("WRITE lock1 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum1, 0, 4, 0, WRITE_LOCK)), + "WRITE lock1 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, WRITE_LOCK))) { - printf("WRITE lock2 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, WRITE_LOCK)), + "WRITE lock2 succeeded! This is a locking bug"); - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, READ_LOCK))) { - printf("READ lock2 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, - NT_STATUS_FILE_LOCK_CONFLICT)) return False; - } + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum1, 100, 4, 0, WRITE_LOCK))) { - printf("lock at 100 failed (%s)\n", smbcli_errstr(cli->tree)); - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum2, 0, 4, 0, READ_LOCK)), + "READ lock2 succeeded! This is a locking bug"); + + if (!check_error(__location__, cli, ERRDOS, ERRlock, + NT_STATUS_FILE_LOCK_CONFLICT)) return False; + + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli->tree, fnum1, 100, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, + "lock at 100 failed (%s)", smbcli_errstr(cli->tree))); cli->session->pid = 2; - if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 100, 4))) { - printf("unlock at 100 succeeded! This is a locking bug\n"); - correct = False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 100, 4)), + "unlock at 100 succeeded! This is a locking bug"); - if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 4))) { - printf("unlock1 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, - ERRDOS, ERRnotlocked, - NT_STATUS_RANGE_NOT_LOCKED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 4)), + "unlock1 succeeded! This is a locking bug"); - if (NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 8))) { - printf("unlock2 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, + if (!check_error(__location__, cli, ERRDOS, ERRnotlocked, NT_STATUS_RANGE_NOT_LOCKED)) return False; - } - if (NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum3, 0, 4, 0, WRITE_LOCK))) { - printf("lock3 succeeded! This is a locking bug\n"); - correct = False; - } else { - if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_unlock(cli->tree, fnum1, 0, 8)), + "unlock2 succeeded! This is a locking bug"); - cli->session->pid = 1; + if (!check_error(__location__, cli, + ERRDOS, ERRnotlocked, + NT_STATUS_RANGE_NOT_LOCKED)) return False; - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) { - printf("close1 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli->tree, fnum3, 0, 4, 0, WRITE_LOCK)), + "lock3 succeeded! This is a locking bug"); - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum2))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + if (!check_error(__location__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; - if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum3))) { - printf("close3 failed (%s)\n", smbcli_errstr(cli->tree)); - return False; - } + cli->session->pid = 1; - if (!torture_close_connection(cli)) { - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum1), + talloc_asprintf(tctx, "close1 failed (%s)", smbcli_errstr(cli->tree))); - printf("locktest2 finished\n"); + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum2), + talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli->tree))); - return correct; + torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum3), + talloc_asprintf(tctx, "close3 failed (%s)", smbcli_errstr(cli->tree))); + + return true; } @@ -337,157 +272,113 @@ BOOL torture_locktest2(struct torture_context *torture) 1) the server supports the full offset range in lock requests */ -BOOL torture_locktest3(struct torture_context *torture) +bool torture_locktest3(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt3.lck"; int fnum1, fnum2, i; uint32_t offset; - BOOL correct = True; extern int torture_numops; #define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest3\n"); - - printf("Testing 32 bit offset ranges\n"); + torture_comment(tctx, "Testing 32 bit offset ranges"); if (!torture_setup_dir(cli1, BASEDIR)) { return False; } fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum1 == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, + talloc_asprintf(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree))); fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE); - if (fnum2 == -1) { - printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree)); - return False; - } + torture_assert(tctx, fnum2 != -1, + talloc_asprintf(tctx, "open2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree))); - printf("Establishing %d locks\n", torture_numops); + torture_comment(tctx, "Establishing %d locks\n", torture_numops); for (offset=i=0;i<torture_numops;i++) { NEXT_OFFSET; - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK))) { - printf("lock1 %d failed (%s)\n", - i, - smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK), + talloc_asprintf(tctx, "lock1 %d failed (%s)", i, smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK))) { - printf("lock2 %d failed (%s)\n", - i, - smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, + smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK), + talloc_asprintf(tctx, "lock2 %d failed (%s)", + i, smbcli_errstr(cli1->tree))); } - printf("Testing %d locks\n", torture_numops); + torture_comment(tctx, "Testing %d locks\n", torture_numops); for (offset=i=0;i<torture_numops;i++) { NEXT_OFFSET; - if (NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-2, 1, 0, WRITE_LOCK))) { - printf("error: lock1 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-2, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock1 %d succeeded!", i)); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-1, 1, 0, WRITE_LOCK))) { - printf("error: lock2 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-1, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock2 %d succeeded!", i)); - if (NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK))) { - printf("error: lock3 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, offset-1, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock3 %d succeeded!", i)); - if (NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK))) { - printf("error: lock4 %d succeeded!\n", i); - return False; - } + torture_assert(tctx, + !NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, offset-2, 1, 0, WRITE_LOCK)), + talloc_asprintf(tctx, "error: lock4 %d succeeded!", i)); } - printf("Removing %d locks\n", torture_numops); + torture_comment(tctx, "Removing %d locks\n", torture_numops); for (offset=i=0;i<torture_numops;i++) { NEXT_OFFSET; - if (NT_STATUS_IS_ERR(smbcli_unlock(cli1->tree, fnum1, offset-1, 1))) { - printf("unlock1 %d failed (%s)\n", + torture_assert_ntstatus_ok(tctx, + smbcli_unlock(cli1->tree, fnum1, offset-1, 1), + talloc_asprintf(tctx, "unlock1 %d failed (%s)", i, - smbcli_errstr(cli1->tree)); - return False; - } + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_unlock(cli2->tree, fnum2, offset-2, 1))) { - printf("unlock2 %d failed (%s)\n", + torture_assert_ntstatus_ok(tctx, + smbcli_unlock(cli2->tree, fnum2, offset-2, 1), + talloc_asprintf(tctx, "unlock2 %d failed (%s)", i, - smbcli_errstr(cli1->tree)); - return False; - } - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("close1 failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) { - printf("close2 failed (%s)\n", smbcli_errstr(cli2->tree)); - return False; + smbcli_errstr(cli1->tree))); } - if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, fname))) { - printf("unlink failed (%s)\n", smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close1 failed (%s)", smbcli_errstr(cli1->tree))); - if (!torture_close_connection(cli1)) { - correct = False; - } - - if (!torture_close_connection(cli2)) { - correct = False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli2->tree, fnum2), + talloc_asprintf(tctx, "close2 failed (%s)", smbcli_errstr(cli2->tree))); - printf("finished locktest3\n"); + torture_assert_ntstatus_ok(tctx, smbcli_unlink(cli1->tree, fname), + talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(cli1->tree))); - return correct; + return true; } #define EXPECTED(ret, v) if ((ret) != (v)) { \ - printf("** "); correct = False; \ + torture_comment(tctx, "** "); correct = False; \ } /* looks at overlapping locks */ -BOOL torture_locktest4(struct torture_context *torture) +BOOL torture_locktest4(struct torture_context *tctx, + struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt4.lck"; int fnum1, fnum2, f; BOOL ret; uint8_t buf[1000]; BOOL correct = True; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest4\n"); - if (!torture_setup_dir(cli1, BASEDIR)) { return False; } @@ -498,7 +389,7 @@ BOOL torture_locktest4(struct torture_context *torture) memset(buf, 0, sizeof(buf)); if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file\n"); + torture_comment(tctx, "Failed to create file\n"); correct = False; goto fail; } @@ -506,74 +397,74 @@ BOOL torture_locktest4(struct torture_context *torture) ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 2, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("the same process %s set overlapping write locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 10, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 12, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s set overlapping read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 20, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 22, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different connection %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 30, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 32, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different connection %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 40, 4, 0, WRITE_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 42, 4, 0, WRITE_LOCK))); EXPECTED(ret, False); - printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different pid %s set overlapping write locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 50, 4, 0, READ_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 52, 4, 0, READ_LOCK))); EXPECTED(ret, True); - printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "a different pid %s set overlapping read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 60, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s set the same read lock twice\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set the same read lock twice\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 70, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("the same process %s set the same write lock twice\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s set the same write lock twice\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 80, 4, 0, WRITE_LOCK)); EXPECTED(ret, False); - printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 90, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK((cli1->session->pid = 1, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, WRITE_LOCK))) && NT_STATUS_IS_OK((cli1->session->pid = 2, smbcli_lock(cli1->tree, fnum1, 100, 4, 0, READ_LOCK))); EXPECTED(ret, False); - printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 110, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 112, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 110, 6)); EXPECTED(ret, False); - printf("the same process %s coalesce read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s coalesce read locks\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 120, 4, 0, WRITE_LOCK)) && (smbcli_read(cli2->tree, fnum2, buf, 120, 4) == 4); EXPECTED(ret, False); - printf("this server %s strict write locking\n", ret?"doesn't do":"does"); + torture_comment(tctx, "this server %s strict write locking\n", ret?"doesn't do":"does"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 130, 4) == 4); EXPECTED(ret, False); - printf("this server %s strict read locking\n", ret?"doesn't do":"does"); + torture_comment(tctx, "this server %s strict read locking\n", ret?"doesn't do":"does"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 140, 4, 0, READ_LOCK)) && @@ -581,7 +472,7 @@ BOOL torture_locktest4(struct torture_context *torture) NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 140, 4)); EXPECTED(ret, True); - printf("this server %s do recursive read locking\n", ret?"does":"doesn't"); + torture_comment(tctx, "this server %s do recursive read locking\n", ret?"does":"doesn't"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 150, 4, 0, WRITE_LOCK)) && @@ -591,21 +482,21 @@ BOOL torture_locktest4(struct torture_context *torture) !(smbcli_write(cli2->tree, fnum2, 0, buf, 150, 4) == 4) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 150, 4)); EXPECTED(ret, True); - printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't"); + torture_comment(tctx, "this server %s do recursive lock overlays\n", ret?"does":"doesn't"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 160, 4, 0, READ_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 160, 4)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 160, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 160, 4) == 4); EXPECTED(ret, True); - printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 170, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 170, 4)) && (smbcli_write(cli2->tree, fnum2, 0, buf, 170, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 170, 4) == 4); EXPECTED(ret, True); - printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 190, 4, 0, READ_LOCK)) && @@ -613,7 +504,7 @@ BOOL torture_locktest4(struct torture_context *torture) !(smbcli_write(cli2->tree, fnum2, 0, buf, 190, 4) == 4) && (smbcli_read(cli2->tree, fnum2, buf, 190, 4) == 4); EXPECTED(ret, True); - printf("the same process %s remove the first lock first\n", ret?"does":"doesn't"); + torture_comment(tctx, "the same process %s remove the first lock first\n", ret?"does":"doesn't"); smbcli_close(cli1->tree, fnum1); smbcli_close(cli2->tree, fnum2); @@ -627,38 +518,28 @@ BOOL torture_locktest4(struct torture_context *torture) smbcli_close(cli1->tree, f); smbcli_close(cli1->tree, fnum1); EXPECTED(ret, True); - printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); + torture_comment(tctx, "the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't"); fail: smbcli_close(cli1->tree, fnum1); smbcli_close(cli2->tree, fnum2); smbcli_unlink(cli1->tree, fname); - torture_close_connection(cli1); - torture_close_connection(cli2); - printf("finished locktest4\n"); return correct; } /* looks at lock upgrade/downgrade. */ -BOOL torture_locktest5(struct torture_context *torture) +BOOL torture_locktest5(struct torture_context *tctx, struct smbcli_state *cli1, + struct smbcli_state *cli2) { - struct smbcli_state *cli1, *cli2; const char *fname = BASEDIR "\\lockt5.lck"; int fnum1, fnum2, fnum3; BOOL ret; uint8_t buf[1000]; BOOL correct = True; - if (!torture_open_connection(&cli1, 0) || - !torture_open_connection(&cli2, 1)) { - return False; - } - - printf("starting locktest5\n"); - if (!torture_setup_dir(cli1, BASEDIR)) { return False; } @@ -669,11 +550,8 @@ BOOL torture_locktest5(struct torture_context *torture) memset(buf, 0, sizeof(buf)); - if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file\n"); - correct = False; - goto fail; - } + torture_assert(tctx, smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) == sizeof(buf), + "Failed to create file"); /* Check for NT bug... */ ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 8, 0, READ_LOCK)) && @@ -682,7 +560,7 @@ BOOL torture_locktest5(struct torture_context *torture) fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 7, 1, 0, WRITE_LOCK)); EXPECTED(ret, True); - printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); + torture_comment(tctx, "this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); smbcli_close(cli1->tree, fnum1); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE); smbcli_unlock(cli1->tree, fnum3, 0, 1); @@ -690,12 +568,12 @@ BOOL torture_locktest5(struct torture_context *torture) ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK)) && NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 1, 1, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); EXPECTED(ret, False); - printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); + torture_comment(tctx, "a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot"); /* Unlock the process 2 lock. */ smbcli_unlock(cli2->tree, fnum2, 0, 4); @@ -703,7 +581,7 @@ BOOL torture_locktest5(struct torture_context *torture) ret = NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum3, 0, 4, 0, READ_LOCK)); EXPECTED(ret, False); - printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); + torture_comment(tctx, "the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot"); /* Unlock the process 1 fnum3 lock. */ smbcli_unlock(cli1->tree, fnum3, 0, 4); @@ -713,7 +591,7 @@ BOOL torture_locktest5(struct torture_context *torture) NT_STATUS_IS_OK(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the same process %s stack read locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s stack read locks\n", ret?"can":"cannot"); /* Unlock the first process lock, then check this was the WRITE lock that was removed. */ @@ -722,7 +600,7 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, READ_LOCK)); EXPECTED(ret, True); - printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ"); + torture_comment(tctx, "the first unlock removes the %s lock\n", ret?"WRITE":"READ"); /* Unlock the process 2 lock. */ smbcli_unlock(cli2->tree, fnum2, 0, 4); @@ -734,32 +612,23 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); EXPECTED(ret, True); - printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); + torture_comment(tctx, "the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot"); /* Ensure the next unlock fails. */ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)); EXPECTED(ret, False); - printf("the same process %s count the lock stack\n", !ret?"can":"cannot"); + torture_comment(tctx, "the same process %s count the lock stack\n", !ret?"can":"cannot"); /* Ensure connection 2 can get a write lock. */ ret = NT_STATUS_IS_OK(smbcli_lock(cli2->tree, fnum2, 0, 4, 0, WRITE_LOCK)); EXPECTED(ret, True); - printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); + torture_comment(tctx, "a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot"); - fail: smbcli_close(cli1->tree, fnum1); smbcli_close(cli2->tree, fnum2); smbcli_unlink(cli1->tree, fname); - if (!torture_close_connection(cli1)) { - correct = False; - } - if (!torture_close_connection(cli2)) { - correct = False; - } - - printf("finished locktest5\n"); return correct; } @@ -767,51 +636,42 @@ ret = NT_STATUS_IS_OK(smbcli_unlock(cli1->tree, fnum1, 0, 4)) && /* tries the unusual lockingX locktype bits */ -BOOL torture_locktest6(struct torture_context *torture) +BOOL torture_locktest6(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname[1] = { "\\lock6.txt" }; int i; int fnum; NTSTATUS status; - if (!torture_open_connection(&cli, 0)) { - return False; - } - if (!torture_setup_dir(cli, BASEDIR)) { return False; } - printf("starting locktest6\n"); - for (i=0;i<1;i++) { - printf("Testing %s\n", fname[i]); + torture_comment(tctx, "Testing %s\n", fname[i]); smbcli_unlink(cli->tree, fname[i]); fnum = smbcli_open(cli->tree, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE); status = smbcli_locktype(cli->tree, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE); smbcli_close(cli->tree, fnum); - printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); + torture_comment(tctx, "CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); fnum = smbcli_open(cli->tree, fname[i], O_RDWR, DENY_NONE); status = smbcli_locktype(cli->tree, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK); smbcli_close(cli->tree, fnum); - printf("CANCEL_LOCK gave %s\n", nt_errstr(status)); + torture_comment(tctx, "CANCEL_LOCK gave %s\n", nt_errstr(status)); smbcli_unlink(cli->tree, fname[i]); } - torture_close_connection(cli); - - printf("finished locktest6\n"); return True; } -BOOL torture_locktest7(struct torture_context *torture) +BOOL torture_locktest7(struct torture_context *tctx, + struct smbcli_state *cli1) { - struct smbcli_state *cli1; const char *fname = BASEDIR "\\lockt7.lck"; int fnum1; int fnum2 = -1; @@ -819,158 +679,109 @@ BOOL torture_locktest7(struct torture_context *torture) uint8_t buf[200]; BOOL correct = False; - if (!torture_open_connection(&cli1, 0)) { - return False; - } - - printf("starting locktest7\n"); - - if (!torture_setup_dir(cli1, BASEDIR)) { - return False; - } + torture_assert(tctx, torture_setup_dir(cli1, BASEDIR), + talloc_asprintf(tctx, "Unable to set up %s", BASEDIR)); fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); memset(buf, 0, sizeof(buf)); - if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { - printf("Failed to create file (%s)\n", __location__); - goto fail; - } + torture_assert(tctx, smbcli_write(cli1->tree, fnum1, 0, buf, 0, sizeof(buf)) == sizeof(buf), + "Failed to create file"); cli1->session->pid = 1; - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK))) { - printf("Unable to apply read lock on range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully locked range 130:4 for READ\n"); - } + torture_assert_ntstatus_ok(tctx, smbcli_lock(cli1->tree, fnum1, 130, 4, 0, READ_LOCK), + talloc_asprintf(tctx, "Unable to apply read lock on range 130:4, error was %s", + smbcli_errstr(cli1->tree))); - if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid1 unable to read the range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully read the range 130:4\n"); - } + torture_comment(tctx, "pid1 successfully locked range 130:4 for READ\n"); + + torture_assert(tctx, smbcli_read(cli1->tree, fnum1, buf, 130, 4) == 4, + talloc_asprintf(tctx, "pid1 unable to read the range 130:4, error was %s)", + smbcli_errstr(cli1->tree))); + + torture_comment(tctx, "pid1 successfully read the range 130:4\n"); if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", - __location__); - goto fail; - } + torture_comment(tctx, "pid1 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + torture_assert_ntstatus_equal(tctx, smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT, + "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)"); } else { - printf("pid1 successfully wrote to the range 130:4 (should be denied) (%s)\n", - __location__); - goto fail; + torture_fail(tctx, "pid1 successfully wrote to the range 130:4 (should be denied)"); } cli1->session->pid = 2; if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + torture_comment(tctx, "pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); } else { - printf("pid2 successfully read the range 130:4\n"); + torture_comment(tctx, "pid2 successfully read the range 130:4\n"); } if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", - __location__); - goto fail; - } + torture_comment(tctx, "pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); + torture_assert_ntstatus_equal(tctx, smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT, + "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)"); } else { - printf("pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", - __location__); - goto fail; + torture_fail(tctx, "pid2 successfully wrote to the range 130:4 (should be denied)"); } cli1->session->pid = 1; smbcli_unlock(cli1->tree, fnum1, 130, 4); - if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 130, 4, 0, WRITE_LOCK))) { - printf("Unable to apply write lock on range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully locked range 130:4 for WRITE\n"); - } + torture_assert_ntstatus_ok(tctx, smbcli_lock(cli1->tree, fnum1, 130, 4, 0, WRITE_LOCK), + talloc_asprintf(tctx, "Unable to apply write lock on range 130:4, error was %s", + smbcli_errstr(cli1->tree))); + torture_comment(tctx, "pid1 successfully locked range 130:4 for WRITE\n"); - if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid1 unable to read the range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully read the range 130:4\n"); - } + torture_assert(tctx, smbcli_read(cli1->tree, fnum1, buf, 130, 4) == 4, + talloc_asprintf(tctx, "pid1 unable to read the range 130:4, error was %s", + smbcli_errstr(cli1->tree))); + torture_comment(tctx, "pid1 successfully read the range 130:4\n"); - if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid1 unable to write to the range 130:4, error was %s (%s)\n", - smbcli_errstr(cli1->tree), __location__); - goto fail; - } else { - printf("pid1 successfully wrote to the range 130:4\n"); - } + torture_assert(tctx, smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) == 4, + talloc_asprintf(tctx, "pid1 unable to write to the range 130:4, error was %s", + smbcli_errstr(cli1->tree))); + torture_comment(tctx, "pid1 successfully wrote to the range 130:4\n"); cli1->session->pid = 2; if (smbcli_read(cli1->tree, fnum1, buf, 130, 4) != 4) { - printf("pid2 unable to read the range 130:4, error was %s\n", + torture_comment(tctx, "pid2 unable to read the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); - if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", - __location__); - goto fail; - } + torture_assert_ntstatus_equal(tctx, smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT, + "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)"); } else { - printf("pid2 successfully read the range 130:4 (should be denied) (%s)\n", - __location__); - goto fail; + torture_fail(tctx, "pid2 successfully read the range 130:4 (should be denied)"); } if (smbcli_write(cli1->tree, fnum1, 0, buf, 130, 4) != 4) { - printf("pid2 unable to write to the range 130:4, error was %s\n", + torture_comment(tctx, "pid2 unable to write to the range 130:4, error was %s\n", smbcli_errstr(cli1->tree)); if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_FILE_LOCK_CONFLICT)) { - printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", + torture_comment(tctx, "Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) (%s)\n", __location__); goto fail; } } else { - printf("pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", + torture_comment(tctx, "pid2 successfully wrote to the range 130:4 (should be denied) (%s)\n", __location__); goto fail; } - printf("Testing truncate of locked file.\n"); + torture_comment(tctx, "Testing truncate of locked file.\n"); fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); - if (fnum2 == -1) { - printf("Unable to truncate locked file (%s)\n", __location__); - correct = False; - goto fail; - } else { - printf("Truncated locked file.\n"); - } + torture_assert(tctx, fnum2 != -1, "Unable to truncate locked file"); - if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &size, NULL))) { - printf("getatr failed (%s) (%s)\n", smbcli_errstr(cli1->tree), __location__); - correct = False; - goto fail; - } + torture_comment(tctx, "Truncated locked file.\n"); - if (size != 0) { - printf("Unable to truncate locked file. Size was %u (%s)\n", - (unsigned)size, __location__); - correct = False; - goto fail; - } + torture_assert_ntstatus_ok(tctx, smbcli_getatr(cli1->tree, fname, NULL, &size, NULL), + talloc_asprintf(tctx, "getatr failed (%s)", smbcli_errstr(cli1->tree))); + + torture_assert(tctx, size == 0, talloc_asprintf(tctx, "Unable to truncate locked file. Size was %u", (unsigned)size)); cli1->session->pid = 1; @@ -981,9 +792,21 @@ fail: smbcli_close(cli1->tree, fnum1); smbcli_close(cli1->tree, fnum2); smbcli_unlink(cli1->tree, fname); - torture_close_connection(cli1); - printf("finished locktest7\n"); return correct; } +struct torture_suite *torture_base_locktest(void) +{ + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), + "LOCK"); + torture_suite_add_2smb_test(suite, "LOCK1", torture_locktest1); + torture_suite_add_1smb_test(suite, "LOCK2", torture_locktest2); + torture_suite_add_2smb_test(suite, "LOCK3", torture_locktest3); + torture_suite_add_2smb_test(suite, "LOCK4", torture_locktest4); + torture_suite_add_2smb_test(suite, "LOCK5", torture_locktest5); + torture_suite_add_1smb_test(suite, "LOCK6", torture_locktest6); + torture_suite_add_1smb_test(suite, "LOCK7", torture_locktest7); + + return suite; +} diff --git a/source4/torture/basic/mangle_test.c b/source4/torture/basic/mangle_test.c index 7e17adece7..091e471e8a 100644 --- a/source4/torture/basic/mangle_test.c +++ b/source4/torture/basic/mangle_test.c @@ -155,18 +155,12 @@ static void gen_name(char *name) } -BOOL torture_mangle(struct torture_context *torture) +BOOL torture_mangle(struct torture_context *torture, + struct smbcli_state *cli) { extern int torture_numops; - static struct smbcli_state *cli; int i; - printf("starting mangle test\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - /* we will use an internal tdb to store the names we have used */ tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); if (!tdb) { @@ -203,8 +197,5 @@ BOOL torture_mangle(struct torture_context *torture) printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", collisions, total, (100.0*collisions) / total, failures); - torture_close_connection(cli); - - printf("mangle test finished\n"); return (failures == 0); } diff --git a/source4/torture/basic/misc.c b/source4/torture/basic/misc.c new file mode 100644 index 0000000000..c00372b805 --- /dev/null +++ b/source4/torture/basic/misc.c @@ -0,0 +1,855 @@ +/* + Unix SMB/CIFS implementation. + SMB torture tester + Copyright (C) Andrew Tridgell 1997-2003 + Copyright (C) Jelmer Vernooij 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" +#include "system/time.h" +#include "system/wait.h" +#include "system/filesys.h" +#include "libcli/raw/ioctl.h" +#include "libcli/libcli.h" +#include "lib/events/events.h" +#include "libcli/resolve/resolve.h" +#include "auth/credentials/credentials.h" +#include "librpc/gen_ndr/ndr_nbt.h" +#include "torture/torture.h" +#include "torture/util.h" +#include "libcli/smb_composite/smb_composite.h" +#include "libcli/composite/composite.h" + +extern struct cli_credentials *cmdline_credentials; +static void benchrw_callback(struct smbcli_request *req); +enum benchrw_stage { + START, + OPEN_CONNECTION, + CLEANUP_TESTDIR, + MK_TESTDIR, + OPEN_FILE, + INITIAL_WRITE, + READ_WRITE_DATA, + MAX_OPS_REACHED, + ERROR, + CLOSE_FILE, + CLEANUP, + FINISHED +}; + +struct benchrw_state{ + struct torture_context *tctx; + char *dname; + char *fname; + uint16_t fnum; + int nr; + struct smbcli_tree *cli; + uint8_t *buffer; + int writecnt; + int readcnt; + int completed; + TALLOC_CTX *mem_ctx; + void *req_params; + enum benchrw_stage mode; + struct params{ + struct unclist{ + const char *host; + const char *share; + } **unc; + const char *workgroup; + int retry; + unsigned int writeblocks; + unsigned int blocksize; + unsigned int writeratio; + } *lp_params; + }; + +static BOOL wait_lock(struct smbcli_state *c, int fnum, uint32_t offset, uint32_t len) +{ + while (NT_STATUS_IS_ERR(smbcli_lock(c->tree, fnum, offset, len, -1, WRITE_LOCK))) { + if (!check_error(__location__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; + } + return True; +} + + +static BOOL rw_torture(struct torture_context *tctx, struct smbcli_state *c) +{ + const char *lockfname = "\\torture.lck"; + char *fname; + int fnum; + int fnum2; + pid_t pid2, pid = getpid(); + int i, j; + uint8_t buf[1024]; + BOOL correct = True; + + fnum2 = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, + DENY_NONE); + if (fnum2 == -1) + fnum2 = smbcli_open(c->tree, lockfname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + torture_comment(tctx, "open of %s failed (%s)\n", lockfname, smbcli_errstr(c->tree)); + return False; + } + + + for (i=0;i<torture_numops;i++) { + uint_t n = (uint_t)random()%10; + if (i % 10 == 0) { + torture_comment(tctx, "%d\r", i); fflush(stdout); + } + asprintf(&fname, "\\torture.%u", n); + + if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) { + return False; + } + + fnum = smbcli_open(c->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL); + if (fnum == -1) { + torture_comment(tctx, "open failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + break; + } + + if (smbcli_write(c->tree, fnum, 0, &pid, 0, sizeof(pid)) != sizeof(pid)) { + torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + } + + for (j=0;j<50;j++) { + if (smbcli_write(c->tree, fnum, 0, buf, + sizeof(pid)+(j*sizeof(buf)), + sizeof(buf)) != sizeof(buf)) { + torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + } + } + + pid2 = 0; + + if (smbcli_read(c->tree, fnum, &pid2, 0, sizeof(pid)) != sizeof(pid)) { + torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + } + + if (pid2 != pid) { + torture_comment(tctx, "data corruption!\n"); + correct = False; + } + + if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) { + torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + } + + if (NT_STATUS_IS_ERR(smbcli_unlink(c->tree, fname))) { + torture_comment(tctx, "unlink failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + } + + if (NT_STATUS_IS_ERR(smbcli_unlock(c->tree, fnum2, n*sizeof(int), sizeof(int)))) { + torture_comment(tctx, "unlock failed (%s)\n", smbcli_errstr(c->tree)); + correct = False; + } + free(fname); + } + + smbcli_close(c->tree, fnum2); + smbcli_unlink(c->tree, lockfname); + + torture_comment(tctx, "%d\n", i); + + return correct; +} + +BOOL run_torture(struct torture_context *tctx, struct smbcli_state *cli, int dummy) +{ + return rw_torture(tctx, cli); +} + + +/* + see how many RPC pipes we can open at once +*/ +BOOL run_pipe_number(struct torture_context *tctx, + struct smbcli_state *cli1) +{ + const char *pipe_name = "\\WKSSVC"; + int fnum; + int num_pipes = 0; + + while(1) { + fnum = smbcli_nt_create_full(cli1->tree, pipe_name, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, + NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0); + + if (fnum == -1) { + torture_comment(tctx, "Open of pipe %s failed with error (%s)\n", pipe_name, smbcli_errstr(cli1->tree)); + break; + } + num_pipes++; + torture_comment(tctx, "%d\r", num_pipes); + fflush(stdout); + } + + torture_comment(tctx, "pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name ); + return True; +} + + + + +/* + open N connections to the server and just hold them open + used for testing performance when there are N idle users + already connected + */ +BOOL torture_holdcon(struct torture_context *tctx) +{ + int i; + struct smbcli_state **cli; + int num_dead = 0; + + torture_comment(tctx, "Opening %d connections\n", torture_numops); + + cli = malloc_array_p(struct smbcli_state *, torture_numops); + + for (i=0;i<torture_numops;i++) { + if (!torture_open_connection(&cli[i], i)) { + return False; + } + torture_comment(tctx, "opened %d connections\r", i); + fflush(stdout); + } + + torture_comment(tctx, "\nStarting pings\n"); + + while (1) { + for (i=0;i<torture_numops;i++) { + NTSTATUS status; + if (cli[i]) { + status = smbcli_chkpath(cli[i]->tree, "\\"); + if (!NT_STATUS_IS_OK(status)) { + torture_comment(tctx, "Connection %d is dead\n", i); + cli[i] = NULL; + num_dead++; + } + usleep(100); + } + } + + if (num_dead == torture_numops) { + torture_comment(tctx, "All connections dead - finishing\n"); + break; + } + + torture_comment(tctx, "."); + fflush(stdout); + } + + return True; +} + +/* +test how many open files this server supports on the one socket +*/ +BOOL run_maxfidtest(struct torture_context *tctx, struct smbcli_state *cli, int dummy) +{ +#define MAXFID_TEMPLATE "\\maxfid\\fid%d\\maxfid.%d.%d" + char *fname; + int fnums[0x11000], i; + int retries=4, maxfid; + BOOL correct = True; + + if (retries <= 0) { + torture_comment(tctx, "failed to connect\n"); + return False; + } + + if (smbcli_deltree(cli->tree, "\\maxfid") == -1) { + torture_comment(tctx, "Failed to deltree \\maxfid - %s\n", + smbcli_errstr(cli->tree)); + return False; + } + if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\maxfid"))) { + torture_comment(tctx, "Failed to mkdir \\maxfid, error=%s\n", + smbcli_errstr(cli->tree)); + return False; + } + + torture_comment(tctx, "Testing maximum number of open files\n"); + + for (i=0; i<0x11000; i++) { + if (i % 1000 == 0) { + asprintf(&fname, "\\maxfid\\fid%d", i/1000); + if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) { + torture_comment(tctx, "Failed to mkdir %s, error=%s\n", + fname, smbcli_errstr(cli->tree)); + return False; + } + free(fname); + } + asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid()); + if ((fnums[i] = smbcli_open(cli->tree, fname, + O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == + -1) { + torture_comment(tctx, "open of %s failed (%s)\n", + fname, smbcli_errstr(cli->tree)); + torture_comment(tctx, "maximum fnum is %d\n", i); + break; + } + free(fname); + torture_comment(tctx, "%6d\r", i); + } + torture_comment(tctx, "%6d\n", i); + i--; + + maxfid = i; + + torture_comment(tctx, "cleaning up\n"); + for (i=0;i<maxfid/2;i++) { + asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid()); + if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) { + torture_comment(tctx, "Close of fnum %d failed - %s\n", fnums[i], smbcli_errstr(cli->tree)); + } + if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { + torture_comment(tctx, "unlink of %s failed (%s)\n", + fname, smbcli_errstr(cli->tree)); + correct = False; + } + free(fname); + + asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000, maxfid-i,(int)getpid()); + if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[maxfid-i]))) { + torture_comment(tctx, "Close of fnum %d failed - %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree)); + } + if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) { + torture_comment(tctx, "unlink of %s failed (%s)\n", + fname, smbcli_errstr(cli->tree)); + correct = False; + } + free(fname); + + torture_comment(tctx, "%6d %6d\r", i, maxfid-i); + } + torture_comment(tctx, "%6d\n", 0); + + if (smbcli_deltree(cli->tree, "\\maxfid") == -1) { + torture_comment(tctx, "Failed to deltree \\maxfid - %s\n", + smbcli_errstr(cli->tree)); + return False; + } + + torture_comment(tctx, "maxfid test finished\n"); + if (!torture_close_connection(cli)) { + correct = False; + } + return correct; +#undef MAXFID_TEMPLATE +} + + + +/* + sees what IOCTLs are supported + */ +BOOL torture_ioctl_test(struct torture_context *tctx, + struct smbcli_state *cli) +{ + uint16_t device, function; + int fnum; + const char *fname = "\\ioctl.dat"; + NTSTATUS status; + union smb_ioctl parms; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_named_const(tctx, 0, "ioctl_test"); + + smbcli_unlink(cli->tree, fname); + + fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + if (fnum == -1) { + torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); + return False; + } + + parms.ioctl.level = RAW_IOCTL_IOCTL; + parms.ioctl.in.file.fnum = fnum; + parms.ioctl.in.request = IOCTL_QUERY_JOB_INFO; + status = smb_raw_ioctl(cli->tree, mem_ctx, &parms); + torture_comment(tctx, "ioctl job info: %s\n", smbcli_errstr(cli->tree)); + + for (device=0;device<0x100;device++) { + torture_comment(tctx, "testing device=0x%x\n", device); + for (function=0;function<0x100;function++) { + parms.ioctl.in.request = (device << 16) | function; + status = smb_raw_ioctl(cli->tree, mem_ctx, &parms); + + if (NT_STATUS_IS_OK(status)) { + torture_comment(tctx, "ioctl device=0x%x function=0x%x OK : %d bytes\n", + device, function, (int)parms.ioctl.out.blob.length); + } + } + } + + return True; +} + +/* + init params using lp_parm_xxx + return number of unclist entries +*/ +static int init_benchrw_params(struct torture_context *tctx, struct params *lpar) +{ + char **unc_list = NULL; + int num_unc_names = 0, conn_index=0, empty_lines=0; + const char *p; + lpar->retry = lp_parm_int(-1, "torture", "retry",3); + lpar->blocksize = lp_parm_int(-1, "torture", "blocksize",65535); + lpar->writeblocks = lp_parm_int(-1, "torture", "writeblocks",15); + lpar->writeratio = lp_parm_int(-1, "torture", "writeratio",5); + lpar->workgroup = lp_workgroup(); + + p = lp_parm_string(-1, "torture", "unclist"); + if (p) { + char *h, *s; + unc_list = file_lines_load(p, &num_unc_names, NULL); + if (!unc_list || num_unc_names <= 0) { + torture_comment(tctx, "Failed to load unc names list from '%s'\n", p); + exit(1); + } + + lpar->unc = talloc_array(tctx, struct unclist *, (num_unc_names-empty_lines)); + for(conn_index = 0; conn_index < num_unc_names; conn_index++) { + /* ignore empty lines */ + if(strlen(unc_list[conn_index % num_unc_names])==0){ + empty_lines++; + continue; + } + if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names], + NULL, &h, &s)) { + torture_comment(tctx, "Failed to parse UNC name %s\n", + unc_list[conn_index % num_unc_names]); + exit(1); + } + lpar->unc[conn_index-empty_lines] = talloc(tctx,struct unclist); + lpar->unc[conn_index-empty_lines]->host = h; + lpar->unc[conn_index-empty_lines]->share = s; + } + return num_unc_names-empty_lines; + }else{ + lpar->unc = talloc_array(tctx, struct unclist *, 1); + lpar->unc[0] = talloc(tctx,struct unclist); + lpar->unc[0]->host = lp_parm_string(-1, "torture", "host"); + lpar->unc[0]->share = lp_parm_string(-1, "torture", "share"); + return 1; + } +} + +/* + Called when the reads & writes are finished. closes the file. +*/ +static NTSTATUS benchrw_close(struct torture_context *tctx,struct smbcli_request *req, + struct benchrw_state *state) +{ + union smb_close close_parms; + + NT_STATUS_NOT_OK_RETURN(req->status); + + torture_comment(tctx, "Close file %d (%d)\n",state->nr,state->fnum); + close_parms.close.level = RAW_CLOSE_CLOSE; + close_parms.close.in.file.fnum = state->fnum ; + close_parms.close.in.write_time = 0; + state->mode=CLOSE_FILE; + + req = smb_raw_close_send(state->cli, &close_parms); + NT_STATUS_HAVE_NO_MEMORY(req); + /*register the callback function!*/ + req->async.fn = benchrw_callback; + req->async.private = state; + + return NT_STATUS_OK; +} + +/* + Called when the initial write is completed is done. write or read a file. +*/ +static NTSTATUS benchrw_readwrite(struct torture_context *tctx,struct smbcli_request *req, + struct benchrw_state *state) +{ + union smb_read rd; + union smb_write wr; + + NT_STATUS_NOT_OK_RETURN(req->status); + + state->completed++; + /*rotate between writes and reads*/ + if( state->completed % state->lp_params->writeratio == 0){ + torture_comment(tctx, "Callback WRITE file:%d (%d/%d)\n", + state->nr,state->completed,torture_numops); + wr.generic.level = RAW_WRITE_WRITEX ; + wr.writex.in.file.fnum = state->fnum ; + wr.writex.in.offset = 0; + wr.writex.in.wmode = 0 ; + wr.writex.in.remaining = 0; + wr.writex.in.count = state->lp_params->blocksize; + wr.writex.in.data = state->buffer; + state->readcnt=0; + req = smb_raw_write_send(state->cli,&wr); + }else{ + torture_comment(tctx, "Callback READ file:%d (%d/%d) Offset:%d\n", + state->nr,state->completed,torture_numops, + (state->readcnt*state->lp_params->blocksize)); + rd.generic.level = RAW_READ_READ ; + rd.read.in.file.fnum = state->fnum ; + rd.read.in.offset = state->readcnt * + state->lp_params->blocksize; + rd.read.in.count = state->lp_params->blocksize; + rd.read.in.remaining = 0 ; + rd.read.out.data = state->buffer; + if(state->readcnt < state->lp_params->writeblocks){ + state->readcnt++; + }else{ + /*start reading from beginn of file*/ + state->readcnt=0; + } + req = smb_raw_read_send(state->cli,&rd); + } + NT_STATUS_HAVE_NO_MEMORY(req); + /*register the callback function!*/ + req->async.fn = benchrw_callback; + req->async.private = state; + + return NT_STATUS_OK; +} + +/* + Called when the open is done. writes to the file. +*/ +static NTSTATUS benchrw_open(struct torture_context *tctx,struct smbcli_request *req, + struct benchrw_state *state) +{ + union smb_write wr; + if(state->mode == OPEN_FILE){ + NTSTATUS status; + status = smb_raw_open_recv(req,state->mem_ctx,( + union smb_open*)state->req_params); + NT_STATUS_NOT_OK_RETURN(status); + + state->fnum = ((union smb_open*)state->req_params) + ->openx.out.file.fnum; + torture_comment(tctx, "File opened (%d)\n",state->fnum); + state->mode=INITIAL_WRITE; + } + + torture_comment(tctx, "Write initial test file:%d (%d/%d)\n",state->nr, + (state->writecnt+1)*state->lp_params->blocksize, + (state->lp_params->writeblocks*state->lp_params->blocksize)); + wr.generic.level = RAW_WRITE_WRITEX ; + wr.writex.in.file.fnum = state->fnum ; + wr.writex.in.offset = state->writecnt * + state->lp_params->blocksize; + wr.writex.in.wmode = 0 ; + wr.writex.in.remaining = (state->lp_params->writeblocks * + state->lp_params->blocksize)- + ((state->writecnt+1)*state-> + lp_params->blocksize); + wr.writex.in.count = state->lp_params->blocksize; + wr.writex.in.data = state->buffer; + state->writecnt++; + if(state->writecnt == state->lp_params->writeblocks){ + state->mode=READ_WRITE_DATA; + } + req = smb_raw_write_send(state->cli,&wr); + NT_STATUS_HAVE_NO_MEMORY(req); + + /*register the callback function!*/ + req->async.fn = benchrw_callback; + req->async.private = state; + return NT_STATUS_OK; +} + +/* + Called when the mkdir is done. Opens a file. +*/ +static NTSTATUS benchrw_mkdir(struct torture_context *tctx,struct smbcli_request *req, + struct benchrw_state *state) +{ + union smb_open *open_parms; + uint8_t *writedata; + + NT_STATUS_NOT_OK_RETURN(req->status); + + /* open/create the files */ + torture_comment(tctx, "Open File %d/%d\n",state->nr+1,torture_nprocs); + open_parms=talloc_zero(state->mem_ctx, union smb_open); + NT_STATUS_HAVE_NO_MEMORY(open_parms); + open_parms->openx.level = RAW_OPEN_OPENX; + open_parms->openx.in.flags = 0; + open_parms->openx.in.open_mode = OPENX_MODE_ACCESS_RDWR; + open_parms->openx.in.search_attrs = + FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; + open_parms->openx.in.file_attrs = 0; + open_parms->openx.in.write_time = 0; + open_parms->openx.in.open_func = OPENX_OPEN_FUNC_CREATE; + open_parms->openx.in.size = 0; + open_parms->openx.in.timeout = 0; + open_parms->openx.in.fname = state->fname; + + writedata = talloc_size(state->mem_ctx,state->lp_params->blocksize); + NT_STATUS_HAVE_NO_MEMORY(writedata); + generate_random_buffer(writedata,state->lp_params->blocksize); + state->buffer=writedata; + state->writecnt=1; + state->readcnt=0; + state->req_params=open_parms; + state->mode=OPEN_FILE; + + req = smb_raw_open_send(state->cli,open_parms); + NT_STATUS_HAVE_NO_MEMORY(req); + + /*register the callback function!*/ + req->async.fn = benchrw_callback; + req->async.private = state; + + return NT_STATUS_OK; +} + +/* + handler for completion of a sub-request of the bench-rw test +*/ +static void benchrw_callback(struct smbcli_request *req) +{ + struct benchrw_state *state = req->async.private; + struct torture_context *tctx = state->tctx; + + /*dont send new requests when torture_numops is reached*/ + if(state->completed >= torture_numops){ + state->completed=0; + state->mode=MAX_OPS_REACHED; + } + + switch (state->mode) { + + case MK_TESTDIR: + if (!NT_STATUS_IS_OK(benchrw_mkdir(tctx, req,state))) { + torture_comment(tctx, "Failed to create the test directory - %s\n", + nt_errstr(req->status)); + state->mode=ERROR; + return; + } + break; + case OPEN_FILE: + case INITIAL_WRITE: + if (!NT_STATUS_IS_OK(benchrw_open(tctx, req,state))){ + torture_comment(tctx, "Failed to open/write the file - %s\n", + nt_errstr(req->status)); + state->mode=ERROR; + return; + } + break; + case READ_WRITE_DATA: + if (!NT_STATUS_IS_OK(benchrw_readwrite(tctx,req,state))){ + torture_comment(tctx, "Failed to read/write the file - %s\n", + nt_errstr(req->status)); + state->mode=ERROR; + return; + } + break; + case MAX_OPS_REACHED: + if (!NT_STATUS_IS_OK(benchrw_close(tctx,req,state))){ + torture_comment(tctx, "Failed to read/write/close the file - %s\n", + nt_errstr(req->status)); + state->mode=ERROR; + return; + } + break; + case CLOSE_FILE: + torture_comment(tctx, "File %d closed\n",state->nr); + if (!NT_STATUS_IS_OK(req->status)) { + torture_comment(tctx, "Failed to close the file - %s\n", + nt_errstr(req->status)); + state->mode=ERROR; + return; + } + state->mode=CLEANUP; + return; + default: + break; + } + +} + +/* open connection async callback function*/ +static void async_open_callback(struct composite_context *con) +{ + struct benchrw_state *state = con->async.private_data; + struct torture_context *tctx = state->tctx; + int retry = state->lp_params->retry; + + if (NT_STATUS_IS_OK(con->status)) { + state->cli=((struct smb_composite_connect*) + state->req_params)->out.tree; + state->mode=CLEANUP_TESTDIR; + }else{ + if(state->writecnt < retry){ + torture_comment(tctx, "Failed to open connection:%d, Retry (%d/%d)\n", + state->nr,state->writecnt,retry); + state->writecnt++; + state->mode=START; + usleep(1000); + }else{ + torture_comment(tctx, "Failed to open connection (%d) - %s\n", + state->nr, nt_errstr(con->status)); + state->mode=ERROR; + } + return; + } +} + +/* + establishs a smbcli_tree from scratch (async) +*/ +static struct composite_context *torture_connect_async( + struct torture_context *tctx, + struct smb_composite_connect *smb, + TALLOC_CTX *mem_ctx, + struct event_context *ev, + const char *host, + const char *share, + const char *workgroup) +{ + torture_comment(tctx, "Open Connection to %s/%s\n",host,share); + smb->in.dest_host=talloc_strdup(mem_ctx,host); + smb->in.service=talloc_strdup(mem_ctx,share); + smb->in.port=0; + smb->in.called_name = strupper_talloc(mem_ctx, host); + smb->in.service_type=NULL; + smb->in.credentials=cmdline_credentials; + smb->in.fallback_to_anonymous=False; + smb->in.workgroup=workgroup; + + return smb_composite_connect_send(smb,mem_ctx,ev); +} + +BOOL run_benchrw(struct torture_context *tctx) +{ + struct smb_composite_connect *smb_con; + const char *fname = "\\rwtest.dat"; + struct smbcli_request *req; + struct benchrw_state **state; + int i , num_unc_names; + struct event_context *ev ; + struct composite_context *req1; + struct params lpparams; + union smb_mkdir parms; + int finished = 0; + BOOL success=True; + + torture_comment(tctx, "Start BENCH-READWRITE num_ops=%d num_nprocs=%d\n", + torture_numops,torture_nprocs); + + /*init talloc context*/ + ev = event_context_init(tctx); + state = talloc_array(tctx, struct benchrw_state *, torture_nprocs); + + /* init params using lp_parm_xxx */ + num_unc_names = init_benchrw_params(tctx,&lpparams); + + /* init private data structs*/ + for(i = 0; i<torture_nprocs;i++){ + state[i]=talloc(tctx,struct benchrw_state); + state[i]->tctx = tctx; + state[i]->completed=0; + state[i]->lp_params=&lpparams; + state[i]->nr=i; + state[i]->dname=talloc_asprintf(tctx,"benchrw%d",i); + state[i]->fname=talloc_asprintf(tctx,"%s%s", + state[i]->dname,fname); + state[i]->mode=START; + state[i]->writecnt=0; + } + + torture_comment(tctx, "Starting async requests\n"); + while(finished != torture_nprocs){ + finished=0; + for(i = 0; i<torture_nprocs;i++){ + switch (state[i]->mode){ + /*open multiple connections with the same userid */ + case START: + smb_con = talloc(tctx,struct smb_composite_connect) ; + state[i]->req_params=smb_con; + state[i]->mode=OPEN_CONNECTION; + req1 = torture_connect_async(tctx, smb_con, + tctx,ev, + lpparams.unc[i % num_unc_names]->host, + lpparams.unc[i % num_unc_names]->share, + lpparams.workgroup); + /* register callback fn + private data */ + req1->async.fn = async_open_callback; + req1->async.private_data=state[i]; + break; + /*setup test dirs (sync)*/ + case CLEANUP_TESTDIR: + torture_comment(tctx, "Setup test dir %d\n",i); + smb_raw_exit(state[i]->cli->session); + if (smbcli_deltree(state[i]->cli, + state[i]->dname) == -1) { + torture_comment(tctx, "Unable to delete %s - %s\n", + state[i]->dname, + smbcli_errstr(state[i]->cli)); + state[i]->mode=ERROR; + break; + } + state[i]->mode=MK_TESTDIR; + parms.mkdir.level = RAW_MKDIR_MKDIR; + parms.mkdir.in.path = state[i]->dname; + req = smb_raw_mkdir_send(state[i]->cli,&parms); + /* register callback fn + private data */ + req->async.fn = benchrw_callback; + req->async.private=state[i]; + break; + /* error occured , finish */ + case ERROR: + finished++; + success=False; + break; + /* cleanup , close connection */ + case CLEANUP: + torture_comment(tctx, "Deleting test dir %s %d/%d\n",state[i]->dname, + i+1,torture_nprocs); + smbcli_deltree(state[i]->cli,state[i]->dname); + if (NT_STATUS_IS_ERR(smb_tree_disconnect( + state[i]->cli))) { + torture_comment(tctx, "ERROR: Tree disconnect failed"); + state[i]->mode=ERROR; + break; + } + state[i]->mode=FINISHED; + case FINISHED: + finished++; + break; + default: + event_loop_once(ev); + } + } + } + + return success; +} + diff --git a/source4/torture/basic/properties.c b/source4/torture/basic/properties.c index 63941263ae..6b0b61419b 100644 --- a/source4/torture/basic/properties.c +++ b/source4/torture/basic/properties.c @@ -89,21 +89,13 @@ static void show_bits(const struct bitmapping *bm, uint32_t value) /* print out server properties */ -BOOL torture_test_properties(struct torture_context *torture) +BOOL torture_test_properties(struct torture_context *torture, + struct smbcli_state *cli) { - struct smbcli_state *cli; BOOL correct = True; union smb_fsinfo fs; NTSTATUS status; - printf("starting properties test\n"); - - ZERO_STRUCT(cli); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - d_printf("Capabilities: 0x%08x\n", cli->transport->negotiate.capabilities); show_bits(capability_bits, cli->transport->negotiate.capabilities); d_printf("\n"); @@ -122,10 +114,6 @@ BOOL torture_test_properties(struct torture_context *torture) d_printf("fstype: %s\n", fs.attribute_info.out.fs_type.s); } - if (!torture_close_connection(cli)) { - correct = False; - } - return correct; } diff --git a/source4/torture/basic/rename.c b/source4/torture/basic/rename.c index b80c909470..2d4fb38e9f 100644 --- a/source4/torture/basic/rename.c +++ b/source4/torture/basic/rename.c @@ -28,20 +28,13 @@ /* Test rename on files open with share delete and no share delete. */ -BOOL torture_test_rename(struct torture_context *torture) +BOOL torture_test_rename(struct torture_context *tctx, + struct smbcli_state *cli1) { - struct smbcli_state *cli1; const char *fname = "\\test.txt"; const char *fname1 = "\\test1.txt"; - BOOL correct = True; int fnum1; - printf("starting rename test\n"); - - if (!torture_open_connection(&cli1, 0)) { - return False; - } - smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname1); fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, @@ -50,24 +43,14 @@ BOOL torture_test_rename(struct torture_context *torture) NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) First open failed - %s\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } - - if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) { - printf("First rename failed (this is correct) - %s\n", smbcli_errstr(cli1->tree)); - } else { - printf("(%s) First rename succeeded - this should have failed !\n", - __location__); - correct = False; - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 1 failed (%s)\n", __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "First open failed - %s", + smbcli_errstr(cli1->tree))); + + torture_assert(tctx, NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1)), + "First rename succeeded - this should have failed !"); + + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 1 failed (%s)", smbcli_errstr(cli1->tree))); smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname1); @@ -77,24 +60,17 @@ BOOL torture_test_rename(struct torture_context *torture) NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) Second open failed - %s\n", __location__, smbcli_errstr(cli1->tree)); - return False; - } - - if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) { - printf("(%s) Second rename failed - this should have succeeded - %s\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - } else { - printf("Second rename succeeded\n"); - } - - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 2 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, + "Second open failed - %s", smbcli_errstr(cli1->tree))); + + torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1), + talloc_asprintf(tctx, + "Second rename failed - this should have succeeded - %s", + smbcli_errstr(cli1->tree))); + + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, + "close - 2 failed (%s)", smbcli_errstr(cli1->tree))); smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname1); @@ -105,33 +81,19 @@ BOOL torture_test_rename(struct torture_context *torture) NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0); - if (fnum1 == -1) { - printf("(%s) Third open failed - %s\n", __location__, smbcli_errstr(cli1->tree)); - return False; - } - + torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "Third open failed - %s", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) { - printf("(%s) Third rename failed - this should have succeeded - %s\n", - __location__, smbcli_errstr(cli1->tree)); - correct = False; - } else { - printf("Third rename succeeded\n"); - } + torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1), + talloc_asprintf(tctx, "Third rename failed - this should have succeeded - %s", + smbcli_errstr(cli1->tree))); - if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) { - printf("(%s) close - 3 failed (%s)\n", - __location__, smbcli_errstr(cli1->tree)); - return False; - } + torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), + talloc_asprintf(tctx, "close - 3 failed (%s)", smbcli_errstr(cli1->tree))); smbcli_unlink(cli1->tree, fname); smbcli_unlink(cli1->tree, fname1); - if (!torture_close_connection(cli1)) { - correct = False; - } - - return correct; + return true; } diff --git a/source4/torture/basic/scanner.c b/source4/torture/basic/scanner.c index 47da8f7efe..60cfacd840 100644 --- a/source4/torture/basic/scanner.c +++ b/source4/torture/basic/scanner.c @@ -242,19 +242,13 @@ static BOOL scan_trans2(struct smbcli_state *cli, int op, int level, } -BOOL torture_trans2_scan(struct torture_context *torture) +BOOL torture_trans2_scan(struct torture_context *torture, + struct smbcli_state *cli) { - static struct smbcli_state *cli; int op, level; const char *fname = "\\scanner.dat"; int fnum, dnum, qfnum; - printf("starting trans2 scan test\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); if (fnum == -1) { printf("file open failed - %s\n", smbcli_errstr(cli->tree)); @@ -299,9 +293,6 @@ BOOL torture_trans2_scan(struct torture_context *torture) } } - torture_close_connection(cli); - - printf("trans2 scan finished\n"); return True; } @@ -483,19 +474,13 @@ static BOOL scan_nttrans(struct smbcli_state *cli, int op, int level, } -BOOL torture_nttrans_scan(struct torture_context *torture) +BOOL torture_nttrans_scan(struct torture_context *torture, + struct smbcli_state *cli) { - static struct smbcli_state *cli; int op, level; const char *fname = "\\scanner.dat"; int fnum, dnum; - printf("starting nttrans scan test\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } - fnum = smbcli_open(cli->tree, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); dnum = smbcli_open(cli->tree, "\\", O_RDONLY, DENY_NONE); diff --git a/source4/torture/basic/secleak.c b/source4/torture/basic/secleak.c index 78267b0295..b39c46b853 100644 --- a/source4/torture/basic/secleak.c +++ b/source4/torture/basic/secleak.c @@ -56,15 +56,10 @@ static BOOL try_failed_login(struct smbcli_state *cli) return True; } -BOOL torture_sec_leak(struct torture_context *torture) +BOOL torture_sec_leak(struct torture_context *tctx, struct smbcli_state *cli) { - struct smbcli_state *cli; time_t t1 = time(NULL); - int timelimit = lp_parm_int(-1, "torture", "timelimit", 20); - - if (!torture_open_connection(&cli, 0)) { - return False; - } + int timelimit = torture_setting_int(tctx, "timelimit", 20); while (time(NULL) < t1+timelimit) { if (!try_failed_login(cli)) { diff --git a/source4/torture/basic/unlink.c b/source4/torture/basic/unlink.c index b64c52e110..a8469e4bf6 100644 --- a/source4/torture/basic/unlink.c +++ b/source4/torture/basic/unlink.c @@ -34,49 +34,36 @@ 1) the server does not allow an unlink on a file that is open */ -BOOL torture_unlinktest(struct torture_context *torture) +BOOL torture_unlinktest(struct torture_context *tctx, struct smbcli_state *cli) { - struct smbcli_state *cli; const char *fname = BASEDIR "\\unlink.tst"; int fnum; BOOL correct = True; union smb_open io; NTSTATUS status; - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("starting unlink test\n"); - - if (!torture_setup_dir(cli, BASEDIR)) { - return False; - } + torture_assert(tctx, torture_setup_dir(cli, BASEDIR), + talloc_asprintf(tctx, "Failed setting up %s", BASEDIR)); cli->session->pid = 1; - printf("Opening a file\n"); + torture_comment(tctx, "Opening a file\n"); fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); - if (fnum == -1) { - printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); - return False; - } - - printf("Unlinking a open file\n"); - - if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) { - printf("(%s) error: server allowed unlink on an open file\n", __location__); - correct = False; - } else { - correct = check_error(__location__, cli, ERRDOS, ERRbadshare, + torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, "open of %s failed (%s)", fname, smbcli_errstr(cli->tree))); + + torture_comment(tctx, "Unlinking a open file\n"); + + torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname)), + "server allowed unlink on an open file"); + + correct = check_error(__location__, cli, ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION); - } smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname); - printf("testing unlink after ntcreatex with DELETE access\n"); + torture_comment(tctx, "testing unlink after ntcreatex with DELETE access\n"); io.ntcreatex.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.root_fid = 0; @@ -92,23 +79,14 @@ BOOL torture_unlinktest(struct torture_context *torture) io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; status = smb_raw_open(cli->tree, cli, &io); - if (!NT_STATUS_IS_OK(status)) { - printf("(%s) failed to open %s\n", __location__, fname); - } - if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) { - printf("(%s) error: server allowed unlink on an open file\n", __location__); - correct = False; - } else { - correct = check_error(__location__, cli, ERRDOS, ERRbadshare, - NT_STATUS_SHARING_VIOLATION); - } + torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "failed to open %s", fname)); - if (!torture_close_connection(cli)) { - correct = False; - } + torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname)), + "server allowed unlink on an open file"); + + correct = check_error(__location__, cli, ERRDOS, ERRbadshare, + NT_STATUS_SHARING_VIOLATION); - printf("unlink test finished\n"); - return correct; } diff --git a/source4/torture/basic/utable.c b/source4/torture/basic/utable.c index 8e13babd0a..28122da214 100644 --- a/source4/torture/basic/utable.c +++ b/source4/torture/basic/utable.c @@ -26,9 +26,9 @@ #include "torture/util.h" #include "pstring.h" -BOOL torture_utable(struct torture_context *torture) +bool torture_utable(struct torture_context *tctx, + struct smbcli_state *cli) { - struct smbcli_state *cli; fstring fname; const char *alt_name; int fnum; @@ -37,19 +37,12 @@ BOOL torture_utable(struct torture_context *torture) int chars_allowed=0, alt_allowed=0; uint8_t valid[0x10000]; - printf("starting utable\n"); - - printf("Generating valid character table\n"); - - if (!torture_open_connection(&cli, 0)) { - return False; - } + torture_comment(tctx, "Generating valid character table\n"); memset(valid, 0, sizeof(valid)); - if (!torture_setup_dir(cli, "\\utable")) { - return False; - } + torture_assert(tctx, torture_setup_dir(cli, "\\utable"), + "Setting up dir \\utable failed"); for (c=1; c < 0x10000; c++) { char *p; @@ -74,32 +67,31 @@ BOOL torture_utable(struct torture_context *torture) if (strncmp(alt_name, "X_A_L", 5) != 0) { alt_allowed++; valid[c] = 1; - d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); + torture_comment(tctx, "fname=[%s] alt_name=[%s]\n", fname, alt_name); } smbcli_close(cli->tree, fnum); smbcli_unlink(cli->tree, fname); if (c % 100 == 0) { - printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed); + torture_comment(tctx, "%d (%d/%d)\r", c, chars_allowed, alt_allowed); } } - printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed); + torture_comment(tctx, "%d (%d/%d)\n", c, chars_allowed, alt_allowed); smbcli_rmdir(cli->tree, "\\utable"); - d_printf("%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); + torture_comment(tctx, "%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (fd == -1) { - d_printf("Failed to create valid.dat - %s", strerror(errno)); - return False; - } + torture_assert(tctx, fd != -1, + talloc_asprintf(tctx, + "Failed to create valid.dat - %s", strerror(errno))); write(fd, valid, 0x10000); close(fd); - d_printf("wrote valid.dat\n"); + torture_comment(tctx, "wrote valid.dat\n"); - return True; + return true; } @@ -121,34 +113,28 @@ static char *form_name(int c) return fname; } -BOOL torture_casetable(struct torture_context *torture) +bool torture_casetable(struct torture_context *tctx, + struct smbcli_state *cli) { - static struct smbcli_state *cli; char *fname; int fnum; int c, i; #define MAX_EQUIVALENCE 8 codepoint_t equiv[0x10000][MAX_EQUIVALENCE]; - printf("starting casetable\n"); - if (!torture_open_connection(&cli, 0)) { - return False; - } - - printf("Determining upper/lower case table\n"); + torture_comment(tctx, "Determining upper/lower case table\n"); memset(equiv, 0, sizeof(equiv)); - if (!torture_setup_dir(cli, "\\utable")) { - return False; - } + torture_assert(tctx, torture_setup_dir(cli, "\\utable"), + "Error setting up dir \\utable"); for (c=1; c < 0x10000; c++) { size_t size; if (c == '.' || c == '\\') continue; - d_printf("%04x (%c)\n", c, isprint(c)?c:'.'); + torture_comment(tctx, "%04x (%c)\n", c, isprint(c)?c:'.'); fname = form_name(c); fnum = smbcli_nt_create_full(cli->tree, fname, 0, @@ -161,10 +147,9 @@ BOOL torture_casetable(struct torture_context *torture) NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0); - if (fnum == -1) { - printf("Failed to create file with char %04x\n", c); - continue; - } + torture_assert(tctx, fnum != -1, + talloc_asprintf(tctx, + "Failed to create file with char %04x\n", c)); size = 0; @@ -176,21 +161,20 @@ BOOL torture_casetable(struct torture_context *torture) int c2[MAX_EQUIVALENCE]; if (size/sizeof(int) >= MAX_EQUIVALENCE) { - printf("too many chars match?? size=%d c=0x%04x\n", + torture_comment(tctx, "too many chars match?? size=%d c=0x%04x\n", (int)size, c); smbcli_close(cli->tree, fnum); return False; } smbcli_read(cli->tree, fnum, c2, 0, size); - printf("%04x: ", c); + torture_comment(tctx, "%04x: ", c); equiv[c][0] = c; for (i=0; i<size/sizeof(int); i++) { - printf("%04x ", c2[i]); + torture_comment(tctx, "%04x ", c2[i]); equiv[c][i+1] = c2[i]; } - printf("\n"); - fflush(stdout); + torture_comment(tctx, "\n"); } smbcli_write(cli->tree, fnum, 0, &c, size, sizeof(c)); @@ -200,5 +184,5 @@ BOOL torture_casetable(struct torture_context *torture) smbcli_unlink(cli->tree, "\\utable\\*"); smbcli_rmdir(cli->tree, "\\utable"); - return True; + return true; } |