UNFINISHED - work on persistent open tests ( honour share-cap-ca and share-cap scaleout)
authorMichael Adam <obnox@samba.org>
Thu, 1 Mar 2012 23:35:38 +0000 (00:35 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 10 May 2012 16:46:53 +0000 (18:46 +0200)
source4/torture/smb2/durable_v2_open.c

index c855a1cec4848d0fba21884fd2ca5a9e48a6930c..21dc0b3b19976f215cf5b156f5b3b0ed215c5dd6 100644 (file)
@@ -542,59 +542,59 @@ bool test_persistent_open_lease(struct torture_context *tctx,
  * This test tests durable open with all possible oplock types.
  */
 
-struct persistent_open_vs_oplock {
+struct oplock_open_input {
        const char *level;
        const char *share_mode;
-       bool durable;
-       bool persistent;
 };
-
 #define NUM_OPLOCK_TYPES 4
 #define NUM_SHARE_MODES 8
 #define NUM_OPLOCK_OPEN_TESTS ( NUM_OPLOCK_TYPES * NUM_SHARE_MODES )
-struct persistent_open_vs_oplock persistent_open_vs_oplock_table[NUM_OPLOCK_OPEN_TESTS] =
-{
-       { "", "", true, true },
-       { "", "R", true, true },
-       { "", "W", true, true },
-       { "", "D", true, true },
-       { "", "RD", true, true },
-       { "", "RW", true, true },
-       { "", "WD", true, true },
-       { "", "RWD", true, true },
-
-       { "s", "", true, true },
-       { "s", "R", true, true },
-       { "s", "W", true, true },
-       { "s", "D", true, true },
-       { "s", "RD", true, true },
-       { "s", "RW", true, true },
-       { "s", "WD", true, true },
-       { "s", "RWD", true, true },
 
-       { "x", "", true, true },
-       { "x", "R", true, true },
-       { "x", "W", true, true },
-       { "x", "D", true, true },
-       { "x", "RD", true, true },
-       { "x", "RW", true, true },
-       { "x", "WD", true, true },
-       { "x", "RWD", true, true },
-
-       { "b", "", true, true },
-       { "b", "R", true, true },
-       { "b", "W", true, true },
-       { "b", "D", true, true },
-       { "b", "RD", true, true },
-       { "b", "RW", true, true },
-       { "b", "WD", true, true },
-       { "b", "RWD", true, true },
+struct oplock_open_input open_oplock_input_table[NUM_OPLOCK_OPEN_TESTS] =
+{
+       { "", "" },
+       { "", "R" },
+       { "", "W" },
+       { "", "D" },
+       { "", "RD" },
+       { "", "RW" },
+       { "", "WD" },
+       { "", "RWD" },
+
+       { "s", "" },
+       { "s", "R" },
+       { "s", "W" },
+       { "s", "D" },
+       { "s", "RD" },
+       { "s", "RW" },
+       { "s", "WD" },
+       { "s", "RWD" },
+
+       { "x", "" },
+       { "x", "R" },
+       { "x", "W" },
+       { "x", "D" },
+       { "x", "RD" },
+       { "x", "RW" },
+       { "x", "WD" },
+       { "x", "RWD" },
+
+       { "b", "" },
+       { "b", "R" },
+       { "b", "W" },
+       { "b", "D" },
+       { "b", "RD" },
+       { "b", "RW" },
+       { "b", "WD" },
+       { "b", "RWD" },
 };
 
 static bool test_one_persistent_open_oplock(struct torture_context *tctx,
                                            struct smb2_tree *tree,
                                            const char *fname,
-                                           struct persistent_open_vs_oplock test)
+                                           struct oplock_open_input input,
+                                           bool expected_durable_v2,
+                                           bool expected_persistent)
 {
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
@@ -606,8 +606,8 @@ static bool test_one_persistent_open_oplock(struct torture_context *tctx,
        smb2_util_unlink(tree, fname);
 
        smb2_oplock_create_share(&io, fname,
-                                smb2_util_share_access(test.share_mode),
-                                smb2_util_oplock_level(test.level));
+                                smb2_util_share_access(input.share_mode),
+                                smb2_util_oplock_level(input.level));
        io.in.durable_open = false;
        io.in.durable_open_v2 = true;
        io.in.persistent_open = true;
@@ -619,9 +619,9 @@ static bool test_one_persistent_open_oplock(struct torture_context *tctx,
        h = &_h;
        CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(io.out.durable_open, false);
-       CHECK_VAL(io.out.durable_open_v2, test.durable);
-       CHECK_VAL(io.out.persistent_open, test.persistent);
-       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level(test.level));
+       CHECK_VAL(io.out.durable_open_v2, expected_durable_v2);
+       CHECK_VAL(io.out.persistent_open, expected_persistent);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level(input.level));
 
 done:
        if (h != NULL) {
@@ -640,7 +640,7 @@ bool test_persistent_open_oplock(struct torture_context *tctx,
        char fname[256];
        bool ret = true;
        int i;
-       bool share_is_ca;
+       bool share_is_ca = false;
 
        /* Choose a random name in case the state is left a little funky. */
        snprintf(fname, 256, "persistent_open_oplock_%s.dat", generate_random_str(tctx, 8));
@@ -655,7 +655,9 @@ bool test_persistent_open_oplock(struct torture_context *tctx,
                ret = test_one_persistent_open_oplock(tctx,
                                                      tree,
                                                      fname,
-                                                     persistent_open_vs_oplock_table[i]);
+                                                     open_oplock_input_table[i],
+                                                     share_is_ca, /* expected durable v2 */
+                                                     share_is_ca  /* expexted persistent */);
                if (ret == false) {
                        goto done;
                }
@@ -677,67 +679,68 @@ done:
  * This test tests persistent open with all valid lease types.
  */
 
-struct persistent_open_vs_lease {
+struct open_lease_input {
        const char *type;
        const char *share_mode;
-       bool durable;
-       bool persistent;
 };
 
 #define NUM_LEASE_TYPES 5
 #define NUM_LEASE_OPEN_TESTS ( NUM_LEASE_TYPES * NUM_SHARE_MODES )
-struct persistent_open_vs_lease persistent_open_vs_lease_table[NUM_LEASE_OPEN_TESTS] =
-{
-       { "", "", true, true },
-       { "", "R", true, true },
-       { "", "W", true, true },
-       { "", "D", true, true },
-       { "", "RW", true, true },
-       { "", "RD", true, true },
-       { "", "WD", true, true },
-       { "", "RWD", true, true },
-
-       { "R", "", true, true },
-       { "R", "R", true, true },
-       { "R", "W", true, true },
-       { "R", "D", true, true },
-       { "R", "RW", true, true },
-       { "R", "RD", true, true },
-       { "R", "DW", true, true },
-       { "R", "RWD", true, true },
-
-       { "RW", "", true, true },
-       { "RW", "R", true, true },
-       { "RW", "W", true, true },
-       { "RW", "D", true, true },
-       { "RW", "RW", true, true },
-       { "RW", "RD", true, true },
-       { "RW", "WD", true, true },
-       { "RW", "RWD", true, true },
-
-       { "RH", "", true, true },
-       { "RH", "R", true, true },
-       { "RH", "W", true, true },
-       { "RH", "D", true, true },
-       { "RH", "RW", true, true },
-       { "RH", "RD", true, true },
-       { "RH", "WD", true, true },
-       { "RH", "RWD", true, true },
 
-       { "RHW", "", true, true },
-       { "RHW", "R", true, true },
-       { "RHW", "W", true, true },
-       { "RHW", "D", true, true },
-       { "RHW", "RW", true, true },
-       { "RHW", "RD", true, true },
-       { "RHW", "WD", true, true },
-       { "RHW", "RWD", true, true },
+struct open_lease_input open_lease_input_table[NUM_LEASE_OPEN_TESTS] =
+{
+       { "", "" },
+       { "", "R" },
+       { "", "W" },
+       { "", "D" },
+       { "", "RW" },
+       { "", "RD" },
+       { "", "WD" },
+       { "", "RWD" },
+
+       { "R", "" },
+       { "R", "R" },
+       { "R", "W" },
+       { "R", "D" },
+       { "R", "RW" },
+       { "R", "RD" },
+       { "R", "DW" },
+       { "R", "RWD" },
+
+       { "RW", "" },
+       { "RW", "R" },
+       { "RW", "W" },
+       { "RW", "D" },
+       { "RW", "RW" },
+       { "RW", "RD" },
+       { "RW", "WD" },
+       { "RW", "RWD" },
+
+       { "RH", "" },
+       { "RH", "R" },
+       { "RH", "W" },
+       { "RH", "D" },
+       { "RH", "RW" },
+       { "RH", "RD" },
+       { "RH", "WD" },
+       { "RH", "RWD" },
+
+       { "RHW", "" },
+       { "RHW", "R" },
+       { "RHW", "W" },
+       { "RHW", "D" },
+       { "RHW", "RW" },
+       { "RHW", "RD" },
+       { "RHW", "WD" },
+       { "RHW", "RWD" },
 };
 
 static bool test_one_persistent_open_lease(struct torture_context *tctx,
                                           struct smb2_tree *tree,
                                           const char *fname,
-                                          struct persistent_open_vs_lease test)
+                                          struct open_lease_input input,
+                                          bool expected_durable_v2,
+                                          bool expected_persistent)
 {
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
@@ -753,9 +756,9 @@ static bool test_one_persistent_open_lease(struct torture_context *tctx,
        lease = random();
 
        smb2_lease_create_share(&io, &ls, false /* dir */, fname,
-                               smb2_util_share_access(test.share_mode),
+                               smb2_util_share_access(input.share_mode),
                                lease,
-                               smb2_util_lease_state(test.type));
+                               smb2_util_lease_state(input.type));
        io.in.durable_open = false;
        io.in.durable_open_v2 = true;
        io.in.persistent_open = true;
@@ -767,13 +770,13 @@ static bool test_one_persistent_open_lease(struct torture_context *tctx,
        h = &_h;
        CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(io.out.durable_open, false);
-       CHECK_VAL(io.out.durable_open_v2, test.durable);
-       CHECK_VAL(io.out.persistent_open, test.persistent);
+       CHECK_VAL(io.out.durable_open_v2, expected_durable_v2);
+       CHECK_VAL(io.out.persistent_open, expected_persistent);
        CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
        CHECK_VAL(io.out.lease_response.lease_key.data[0], lease);
        CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease);
        CHECK_VAL(io.out.lease_response.lease_state,
-                 smb2_util_lease_state(test.type));
+                 smb2_util_lease_state(input.type));
 done:
        if (h != NULL) {
                smb2_util_close(tree, *h);
@@ -792,6 +795,10 @@ bool test_persistent_open_lease(struct torture_context *tctx,
        bool ret = true;
        int i;
        uint32_t caps;
+       bool share_is_ca;
+       bool share_is_scaleout;
+       bool expected_persistent;
+       bool expected_durable_v2;
 
        caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
        if (!(caps & SMB2_CAP_LEASING)) {
@@ -803,6 +810,11 @@ bool test_persistent_open_lease(struct torture_context *tctx,
 
        smb2_util_unlink(tree, fname);
 
+       share_is_ca = tree->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY;
+       share_is_scaleout = tree->capabilities & SMB2_SHARE_CAP_SCALEOUT;
+
+       expected_persistent = share_is_ca;
+       expected_durable_v2 = !share_is_scaleout;
 
        /* test various oplock levels with persistent open */
 
@@ -810,7 +822,9 @@ bool test_persistent_open_lease(struct torture_context *tctx,
                ret = test_one_persistent_open_lease(tctx,
                                                     tree,
                                                     fname,
-                                                    persistent_open_vs_lease_table[i]);
+                                                    open_lease_input_table[i],
+                                                    share_is_ca, /* expected durable v2 */
+                                                    share_is_ca  /* expected persistent */);
                if (ret == false) {
                        goto done;
                }