1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s4:torture/smb2: make smb2.durable-v2-delay tests more robust

We should not crash when the test fails, so we use a 2nd independent
connection to unlink the file at the end.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
This commit is contained in:
Stefan Metzmacher 2020-07-04 11:50:14 +02:00 committed by Günther Deschner
parent 3fa9c3d5bb
commit 8fbb7ad275

View File

@ -2040,7 +2040,8 @@ struct torture_suite *torture_smb2_durable_v2_open_init(TALLOC_CTX *ctx)
* tcp disconnect, reconnect, do a durable reopen (succeeds) * tcp disconnect, reconnect, do a durable reopen (succeeds)
*/ */
static bool test_durable_v2_reconnect_delay(struct torture_context *tctx, static bool test_durable_v2_reconnect_delay(struct torture_context *tctx,
struct smb2_tree *tree) struct smb2_tree *tree,
struct smb2_tree *tree2)
{ {
NTSTATUS status; NTSTATUS status;
TALLOC_CTX *mem_ctx = talloc_new(tctx); TALLOC_CTX *mem_ctx = talloc_new(tctx);
@ -2053,6 +2054,7 @@ static bool test_durable_v2_reconnect_delay(struct torture_context *tctx,
uint64_t previous_session_id; uint64_t previous_session_id;
uint8_t b = 0; uint8_t b = 0;
bool ret = true; bool ret = true;
bool ok;
options = tree->session->transport->options; options = tree->session->transport->options;
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
@ -2087,20 +2089,17 @@ static bool test_durable_v2_reconnect_delay(struct torture_context *tctx,
/* disconnect, leaving the durable open */ /* disconnect, leaving the durable open */
TALLOC_FREE(tree); TALLOC_FREE(tree);
h = NULL;
if (!torture_smb2_connection_ext(tctx, previous_session_id, ok = torture_smb2_connection_ext(tctx, previous_session_id,
&options, &tree)) { &options, &tree);
torture_warning(tctx, "couldn't reconnect, bailing\n"); torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n");
ret = false;
goto done;
}
ZERO_STRUCT(io); ZERO_STRUCT(io);
io.in.fname = fname; io.in.fname = fname;
io.in.durable_open_v2 = false; io.in.durable_open_v2 = false;
io.in.durable_handle_v2 = h; io.in.durable_handle_v2 = &_h;
io.in.create_guid = create_guid; io.in.create_guid = create_guid;
h = NULL;
status = smb2_create(tree, mem_ctx, &io); status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK); CHECK_STATUS(status, NT_STATUS_OK);
@ -2112,10 +2111,11 @@ done:
if (h != NULL) { if (h != NULL) {
smb2_util_close(tree, *h); smb2_util_close(tree, *h);
} }
TALLOC_FREE(tree);
smb2_util_unlink(tree, fname); smb2_util_unlink(tree2, fname);
talloc_free(tree); TALLOC_FREE(tree2);
talloc_free(mem_ctx); talloc_free(mem_ctx);
@ -2126,8 +2126,9 @@ done:
* basic test for doing a durable open with 1msec cleanup time * basic test for doing a durable open with 1msec cleanup time
* tcp disconnect, wait a bit, reconnect, do a durable reopen (fails) * tcp disconnect, wait a bit, reconnect, do a durable reopen (fails)
*/ */
static bool test_durable_v2_reconnect_delay_msec( static bool test_durable_v2_reconnect_delay_msec(struct torture_context *tctx,
struct torture_context *tctx, struct smb2_tree *tree) struct smb2_tree *tree,
struct smb2_tree *tree2)
{ {
NTSTATUS status; NTSTATUS status;
TALLOC_CTX *mem_ctx = talloc_new(tctx); TALLOC_CTX *mem_ctx = talloc_new(tctx);
@ -2141,6 +2142,7 @@ static bool test_durable_v2_reconnect_delay_msec(
uint64_t previous_session_id; uint64_t previous_session_id;
uint8_t b = 0; uint8_t b = 0;
bool ret = true; bool ret = true;
bool ok;
options = tree->session->transport->options; options = tree->session->transport->options;
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
@ -2179,22 +2181,19 @@ static bool test_durable_v2_reconnect_delay_msec(
/* disconnect, leaving the durable open */ /* disconnect, leaving the durable open */
TALLOC_FREE(tree); TALLOC_FREE(tree);
h = NULL;
if (!torture_smb2_connection_ext(tctx, previous_session_id, ok = torture_smb2_connection_ext(tctx, previous_session_id,
&options, &tree)) { &options, &tree);
torture_warning(tctx, "couldn't reconnect, bailing\n"); torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n");
ret = false;
goto done;
}
sleep(10); sleep(10);
ZERO_STRUCT(io); ZERO_STRUCT(io);
io.in.fname = fname; io.in.fname = fname;
io.in.durable_open_v2 = false; io.in.durable_open_v2 = false;
io.in.durable_handle_v2 = h; io.in.durable_handle_v2 = &_h;
io.in.create_guid = create_guid; io.in.create_guid = create_guid;
h = NULL;
status = smb2_create(tree, mem_ctx, &io); status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
@ -2205,10 +2204,11 @@ done:
if (h != NULL) { if (h != NULL) {
smb2_util_close(tree, *h); smb2_util_close(tree, *h);
} }
TALLOC_FREE(tree);
smb2_util_unlink(tree, fname); smb2_util_unlink(tree2, fname);
talloc_free(tree); TALLOC_FREE(tree2);
talloc_free(mem_ctx); talloc_free(mem_ctx);
@ -2220,8 +2220,10 @@ struct torture_suite *torture_smb2_durable_v2_delay_init(TALLOC_CTX *ctx)
struct torture_suite *suite = struct torture_suite *suite =
torture_suite_create(ctx, "durable-v2-delay"); torture_suite_create(ctx, "durable-v2-delay");
torture_suite_add_1smb2_test(suite, "durable_v2_reconnect_delay", test_durable_v2_reconnect_delay); torture_suite_add_2smb2_test(suite,
torture_suite_add_1smb2_test(suite, "durable_v2_reconnect_delay",
test_durable_v2_reconnect_delay);
torture_suite_add_2smb2_test(suite,
"durable_v2_reconnect_delay_msec", "durable_v2_reconnect_delay_msec",
test_durable_v2_reconnect_delay_msec); test_durable_v2_reconnect_delay_msec);