Split test 1 off test_multichannel_oplock_break()
authorSachin Prabhu <sprabhu@redhat.com>
Fri, 16 Feb 2018 06:47:07 +0000 (12:17 +0530)
committerSachin Prabhu <sprabhu@redhat.com>
Tue, 17 Jul 2018 20:46:27 +0000 (21:46 +0100)
Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
source4/torture/smb2/multichannel.c

index c5329dbb5760d6c2bafad8f8d08fbde339de0788..96a14afe68730983049ae763f8ab06a860a93b5c 100644 (file)
@@ -439,10 +439,17 @@ static void test_multichannel_init_smb_create(struct smb2_create *io)
        /* windows 2016 returns 300000 0x493E0 */
 }
 
-/**
- * Test Oplock Break with Multi Channel
+/*
+ * Oplock break - Test 1
+ * open file1 in session 2A
+ * open file2 in session 2B
+ * open file1 in session 1
+ *     oplock break received on 2B(last created channel)
+ * open file1 in session 1
+ *     oplock break received on 2B
+ * Cleanup
  */
-static bool test_multichannel_oplock_break(struct torture_context *tctx,
+static bool test_multichannel_oplock_break_test1(struct torture_context *tctx,
                                           struct smb2_tree *tree1)
 {
        const char *host = torture_setting_string(tctx, "host", NULL);
@@ -451,7 +458,6 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_handle _h;
-       struct smb2_handle *h = NULL;
        struct smb2_handle h_client1_file1 = { 0 };
        struct smb2_handle h_client1_file2 = { 0 };
        struct smb2_handle h_client1_file3 = { 0 };
@@ -469,13 +475,9 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        struct smb2_tree *tree2C = NULL;
        struct smb2_transport *transport1 = tree1->session->transport;
        struct smb2_transport *transport2B = NULL;
-       struct smb2_transport *transport2C = NULL;
        struct smbcli_options transport2_options;
        struct smb2_session *session1 = tree1->session;
        uint16_t local_port = 0;
-       bool block_ok = false;
-       bool unblock_ok = false;
-       DATA_BLOB blob;
 
        if (!test_multichannel_initial_checks(tctx, tree1))
                return true;
@@ -512,6 +514,8 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        test_multichannel_init_smb_create(&io3);
 
        transport2_options = transport1->options;
+
+       torture_comment(tctx, "Test 1 start \n");
        rval = test_multichannel_create_channels2(tctx, host, share,
                                                  credentials,
                                                  &transport2_options,
@@ -519,12 +523,8 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        CHECK_VAL(rval, 0);
        transport2B = tree2B->session->transport;
 
-       /* now the real test starts with opening files */
-
-       torture_comment(tctx, "client2 opens fname1 via session 2A\n");
-
        /* 2a opens file1 */
-
+       torture_comment(tctx, "client2 opens fname1 via session 2A\n");
        status = smb2_create(tree2A, mem_ctx, &io1);
        CHECK_STATUS(status, NT_STATUS_OK);
        h_client2_file1 = io1.out.file.handle;
@@ -533,9 +533,8 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        torture_wait_for_oplock_break(tctx);
        CHECK_VAL(break_info.count, 0);
 
-       torture_comment(tctx, "client2 opens fname2 via session 2B\n");
-
        /* 2b opens file2 */
+       torture_comment(tctx, "client2 opens fname2 via session 2B\n");
        status = smb2_create(tree2B, mem_ctx, &io2);
        CHECK_STATUS(status, NT_STATUS_OK);
        h_client2_file2 = io2.out.file.handle;
@@ -551,7 +550,6 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
         */
 
        torture_comment(tctx, "client1 opens fname1 via session 1\n");
-
        io1.in.oplock_level = smb2_util_oplock_level("b");
        status = smb2_create(tree1, mem_ctx, &io1);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -597,6 +595,103 @@ static bool test_multichannel_oplock_break(struct torture_context *tctx,
        CHECK_VAL(break_info.count, 0);
        test_multichannel_free_channels2(tree2A, tree2B, tree2C);
        tree2A = tree2B = tree2C = NULL;
+done:
+       tree1->session = session1;
+
+       smb2_util_close(tree1, h_client1_file1);
+       smb2_util_close(tree1, h_client1_file2);
+       smb2_util_close(tree1, h_client1_file3);
+       if (tree2A != NULL) {
+               smb2_util_close(tree2A, h_client2_file1);
+               smb2_util_close(tree2A, h_client2_file2);
+               smb2_util_close(tree2A, h_client2_file3);
+       }
+
+       smb2_util_unlink(tree1, fname1);
+       smb2_util_unlink(tree1, fname2);
+       smb2_util_unlink(tree1, fname3);
+       smb2_deltree(tree1, BASEDIR);
+
+       test_multichannel_free_channels2(tree2A, tree2B, tree2C);
+       talloc_free(tree1);
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/**
+ * Test Oplock Break with Multi Channel
+ */
+static bool test_multichannel_oplock_break(struct torture_context *tctx,
+                                          struct smb2_tree *tree1)
+{
+       const char *host = torture_setting_string(tctx, "host", NULL);
+       const char *share = torture_setting_string(tctx, "share", NULL);
+       struct cli_credentials *credentials = popt_get_cmdline_credentials();
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       struct smb2_handle _h;
+       struct smb2_handle *h = NULL;
+       struct smb2_handle h_client1_file1 = { 0 };
+       struct smb2_handle h_client1_file2 = { 0 };
+       struct smb2_handle h_client1_file3 = { 0 };
+       struct smb2_handle h_client2_file1 = { 0 };
+       struct smb2_handle h_client2_file2 = { 0 };
+       struct smb2_handle h_client2_file3 = { 0 };
+       struct smb2_create io1, io2, io3;
+       bool ret = true;
+       int rval;
+       const char *fname1 = BASEDIR "\\oplock_break_test1.dat";
+       const char *fname2 = BASEDIR "\\oplock_break_test2.dat";
+       const char *fname3 = BASEDIR "\\oplock_break_test3.dat";
+       struct smb2_tree *tree2A = NULL;
+       struct smb2_tree *tree2B = NULL;
+       struct smb2_tree *tree2C = NULL;
+       struct smb2_transport *transport1 = tree1->session->transport;
+       struct smb2_transport *transport2B = NULL;
+       struct smb2_transport *transport2C = NULL;
+       struct smbcli_options transport2_options;
+       struct smb2_session *session1 = tree1->session;
+       uint16_t local_port = 0;
+       bool block_ok = false;
+       bool unblock_ok = false;
+       DATA_BLOB blob;
+
+       if (!test_multichannel_initial_checks(tctx, tree1))
+               return true;
+
+       torture_reset_break_info(tctx, &break_info);
+
+       transport1->oplock.handler = torture_oplock_ack_handler;
+       transport1->oplock.private_data = tree1;
+       torture_comment(tctx, "transport1  [%p]\n", transport1);
+       local_port = torture_get_local_port_from_transport(transport1);
+       torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
+
+       status = torture_smb2_testdir(tree1, BASEDIR, &_h);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       smb2_util_close(tree1, _h);
+       smb2_util_unlink(tree1, fname1);
+       smb2_util_unlink(tree1, fname2);
+       smb2_util_unlink(tree1, fname3);
+       CHECK_VAL(break_info.count, 0);
+
+       smb2_oplock_create_share(&io1, fname1,
+                       smb2_util_share_access("RWD"),
+                       smb2_util_oplock_level("b"));
+       test_multichannel_init_smb_create(&io1);
+
+       smb2_oplock_create_share(&io2, fname2,
+                       smb2_util_share_access("RWD"),
+                       smb2_util_oplock_level("b"));
+       test_multichannel_init_smb_create(&io2);
+
+       smb2_oplock_create_share(&io3, fname3,
+                       smb2_util_share_access("RWD"),
+                       smb2_util_oplock_level("b"));
+       test_multichannel_init_smb_create(&io3);
+
+       transport2_options = transport1->options;
 
        /* now repeat the test with the third channel */
        rval = test_multichannel_create_channels2(tctx, host, share,
@@ -1906,6 +2001,7 @@ struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx)
        torture_suite_add_1smb2_test(suite, "session_bind_multiple_nics", test_session_bind_multiple_nics);
        torture_suite_add_1smb2_test(suite, "interface_info", test_multichannel_interface_info);
        torture_suite_add_1smb2_test(suite, "oplock_break", test_multichannel_oplock_break);
+       torture_suite_add_1smb2_test(suite, "oplock_break_test1", test_multichannel_oplock_break_test1);
        //torture_suite_add_1smb2_test(suite, "lease_break", test_multichannel_lease_break);
        torture_suite_add_1smb2_test(suite, "lease_break_test1", test_multichannel_lease_break_test1);
        torture_suite_add_1smb2_test(suite, "lease_break_test2", test_multichannel_lease_break_test2);