2 Unix SMB/CIFS implementation.
4 generic testing tool - version with SMB2 support
6 Copyright (C) Andrew Tridgell 2003-2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/cmdline/popt_common.h"
24 #include "lib/events/events.h"
25 #include "system/time.h"
26 #include "system/filesys.h"
27 #include "libcli/raw/request.h"
28 #include "libcli/libcli.h"
29 #include "libcli/raw/libcliraw.h"
30 #include "libcli/smb2/smb2.h"
31 #include "libcli/smb2/smb2_calls.h"
32 #include "librpc/gen_ndr/security.h"
33 #include "auth/credentials/credentials.h"
34 #include "libcli/resolve/resolve.h"
35 #include "auth/gensec/gensec.h"
36 #include "param/param.h"
37 #include "dynconfig.h"
43 static struct gentest_options {
47 int analyze_continuous;
48 uint_t max_open_handles;
52 char **ignore_patterns;
53 const char *seeds_file;
58 /* mapping between open handles on the server and local handles */
62 struct smb2_handle server_handle[NSERVERS];
65 static uint_t num_open_handles;
67 /* state information for the servers. We open NINSTANCES connections to
70 struct smb2_tree *tree[NINSTANCES];
73 struct cli_credentials *credentials;
76 /* the seeds and flags for each operation */
83 /* oplock break info */
86 struct smb2_handle server_handle;
90 } oplocks[NSERVERS][NINSTANCES];
92 /* change notify reply info */
96 union smb_notify notify;
97 } notifies[NSERVERS][NINSTANCES];
99 /* info relevant to the current operation */
108 static struct smb2_handle bad_smb2_handle;
111 #define BAD_HANDLE 0xFFFE
113 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
114 static void idle_func(struct smb2_transport *transport, void *private);
117 check if a string should be ignored. This is used as the basis
118 for all error ignore settings
120 static bool ignore_pattern(const char *str)
123 if (!options.ignore_patterns) return false;
125 for (i=0;options.ignore_patterns[i];i++) {
126 if (strcmp(options.ignore_patterns[i], str) == 0 ||
127 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
128 DEBUG(2,("Ignoring '%s'\n", str));
135 /*****************************************************
136 connect to the servers
137 *******************************************************/
138 static bool connect_servers_fast(void)
142 /* close all open files */
143 for (h=0;h<options.max_open_handles;h++) {
144 if (!open_handles[h].active) continue;
145 for (i=0;i<NSERVERS;i++) {
146 NTSTATUS status = smb2_util_close(servers[i].tree[open_handles[h].instance],
147 open_handles[h].server_handle[i]);
148 if (NT_STATUS_IS_ERR(status)) {
151 open_handles[h].active = false;
161 /*****************************************************
162 connect to the servers
163 *******************************************************/
164 static bool connect_servers(struct event_context *ev,
165 struct loadparm_context *lp_ctx)
169 if (options.fast_reconnect && servers[0].tree[0]) {
170 if (connect_servers_fast()) {
175 /* close any existing connections */
176 for (i=0;i<NSERVERS;i++) {
177 for (j=0;j<NINSTANCES;j++) {
178 if (servers[i].tree[j]) {
179 smb2_tdis(servers[i].tree[j]);
180 talloc_free(servers[i].tree[j]);
181 servers[i].tree[j] = NULL;
186 for (i=0;i<NSERVERS;i++) {
187 for (j=0;j<NINSTANCES;j++) {
189 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
190 servers[i].server_name, servers[i].share_name,
191 servers[i].credentials->username, j);
193 cli_credentials_set_workstation(servers[i].credentials,
194 "gentest", CRED_SPECIFIED);
196 status = smb2_connect(NULL, servers[i].server_name,
197 servers[i].share_name,
198 lp_resolve_context(lp_ctx),
199 servers[i].credentials,
202 if (!NT_STATUS_IS_OK(status)) {
203 printf("Failed to connect to \\\\%s\\%s - %s\n",
204 servers[i].server_name, servers[i].share_name,
209 // smb2_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
210 smb2_transport_idle_handler(servers[i].tree[j]->session->transport, idle_func, 50000, NULL);
218 work out the time skew between the servers - be conservative
220 static uint_t time_skew(void)
223 ret = labs(servers[0].tree[0]->session->transport->negotiate.system_time -
224 servers[1].tree[0]->session->transport->negotiate.system_time);
229 static bool smb2_handle_equal(const struct smb2_handle *h1, const struct smb2_handle *h2)
231 return memcmp(h1, h2, sizeof(struct smb2_handle)) == 0;
235 turn a server handle into a local handle
237 static uint_t fnum_to_handle(int server, int instance, struct smb2_handle server_handle)
240 for (i=0;i<options.max_open_handles;i++) {
241 if (!open_handles[i].active ||
242 instance != open_handles[i].instance) continue;
243 if (smb2_handle_equal(&open_handles[i].server_handle[server], &server_handle)) {
247 printf("Invalid server handle in fnum_to_handle on server %d instance %d\n",
253 add some newly opened handles
255 static void gen_add_handle(int instance, const char *name, struct smb2_handle handles[NSERVERS])
258 for (h=0;h<options.max_open_handles;h++) {
259 if (!open_handles[h].active) break;
261 if (h == options.max_open_handles) {
262 /* we have to force close a random handle */
263 h = random() % options.max_open_handles;
264 for (i=0;i<NSERVERS;i++) {
266 status = smb2_util_close(servers[i].tree[open_handles[h].instance],
267 open_handles[h].server_handle[i]);
268 if (NT_STATUS_IS_ERR(status)) {
269 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
273 printf("Recovered handle %d\n", h);
276 for (i=0;i<NSERVERS;i++) {
277 open_handles[h].server_handle[i] = handles[i];
278 open_handles[h].instance = instance;
279 open_handles[h].active = true;
280 open_handles[h].name = name;
284 printf("OPEN num_open_handles=%d h=%d (%s)\n",
285 num_open_handles, h, name);
289 remove a closed handle
291 static void gen_remove_handle(int instance, struct smb2_handle handles[NSERVERS])
294 for (h=0;h<options.max_open_handles;h++) {
295 if (instance == open_handles[h].instance &&
296 smb2_handle_equal(&open_handles[h].server_handle[0], &handles[0])) {
297 open_handles[h].active = false;
299 printf("CLOSE num_open_handles=%d h=%d (%s)\n",
301 open_handles[h].name);
305 printf("Removing invalid handle!?\n");
310 return true with 'chance' probability as a percentage
312 static bool gen_chance(uint_t chance)
314 return ((random() % 100) <= chance);
318 map an internal handle number to a server handle
320 static struct smb2_handle gen_lookup_handle(int server, uint16_t handle)
322 if (handle == BAD_HANDLE) return bad_smb2_handle;
323 return open_handles[handle].server_handle[server];
329 static uint16_t gen_fnum(int instance)
334 if (gen_chance(20)) return BAD_HANDLE;
336 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
337 h = random() % options.max_open_handles;
338 if (open_handles[h].active &&
339 open_handles[h].instance == instance) {
347 return a file handle, but skewed so we don't close the last
348 couple of handles too readily
350 static uint16_t gen_fnum_close(int instance)
352 if (num_open_handles < 5) {
353 if (gen_chance(90)) return BAD_HANDLE;
356 return gen_fnum(instance);
360 generate an integer in a specified range
362 static int gen_int_range(uint64_t min, uint64_t max)
365 return min + (r % (1+max-min));
369 return a fnum for use as a root fid
370 be careful to call GEN_SET_FNUM() when you use this!
372 static uint16_t gen_root_fid(int instance)
374 if (gen_chance(5)) return gen_fnum(instance);
379 generate a file offset
381 static int gen_offset(void)
383 if (gen_chance(20)) return 0;
384 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
385 return gen_int_range(0, 1024*1024);
391 static int gen_io_count(void)
393 if (gen_chance(20)) return 0;
394 // if (gen_chance(5)) return gen_int_range(0, 0xFFFFFFFF);
395 return gen_int_range(0, 4096);
401 static const char *gen_fname(void)
403 const char *names[] = {"gentest\\gentest.dat",
408 "gentest\\foo4:teststream1",
409 "gentest\\foo4:teststream2",
411 "gentest\\foo5.exe:teststream3",
412 "gentest\\foo5.exe:teststream4",
415 "gentest\\blah\\blergh.txt",
416 "gentest\\blah\\blergh2",
417 "gentest\\blah\\blergh3.txt",
418 "gentest\\blah\\blergh4",
419 "gentest\\blah\\blergh5.txt",
420 "gentest\\blah\\blergh5",
423 /* this causes problem with w2k3 */
426 "gentest\\a_very_long_name.bin",
432 i = gen_int_range(0, ARRAY_SIZE(names)-1);
433 } while (ignore_pattern(names[i]));
439 generate a filename with a higher chance of choosing an already
442 static const char *gen_fname_open(int instance)
445 h = gen_fnum(instance);
446 if (h == BAD_HANDLE) {
449 return open_handles[h].name;
453 generate a wildcard pattern
455 static const char *gen_pattern(void)
458 const char *names[] = {"gentest\\*.dat",
461 "gentest\\blah\\*.*",
465 if (gen_chance(50)) return gen_fname();
468 i = gen_int_range(0, ARRAY_SIZE(names)-1);
469 } while (ignore_pattern(names[i]));
474 static uint32_t gen_bits_levels(int nlevels, ...)
480 va_start(ap, nlevels);
481 for (i=0;i<nlevels;i++) {
482 pct = va_arg(ap, uint32_t);
483 mask = va_arg(ap, uint32_t);
484 if (pct == 100 || gen_chance(pct)) {
486 return mask & random();
496 static uint32_t gen_bits_mask(uint_t mask)
498 uint_t ret = random();
503 generate a bitmask with high probability of the first mask
504 and low of the second
506 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
508 if (gen_chance(10)) return gen_bits_mask(mask2);
509 return gen_bits_mask(mask1);
515 static bool gen_bool(void)
517 return gen_bits_mask2(0x1, 0xFF);
521 generate ntrename flags
523 static uint16_t gen_rename_flags(void)
525 if (gen_chance(30)) return RENAME_FLAG_RENAME;
526 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
527 if (gen_chance(30)) return RENAME_FLAG_COPY;
528 return gen_bits_mask(0xFFFF);
533 return a set of lock flags
535 static uint16_t gen_lock_flags(void)
537 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
538 if (gen_chance(20)) return gen_bits_mask(0x1F);
539 if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK;
540 return gen_bits_mask(SMB2_LOCK_FLAG_SHARED |
541 SMB2_LOCK_FLAG_EXCLUSIVE |
542 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY);
548 static uint16_t gen_pid(void)
550 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
555 generate a lock count
557 static off_t gen_lock_count(void)
559 return gen_int_range(0, 3);
563 generate a ntcreatex flags field
565 static uint32_t gen_ntcreatex_flags(void)
567 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
568 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
572 generate a NT access mask
574 static uint32_t gen_access_mask(void)
576 if (gen_chance(70)) return SEC_FLAG_MAXIMUM_ALLOWED;
577 if (gen_chance(70)) return SEC_FILE_ALL;
578 return gen_bits_mask(0xFFFFFFFF);
582 generate a ntcreatex create options bitfield
584 static uint32_t gen_create_options(void)
586 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
587 if (gen_chance(50)) return 0;
588 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
592 generate a ntcreatex open disposition
594 static uint32_t gen_open_disp(void)
596 if (gen_chance(50)) return NTCREATEX_DISP_OPEN_IF;
597 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
598 return gen_int_range(0, 5);
602 generate an openx open mode
604 static uint16_t gen_openx_mode(void)
606 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
607 if (gen_chance(20)) return gen_bits_mask(0xFF);
608 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
612 generate an openx flags field
614 static uint16_t gen_openx_flags(void)
616 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
617 return gen_bits_mask(0x7);
621 generate an openx open function
623 static uint16_t gen_openx_func(void)
625 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
626 return gen_bits_mask(0x13);
630 generate a file attrib combination
632 static uint32_t gen_attrib(void)
634 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
635 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
639 generate a unix timestamp
641 static time_t gen_timet(void)
643 if (gen_chance(30)) return 0;
644 return (time_t)random();
648 generate a unix timestamp
650 static NTTIME gen_nttime(void)
653 unix_to_nt_time(&ret, gen_timet());
658 generate a milliseconds protocol timeout
660 static uint32_t gen_timeout(void)
662 if (gen_chance(98)) return 0;
663 return random() % 50;
667 generate a file allocation size
669 static uint_t gen_alloc_size(void)
673 if (gen_chance(30)) return 0;
675 ret = random() % 4*1024*1024;
676 /* give a high chance of a round number */
677 if (gen_chance(60)) {
678 ret &= ~(1024*1024 - 1);
684 generate an ea_struct
686 static struct ea_struct gen_ea_struct(void)
689 const char *names[] = {"EAONE",
694 "AVERYLONGATTRIBUTENAME"};
695 const char *values[] = {"VALUE1",
700 "ASOMEWHATLONGERATTRIBUTEVALUE"};
706 i = gen_int_range(0, ARRAY_SIZE(names)-1);
707 } while (ignore_pattern(names[i]));
709 ea.name.s = names[i];
712 i = gen_int_range(0, ARRAY_SIZE(values)-1);
713 } while (ignore_pattern(values[i]));
715 ea.value = data_blob(values[i], strlen(values[i]));
717 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
724 the idle function tries to cope with getting an oplock break on a connection, and
725 an operation on another connection blocking until that break is acked
726 we check for operations on all transports in the idle function
728 static void idle_func(struct smb2_transport *transport, void *private)
731 for (i=0;i<NSERVERS;i++) {
732 for (j=0;j<NINSTANCES;j++) {
733 if (servers[i].tree[j] &&
734 transport != servers[i].tree[j]->session->transport) {
735 // smb2_transport_process(servers[i].tree[j]->session->transport);
744 compare NTSTATUS, using checking ignored patterns
746 static bool compare_status(NTSTATUS status1, NTSTATUS status2)
748 if (NT_STATUS_EQUAL(status1, status2)) return true;
750 /* one code being an error and the other OK is always an error */
751 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return false;
753 /* if we are ignoring one of the status codes then consider this a match */
754 if (ignore_pattern(nt_errstr(status1)) ||
755 ignore_pattern(nt_errstr(status2))) {
763 check for pending packets on all connections
765 static void check_pending(void)
771 for (j=0;j<NINSTANCES;j++) {
772 for (i=0;i<NSERVERS;i++) {
773 // smb2_transport_process(servers[i].tree[j]->session->transport);
779 check that the same oplock breaks have been received by all instances
781 static bool check_oplocks(const char *call)
790 for (j=0;j<NINSTANCES;j++) {
791 for (i=1;i<NSERVERS;i++) {
792 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
793 oplocks[0][j].handle != oplocks[i][j].handle ||
794 oplocks[0][j].level != oplocks[i][j].level) {
795 if (tries++ < 10) goto again;
796 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
797 oplocks[0][j].got_break,
798 oplocks[0][j].handle,
800 oplocks[i][j].got_break,
801 oplocks[i][j].handle,
802 oplocks[i][j].level);
808 /* if we got a break and closed then remove the handle */
809 for (j=0;j<NINSTANCES;j++) {
810 if (oplocks[0][j].got_break &&
811 oplocks[0][j].do_close) {
812 uint16_t fnums[NSERVERS];
813 for (i=0;i<NSERVERS;i++) {
814 fnums[i] = oplocks[i][j].fnum;
816 gen_remove_handle(j, fnums);
826 check that the same change notify info has been received by all instances
828 static bool check_notifies(const char *call)
837 for (j=0;j<NINSTANCES;j++) {
838 for (i=1;i<NSERVERS;i++) {
840 union smb_notify not1, not2;
842 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
843 if (tries++ < 10) goto again;
844 printf("Notify count inconsistent %d %d\n",
845 notifies[0][j].notify_count,
846 notifies[i][j].notify_count);
850 if (notifies[0][j].notify_count == 0) continue;
852 if (!NT_STATUS_EQUAL(notifies[0][j].status,
853 notifies[i][j].status)) {
854 printf("Notify status mismatch - %s - %s\n",
855 nt_errstr(notifies[0][j].status),
856 nt_errstr(notifies[i][j].status));
860 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
864 not1 = notifies[0][j].notify;
865 not2 = notifies[i][j].notify;
867 for (n=0;n<not1.nttrans.out.num_changes;n++) {
868 if (not1.nttrans.out.changes[n].action !=
869 not2.nttrans.out.changes[n].action) {
870 printf("Notify action %d inconsistent %d %d\n", n,
871 not1.nttrans.out.changes[n].action,
872 not2.nttrans.out.changes[n].action);
875 if (strcmp(not1.nttrans.out.changes[n].name.s,
876 not2.nttrans.out.changes[n].name.s)) {
877 printf("Notify name %d inconsistent %s %s\n", n,
878 not1.nttrans.out.changes[n].name.s,
879 not2.nttrans.out.changes[n].name.s);
882 if (not1.nttrans.out.changes[n].name.private_length !=
883 not2.nttrans.out.changes[n].name.private_length) {
884 printf("Notify name length %d inconsistent %d %d\n", n,
885 not1.nttrans.out.changes[n].name.private_length,
886 not2.nttrans.out.changes[n].name.private_length);
893 ZERO_STRUCT(notifies);
899 #define GEN_COPY_PARM do { \
901 for (i=1;i<NSERVERS;i++) { \
906 #define GEN_CALL(call) do { \
908 ZERO_STRUCT(oplocks); \
909 ZERO_STRUCT(notifies); \
910 for (i=0;i<NSERVERS;i++) { \
911 struct smb2_tree *tree = servers[i].tree[instance]; \
914 current_op.status = status[0]; \
915 for (i=1;i<NSERVERS;i++) { \
916 if (!compare_status(status[i], status[0])) { \
917 printf("status different in %s - %s %s\n", #call, \
918 nt_errstr(status[0]), nt_errstr(status[i])); \
922 if (!check_oplocks(#call)) return false; \
923 if (!check_notifies(#call)) return false; \
924 if (!NT_STATUS_IS_OK(status[0])) { \
929 #define ADD_HANDLE(name, field) do { \
930 struct smb2_handle handles[NSERVERS]; \
932 for (i=0;i<NSERVERS;i++) { \
933 handles[i] = parm[i].field; \
935 gen_add_handle(instance, name, handles); \
938 #define REMOVE_HANDLE(field) do { \
939 struct smb2_handle handles[NSERVERS]; \
941 for (i=0;i<NSERVERS;i++) { \
942 handles[i] = parm[i].field; \
944 gen_remove_handle(instance, handles); \
947 #define GEN_SET_FNUM(field) do { \
949 for (i=0;i<NSERVERS;i++) { \
950 parm[i].field = gen_lookup_handle(i, parm[i].field.data[0]); \
954 #define CHECK_EQUAL(field) do { \
955 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
956 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
957 (int)parm[0].field, (int)parm[1].field); \
962 #define CHECK_WSTR_EQUAL(field) do { \
963 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
964 printf("%s is NULL!\n", #field); \
967 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
968 printf("Mismatch in %s - %s %s\n", #field, \
969 parm[0].field.s, parm[1].field.s); \
972 CHECK_EQUAL(field.private_length); \
975 #define CHECK_BLOB_EQUAL(field) do { \
976 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
977 printf("Mismatch in %s\n", #field); \
980 CHECK_EQUAL(field.length); \
983 #define CHECK_TIMES_EQUAL(field) do { \
984 if (labs(parm[0].field - parm[1].field) > time_skew() && \
985 !ignore_pattern(#field)) { \
986 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
987 (int)parm[0].field, (int)parm[1].field); \
992 #define CHECK_NTTIMES_EQUAL(field) do { \
993 if (labs(nt_time_to_unix(parm[0].field) - \
994 nt_time_to_unix(parm[1].field)) > time_skew() && \
995 !ignore_pattern(#field)) { \
996 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
997 (int)nt_time_to_unix(parm[0].field), \
998 (int)nt_time_to_unix(parm[1].field)); \
1004 generate ntcreatex operations
1006 static bool handler_create(int instance)
1008 struct smb2_create parm[NSERVERS];
1009 NTSTATUS status[NSERVERS];
1011 ZERO_STRUCT(parm[0]);
1012 parm[0].in.security_flags = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFF);
1013 parm[0].in.oplock_level = gen_bits_levels(3, 90, 0x0, 70, 0x9, 100, 0xFF);
1014 parm[0].in.impersonation_level = gen_bits_levels(3, 90, 0x0, 70, 0x3, 100, 0xFFFFFFFF);
1015 parm[0].in.create_flags = gen_bits_levels(2, 90, 0x0, 100, 0xFFFFFFFF);
1016 if (gen_chance(2)) {
1017 parm[0].in.create_flags |= gen_bits_mask(0xFFFFFFFF);
1019 parm[0].in.reserved = gen_bits_levels(2, 95, 0x0, 100, 0xFFFFFFFF);
1020 if (gen_chance(2)) {
1021 parm[0].in.reserved |= gen_bits_mask(0xFFFFFFFF);
1023 parm[0].in.desired_access = gen_access_mask();
1024 parm[0].in.file_attributes = gen_attrib();
1025 parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1026 parm[0].in.create_disposition = gen_open_disp();
1027 parm[0].in.create_options = gen_create_options();
1028 parm[0].in.fname = gen_fname_open(instance);
1030 if (!options.use_oplocks) {
1031 /* mask out oplocks */
1032 parm[0].in.oplock_level = 0;
1036 GEN_CALL(smb2_create(tree, current_op.mem_ctx, &parm[i]));
1038 CHECK_EQUAL(out.oplock_level);
1039 CHECK_EQUAL(out.reserved);
1040 CHECK_EQUAL(out.create_action);
1041 CHECK_NTTIMES_EQUAL(out.create_time);
1042 CHECK_NTTIMES_EQUAL(out.access_time);
1043 CHECK_NTTIMES_EQUAL(out.write_time);
1044 CHECK_NTTIMES_EQUAL(out.change_time);
1045 CHECK_EQUAL(out.alloc_size);
1046 CHECK_EQUAL(out.size);
1047 CHECK_EQUAL(out.file_attr);
1048 CHECK_EQUAL(out.reserved2);
1050 /* ntcreatex creates a new file handle */
1051 ADD_HANDLE(parm[0].in.fname, out.file.handle);
1057 generate close operations
1059 static bool handler_close(int instance)
1061 struct smb2_close parm[NSERVERS];
1062 NTSTATUS status[NSERVERS];
1064 ZERO_STRUCT(parm[0]);
1065 parm[0].in.file.handle.data[0] = gen_fnum_close(instance);
1066 parm[0].in.flags = gen_bits_mask2(0x1, 0xFFFF);
1069 GEN_SET_FNUM(in.file.handle);
1070 GEN_CALL(smb2_close(tree, &parm[i]));
1072 CHECK_EQUAL(out.flags);
1073 CHECK_EQUAL(out._pad);
1074 CHECK_NTTIMES_EQUAL(out.create_time);
1075 CHECK_NTTIMES_EQUAL(out.access_time);
1076 CHECK_NTTIMES_EQUAL(out.write_time);
1077 CHECK_NTTIMES_EQUAL(out.change_time);
1078 CHECK_EQUAL(out.alloc_size);
1079 CHECK_EQUAL(out.size);
1080 CHECK_EQUAL(out.file_attr);
1082 REMOVE_HANDLE(in.file.handle);
1088 generate read operations
1090 static bool handler_read(int instance)
1092 struct smb2_read parm[NSERVERS];
1093 NTSTATUS status[NSERVERS];
1095 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1096 parm[0].in.reserved = gen_bits_mask2(0x0, 0xFF);
1097 parm[0].in.length = gen_io_count();
1098 parm[0].in.offset = gen_offset();
1099 parm[0].in.min_count = gen_io_count();
1100 parm[0].in.channel = gen_bits_mask2(0x0, 0xFFFFFFFF);
1101 parm[0].in.remaining = gen_bits_mask2(0x0, 0xFFFFFFFF);
1102 parm[0].in.channel_offset = gen_bits_mask2(0x0, 0xFFFF);
1103 parm[0].in.channel_length = gen_bits_mask2(0x0, 0xFFFF);
1106 GEN_SET_FNUM(in.file.handle);
1107 GEN_CALL(smb2_read(tree, current_op.mem_ctx, &parm[i]));
1109 CHECK_EQUAL(out.remaining);
1110 CHECK_EQUAL(out.reserved);
1111 CHECK_EQUAL(out.data.length);
1117 generate write operations
1119 static bool handler_write(int instance)
1121 struct smb2_write parm[NSERVERS];
1122 NTSTATUS status[NSERVERS];
1124 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1125 parm[0].in.offset = gen_offset();
1126 parm[0].in.unknown1 = gen_bits_mask2(0, 0xFFFFFFFF);
1127 parm[0].in.unknown2 = gen_bits_mask2(0, 0xFFFFFFFF);
1128 parm[0].in.data = data_blob_talloc(current_op.mem_ctx, NULL,
1132 GEN_SET_FNUM(in.file.handle);
1133 GEN_CALL(smb2_write(tree, &parm[i]));
1135 CHECK_EQUAL(out._pad);
1136 CHECK_EQUAL(out.nwritten);
1137 CHECK_EQUAL(out.unknown1);
1143 generate lockingx operations
1145 static bool handler_lock(int instance)
1147 struct smb2_lock parm[NSERVERS];
1148 NTSTATUS status[NSERVERS];
1151 parm[0].level = RAW_LOCK_LOCKX;
1152 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1153 parm[0].in.lock_count = gen_lock_count();
1154 parm[0].in.reserved = gen_bits_mask2(0, 0xFFFFFFFF);
1156 parm[0].in.locks = talloc_array(current_op.mem_ctx,
1157 struct smb2_lock_element,
1158 parm[0].in.lock_count);
1159 for (n=0;n<parm[0].in.lock_count;n++) {
1160 parm[0].in.locks[n].offset = gen_offset();
1161 parm[0].in.locks[n].length = gen_io_count();
1162 /* don't yet cope with async replies */
1163 parm[0].in.locks[n].flags = gen_lock_flags() |
1164 SMB2_LOCK_FLAG_FAIL_IMMEDIATELY;
1165 parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF);
1169 GEN_SET_FNUM(in.file.handle);
1170 GEN_CALL(smb2_lock(tree, &parm[i]));
1176 generate flush operations
1178 static bool handler_flush(int instance)
1180 struct smb2_flush parm[NSERVERS];
1181 NTSTATUS status[NSERVERS];
1183 ZERO_STRUCT(parm[0]);
1184 parm[0].in.file.handle.data[0] = gen_fnum(instance);
1185 parm[0].in.reserved1 = gen_bits_mask2(0x0, 0xFFFF);
1186 parm[0].in.reserved2 = gen_bits_mask2(0x0, 0xFFFFFFFF);
1189 GEN_SET_FNUM(in.file.handle);
1190 GEN_CALL(smb2_flush(tree, &parm[i]));
1192 CHECK_EQUAL(out.reserved);
1198 generate echo operations
1200 static bool handler_echo(int instance)
1202 NTSTATUS status[NSERVERS];
1204 GEN_CALL(smb2_keepalive(tree->session->transport));
1212 generate a fileinfo query structure
1214 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1217 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1219 enum smb_fileinfo_level level;
1222 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1223 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1224 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1225 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1226 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1227 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1228 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1229 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1230 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1231 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1234 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1235 } while (ignore_pattern(levels[i].name));
1237 info->generic.level = levels[i].level;
1241 compare returned fileinfo structures
1243 static bool cmp_fileinfo(int instance,
1244 union smb_fileinfo parm[NSERVERS],
1245 NTSTATUS status[NSERVERS])
1249 switch (parm[0].generic.level) {
1250 case RAW_FILEINFO_GENERIC:
1253 case RAW_FILEINFO_GETATTR:
1254 CHECK_EQUAL(getattr.out.attrib);
1255 CHECK_EQUAL(getattr.out.size);
1256 CHECK_TIMES_EQUAL(getattr.out.write_time);
1259 case RAW_FILEINFO_GETATTRE:
1260 CHECK_TIMES_EQUAL(getattre.out.create_time);
1261 CHECK_TIMES_EQUAL(getattre.out.access_time);
1262 CHECK_TIMES_EQUAL(getattre.out.write_time);
1263 CHECK_EQUAL(getattre.out.size);
1264 CHECK_EQUAL(getattre.out.alloc_size);
1265 CHECK_EQUAL(getattre.out.attrib);
1268 case RAW_FILEINFO_STANDARD:
1269 CHECK_TIMES_EQUAL(standard.out.create_time);
1270 CHECK_TIMES_EQUAL(standard.out.access_time);
1271 CHECK_TIMES_EQUAL(standard.out.write_time);
1272 CHECK_EQUAL(standard.out.size);
1273 CHECK_EQUAL(standard.out.alloc_size);
1274 CHECK_EQUAL(standard.out.attrib);
1277 case RAW_FILEINFO_EA_SIZE:
1278 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1279 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1280 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1281 CHECK_EQUAL(ea_size.out.size);
1282 CHECK_EQUAL(ea_size.out.alloc_size);
1283 CHECK_EQUAL(ea_size.out.attrib);
1284 CHECK_EQUAL(ea_size.out.ea_size);
1287 case RAW_FILEINFO_ALL_EAS:
1288 CHECK_EQUAL(all_eas.out.num_eas);
1289 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1290 CHECK_EQUAL(all_eas.out.eas[i].flags);
1291 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1292 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1296 case RAW_FILEINFO_IS_NAME_VALID:
1299 case RAW_FILEINFO_BASIC_INFO:
1300 case RAW_FILEINFO_BASIC_INFORMATION:
1301 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1302 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1303 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1304 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1305 CHECK_EQUAL(basic_info.out.attrib);
1308 case RAW_FILEINFO_STANDARD_INFO:
1309 case RAW_FILEINFO_STANDARD_INFORMATION:
1310 CHECK_EQUAL(standard_info.out.alloc_size);
1311 CHECK_EQUAL(standard_info.out.size);
1312 CHECK_EQUAL(standard_info.out.nlink);
1313 CHECK_EQUAL(standard_info.out.delete_pending);
1314 CHECK_EQUAL(standard_info.out.directory);
1317 case RAW_FILEINFO_EA_INFO:
1318 case RAW_FILEINFO_EA_INFORMATION:
1319 CHECK_EQUAL(ea_info.out.ea_size);
1322 case RAW_FILEINFO_NAME_INFO:
1323 case RAW_FILEINFO_NAME_INFORMATION:
1324 CHECK_WSTR_EQUAL(name_info.out.fname);
1327 case RAW_FILEINFO_ALL_INFO:
1328 case RAW_FILEINFO_ALL_INFORMATION:
1329 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1330 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1331 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1332 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1333 CHECK_EQUAL(all_info.out.attrib);
1334 CHECK_EQUAL(all_info.out.alloc_size);
1335 CHECK_EQUAL(all_info.out.size);
1336 CHECK_EQUAL(all_info.out.nlink);
1337 CHECK_EQUAL(all_info.out.delete_pending);
1338 CHECK_EQUAL(all_info.out.directory);
1339 CHECK_EQUAL(all_info.out.ea_size);
1340 CHECK_WSTR_EQUAL(all_info.out.fname);
1343 case RAW_FILEINFO_ALT_NAME_INFO:
1344 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1345 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1348 case RAW_FILEINFO_STREAM_INFO:
1349 case RAW_FILEINFO_STREAM_INFORMATION:
1350 CHECK_EQUAL(stream_info.out.num_streams);
1351 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1352 CHECK_EQUAL(stream_info.out.streams[i].size);
1353 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1354 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1358 case RAW_FILEINFO_COMPRESSION_INFO:
1359 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1360 CHECK_EQUAL(compression_info.out.compressed_size);
1361 CHECK_EQUAL(compression_info.out.format);
1362 CHECK_EQUAL(compression_info.out.unit_shift);
1363 CHECK_EQUAL(compression_info.out.chunk_shift);
1364 CHECK_EQUAL(compression_info.out.cluster_shift);
1367 case RAW_FILEINFO_INTERNAL_INFORMATION:
1368 CHECK_EQUAL(internal_information.out.file_id);
1371 case RAW_FILEINFO_ACCESS_INFORMATION:
1372 CHECK_EQUAL(access_information.out.access_flags);
1375 case RAW_FILEINFO_POSITION_INFORMATION:
1376 CHECK_EQUAL(position_information.out.position);
1379 case RAW_FILEINFO_MODE_INFORMATION:
1380 CHECK_EQUAL(mode_information.out.mode);
1383 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1384 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1387 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1388 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1389 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1390 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1391 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1392 CHECK_EQUAL(network_open_information.out.alloc_size);
1393 CHECK_EQUAL(network_open_information.out.size);
1394 CHECK_EQUAL(network_open_information.out.attrib);
1397 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1398 CHECK_EQUAL(attribute_tag_information.out.attrib);
1399 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1402 /* Unhandled levels */
1404 case RAW_FILEINFO_SEC_DESC:
1405 case RAW_FILEINFO_EA_LIST:
1406 case RAW_FILEINFO_UNIX_BASIC:
1407 case RAW_FILEINFO_UNIX_LINK:
1408 case RAW_FILEINFO_SMB2_ALL_EAS:
1409 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1410 case RAW_FILEINFO_UNIX_INFO2:
1418 generate qfileinfo operations
1420 static bool handler_qfileinfo(int instance)
1422 union smb_fileinfo parm[NSERVERS];
1423 NTSTATUS status[NSERVERS];
1425 parm[0].generic.in.file.fnum = gen_fnum(instance);
1427 gen_fileinfo(instance, &parm[0]);
1430 GEN_SET_FNUM(generic.in.file.fnum);
1431 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1433 return cmp_fileinfo(instance, parm, status);
1438 generate a fileinfo query structure
1440 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1444 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1446 enum smb_setfileinfo_level level;
1450 /* disabled until win2003 can handle them ... */
1451 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1452 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1454 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1455 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1456 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1457 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1458 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1461 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1462 } while (ignore_pattern(levels[i].name));
1464 info->generic.level = levels[i].level;
1466 switch (info->generic.level) {
1467 case RAW_SFILEINFO_SETATTR:
1468 info->setattr.in.attrib = gen_attrib();
1469 info->setattr.in.write_time = gen_timet();
1471 case RAW_SFILEINFO_SETATTRE:
1472 info->setattre.in.create_time = gen_timet();
1473 info->setattre.in.access_time = gen_timet();
1474 info->setattre.in.write_time = gen_timet();
1476 case RAW_SFILEINFO_STANDARD:
1477 info->standard.in.create_time = gen_timet();
1478 info->standard.in.access_time = gen_timet();
1479 info->standard.in.write_time = gen_timet();
1481 case RAW_SFILEINFO_EA_SET: {
1482 static struct ea_struct ea;
1483 info->ea_set.in.num_eas = 1;
1484 info->ea_set.in.eas = &ea;
1485 info->ea_set.in.eas[0] = gen_ea_struct();
1488 case RAW_SFILEINFO_BASIC_INFO:
1489 case RAW_SFILEINFO_BASIC_INFORMATION:
1490 info->basic_info.in.create_time = gen_nttime();
1491 info->basic_info.in.access_time = gen_nttime();
1492 info->basic_info.in.write_time = gen_nttime();
1493 info->basic_info.in.change_time = gen_nttime();
1494 info->basic_info.in.attrib = gen_attrib();
1496 case RAW_SFILEINFO_DISPOSITION_INFO:
1497 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1498 info->disposition_info.in.delete_on_close = gen_bool();
1500 case RAW_SFILEINFO_ALLOCATION_INFO:
1501 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1502 info->allocation_info.in.alloc_size = gen_alloc_size();
1504 case RAW_SFILEINFO_END_OF_FILE_INFO:
1505 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1506 info->end_of_file_info.in.size = gen_offset();
1508 case RAW_SFILEINFO_RENAME_INFORMATION:
1509 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
1510 info->rename_information.in.overwrite = gen_bool();
1511 info->rename_information.in.root_fid = gen_root_fid(instance);
1512 info->rename_information.in.new_name = gen_fname_open(instance);
1514 case RAW_SFILEINFO_POSITION_INFORMATION:
1515 info->position_information.in.position = gen_offset();
1517 case RAW_SFILEINFO_MODE_INFORMATION:
1518 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1520 case RAW_SFILEINFO_GENERIC:
1521 case RAW_SFILEINFO_SEC_DESC:
1522 case RAW_SFILEINFO_UNIX_BASIC:
1523 case RAW_SFILEINFO_UNIX_LINK:
1524 case RAW_SFILEINFO_UNIX_HLINK:
1525 case RAW_SFILEINFO_1023:
1526 case RAW_SFILEINFO_1025:
1527 case RAW_SFILEINFO_1029:
1528 case RAW_SFILEINFO_1032:
1529 case RAW_SFILEINFO_1039:
1530 case RAW_SFILEINFO_1040:
1531 case RAW_SFILEINFO_UNIX_INFO2:
1538 generate setfileinfo operations
1540 static bool handler_sfileinfo(int instance)
1542 union smb_setfileinfo parm[NSERVERS];
1543 NTSTATUS status[NSERVERS];
1545 parm[0].generic.in.file.fnum = gen_fnum(instance);
1547 gen_setfileinfo(instance, &parm[0]);
1550 GEN_SET_FNUM(generic.in.file.fnum);
1551 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1560 wipe any relevant files
1562 static void wipe_files(void)
1567 for (i=0;i<NSERVERS;i++) {
1568 int n = smb2_deltree(servers[i].tree[0], "gentest");
1570 printf("Failed to wipe tree on server %d\n", i);
1573 status = smb2_util_mkdir(servers[i].tree[0], "gentest");
1574 if (NT_STATUS_IS_ERR(status)) {
1575 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
1579 printf("Deleted %d files on server %d\n", n, i);
1585 dump the current seeds - useful for continuing a backtrack
1587 static void dump_seeds(void)
1592 if (!options.seeds_file) {
1595 f = fopen("seeds.tmp", "w");
1598 for (i=0;i<options.numops;i++) {
1599 fprintf(f, "%u\n", op_parms[i].seed);
1602 rename("seeds.tmp", options.seeds_file);
1608 the list of top-level operations that we will generate
1612 bool (*handler)(int instance);
1613 int count, success_count;
1615 {"CREATE", handler_create},
1616 {"CLOSE", handler_close},
1617 {"READ", handler_read},
1618 {"WRITE", handler_write},
1619 {"LOCK", handler_lock},
1620 {"FLUSH", handler_flush},
1621 {"ECHO", handler_echo},
1626 run the test with the current set of op_parms parameters
1627 return the number of operations that completed successfully
1629 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
1633 if (!connect_servers(ev, lp_ctx)) {
1634 printf("Failed to connect to servers\n");
1640 /* wipe any leftover files from old runs */
1643 /* reset the open handles array */
1644 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1645 num_open_handles = 0;
1647 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1648 gen_ops[i].count = 0;
1649 gen_ops[i].success_count = 0;
1652 for (op=0; op<options.numops; op++) {
1653 int instance, which_op;
1656 if (op_parms[op].disabled) continue;
1658 srandom(op_parms[op].seed);
1660 instance = gen_int_range(0, NINSTANCES-1);
1662 /* generate a non-ignored operation */
1664 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1665 } while (ignore_pattern(gen_ops[which_op].name));
1667 DEBUG(3,("Generating op %s on instance %d\n",
1668 gen_ops[which_op].name, instance));
1670 current_op.seed = op_parms[op].seed;
1671 current_op.opnum = op;
1672 current_op.name = gen_ops[which_op].name;
1673 current_op.status = NT_STATUS_OK;
1674 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1676 ret = gen_ops[which_op].handler(instance);
1678 talloc_free(current_op.mem_ctx);
1680 gen_ops[which_op].count++;
1681 if (NT_STATUS_IS_OK(current_op.status)) {
1682 gen_ops[which_op].success_count++;
1686 printf("Failed at operation %d - %s\n",
1687 op, gen_ops[which_op].name);
1691 if (op % 100 == 0) {
1696 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1697 printf("Op %-10s got %d/%d success\n",
1699 gen_ops[i].success_count,
1707 perform a backtracking analysis of the minimal set of operations
1708 to generate an error
1710 static void backtrack_analyze(struct event_context *ev,
1711 struct loadparm_context *lp_ctx)
1715 chunk = options.numops / 2;
1720 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1723 chunk = MIN(chunk, options.numops / 2);
1725 /* mark this range as disabled */
1726 max = MIN(options.numops, base+chunk);
1727 for (i=base;i<max; i++) {
1728 op_parms[i].disabled = true;
1730 printf("Testing %d ops with %d-%d disabled\n",
1731 options.numops, base, max-1);
1732 ret = run_test(ev, lp_ctx);
1733 printf("Completed %d of %d ops\n", ret, options.numops);
1734 for (i=base;i<max; i++) {
1735 op_parms[i].disabled = false;
1737 if (ret == options.numops) {
1738 /* this chunk is needed */
1740 } else if (ret < base) {
1741 printf("damn - inconsistent errors! found early error\n");
1742 options.numops = ret+1;
1745 /* it failed - this chunk isn't needed for a failure */
1746 memmove(&op_parms[base], &op_parms[max],
1747 sizeof(op_parms[0]) * (options.numops - max));
1748 options.numops = (ret+1) - (max - base);
1758 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
1761 } while (chunk > 0);
1763 printf("Reduced to %d ops\n", options.numops);
1764 ret = run_test(ev, lp_ctx);
1765 if (ret != options.numops - 1) {
1766 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
1771 start the main gentest process
1773 static bool start_gentest(struct event_context *ev,
1774 struct loadparm_context *lp_ctx)
1779 /* allocate the open_handles array */
1780 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
1782 srandom(options.seed);
1783 op_parms = calloc(options.numops, sizeof(op_parms[0]));
1785 /* generate the seeds - after this everything is deterministic */
1786 if (options.use_preset_seeds) {
1788 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
1790 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
1793 if (numops < options.numops) {
1794 options.numops = numops;
1796 for (op=0;op<options.numops;op++) {
1798 printf("Not enough seeds in %s\n", options.seeds_file);
1801 op_parms[op].seed = atoi(preset[op]);
1803 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
1805 for (op=0; op<options.numops; op++) {
1806 op_parms[op].seed = random();
1810 ret = run_test(ev, lp_ctx);
1812 if (ret != options.numops && options.analyze) {
1813 options.numops = ret+1;
1814 backtrack_analyze(ev, lp_ctx);
1815 } else if (options.analyze_always) {
1816 backtrack_analyze(ev, lp_ctx);
1817 } else if (options.analyze_continuous) {
1818 while (run_test(ev, lp_ctx) == options.numops) ;
1821 return ret == options.numops;
1825 static void usage(poptContext pc)
1829 gentest //server1/share1 //server2/share2 [options..]\n\
1831 poptPrintUsage(pc, stdout, 0);
1835 split a UNC name into server and share names
1837 static bool split_unc_name(const char *unc, char **server, char **share)
1839 char *p = strdup(unc);
1840 if (!p) return false;
1841 all_string_sub(p, "\\", "/", 0);
1842 if (strncmp(p, "//", 2) != 0) return false;
1845 p = strchr(*server, '/');
1846 if (!p) return false;
1856 /****************************************************************************
1858 ****************************************************************************/
1859 int main(int argc, char *argv[])
1862 int i, username_count=0;
1864 char *ignore_file=NULL;
1865 struct event_context *ev;
1866 struct loadparm_context *lp_ctx;
1870 enum {OPT_UNCLIST=1000};
1871 struct poptOption long_options[] = {
1873 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
1874 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
1875 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
1876 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
1877 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
1878 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
1879 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
1880 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
1881 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
1882 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
1883 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
1884 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
1885 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
1887 POPT_COMMON_CONNECTION
1888 POPT_COMMON_CREDENTIALS
1893 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
1896 options.seed = time(NULL);
1897 options.numops = 1000;
1898 options.max_open_handles = 20;
1899 options.seeds_file = "gentest_seeds.dat";
1901 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
1902 POPT_CONTEXT_KEEP_FIRST);
1904 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
1906 lp_ctx = cmdline_lp_ctx;
1907 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
1908 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
1909 cli_credentials_guess(servers[0].credentials, lp_ctx);
1910 cli_credentials_guess(servers[1].credentials, lp_ctx);
1912 while((opt = poptGetNextOpt(pc)) != -1) {
1915 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
1918 if (username_count == 2) {
1922 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
1929 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
1932 argv_new = discard_const_p(char *, poptGetArgs(pc));
1934 for (i=0; i<argc; i++) {
1935 if (argv_new[i] == NULL) {
1941 if (!(argc_new >= 3)) {
1948 setup_logging("gentest", DEBUG_STDOUT);
1950 if (argc < 3 || argv[1][0] == '-') {
1955 setup_logging(argv[0], DEBUG_STDOUT);
1957 for (i=0;i<NSERVERS;i++) {
1958 const char *share = argv[1+i];
1959 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
1960 printf("Invalid share name '%s'\n", share);
1965 if (username_count == 0) {
1969 if (username_count == 1) {
1970 servers[1].credentials = servers[0].credentials;
1973 printf("seed=%u\n", options.seed);
1975 ev = event_context_init(talloc_autofree_context());
1977 gensec_init(lp_ctx);
1979 ret = start_gentest(ev, lp_ctx);
1982 printf("gentest completed - no errors\n");
1984 printf("gentest failed\n");