1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s4:torture:smb2 prefer torture_comment() to printf().

Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
This commit is contained in:
Günther Deschner 2016-02-22 15:40:50 +01:00
parent 16592252cf
commit 5bbaf81612
8 changed files with 88 additions and 80 deletions

View File

@ -96,7 +96,7 @@ static NTSTATUS torture_smb2_write(struct torture_context *tctx, struct smb2_tre
return status;
}
torture_smb2_all_info(tree, handle);
torture_smb2_all_info(tctx, tree, handle);
status = smb2_write(tree, &w);
if (!NT_STATUS_IS_OK(status)) {
@ -104,7 +104,7 @@ static NTSTATUS torture_smb2_write(struct torture_context *tctx, struct smb2_tre
return status;
}
torture_smb2_all_info(tree, handle);
torture_smb2_all_info(tctx, tree, handle);
ZERO_STRUCT(f);
f.in.file.handle = handle;

View File

@ -808,7 +808,7 @@ static bool test_smb2_open(struct torture_context *tctx,
smb2_util_close(tree, h1);
smb2_util_unlink(tree, fname);
status = smb2_create_complex_file(tree, fname, &h1);
status = smb2_create_complex_file(tctx, tree, fname, &h1);
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_close(tree, h1);

View File

@ -441,7 +441,7 @@ static bool test_one_file(struct torture_context *tctx,
status = torture_smb2_testdir(tree, DNAME, &h);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
status = smb2_create_complex_file(tree, DNAME "\\torture_search.txt",
status = smb2_create_complex_file(tctx, tree, DNAME "\\torture_search.txt",
&h2);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
@ -1012,7 +1012,7 @@ static bool test_modify_search(struct torture_context *tctx,
smb2_util_close(tree, create.out.file.handle);
files[num_files + 2].name = talloc_asprintf(mem_ctx, "T013-13.txt.3");
status = smb2_create_complex_file(tree, DNAME "\\T013-13.txt.3", &h);
status = smb2_create_complex_file(tctx, tree, DNAME "\\T013-13.txt.3", &h);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
smb2_util_unlink(tree, DNAME "\\T014-14.txt");

View File

@ -95,8 +95,8 @@ static bool torture_smb2_fileinfo(struct torture_context *tctx, struct smb2_tree
DNAME "\n");
torture_comment(tctx, "Testing file info levels\n");
torture_smb2_all_info(tree, hfile);
torture_smb2_all_info(tree, hdir);
torture_smb2_all_info(tctx, tree, hfile);
torture_smb2_all_info(tctx, tree, hdir);
for (i=0;i<ARRAY_SIZE(file_levels);i++) {
if (file_levels[i].level == RAW_FILEINFO_SEC_DESC) {
@ -441,35 +441,35 @@ static bool torture_smb2_qsec_buffercheck(struct torture_context *tctx)
/* basic testing of all SMB2 getinfo levels
*/
static bool torture_smb2_getinfo(struct torture_context *torture)
static bool torture_smb2_getinfo(struct torture_context *tctx)
{
struct smb2_tree *tree;
bool ret = true;
NTSTATUS status;
ret = torture_smb2_connection(torture, &tree);
torture_assert(torture, ret, "connection failed");
ret = torture_smb2_connection(tctx, &tree);
torture_assert(tctx, ret, "connection failed");
smb2_deltree(tree, FNAME);
smb2_deltree(tree, DNAME);
status = torture_setup_complex_file(tree, FNAME);
torture_assert_ntstatus_ok(torture, status,
status = torture_setup_complex_file(tctx, tree, FNAME);
torture_assert_ntstatus_ok(tctx, status,
"setup complex file " FNAME);
status = torture_setup_complex_file(tree, FNAME ":streamtwo");
torture_assert_ntstatus_ok(torture, status,
status = torture_setup_complex_file(tctx, tree, FNAME ":streamtwo");
torture_assert_ntstatus_ok(tctx, status,
"setup complex file " FNAME ":streamtwo");
status = torture_setup_complex_dir(tree, DNAME);
torture_assert_ntstatus_ok(torture, status,
status = torture_setup_complex_dir(tctx, tree, DNAME);
torture_assert_ntstatus_ok(tctx, status,
"setup complex dir " DNAME);
status = torture_setup_complex_file(tree, DNAME ":streamtwo");
torture_assert_ntstatus_ok(torture, status,
status = torture_setup_complex_file(tctx, tree, DNAME ":streamtwo");
torture_assert_ntstatus_ok(tctx, status,
"setup complex dir " DNAME ":streamtwo");
ret &= torture_smb2_fileinfo(torture, tree);
ret &= torture_smb2_fileinfo(tctx, tree);
return ret;
}

View File

@ -114,7 +114,7 @@ static bool test_valid_request(struct torture_context *torture,
}
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(torture, tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, torture, &n);
@ -136,7 +136,7 @@ static bool test_valid_request(struct torture_context *torture,
}
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(torture, tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, torture, &n);
@ -155,7 +155,7 @@ static bool test_valid_request(struct torture_context *torture,
}
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(torture, tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, torture, &n);
@ -187,7 +187,7 @@ static bool test_valid_request(struct torture_context *torture,
}
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(torture, tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, torture, &n);
@ -201,7 +201,7 @@ static bool test_valid_request(struct torture_context *torture,
}
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(torture, tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, torture, &n);
@ -1066,7 +1066,7 @@ static bool torture_smb2_notify_mask(struct torture_context *torture,
sinfo.basic_info.in.create_time = 0;
torture_comment(torture, "Testing set file create time\n");
NOTIFY_MASK_TEST("Testing set file create time",
smb2_create_complex_file(tree2,
smb2_create_complex_file(torture, tree2,
BASEDIR "\\tname1", &h2);,
smb2_setinfo_file(tree2, &sinfo);,
(smb2_util_close(tree2, h2),
@ -1081,7 +1081,7 @@ static bool torture_smb2_notify_mask(struct torture_context *torture,
sinfo.basic_info.in.access_time = 0;
torture_comment(torture, "Testing set file access time\n");
NOTIFY_MASK_TEST("Testing set file access time",
smb2_create_complex_file(tree2, BASEDIR "\\tname1", &h2);,
smb2_create_complex_file(torture, tree2, BASEDIR "\\tname1", &h2);,
smb2_setinfo_file(tree2, &sinfo);,
(smb2_util_close(tree2, h2),
smb2_util_unlink(tree2, BASEDIR "\\tname1"));,
@ -1094,7 +1094,7 @@ static bool torture_smb2_notify_mask(struct torture_context *torture,
sinfo.basic_info.in.change_time = 0;
torture_comment(torture, "Testing set file change time\n");
NOTIFY_MASK_TEST("Testing set file change time",
smb2_create_complex_file(tree2, BASEDIR "\\tname1", &h2);,
smb2_create_complex_file(torture, tree2, BASEDIR "\\tname1", &h2);,
smb2_setinfo_file(tree2, &sinfo);,
(smb2_util_close(tree2, h2),
smb2_util_unlink(tree2, BASEDIR "\\tname1"));,
@ -1104,7 +1104,7 @@ static bool torture_smb2_notify_mask(struct torture_context *torture,
torture_comment(torture, "Testing write\n");
NOTIFY_MASK_TEST("Testing write",
smb2_create_complex_file(tree2, BASEDIR "\\tname1", &h2);,
smb2_create_complex_file(torture, tree2, BASEDIR "\\tname1", &h2);,
smb2_util_write(tree2, h2, &c, 10000, 1);,
(smb2_util_close(tree2, h2),
smb2_util_unlink(tree2, BASEDIR "\\tname1"));,

View File

@ -49,22 +49,22 @@ static bool torture_smb2_getinfo_scan(struct torture_context *tctx)
return false;
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(tctx, tree, FNAME);
if (!NT_STATUS_IS_OK(status)) {
torture_comment(tctx, "Failed to setup complex file '%s': %s\n",
FNAME, nt_errstr(status));
return false;
}
torture_setup_complex_file(tree, FNAME2);
torture_setup_complex_file(tctx, tree, FNAME2);
status = torture_setup_complex_dir(tree, DNAME);
status = torture_setup_complex_dir(tctx, tree, DNAME);
if (!NT_STATUS_IS_OK(status)) {
torture_comment(tctx, "Failed to setup complex dir '%s': %s\n",
DNAME, nt_errstr(status));
smb2_util_unlink(tree, FNAME);
return false;
}
torture_setup_complex_file(tree, DNAME2);
torture_setup_complex_file(tctx, tree, DNAME2);
torture_smb2_testfile(tree, FNAME, &fhandle);
torture_smb2_testdir(tree, DNAME, &dhandle);
@ -123,13 +123,13 @@ static bool torture_smb2_setinfo_scan(struct torture_context *tctx)
return false;
}
status = torture_setup_complex_file(tree, FNAME);
status = torture_setup_complex_file(tctx, tree, FNAME);
if (!NT_STATUS_IS_OK(status)) {
torture_comment(tctx, "Failed to setup complex file '%s': %s\n",
FNAME, nt_errstr(status));
return false;
}
torture_setup_complex_file(tree, FNAME2);
torture_setup_complex_file(tctx, tree, FNAME2);
torture_smb2_testfile(tree, FNAME, &handle);

View File

@ -102,7 +102,7 @@ bool torture_smb2_setinfo(struct torture_context *tctx)
#define RECREATE_FILE(fname) do { \
smb2_util_close(tree, handle); \
status = smb2_create_complex_file(tree, fname, &handle); \
status = smb2_create_complex_file(tctx, tree, fname, &handle); \
if (!NT_STATUS_IS_OK(status)) { \
torture_result(tctx, TORTURE_FAIL, "(%s) ERROR: open of %s failed (%s)\n", \
__location__, fname, nt_errstr(status)); \
@ -147,7 +147,7 @@ bool torture_smb2_setinfo(struct torture_context *tctx)
torture_result(tctx, TORTURE_FAIL, "(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(unsigned int)value, (unsigned int)finfo2.stype.out.field); \
torture_smb2_all_info(tree, handle); \
torture_smb2_all_info(tctx, tree, handle); \
ret = false; \
goto done; \
}} while (0)
@ -161,7 +161,7 @@ bool torture_smb2_setinfo(struct torture_context *tctx)
(unsigned int)nt_time_to_unix(finfo2.stype.out.field)); \
torture_warning(tctx, "\t%s", timestring(tctx, value)); \
torture_warning(tctx, "\t%s\n", nt_time_string(tctx, finfo2.stype.out.field)); \
torture_smb2_all_info(tree, handle); \
torture_smb2_all_info(tctx, tree, handle); \
ret = false; \
goto done; \
}} while (0)
@ -174,7 +174,7 @@ bool torture_smb2_setinfo(struct torture_context *tctx)
goto done; \
}} while (0)
torture_smb2_all_info(tree, handle);
torture_smb2_all_info(tctx, tree, handle);
torture_comment(tctx, "Test basic_information level\n");
basetime += 86400;

View File

@ -55,8 +55,11 @@ NTSTATUS smb2_util_write(struct smb2_tree *tree,
/*
create a complex file/dir using the SMB2 protocol
*/
static NTSTATUS smb2_create_complex(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle, bool dir)
static NTSTATUS smb2_create_complex(struct torture_context *tctx,
struct smb2_tree *tree,
const char *fname,
struct smb2_handle *handle,
bool dir)
{
TALLOC_CTX *tmp_ctx = talloc_new(tree);
char buf[7] = "abc";
@ -121,7 +124,7 @@ static NTSTATUS smb2_create_complex(struct smb2_tree *tree, const char *fname,
status = smb2_setinfo_file(tree, &setfile);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to setup file times - %s\n", nt_errstr(status));
torture_comment(tctx, "Failed to setup file times - %s\n", nt_errstr(status));
return status;
}
@ -131,14 +134,14 @@ static NTSTATUS smb2_create_complex(struct smb2_tree *tree, const char *fname,
status = smb2_getinfo_file(tree, tree, &fileinfo);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to query file times - %s\n", nt_errstr(status));
torture_comment(tctx, "Failed to query file times - %s\n", nt_errstr(status));
return status;
}
#define CHECK_TIME(field) do {\
if (setfile.basic_info.in.field != fileinfo.all_info2.out.field) { \
printf("(%s) " #field " not setup correctly: %s(%llu) => %s(%llu)\n", \
torture_comment(tctx, "(%s) " #field " not setup correctly: %s(%llu) => %s(%llu)\n", \
__location__, \
nt_time_string(tree, setfile.basic_info.in.field), \
(unsigned long long)setfile.basic_info.in.field, \
@ -159,25 +162,28 @@ static NTSTATUS smb2_create_complex(struct smb2_tree *tree, const char *fname,
/*
create a complex file using the SMB2 protocol
*/
NTSTATUS smb2_create_complex_file(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
NTSTATUS smb2_create_complex_file(struct torture_context *tctx,
struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
{
return smb2_create_complex(tree, fname, handle, false);
return smb2_create_complex(tctx, tree, fname, handle, false);
}
/*
create a complex dir using the SMB2 protocol
*/
NTSTATUS smb2_create_complex_dir(struct smb2_tree *tree, const char *fname,
NTSTATUS smb2_create_complex_dir(struct torture_context *tctx,
struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
{
return smb2_create_complex(tree, fname, handle, true);
return smb2_create_complex(tctx, tree, fname, handle, true);
}
/*
show lots of information about a file
*/
void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
void torture_smb2_all_info(struct torture_context *tctx,
struct smb2_tree *tree, struct smb2_handle handle)
{
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tree);
@ -193,29 +199,29 @@ void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
return;
}
d_printf("all_info for '%s'\n", io.all_info2.out.fname.s);
d_printf("\tcreate_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.create_time));
d_printf("\taccess_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.access_time));
d_printf("\twrite_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.write_time));
d_printf("\tchange_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.change_time));
d_printf("\tattrib: 0x%x\n", io.all_info2.out.attrib);
d_printf("\tunknown1: 0x%x\n", io.all_info2.out.unknown1);
d_printf("\talloc_size: %llu\n", (long long)io.all_info2.out.alloc_size);
d_printf("\tsize: %llu\n", (long long)io.all_info2.out.size);
d_printf("\tnlink: %u\n", io.all_info2.out.nlink);
d_printf("\tdelete_pending: %u\n", io.all_info2.out.delete_pending);
d_printf("\tdirectory: %u\n", io.all_info2.out.directory);
d_printf("\tfile_id: %llu\n", (long long)io.all_info2.out.file_id);
d_printf("\tea_size: %u\n", io.all_info2.out.ea_size);
d_printf("\taccess_mask: 0x%08x\n", io.all_info2.out.access_mask);
d_printf("\tposition: 0x%llx\n", (long long)io.all_info2.out.position);
d_printf("\tmode: 0x%llx\n", (long long)io.all_info2.out.mode);
torture_comment(tctx, "all_info for '%s'\n", io.all_info2.out.fname.s);
torture_comment(tctx, "\tcreate_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.create_time));
torture_comment(tctx, "\taccess_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.access_time));
torture_comment(tctx, "\twrite_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.write_time));
torture_comment(tctx, "\tchange_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.change_time));
torture_comment(tctx, "\tattrib: 0x%x\n", io.all_info2.out.attrib);
torture_comment(tctx, "\tunknown1: 0x%x\n", io.all_info2.out.unknown1);
torture_comment(tctx, "\talloc_size: %llu\n", (long long)io.all_info2.out.alloc_size);
torture_comment(tctx, "\tsize: %llu\n", (long long)io.all_info2.out.size);
torture_comment(tctx, "\tnlink: %u\n", io.all_info2.out.nlink);
torture_comment(tctx, "\tdelete_pending: %u\n", io.all_info2.out.delete_pending);
torture_comment(tctx, "\tdirectory: %u\n", io.all_info2.out.directory);
torture_comment(tctx, "\tfile_id: %llu\n", (long long)io.all_info2.out.file_id);
torture_comment(tctx, "\tea_size: %u\n", io.all_info2.out.ea_size);
torture_comment(tctx, "\taccess_mask: 0x%08x\n", io.all_info2.out.access_mask);
torture_comment(tctx, "\tposition: 0x%llx\n", (long long)io.all_info2.out.position);
torture_comment(tctx, "\tmode: 0x%llx\n", (long long)io.all_info2.out.mode);
/* short name, if any */
io.generic.level = RAW_FILEINFO_ALT_NAME_INFORMATION;
status = smb2_getinfo_file(tree, tmp_ctx, &io);
if (NT_STATUS_IS_OK(status)) {
d_printf("\tshort name: '%s'\n", io.alt_name_info.out.fname.s);
torture_comment(tctx, "\tshort name: '%s'\n", io.alt_name_info.out.fname.s);
}
/* the EAs, if any */
@ -224,7 +230,7 @@ void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
if (NT_STATUS_IS_OK(status)) {
int i;
for (i=0;i<io.all_eas.out.num_eas;i++) {
d_printf("\tEA[%d] flags=%d len=%d '%s'\n", i,
torture_comment(tctx, "\tEA[%d] flags=%d len=%d '%s'\n", i,
io.all_eas.out.eas[i].flags,
(int)io.all_eas.out.eas[i].value.length,
io.all_eas.out.eas[i].name.s);
@ -237,12 +243,12 @@ void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
if (NT_STATUS_IS_OK(status)) {
int i;
for (i=0;i<io.stream_info.out.num_streams;i++) {
d_printf("\tstream %d:\n", i);
d_printf("\t\tsize %ld\n",
torture_comment(tctx, "\tstream %d:\n", i);
torture_comment(tctx, "\t\tsize %ld\n",
(long)io.stream_info.out.streams[i].size);
d_printf("\t\talloc size %ld\n",
torture_comment(tctx, "\t\talloc size %ld\n",
(long)io.stream_info.out.streams[i].alloc_size);
d_printf("\t\tname %s\n", io.stream_info.out.streams[i].stream_name.s);
torture_comment(tctx, "\t\tname %s\n", io.stream_info.out.streams[i].stream_name.s);
}
}
@ -358,7 +364,7 @@ bool torture_smb2_session_setup(struct torture_context *tctx,
status = smb2_session_setup_spnego(session, credentials,
previous_session_id);
if (!NT_STATUS_IS_OK(status)) {
printf("session setup failed: %s\n", nt_errstr(status));
torture_comment(tctx, "session setup failed: %s\n", nt_errstr(status));
talloc_free(session);
return false;
}
@ -395,7 +401,7 @@ bool torture_smb2_connection_ext(struct torture_context *tctx,
lpcfg_gensec_settings(tctx, tctx->lp_ctx)
);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
torture_comment(tctx, "Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
host, share, nt_errstr(status));
return false;
}
@ -430,7 +436,7 @@ bool torture_smb2_con_sopt(struct torture_context *tctx,
lpcfg_smbcli_options(tctx->lp_ctx, &options);
if (share == NULL) {
printf("No share for option %s\n", soption);
torture_comment(tctx, "No share for option %s\n", soption);
return false;
}
@ -448,7 +454,7 @@ bool torture_smb2_con_sopt(struct torture_context *tctx,
lpcfg_gensec_settings(tctx, tctx->lp_ctx)
);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
torture_comment(tctx, "Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
host, share, nt_errstr(status));
return false;
}
@ -538,10 +544,11 @@ NTSTATUS torture_smb2_testdir(struct smb2_tree *tree, const char *fname,
create a complex file using SMB2, to make it easier to
find fields in SMB2 getinfo levels
*/
NTSTATUS torture_setup_complex_file(struct smb2_tree *tree, const char *fname)
NTSTATUS torture_setup_complex_file(struct torture_context *tctx,
struct smb2_tree *tree, const char *fname)
{
struct smb2_handle handle;
NTSTATUS status = smb2_create_complex_file(tree, fname, &handle);
NTSTATUS status = smb2_create_complex_file(tctx, tree, fname, &handle);
NT_STATUS_NOT_OK_RETURN(status);
return smb2_util_close(tree, handle);
}
@ -551,10 +558,11 @@ NTSTATUS torture_setup_complex_file(struct smb2_tree *tree, const char *fname)
create a complex dir using SMB2, to make it easier to
find fields in SMB2 getinfo levels
*/
NTSTATUS torture_setup_complex_dir(struct smb2_tree *tree, const char *fname)
NTSTATUS torture_setup_complex_dir(struct torture_context *tctx,
struct smb2_tree *tree, const char *fname)
{
struct smb2_handle handle;
NTSTATUS status = smb2_create_complex_dir(tree, fname, &handle);
NTSTATUS status = smb2_create_complex_dir(tctx, tree, fname, &handle);
NT_STATUS_NOT_OK_RETURN(status);
return smb2_util_close(tree, handle);
}