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);
1200 generate a fileinfo query structure
1202 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1205 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1207 enum smb_fileinfo_level level;
1210 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1211 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1212 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1213 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1214 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1215 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1216 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1217 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1218 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1219 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1222 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1223 } while (ignore_pattern(levels[i].name));
1225 info->generic.level = levels[i].level;
1229 compare returned fileinfo structures
1231 static bool cmp_fileinfo(int instance,
1232 union smb_fileinfo parm[NSERVERS],
1233 NTSTATUS status[NSERVERS])
1237 switch (parm[0].generic.level) {
1238 case RAW_FILEINFO_GENERIC:
1241 case RAW_FILEINFO_GETATTR:
1242 CHECK_EQUAL(getattr.out.attrib);
1243 CHECK_EQUAL(getattr.out.size);
1244 CHECK_TIMES_EQUAL(getattr.out.write_time);
1247 case RAW_FILEINFO_GETATTRE:
1248 CHECK_TIMES_EQUAL(getattre.out.create_time);
1249 CHECK_TIMES_EQUAL(getattre.out.access_time);
1250 CHECK_TIMES_EQUAL(getattre.out.write_time);
1251 CHECK_EQUAL(getattre.out.size);
1252 CHECK_EQUAL(getattre.out.alloc_size);
1253 CHECK_EQUAL(getattre.out.attrib);
1256 case RAW_FILEINFO_STANDARD:
1257 CHECK_TIMES_EQUAL(standard.out.create_time);
1258 CHECK_TIMES_EQUAL(standard.out.access_time);
1259 CHECK_TIMES_EQUAL(standard.out.write_time);
1260 CHECK_EQUAL(standard.out.size);
1261 CHECK_EQUAL(standard.out.alloc_size);
1262 CHECK_EQUAL(standard.out.attrib);
1265 case RAW_FILEINFO_EA_SIZE:
1266 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1267 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1268 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1269 CHECK_EQUAL(ea_size.out.size);
1270 CHECK_EQUAL(ea_size.out.alloc_size);
1271 CHECK_EQUAL(ea_size.out.attrib);
1272 CHECK_EQUAL(ea_size.out.ea_size);
1275 case RAW_FILEINFO_ALL_EAS:
1276 CHECK_EQUAL(all_eas.out.num_eas);
1277 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1278 CHECK_EQUAL(all_eas.out.eas[i].flags);
1279 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1280 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1284 case RAW_FILEINFO_IS_NAME_VALID:
1287 case RAW_FILEINFO_BASIC_INFO:
1288 case RAW_FILEINFO_BASIC_INFORMATION:
1289 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1290 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1291 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1292 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1293 CHECK_EQUAL(basic_info.out.attrib);
1296 case RAW_FILEINFO_STANDARD_INFO:
1297 case RAW_FILEINFO_STANDARD_INFORMATION:
1298 CHECK_EQUAL(standard_info.out.alloc_size);
1299 CHECK_EQUAL(standard_info.out.size);
1300 CHECK_EQUAL(standard_info.out.nlink);
1301 CHECK_EQUAL(standard_info.out.delete_pending);
1302 CHECK_EQUAL(standard_info.out.directory);
1305 case RAW_FILEINFO_EA_INFO:
1306 case RAW_FILEINFO_EA_INFORMATION:
1307 CHECK_EQUAL(ea_info.out.ea_size);
1310 case RAW_FILEINFO_NAME_INFO:
1311 case RAW_FILEINFO_NAME_INFORMATION:
1312 CHECK_WSTR_EQUAL(name_info.out.fname);
1315 case RAW_FILEINFO_ALL_INFO:
1316 case RAW_FILEINFO_ALL_INFORMATION:
1317 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1318 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1319 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1320 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1321 CHECK_EQUAL(all_info.out.attrib);
1322 CHECK_EQUAL(all_info.out.alloc_size);
1323 CHECK_EQUAL(all_info.out.size);
1324 CHECK_EQUAL(all_info.out.nlink);
1325 CHECK_EQUAL(all_info.out.delete_pending);
1326 CHECK_EQUAL(all_info.out.directory);
1327 CHECK_EQUAL(all_info.out.ea_size);
1328 CHECK_WSTR_EQUAL(all_info.out.fname);
1331 case RAW_FILEINFO_ALT_NAME_INFO:
1332 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1333 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1336 case RAW_FILEINFO_STREAM_INFO:
1337 case RAW_FILEINFO_STREAM_INFORMATION:
1338 CHECK_EQUAL(stream_info.out.num_streams);
1339 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1340 CHECK_EQUAL(stream_info.out.streams[i].size);
1341 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1342 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1346 case RAW_FILEINFO_COMPRESSION_INFO:
1347 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1348 CHECK_EQUAL(compression_info.out.compressed_size);
1349 CHECK_EQUAL(compression_info.out.format);
1350 CHECK_EQUAL(compression_info.out.unit_shift);
1351 CHECK_EQUAL(compression_info.out.chunk_shift);
1352 CHECK_EQUAL(compression_info.out.cluster_shift);
1355 case RAW_FILEINFO_INTERNAL_INFORMATION:
1356 CHECK_EQUAL(internal_information.out.file_id);
1359 case RAW_FILEINFO_ACCESS_INFORMATION:
1360 CHECK_EQUAL(access_information.out.access_flags);
1363 case RAW_FILEINFO_POSITION_INFORMATION:
1364 CHECK_EQUAL(position_information.out.position);
1367 case RAW_FILEINFO_MODE_INFORMATION:
1368 CHECK_EQUAL(mode_information.out.mode);
1371 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1372 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1375 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1376 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1377 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1378 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1379 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1380 CHECK_EQUAL(network_open_information.out.alloc_size);
1381 CHECK_EQUAL(network_open_information.out.size);
1382 CHECK_EQUAL(network_open_information.out.attrib);
1385 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1386 CHECK_EQUAL(attribute_tag_information.out.attrib);
1387 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1390 /* Unhandled levels */
1392 case RAW_FILEINFO_SEC_DESC:
1393 case RAW_FILEINFO_EA_LIST:
1394 case RAW_FILEINFO_UNIX_BASIC:
1395 case RAW_FILEINFO_UNIX_LINK:
1396 case RAW_FILEINFO_SMB2_ALL_EAS:
1397 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
1398 case RAW_FILEINFO_UNIX_INFO2:
1406 generate qfileinfo operations
1408 static bool handler_qfileinfo(int instance)
1410 union smb_fileinfo parm[NSERVERS];
1411 NTSTATUS status[NSERVERS];
1413 parm[0].generic.in.file.fnum = gen_fnum(instance);
1415 gen_fileinfo(instance, &parm[0]);
1418 GEN_SET_FNUM(generic.in.file.fnum);
1419 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1421 return cmp_fileinfo(instance, parm, status);
1426 generate a fileinfo query structure
1428 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1432 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1434 enum smb_setfileinfo_level level;
1438 /* disabled until win2003 can handle them ... */
1439 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1440 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1442 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1443 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1444 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1445 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1446 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1449 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1450 } while (ignore_pattern(levels[i].name));
1452 info->generic.level = levels[i].level;
1454 switch (info->generic.level) {
1455 case RAW_SFILEINFO_SETATTR:
1456 info->setattr.in.attrib = gen_attrib();
1457 info->setattr.in.write_time = gen_timet();
1459 case RAW_SFILEINFO_SETATTRE:
1460 info->setattre.in.create_time = gen_timet();
1461 info->setattre.in.access_time = gen_timet();
1462 info->setattre.in.write_time = gen_timet();
1464 case RAW_SFILEINFO_STANDARD:
1465 info->standard.in.create_time = gen_timet();
1466 info->standard.in.access_time = gen_timet();
1467 info->standard.in.write_time = gen_timet();
1469 case RAW_SFILEINFO_EA_SET: {
1470 static struct ea_struct ea;
1471 info->ea_set.in.num_eas = 1;
1472 info->ea_set.in.eas = &ea;
1473 info->ea_set.in.eas[0] = gen_ea_struct();
1476 case RAW_SFILEINFO_BASIC_INFO:
1477 case RAW_SFILEINFO_BASIC_INFORMATION:
1478 info->basic_info.in.create_time = gen_nttime();
1479 info->basic_info.in.access_time = gen_nttime();
1480 info->basic_info.in.write_time = gen_nttime();
1481 info->basic_info.in.change_time = gen_nttime();
1482 info->basic_info.in.attrib = gen_attrib();
1484 case RAW_SFILEINFO_DISPOSITION_INFO:
1485 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1486 info->disposition_info.in.delete_on_close = gen_bool();
1488 case RAW_SFILEINFO_ALLOCATION_INFO:
1489 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1490 info->allocation_info.in.alloc_size = gen_alloc_size();
1492 case RAW_SFILEINFO_END_OF_FILE_INFO:
1493 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1494 info->end_of_file_info.in.size = gen_offset();
1496 case RAW_SFILEINFO_RENAME_INFORMATION:
1497 case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
1498 info->rename_information.in.overwrite = gen_bool();
1499 info->rename_information.in.root_fid = gen_root_fid(instance);
1500 info->rename_information.in.new_name = gen_fname_open(instance);
1502 case RAW_SFILEINFO_POSITION_INFORMATION:
1503 info->position_information.in.position = gen_offset();
1505 case RAW_SFILEINFO_MODE_INFORMATION:
1506 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1508 case RAW_SFILEINFO_GENERIC:
1509 case RAW_SFILEINFO_SEC_DESC:
1510 case RAW_SFILEINFO_UNIX_BASIC:
1511 case RAW_SFILEINFO_UNIX_LINK:
1512 case RAW_SFILEINFO_UNIX_HLINK:
1513 case RAW_SFILEINFO_1023:
1514 case RAW_SFILEINFO_1025:
1515 case RAW_SFILEINFO_1029:
1516 case RAW_SFILEINFO_1032:
1517 case RAW_SFILEINFO_1039:
1518 case RAW_SFILEINFO_1040:
1519 case RAW_SFILEINFO_UNIX_INFO2:
1526 generate setfileinfo operations
1528 static bool handler_sfileinfo(int instance)
1530 union smb_setfileinfo parm[NSERVERS];
1531 NTSTATUS status[NSERVERS];
1533 parm[0].generic.in.file.fnum = gen_fnum(instance);
1535 gen_setfileinfo(instance, &parm[0]);
1538 GEN_SET_FNUM(generic.in.file.fnum);
1539 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1548 wipe any relevant files
1550 static void wipe_files(void)
1555 for (i=0;i<NSERVERS;i++) {
1556 int n = smb2_deltree(servers[i].tree[0], "gentest");
1558 printf("Failed to wipe tree on server %d\n", i);
1561 status = smb2_util_mkdir(servers[i].tree[0], "gentest");
1562 if (NT_STATUS_IS_ERR(status)) {
1563 printf("Failed to create gentest on server %d - %s\n", i, nt_errstr(status));
1567 printf("Deleted %d files on server %d\n", n, i);
1573 dump the current seeds - useful for continuing a backtrack
1575 static void dump_seeds(void)
1580 if (!options.seeds_file) {
1583 f = fopen("seeds.tmp", "w");
1586 for (i=0;i<options.numops;i++) {
1587 fprintf(f, "%u\n", op_parms[i].seed);
1590 rename("seeds.tmp", options.seeds_file);
1596 the list of top-level operations that we will generate
1600 bool (*handler)(int instance);
1601 int count, success_count;
1603 {"CREATE", handler_create},
1604 {"CLOSE", handler_close},
1605 {"READ", handler_read},
1606 {"WRITE", handler_write},
1607 {"LOCK", handler_lock},
1608 {"FLUSH", handler_flush},
1613 run the test with the current set of op_parms parameters
1614 return the number of operations that completed successfully
1616 static int run_test(struct event_context *ev, struct loadparm_context *lp_ctx)
1620 if (!connect_servers(ev, lp_ctx)) {
1621 printf("Failed to connect to servers\n");
1627 /* wipe any leftover files from old runs */
1630 /* reset the open handles array */
1631 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1632 num_open_handles = 0;
1634 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1635 gen_ops[i].count = 0;
1636 gen_ops[i].success_count = 0;
1639 for (op=0; op<options.numops; op++) {
1640 int instance, which_op;
1643 if (op_parms[op].disabled) continue;
1645 srandom(op_parms[op].seed);
1647 instance = gen_int_range(0, NINSTANCES-1);
1649 /* generate a non-ignored operation */
1651 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1652 } while (ignore_pattern(gen_ops[which_op].name));
1654 DEBUG(3,("Generating op %s on instance %d\n",
1655 gen_ops[which_op].name, instance));
1657 current_op.seed = op_parms[op].seed;
1658 current_op.opnum = op;
1659 current_op.name = gen_ops[which_op].name;
1660 current_op.status = NT_STATUS_OK;
1661 current_op.mem_ctx = talloc_named(NULL, 0, "%s", current_op.name);
1663 ret = gen_ops[which_op].handler(instance);
1665 talloc_free(current_op.mem_ctx);
1667 gen_ops[which_op].count++;
1668 if (NT_STATUS_IS_OK(current_op.status)) {
1669 gen_ops[which_op].success_count++;
1673 printf("Failed at operation %d - %s\n",
1674 op, gen_ops[which_op].name);
1678 if (op % 100 == 0) {
1683 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1684 printf("Op %-10s got %d/%d success\n",
1686 gen_ops[i].success_count,
1694 perform a backtracking analysis of the minimal set of operations
1695 to generate an error
1697 static void backtrack_analyze(struct event_context *ev,
1698 struct loadparm_context *lp_ctx)
1702 chunk = options.numops / 2;
1707 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1710 chunk = MIN(chunk, options.numops / 2);
1712 /* mark this range as disabled */
1713 max = MIN(options.numops, base+chunk);
1714 for (i=base;i<max; i++) {
1715 op_parms[i].disabled = true;
1717 printf("Testing %d ops with %d-%d disabled\n",
1718 options.numops, base, max-1);
1719 ret = run_test(ev, lp_ctx);
1720 printf("Completed %d of %d ops\n", ret, options.numops);
1721 for (i=base;i<max; i++) {
1722 op_parms[i].disabled = false;
1724 if (ret == options.numops) {
1725 /* this chunk is needed */
1727 } else if (ret < base) {
1728 printf("damn - inconsistent errors! found early error\n");
1729 options.numops = ret+1;
1732 /* it failed - this chunk isn't needed for a failure */
1733 memmove(&op_parms[base], &op_parms[max],
1734 sizeof(op_parms[0]) * (options.numops - max));
1735 options.numops = (ret+1) - (max - base);
1745 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
1748 } while (chunk > 0);
1750 printf("Reduced to %d ops\n", options.numops);
1751 ret = run_test(ev, lp_ctx);
1752 if (ret != options.numops - 1) {
1753 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
1758 start the main gentest process
1760 static bool start_gentest(struct event_context *ev,
1761 struct loadparm_context *lp_ctx)
1766 /* allocate the open_handles array */
1767 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
1769 srandom(options.seed);
1770 op_parms = calloc(options.numops, sizeof(op_parms[0]));
1772 /* generate the seeds - after this everything is deterministic */
1773 if (options.use_preset_seeds) {
1775 char **preset = file_lines_load(options.seeds_file, &numops, NULL);
1777 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
1780 if (numops < options.numops) {
1781 options.numops = numops;
1783 for (op=0;op<options.numops;op++) {
1785 printf("Not enough seeds in %s\n", options.seeds_file);
1788 op_parms[op].seed = atoi(preset[op]);
1790 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
1792 for (op=0; op<options.numops; op++) {
1793 op_parms[op].seed = random();
1797 ret = run_test(ev, lp_ctx);
1799 if (ret != options.numops && options.analyze) {
1800 options.numops = ret+1;
1801 backtrack_analyze(ev, lp_ctx);
1802 } else if (options.analyze_always) {
1803 backtrack_analyze(ev, lp_ctx);
1804 } else if (options.analyze_continuous) {
1805 while (run_test(ev, lp_ctx) == options.numops) ;
1808 return ret == options.numops;
1812 static void usage(poptContext pc)
1816 gentest //server1/share1 //server2/share2 [options..]\n\
1818 poptPrintUsage(pc, stdout, 0);
1822 split a UNC name into server and share names
1824 static bool split_unc_name(const char *unc, char **server, char **share)
1826 char *p = strdup(unc);
1827 if (!p) return false;
1828 all_string_sub(p, "\\", "/", 0);
1829 if (strncmp(p, "//", 2) != 0) return false;
1832 p = strchr(*server, '/');
1833 if (!p) return false;
1843 /****************************************************************************
1845 ****************************************************************************/
1846 int main(int argc, char *argv[])
1849 int i, username_count=0;
1851 char *ignore_file=NULL;
1852 struct event_context *ev;
1853 struct loadparm_context *lp_ctx;
1857 enum {OPT_UNCLIST=1000};
1858 struct poptOption long_options[] = {
1860 {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL},
1861 {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL},
1862 {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL},
1863 {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL},
1864 {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL},
1865 {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL},
1866 {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL},
1867 {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL},
1868 {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL},
1869 {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL},
1870 {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL},
1871 {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL},
1872 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
1874 POPT_COMMON_CONNECTION
1875 POPT_COMMON_CREDENTIALS
1880 memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
1883 options.seed = time(NULL);
1884 options.numops = 1000;
1885 options.max_open_handles = 20;
1886 options.seeds_file = "gentest_seeds.dat";
1888 pc = poptGetContext("gentest", argc, (const char **) argv, long_options,
1889 POPT_CONTEXT_KEEP_FIRST);
1891 poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
1893 lp_ctx = cmdline_lp_ctx;
1894 servers[0].credentials = cli_credentials_init(talloc_autofree_context());
1895 servers[1].credentials = cli_credentials_init(talloc_autofree_context());
1896 cli_credentials_guess(servers[0].credentials, lp_ctx);
1897 cli_credentials_guess(servers[1].credentials, lp_ctx);
1899 while((opt = poptGetNextOpt(pc)) != -1) {
1902 lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
1905 if (username_count == 2) {
1909 cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED);
1916 options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
1919 argv_new = discard_const_p(char *, poptGetArgs(pc));
1921 for (i=0; i<argc; i++) {
1922 if (argv_new[i] == NULL) {
1928 if (!(argc_new >= 3)) {
1935 setup_logging("gentest", DEBUG_STDOUT);
1937 if (argc < 3 || argv[1][0] == '-') {
1942 setup_logging(argv[0], DEBUG_STDOUT);
1944 for (i=0;i<NSERVERS;i++) {
1945 const char *share = argv[1+i];
1946 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
1947 printf("Invalid share name '%s'\n", share);
1952 if (username_count == 0) {
1956 if (username_count == 1) {
1957 servers[1].credentials = servers[0].credentials;
1960 printf("seed=%u\n", options.seed);
1962 ev = event_context_init(talloc_autofree_context());
1964 gensec_init(lp_ctx);
1966 ret = start_gentest(ev, lp_ctx);
1969 printf("gentest completed - no errors\n");
1971 printf("gentest failed\n");