From c125a7c5a7aee1b0506ab4eddbb4868ca8411fba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Sep 2007 23:01:33 +0000 Subject: r24872: Use torture API a bit more (This used to be commit a71355dfc933d4273d81e7b05a28197ca86e0cc6) --- source4/torture/rpc/echo.c | 6 +- source4/torture/rpc/scanner.c | 15 +- source4/torture/rpc/srvsvc.c | 430 ++++++++++++------------------------------ 3 files changed, 133 insertions(+), 318 deletions(-) (limited to 'source4') diff --git a/source4/torture/rpc/echo.c b/source4/torture/rpc/echo.c index 814c8e31b9..52f6d76d0e 100644 --- a/source4/torture/rpc/echo.c +++ b/source4/torture/rpc/echo.c @@ -240,7 +240,7 @@ static bool test_sleep(struct torture_context *tctx, if (torture_setting_bool(tctx, "quick", false)) { torture_skip(tctx, "TestSleep disabled - use \"torture:quick=no\" to enable\n"); } - torture_comment(tctx, "Testing TestSleep - use \"torture:quick=no\" to disable\n"); + torture_comment(tctx, "Testing TestSleep - use \"torture:quick=yes\" to disable\n"); for (i=0;inext) { - loop_ctx = talloc_named(mem_ctx, 0, "torture_rpc_scanner loop context"); + loop_ctx = talloc_named(torture, 0, "torture_rpc_scanner loop context"); /* some interfaces are not mappable */ if (l->table->num_calls == 0 || strcmp(l->table->name, "mgmt") == 0) { @@ -122,7 +119,7 @@ bool torture_rpc_scanner(struct torture_context *torture) printf("\nTesting pipe '%s'\n", l->table->name); if (b->transport == NCACN_IP_TCP) { - status = dcerpc_epm_map_binding(mem_ctx, b, l->table, NULL); + status = dcerpc_epm_map_binding(torture, b, l->table, NULL); if (!NT_STATUS_IS_OK(status)) { printf("Failed to map port for uuid %s\n", GUID_string(loop_ctx, &l->table->syntax_id.uuid)); @@ -133,7 +130,7 @@ bool torture_rpc_scanner(struct torture_context *torture) b->endpoint = talloc_strdup(b, l->table->name); } - lp_set_cmdline("torture:binding", dcerpc_binding_string(mem_ctx, b)); + lp_set_cmdline("torture:binding", dcerpc_binding_string(torture, b)); status = torture_rpc_connection(torture, &p, &ndr_table_mgmt); if (!NT_STATUS_IS_OK(status)) { @@ -142,7 +139,7 @@ bool torture_rpc_scanner(struct torture_context *torture) continue; } - if (!test_inq_if_ids(torture, p, mem_ctx, test_num_calls, l->table)) { + if (!test_inq_if_ids(torture, p, torture, test_num_calls, l->table)) { ret = False; } } diff --git a/source4/torture/rpc/srvsvc.c b/source4/torture/rpc/srvsvc.c index 30763f896c..4a60e600d6 100644 --- a/source4/torture/rpc/srvsvc.c +++ b/source4/torture/rpc/srvsvc.c @@ -27,70 +27,52 @@ /**************************/ /* srvsvc_NetCharDev */ /**************************/ -static BOOL test_NetCharDevGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_NetCharDevGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx, const char *devname) { NTSTATUS status; struct srvsvc_NetCharDevGetInfo r; uint32_t levels[] = {0, 1}; int i; - BOOL ret = True; - r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p)); + r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p)); r.in.device_name = devname; for (i=0;iarray[j].device; if (!test_NetCharDevGetInfo(p, tctx, device)) { - ret = False; + return false; } if (!test_NetCharDevControl(p, tctx, device)) { - ret = False; + return false; } } } } - return ret; + return true; } /**************************/ /* srvsvc_NetCharDevQ */ /**************************/ -static BOOL test_NetCharDevQGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_NetCharDevQGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx, const char *devicequeue) { NTSTATUS status; struct srvsvc_NetCharDevQGetInfo r; uint32_t levels[] = {0, 1}; int i; - BOOL ret = True; - r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p)); + r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p)); r.in.queue_name = devicequeue; - r.in.user = talloc_asprintf(mem_ctx,"Administrator"); + r.in.user = talloc_asprintf(tctx,"Administrator"); for (i=0;iarray[j].device; if (!test_NetCharDevQGetInfo(p, tctx, device)) { - ret = False; + return false; } } } } - return ret; + return true; } /**************************/ /* srvsvc_NetConn */ /**************************/ -static BOOL test_NetConnEnum(struct torture_context *tctx, - struct dcerpc_pipe *p) +static bool test_NetConnEnum(struct torture_context *tctx, + struct dcerpc_pipe *p) { NTSTATUS status; struct srvsvc_NetConnEnum r; struct srvsvc_NetConnCtr0 c0; uint32_t levels[] = {0, 1}; int i; - BOOL ret = True; r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p)); r.in.path = talloc_asprintf(tctx,"%s","ADMIN$"); @@ -313,34 +267,26 @@ static BOOL test_NetConnEnum(struct torture_context *tctx, for (i=0;ipath) continue; if (!test_NetShareCheck(p, tctx, r.out.info.info2->path)) { - ret = False; + return false; } } - return ret; + return true; } static bool test_NetShareGetInfoAdminFull(struct torture_context *tctx, @@ -536,7 +448,6 @@ static bool test_NetShareAddSetDel(struct torture_context *tctx, { 1501, WERR_OK }, }; int i; - BOOL ret = True; a.in.server_unc = r.in.server_unc = q.in.server_unc = d.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); @@ -556,15 +467,8 @@ static bool test_NetShareAddSetDel(struct torture_context *tctx, a.in.parm_error = NULL; status = dcerpc_srvsvc_NetShareAdd(p, tctx, &a); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetShareAdd level 2 on share 'testshare' failed - %s\n", - nt_errstr(status)); - return False; - } else if (!W_ERROR_EQUAL(a.out.result, WERR_OK)) { - d_printf("NetShareAdd level 2 on share 'testshare' failed - %s\n", - win_errstr(a.out.result)); - return False; - } + torture_assert_ntstatus_ok(tctx, status, "NetShareAdd level 2 on share 'testshare' failed"); + torture_assert_werr_ok(tctx, a.out.result, "NetShareAdd level 2 on share 'testshare' failed"); r.in.parm_error = NULL; @@ -575,7 +479,7 @@ static bool test_NetShareAddSetDel(struct torture_context *tctx, r.in.level = levels[i].level; ZERO_STRUCT(r.out); - d_printf("testing NetShareSetInfo level %u on share '%s'\n", + torture_comment(tctx, "testing NetShareSetInfo level %u on share '%s'\n", r.in.level, r.in.share_name); switch (levels[i].level) { @@ -644,73 +548,45 @@ static bool test_NetShareAddSetDel(struct torture_context *tctx, } status = dcerpc_srvsvc_NetShareSetInfo(p, tctx, &r); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetShareGetInfo level %u on share '%s' failed - %s\n", - r.in.level, r.in.share_name, nt_errstr(status)); - ret = False; - continue; - } else if (!W_ERROR_EQUAL(r.out.result, levels[i].expected)) { - d_printf("NetShareSetInfo level %u on share '%s' failed - %s (expected %s)\n", - r.in.level, r.in.share_name, win_errstr(r.out.result), - win_errstr(levels[i].expected)); - ret = False; - continue; - } + torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed"); + torture_assert_werr_equal(tctx, r.out.result, levels[i].expected, "NetShareSetInfo failed"); q.in.share_name = r.in.share_name; status = dcerpc_srvsvc_NetShareGetInfo(p, tctx, &q); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetShareGetInfo level %u on share '%s' failed - %s\n", - q.in.level, q.in.share_name, nt_errstr(status)); - ret = False; - continue; - } else if (!W_ERROR_EQUAL(q.out.result, WERR_OK)) { - d_printf("NetShareGetInfo level %u on share '%s' failed - %s\n", - q.in.level, q.in.share_name, win_errstr(q.out.result)); - ret = False; - continue; - } + torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed"); + torture_assert_werr_ok(tctx, q.out.result, "NetShareGetInfo failed"); + + torture_assert_str_equal(tctx, q.out.info.info502->name, r.in.share_name, + "share name invalid"); - if (strcmp(q.out.info.info502->name, r.in.share_name) != 0) { - ret = False; - } switch (levels[i].level) { case 0: break; case 1: - if (strcmp(q.out.info.info502->comment, "test comment 1") != 0) - ret = False; + torture_assert_str_equal(tctx, q.out.info.info502->comment, "test comment 1", "comment"); break; case 2: - if (strcmp(q.out.info.info502->comment, "test comment 2") != 0) - ret = False; - if (q.out.info.info2->max_users != 2) - ret = False; - if (strcmp(q.out.info.info2->path, "C:\\") != 0) - ret = False; + torture_assert_str_equal(tctx, q.out.info.info502->comment, "test comment 2", "comment"); + torture_assert_int_equal(tctx, q.out.info.info2->max_users, 2, "max users"); + torture_assert_str_equal(tctx, q.out.info.info2->path, "C:\\", "path"); break; case 501: - if (strcmp(q.out.info.info501->comment, "test comment 501") != 0) - ret = False; + torture_assert_str_equal(tctx, q.out.info.info501->comment, "test comment 501", "comment"); break; case 502: - if (strcmp(q.out.info.info502->comment, "test comment 502") != 0) - ret = False; - if (q.out.info.info2->max_users != 502) - ret = False; - if (strcmp(q.out.info.info2->path, "C:\\") != 0) - ret = False; + torture_assert_str_equal(tctx, q.out.info.info502->comment, "test comment 502", "comment"); + torture_assert_int_equal(tctx, q.out.info.info2->max_users, 502, "max users"); + torture_assert_str_equal(tctx, q.out.info.info2->path, "C:\\", "path"); break; case 1004: - if (strcmp(q.out.info.info502->comment, "test comment 1004") != 0) - ret = False; + torture_assert_str_equal(tctx, q.out.info.info502->comment, "test comment 1004", + "comment"); break; case 1005: break; case 1006: - if (q.out.info.info2->max_users != 1006) - ret = False; + torture_assert_int_equal(tctx, q.out.info.info2->max_users, 1006, "Max users"); break; /* case 1007: break; @@ -724,17 +600,10 @@ static bool test_NetShareAddSetDel(struct torture_context *tctx, d.in.reserved = 0; status = dcerpc_srvsvc_NetShareDel(p, tctx, &d); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetShareDel on share 'testshare502' failed - %s\n", - nt_errstr(status)); - ret = False; - } else if (!W_ERROR_EQUAL(a.out.result, WERR_OK)) { - d_printf("NetShareDel on share 'testshare502' failed - %s\n", - win_errstr(d.out.result)); - ret = False; - } + torture_assert_ntstatus_ok(tctx, status, "NetShareDel on share 'testshare502' failed"); + torture_assert_werr_ok(tctx, a.out.result, "NetShareDel on share 'testshare502' failed"); - return ret; + return true; } /**************************/ @@ -759,7 +628,6 @@ static bool test_NetShareEnumAll(struct torture_context *tctx, { 502, WERR_ACCESS_DENIED, WERR_OK }, }; int i; - BOOL ret = True; uint32_t resume_handle; ZERO_STRUCT(c0); @@ -781,19 +649,10 @@ static bool test_NetShareEnumAll(struct torture_context *tctx, ZERO_STRUCT(r.out); resume_handle = 0; - d_printf("testing NetShareEnumAll level %u\n", r.in.level); + torture_comment(tctx, "testing NetShareEnumAll level %u\n", r.in.level); status = dcerpc_srvsvc_NetShareEnumAll(p, tctx, &r); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status)); - ret = False; - continue; - } - if (!W_ERROR_EQUAL(r.out.result, expected)) { - d_printf("NetShareEnumAll level %u failed - %s (expected %s)\n", - r.in.level, win_errstr(r.out.result), - win_errstr(expected)); - continue; - } + torture_assert_ntstatus_ok(tctx, status, "NetShareEnumAll failed"); + torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareEnumAll failed"); /* call srvsvc_NetShareGetInfo for each returned share */ if (r.in.level == 2 && r.out.ctr.ctr2) { @@ -801,13 +660,13 @@ static bool test_NetShareEnumAll(struct torture_context *tctx, const char *name; name = r.out.ctr.ctr2->array[j].name; if (!test_NetShareGetInfo(tctx, p, name, admin)) { - ret = False; + return false; } } } } - return ret; + return true; } static bool test_NetShareEnumAllFull(struct torture_context *tctx, @@ -840,7 +699,6 @@ static bool test_NetShareEnum(struct torture_context *tctx, { 502, WERR_ACCESS_DENIED, WERR_OK }, }; int i; - BOOL ret = True; r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p)); r.in.ctr.ctr0 = &c0; @@ -858,22 +716,13 @@ static bool test_NetShareEnum(struct torture_context *tctx, ZERO_STRUCT(r.out); - d_printf("testing NetShareEnum level %u\n", r.in.level); + torture_comment(tctx, "testing NetShareEnum level %u\n", r.in.level); status = dcerpc_srvsvc_NetShareEnum(p, tctx, &r); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status)); - ret = False; - continue; - } - if (!W_ERROR_EQUAL(r.out.result, expected)) { - d_printf("NetShareEnum level %u failed - %s (expected %s)\n", - r.in.level, win_errstr(r.out.result), - win_errstr(expected)); - continue; - } + torture_assert_ntstatus_ok(tctx, status, "NetShareEnum failed"); + torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareEnum failed"); } - return ret; + return true; } static bool test_NetShareEnumFull(struct torture_context *tctx, @@ -899,7 +748,6 @@ static bool test_NetSrvGetInfo(struct torture_context *tctx, struct srvsvc_NetSrvInfo503 i503; uint32_t levels[] = {100, 101, 102, 502, 503}; int i; - BOOL ret = True; uint32_t resume_handle; ZERO_STRUCT(i503); @@ -910,33 +758,25 @@ static bool test_NetSrvGetInfo(struct torture_context *tctx, ZERO_STRUCT(r.out); resume_handle = 0; r.in.level = levels[i]; - d_printf("testing NetSrvGetInfo level %u\n", r.in.level); + torture_comment(tctx, "testing NetSrvGetInfo level %u\n", r.in.level); status = dcerpc_srvsvc_NetSrvGetInfo(p, tctx, &r); - if (!NT_STATUS_IS_OK(status)) { - d_printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, nt_errstr(status)); - ret = False; - continue; - } - if (!W_ERROR_IS_OK(r.out.result)) { - d_printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, win_errstr(r.out.result)); - continue; - } + torture_assert_ntstatus_ok(tctx, status, "NetSrvGetInfo failed"); + torture_assert_werr_ok(tctx, r.out.result, "NetSrvGetInfo failed"); } - return ret; + return true; } /**************************/ /* srvsvc_NetDisk */ /**************************/ -static BOOL test_NetDiskEnum(struct torture_context *tctx, - struct dcerpc_pipe *p) +static bool test_NetDiskEnum(struct torture_context *tctx, + struct dcerpc_pipe *p) { NTSTATUS status; struct srvsvc_NetDiskEnum r; uint32_t levels[] = {0}; int i; - BOOL ret = True; uint32_t resume_handle=0; ZERO_STRUCT(r.in); @@ -946,21 +786,13 @@ static BOOL test_NetDiskEnum(struct torture_context *tctx, for (i=0;i