2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 static struct gentest_options {
31 BOOL analyze_continuous;
32 uint_t max_open_handles;
36 char **ignore_patterns;
37 const char *seeds_file;
38 BOOL use_preset_seeds;
42 /* mapping between open handles on the server and local handles */
46 uint_t server_fnum[NSERVERS];
49 static uint_t num_open_handles;
51 /* state information for the servers. We open NINSTANCES connections to
54 struct smbcli_state *cli[NINSTANCES];
61 /* the seeds and flags for each operation */
68 /* oplock break info */
75 } oplocks[NSERVERS][NINSTANCES];
77 /* change notify reply info */
81 struct smb_notify notify;
82 } notifies[NSERVERS][NINSTANCES];
84 /* info relevant to the current operation */
95 #define BAD_HANDLE 0xFFFE
97 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
98 static void idle_func(struct smbcli_transport *transport, void *private);
101 check if a string should be ignored. This is used as the basis
102 for all error ignore settings
104 static BOOL ignore_pattern(const char *str)
107 if (!options.ignore_patterns) return False;
109 for (i=0;options.ignore_patterns[i];i++) {
110 if (strcmp(options.ignore_patterns[i], str) == 0 ||
111 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
112 DEBUG(2,("Ignoring '%s'\n", str));
119 /*****************************************************
120 connect to the servers
121 *******************************************************/
122 static BOOL connect_servers_fast(void)
126 /* close all open files */
127 for (h=0;h<options.max_open_handles;h++) {
128 if (!open_handles[h].active) continue;
129 for (i=0;i<NSERVERS;i++) {
130 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
131 open_handles[h].server_fnum[i])))) {
134 open_handles[h].active = False;
144 /*****************************************************
145 connect to the servers
146 *******************************************************/
147 static BOOL connect_servers(void)
151 if (options.fast_reconnect && servers[0].cli[0]) {
152 if (connect_servers_fast()) {
157 /* close any existing connections */
158 for (i=0;i<NSERVERS;i++) {
159 for (j=0;j<NINSTANCES;j++) {
160 if (servers[i].cli[j]) {
161 smbcli_tdis(servers[i].cli[j]);
162 smbcli_shutdown(servers[i].cli[j]);
163 servers[i].cli[j] = NULL;
168 for (i=0;i<NSERVERS;i++) {
169 for (j=0;j<NINSTANCES;j++) {
171 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
172 servers[i].server_name, servers[i].share_name,
173 servers[i].username, j);
174 status = smbcli_full_connection(&servers[i].cli[j],
176 servers[i].server_name, NULL,
177 servers[i].share_name, "?????",
178 servers[i].username, lp_workgroup(),
179 servers[i].password, 0, NULL);
180 if (!NT_STATUS_IS_OK(status)) {
181 printf("Failed to connect to \\\\%s\\%s - %s\n",
182 servers[i].server_name, servers[i].share_name,
187 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
188 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 1, NULL);
196 work out the time skew between the servers - be conservative
198 static uint_t time_skew(void)
201 ret = ABS(servers[0].cli[0]->transport->negotiate.server_time -
202 servers[1].cli[0]->transport->negotiate.server_time);
207 turn an fnum for an instance into a handle
209 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
212 for (i=0;i<options.max_open_handles;i++) {
213 if (!open_handles[i].active ||
214 instance != open_handles[i].instance) continue;
215 if (open_handles[i].server_fnum[server] == fnum) {
219 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
220 fnum, server, instance);
225 add some newly opened handles
227 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
230 for (h=0;h<options.max_open_handles;h++) {
231 if (!open_handles[h].active) break;
233 if (h == options.max_open_handles) {
234 /* we have to force close a random handle */
235 h = random() % options.max_open_handles;
236 for (i=0;i<NSERVERS;i++) {
237 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
238 open_handles[h].server_fnum[i])))) {
239 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
240 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
243 printf("Recovered handle %d\n", h);
246 for (i=0;i<NSERVERS;i++) {
247 open_handles[h].server_fnum[i] = fnums[i];
248 open_handles[h].instance = instance;
249 open_handles[h].active = True;
250 open_handles[h].name = name;
254 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
256 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
261 remove a closed handle
263 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
266 for (h=0;h<options.max_open_handles;h++) {
267 if (instance == open_handles[h].instance &&
268 open_handles[h].server_fnum[0] == fnums[0]) {
269 open_handles[h].active = False;
271 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
273 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
274 open_handles[h].name);
278 printf("Removing invalid handle!?\n");
283 return True with 'chance' probability as a percentage
285 static BOOL gen_chance(uint_t chance)
287 return ((random() % 100) <= chance);
291 map an internal handle number to a server fnum
293 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
295 if (handle == BAD_HANDLE) return handle;
296 return open_handles[handle].server_fnum[server];
302 static uint16_t gen_fnum(int instance)
307 if (gen_chance(20)) return BAD_HANDLE;
309 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
310 h = random() % options.max_open_handles;
311 if (open_handles[h].active &&
312 open_handles[h].instance == instance) {
320 return a file handle, but skewed so we don't close the last
321 couple of handles too readily
323 static uint16_t gen_fnum_close(int instance)
325 if (num_open_handles < 3) {
326 if (gen_chance(80)) return BAD_HANDLE;
329 return gen_fnum(instance);
333 generate an integer in a specified range
335 static int gen_int_range(uint_t min, uint_t max)
338 return min + (r % (1+max-min));
342 return a fnum for use as a root fid
343 be careful to call GEN_SET_FNUM() when you use this!
345 static uint16_t gen_root_fid(int instance)
347 if (gen_chance(5)) return gen_fnum(instance);
352 generate a file offset
354 static int gen_offset(void)
356 if (gen_chance(20)) return 0;
357 return gen_int_range(0, 1024*1024);
363 static int gen_io_count(void)
365 if (gen_chance(20)) return 0;
366 return gen_int_range(0, 4096);
372 static const char *gen_fname(void)
374 const char *names[] = {"\\gentest\\gentest.dat",
376 "\\gentest\\foo2.sym",
377 "\\gentest\\foo3.dll",
379 "\\gentest\\foo4:teststream1",
380 "\\gentest\\foo4:teststream2",
381 "\\gentest\\foo5.exe",
382 "\\gentest\\foo5.exe:teststream3",
383 "\\gentest\\foo5.exe:teststream4",
384 "\\gentest\\foo6.com",
386 "\\gentest\\blah\\blergh.txt",
387 "\\gentest\\blah\\blergh2",
388 "\\gentest\\blah\\blergh3.txt",
389 "\\gentest\\blah\\blergh4",
390 "\\gentest\\blah\\blergh5.txt",
391 "\\gentest\\blah\\blergh5",
392 "\\gentest\\blah\\.",
394 /* this causes problem with w2k3 */
395 "\\gentest\\blah\\..",
397 "\\gentest\\a_very_long_name.bin",
403 i = gen_int_range(0, ARRAY_SIZE(names)-1);
404 } while (ignore_pattern(names[i]));
410 generate a filename with a higher chance of choosing an already
413 static const char *gen_fname_open(int instance)
416 h = gen_fnum(instance);
417 if (h == BAD_HANDLE) {
420 return open_handles[h].name;
424 generate a wildcard pattern
426 static const char *gen_pattern(void)
429 const char *names[] = {"\\gentest\\*.dat",
432 "\\gentest\\blah\\*.*",
433 "\\gentest\\blah\\*",
436 if (gen_chance(50)) return gen_fname();
439 i = gen_int_range(0, ARRAY_SIZE(names)-1);
440 } while (ignore_pattern(names[i]));
448 static uint32_t gen_bits_mask(uint_t mask)
450 uint_t ret = random();
455 generate a bitmask with high probability of the first mask
456 and low of the second
458 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
460 if (gen_chance(10)) return gen_bits_mask(mask2);
461 return gen_bits_mask(mask1);
467 static BOOL gen_bool(void)
469 return gen_bits_mask2(0x1, 0xFF);
473 generate ntrename flags
475 static uint16_t gen_rename_flags(void)
477 if (gen_chance(30)) return RENAME_FLAG_RENAME;
478 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
479 if (gen_chance(30)) return RENAME_FLAG_COPY;
480 return gen_bits_mask(0xFFFF);
485 return a lockingx lock mode
487 static uint16_t gen_lock_mode(void)
489 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
490 if (gen_chance(20)) return gen_bits_mask(0x1F);
491 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
497 static uint16_t gen_pid(void)
499 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
504 generate a lock count
506 static SMB_OFF_T gen_lock_count(void)
508 return gen_int_range(0, 3);
512 generate a ntcreatex flags field
514 static uint32_t gen_ntcreatex_flags(void)
516 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
517 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
521 generate a NT access mask
523 static uint32_t gen_access_mask(void)
525 if (gen_chance(50)) return SEC_RIGHT_MAXIMUM_ALLOWED;
526 if (gen_chance(20)) return GENERIC_RIGHTS_FILE_ALL_ACCESS;
527 return gen_bits_mask(0xFFFFFFFF);
531 generate a ntcreatex create options bitfield
533 static uint32_t gen_create_options(void)
535 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
536 if (gen_chance(50)) return 0;
537 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
541 generate a ntcreatex open disposition
543 static uint32_t gen_open_disp(void)
545 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
546 return gen_int_range(0, 5);
550 generate an openx open mode
552 static uint16_t gen_openx_mode(void)
554 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
555 if (gen_chance(20)) return gen_bits_mask(0xFF);
556 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
560 generate an openx flags field
562 static uint16_t gen_openx_flags(void)
564 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
565 return gen_bits_mask(0x7);
569 generate an openx open function
571 static uint16_t gen_openx_func(void)
573 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
574 return gen_bits_mask(0x13);
578 generate a file attrib combination
580 static uint32_t gen_attrib(void)
582 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
583 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
587 generate a unix timestamp
589 static time_t gen_timet(void)
591 if (gen_chance(30)) return 0;
592 return (time_t)random();
596 generate a unix timestamp
598 static NTTIME gen_nttime(void)
601 unix_to_nt_time(&ret, gen_timet());
606 generate a milliseconds protocol timeout
608 static uint32_t gen_timeout(void)
610 if (gen_chance(98)) return 0;
611 return random() % 50;
615 generate a file allocation size
617 static uint_t gen_alloc_size(void)
621 if (gen_chance(30)) return 0;
623 ret = random() % 4*1024*1024;
624 /* give a high chance of a round number */
625 if (gen_chance(60)) {
626 ret &= ~(1024*1024 - 1);
632 generate an ea_struct
634 static struct ea_struct gen_ea_struct(void)
637 const char *names[] = {"EAONE",
642 "AVERYLONGATTRIBUTENAME"};
643 const char *values[] = {"VALUE1",
648 "ASOMEWHATLONGERATTRIBUTEVALUE"};
652 i = gen_int_range(0, ARRAY_SIZE(names)-1);
653 } while (ignore_pattern(names[i]));
655 ea.name.s = names[i];
658 i = gen_int_range(0, ARRAY_SIZE(values)-1);
659 } while (ignore_pattern(values[i]));
661 ea.value = data_blob(values[i], strlen(values[i]));
663 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
671 this is called when a change notify reply comes in
673 static void async_notify(struct smbcli_request *req)
675 struct smb_notify notify;
679 struct smbcli_transport *transport = req->transport;
681 tid = SVAL(req->in.hdr, HDR_TID);
683 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
684 if (NT_STATUS_IS_OK(status)) {
685 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
687 notify.out.num_changes,
688 notify.out.changes[0].action,
689 notify.out.changes[0].name.s);
692 for (i=0;i<NSERVERS;i++) {
693 for (j=0;j<NINSTANCES;j++) {
694 if (transport == servers[i].cli[j]->transport &&
695 tid == servers[i].cli[j]->tree->tid) {
696 notifies[i][j].notify_count++;
697 notifies[i][j].status = status;
698 notifies[i][j].notify = notify;
705 the oplock handler will either ack the break or close the file
707 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
713 struct smbcli_tree *tree = NULL;
715 srandom(current_op.seed);
716 do_close = gen_chance(50);
718 for (i=0;i<NSERVERS;i++) {
719 for (j=0;j<NINSTANCES;j++) {
720 if (transport == servers[i].cli[j]->transport &&
721 tid == servers[i].cli[j]->tree->tid) {
722 oplocks[i][j].got_break = True;
723 oplocks[i][j].fnum = fnum;
724 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
725 oplocks[i][j].level = level;
726 oplocks[i][j].do_close = do_close;
727 tree = servers[i].cli[j]->tree;
733 printf("Oplock break not for one of our trees!?\n");
738 printf("oplock ack fnum=%d\n", fnum);
739 return smbcli_oplock_ack(tree, fnum, level);
742 printf("oplock close fnum=%d\n", fnum);
744 io.close.level = RAW_CLOSE_CLOSE;
745 io.close.in.fnum = fnum;
746 io.close.in.write_time = 0;
747 status = smb_raw_close(tree, &io);
749 if (!NT_STATUS_IS_OK(status)) {
750 printf("WARNING: close failed in oplock_handler_close - %s\n", nt_errstr(status));
757 the idle function tries to cope with getting an oplock break on a connection, and
758 an operation on another connection blocking until that break is acked
759 we check for operations on all transports in the idle function
761 static void idle_func(struct smbcli_transport *transport, void *private)
764 for (i=0;i<NSERVERS;i++) {
765 for (j=0;j<NINSTANCES;j++) {
766 if (servers[i].cli[j] &&
767 transport != servers[i].cli[j]->transport) {
768 smbcli_transport_process(servers[i].cli[j]->transport);
777 compare NTSTATUS, using checking ignored patterns
779 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
781 if (NT_STATUS_EQUAL(status1, status2)) return True;
783 /* one code being an error and the other OK is always an error */
784 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
786 /* if we are ignoring one of the status codes then consider this a match */
787 if (ignore_pattern(nt_errstr(status1)) ||
788 ignore_pattern(nt_errstr(status2))) {
796 check for pending packets on all connections
798 static void check_pending(void)
804 for (j=0;j<NINSTANCES;j++) {
805 for (i=0;i<NSERVERS;i++) {
806 smbcli_transport_process(servers[i].cli[j]->transport);
812 check that the same oplock breaks have been received by all instances
814 static BOOL check_oplocks(const char *call)
822 for (j=0;j<NINSTANCES;j++) {
823 for (i=1;i<NSERVERS;i++) {
824 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
825 oplocks[0][j].handle != oplocks[i][j].handle ||
826 oplocks[0][j].level != oplocks[i][j].level) {
827 if (tries++ < 10) goto again;
828 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
829 oplocks[0][j].got_break,
830 oplocks[0][j].handle,
832 oplocks[i][j].got_break,
833 oplocks[i][j].handle,
834 oplocks[i][j].level);
840 /* if we got a break and closed then remove the handle */
841 for (j=0;j<NINSTANCES;j++) {
842 if (oplocks[0][j].got_break &&
843 oplocks[0][j].do_close) {
844 uint16_t fnums[NSERVERS];
845 for (i=0;i<NSERVERS;i++) {
846 fnums[i] = oplocks[i][j].fnum;
848 gen_remove_handle(j, fnums);
857 check that the same change notify info has been received by all instances
859 static BOOL check_notifies(const char *call)
867 for (j=0;j<NINSTANCES;j++) {
868 for (i=1;i<NSERVERS;i++) {
870 struct smb_notify not1, not2;
872 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
873 if (tries++ < 10) goto again;
874 printf("Notify count inconsistent %d %d\n",
875 notifies[0][j].notify_count,
876 notifies[i][j].notify_count);
880 if (notifies[0][j].notify_count == 0) continue;
882 if (!NT_STATUS_EQUAL(notifies[0][j].status,
883 notifies[i][j].status)) {
884 printf("Notify status mismatch - %s - %s\n",
885 nt_errstr(notifies[0][j].status),
886 nt_errstr(notifies[i][j].status));
890 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
894 not1 = notifies[0][j].notify;
895 not2 = notifies[i][j].notify;
897 for (n=0;n<not1.out.num_changes;n++) {
898 if (not1.out.changes[n].action !=
899 not2.out.changes[n].action) {
900 printf("Notify action %d inconsistent %d %d\n", n,
901 not1.out.changes[n].action,
902 not2.out.changes[n].action);
905 if (strcmp(not1.out.changes[n].name.s,
906 not2.out.changes[n].name.s)) {
907 printf("Notify name %d inconsistent %s %s\n", n,
908 not1.out.changes[n].name.s,
909 not2.out.changes[n].name.s);
912 if (not1.out.changes[n].name.private_length !=
913 not2.out.changes[n].name.private_length) {
914 printf("Notify name length %d inconsistent %d %d\n", n,
915 not1.out.changes[n].name.private_length,
916 not2.out.changes[n].name.private_length);
923 ZERO_STRUCT(notifies);
929 #define GEN_COPY_PARM do { \
931 for (i=1;i<NSERVERS;i++) { \
936 #define GEN_CALL(call) do { \
938 ZERO_STRUCT(oplocks); \
939 ZERO_STRUCT(notifies); \
940 for (i=0;i<NSERVERS;i++) { \
941 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
944 current_op.status = status[0]; \
945 for (i=1;i<NSERVERS;i++) { \
946 if (!compare_status(status[i], status[0])) { \
947 printf("status different in %s - %s %s\n", #call, \
948 nt_errstr(status[0]), nt_errstr(status[i])); \
952 if (!check_oplocks(#call)) return False; \
953 if (!check_notifies(#call)) return False; \
954 if (!NT_STATUS_IS_OK(status[0])) { \
959 #define ADD_HANDLE(name, field) do { \
960 uint16_t fnums[NSERVERS]; \
962 for (i=0;i<NSERVERS;i++) { \
963 fnums[i] = parm[i].field; \
965 gen_add_handle(instance, name, fnums); \
968 #define REMOVE_HANDLE(field) do { \
969 uint16_t fnums[NSERVERS]; \
971 for (i=0;i<NSERVERS;i++) { \
972 fnums[i] = parm[i].field; \
974 gen_remove_handle(instance, fnums); \
977 #define GEN_SET_FNUM(field) do { \
979 for (i=0;i<NSERVERS;i++) { \
980 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
984 #define CHECK_EQUAL(field) do { \
985 if (parm[0].field != parm[1].field && !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_WSTR_EQUAL(field) do { \
993 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
994 printf("%s is NULL!\n", #field); \
997 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
998 printf("Mismatch in %s - %s %s\n", #field, \
999 parm[0].field.s, parm[1].field.s); \
1002 CHECK_EQUAL(field.private_length); \
1005 #define CHECK_BLOB_EQUAL(field) do { \
1006 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1007 printf("Mismatch in %s\n", #field); \
1010 CHECK_EQUAL(field.length); \
1013 #define CHECK_TIMES_EQUAL(field) do { \
1014 if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1015 !ignore_pattern(#field)) { \
1016 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1017 (int)parm[0].field, (int)parm[1].field); \
1022 #define CHECK_NTTIMES_EQUAL(field) do { \
1023 if (ABS(nt_time_to_unix(parm[0].field) - \
1024 nt_time_to_unix(parm[1].field)) > time_skew() && \
1025 !ignore_pattern(#field)) { \
1026 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1027 (int)nt_time_to_unix(parm[0].field), \
1028 (int)nt_time_to_unix(parm[1].field)); \
1034 generate openx operations
1036 static BOOL handler_openx(int instance)
1038 union smb_open parm[NSERVERS];
1039 NTSTATUS status[NSERVERS];
1041 parm[0].openx.level = RAW_OPEN_OPENX;
1042 parm[0].openx.in.flags = gen_openx_flags();
1043 parm[0].openx.in.open_mode = gen_openx_mode();
1044 parm[0].openx.in.search_attrs = gen_attrib();
1045 parm[0].openx.in.file_attrs = gen_attrib();
1046 parm[0].openx.in.write_time = gen_timet();
1047 parm[0].openx.in.open_func = gen_openx_func();
1048 parm[0].openx.in.size = gen_io_count();
1049 parm[0].openx.in.timeout = gen_timeout();
1050 parm[0].openx.in.fname = gen_fname_open(instance);
1052 if (!options.use_oplocks) {
1053 /* mask out oplocks */
1054 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1055 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1059 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1061 CHECK_EQUAL(openx.out.attrib);
1062 CHECK_EQUAL(openx.out.size);
1063 CHECK_EQUAL(openx.out.access);
1064 CHECK_EQUAL(openx.out.ftype);
1065 CHECK_EQUAL(openx.out.devstate);
1066 CHECK_EQUAL(openx.out.action);
1067 CHECK_EQUAL(openx.out.access_mask);
1068 CHECK_EQUAL(openx.out.unknown);
1069 CHECK_TIMES_EQUAL(openx.out.write_time);
1071 /* open creates a new file handle */
1072 ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum);
1079 generate open operations
1081 static BOOL handler_open(int instance)
1083 union smb_open parm[NSERVERS];
1084 NTSTATUS status[NSERVERS];
1086 parm[0].open.level = RAW_OPEN_OPEN;
1087 parm[0].open.in.flags = gen_bits_mask2(0xF, 0xFFFF);
1088 parm[0].open.in.search_attrs = gen_attrib();
1089 parm[0].open.in.fname = gen_fname_open(instance);
1091 if (!options.use_oplocks) {
1092 /* mask out oplocks */
1093 parm[0].open.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1094 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1098 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1100 CHECK_EQUAL(open.out.attrib);
1101 CHECK_TIMES_EQUAL(open.out.write_time);
1102 CHECK_EQUAL(open.out.size);
1103 CHECK_EQUAL(open.out.rmode);
1105 /* open creates a new file handle */
1106 ADD_HANDLE(parm[0].open.in.fname, open.out.fnum);
1113 generate ntcreatex operations
1115 static BOOL handler_ntcreatex(int instance)
1117 union smb_open parm[NSERVERS];
1118 NTSTATUS status[NSERVERS];
1120 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1121 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1122 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1123 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1124 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1125 parm[0].ntcreatex.in.file_attr = gen_attrib();
1126 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1127 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1128 parm[0].ntcreatex.in.create_options = gen_create_options();
1129 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1130 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1131 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1133 if (!options.use_oplocks) {
1134 /* mask out oplocks */
1135 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1136 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1140 if (parm[0].ntcreatex.in.root_fid != 0) {
1141 GEN_SET_FNUM(ntcreatex.in.root_fid);
1143 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1145 CHECK_EQUAL(ntcreatex.out.oplock_level);
1146 CHECK_EQUAL(ntcreatex.out.create_action);
1147 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1148 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1149 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1150 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1151 CHECK_EQUAL(ntcreatex.out.attrib);
1152 CHECK_EQUAL(ntcreatex.out.alloc_size);
1153 CHECK_EQUAL(ntcreatex.out.size);
1154 CHECK_EQUAL(ntcreatex.out.file_type);
1155 CHECK_EQUAL(ntcreatex.out.ipc_state);
1156 CHECK_EQUAL(ntcreatex.out.is_directory);
1158 /* ntcreatex creates a new file handle */
1159 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum);
1165 generate close operations
1167 static BOOL handler_close(int instance)
1169 union smb_close parm[NSERVERS];
1170 NTSTATUS status[NSERVERS];
1172 parm[0].close.level = RAW_CLOSE_CLOSE;
1173 parm[0].close.in.fnum = gen_fnum_close(instance);
1174 parm[0].close.in.write_time = gen_timet();
1177 GEN_SET_FNUM(close.in.fnum);
1178 GEN_CALL(smb_raw_close(tree, &parm[i]));
1180 REMOVE_HANDLE(close.in.fnum);
1186 generate unlink operations
1188 static BOOL handler_unlink(int instance)
1190 struct smb_unlink parm[NSERVERS];
1191 NTSTATUS status[NSERVERS];
1193 parm[0].in.pattern = gen_pattern();
1194 parm[0].in.attrib = gen_attrib();
1197 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1203 generate chkpath operations
1205 static BOOL handler_chkpath(int instance)
1207 struct smb_chkpath parm[NSERVERS];
1208 NTSTATUS status[NSERVERS];
1210 parm[0].in.path = gen_fname_open(instance);
1213 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1219 generate mkdir operations
1221 static BOOL handler_mkdir(int instance)
1223 union smb_mkdir parm[NSERVERS];
1224 NTSTATUS status[NSERVERS];
1226 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1227 parm[0].mkdir.in.path = gen_fname_open(instance);
1230 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1236 generate rmdir operations
1238 static BOOL handler_rmdir(int instance)
1240 struct smb_rmdir parm[NSERVERS];
1241 NTSTATUS status[NSERVERS];
1243 parm[0].in.path = gen_fname_open(instance);
1246 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1252 generate rename operations
1254 static BOOL handler_rename(int instance)
1256 union smb_rename parm[NSERVERS];
1257 NTSTATUS status[NSERVERS];
1259 parm[0].generic.level = RAW_RENAME_RENAME;
1260 parm[0].rename.in.pattern1 = gen_pattern();
1261 parm[0].rename.in.pattern2 = gen_pattern();
1262 parm[0].rename.in.attrib = gen_attrib();
1265 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1271 generate ntrename operations
1273 static BOOL handler_ntrename(int instance)
1275 union smb_rename parm[NSERVERS];
1276 NTSTATUS status[NSERVERS];
1278 parm[0].generic.level = RAW_RENAME_NTRENAME;
1279 parm[0].ntrename.in.old_name = gen_fname();
1280 parm[0].ntrename.in.new_name = gen_fname();
1281 parm[0].ntrename.in.attrib = gen_attrib();
1282 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1283 parm[0].ntrename.in.flags = gen_rename_flags();
1286 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1293 generate seek operations
1295 static BOOL handler_seek(int instance)
1297 struct smb_seek parm[NSERVERS];
1298 NTSTATUS status[NSERVERS];
1300 parm[0].in.fnum = gen_fnum(instance);
1301 parm[0].in.mode = gen_bits_mask2(0x3, 0xFFFF);
1302 parm[0].in.offset = gen_offset();
1305 GEN_SET_FNUM(in.fnum);
1306 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1308 CHECK_EQUAL(out.offset);
1315 generate readx operations
1317 static BOOL handler_readx(int instance)
1319 union smb_read parm[NSERVERS];
1320 NTSTATUS status[NSERVERS];
1322 parm[0].readx.level = RAW_READ_READX;
1323 parm[0].readx.in.fnum = gen_fnum(instance);
1324 parm[0].readx.in.offset = gen_offset();
1325 parm[0].readx.in.mincnt = gen_io_count();
1326 parm[0].readx.in.maxcnt = gen_io_count();
1327 parm[0].readx.in.remaining = gen_io_count();
1328 parm[0].readx.out.data = talloc(current_op.mem_ctx,
1329 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1332 GEN_SET_FNUM(readx.in.fnum);
1333 GEN_CALL(smb_raw_read(tree, &parm[i]));
1335 CHECK_EQUAL(readx.out.remaining);
1336 CHECK_EQUAL(readx.out.compaction_mode);
1337 CHECK_EQUAL(readx.out.nread);
1343 generate writex operations
1345 static BOOL handler_writex(int instance)
1347 union smb_write parm[NSERVERS];
1348 NTSTATUS status[NSERVERS];
1350 parm[0].writex.level = RAW_WRITE_WRITEX;
1351 parm[0].writex.in.fnum = gen_fnum(instance);
1352 parm[0].writex.in.offset = gen_offset();
1353 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1354 parm[0].writex.in.remaining = gen_io_count();
1355 parm[0].writex.in.count = gen_io_count();
1356 parm[0].writex.in.data = talloc_zero(current_op.mem_ctx, parm[0].writex.in.count);
1359 GEN_SET_FNUM(writex.in.fnum);
1360 GEN_CALL(smb_raw_write(tree, &parm[i]));
1362 CHECK_EQUAL(writex.out.nwritten);
1363 CHECK_EQUAL(writex.out.remaining);
1369 generate lockingx operations
1371 static BOOL handler_lockingx(int instance)
1373 union smb_lock parm[NSERVERS];
1374 NTSTATUS status[NSERVERS];
1377 parm[0].lockx.level = RAW_LOCK_LOCKX;
1378 parm[0].lockx.in.fnum = gen_fnum(instance);
1379 parm[0].lockx.in.mode = gen_lock_mode();
1380 parm[0].lockx.in.timeout = gen_timeout();
1382 /* make sure we don't accidentially generate an oplock
1383 break ack - otherwise the server can just block forever */
1384 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1385 parm[0].lockx.in.lock_cnt = gen_lock_count();
1386 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1387 } while (nlocks == 0);
1390 parm[0].lockx.in.locks = talloc(current_op.mem_ctx,
1391 sizeof(parm[0].lockx.in.locks[0]) * nlocks);
1392 for (n=0;n<nlocks;n++) {
1393 parm[0].lockx.in.locks[n].pid = gen_pid();
1394 parm[0].lockx.in.locks[n].offset = gen_offset();
1395 parm[0].lockx.in.locks[n].count = gen_io_count();
1400 GEN_SET_FNUM(lockx.in.fnum);
1401 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1407 generate a fileinfo query structure
1409 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1412 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1414 enum smb_fileinfo_level level;
1417 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1418 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1419 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1420 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1421 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1422 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1423 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1424 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1425 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1426 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1429 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1430 } while (ignore_pattern(levels[i].name));
1432 info->generic.level = levels[i].level;
1436 compare returned fileinfo structures
1438 static BOOL cmp_fileinfo(int instance,
1439 union smb_fileinfo parm[NSERVERS],
1440 NTSTATUS status[NSERVERS])
1444 switch (parm[0].generic.level) {
1445 case RAW_FILEINFO_GENERIC:
1448 case RAW_FILEINFO_GETATTR:
1449 CHECK_EQUAL(getattr.out.attrib);
1450 CHECK_EQUAL(getattr.out.size);
1451 CHECK_TIMES_EQUAL(getattr.out.write_time);
1454 case RAW_FILEINFO_GETATTRE:
1455 CHECK_TIMES_EQUAL(getattre.out.create_time);
1456 CHECK_TIMES_EQUAL(getattre.out.access_time);
1457 CHECK_TIMES_EQUAL(getattre.out.write_time);
1458 CHECK_EQUAL(getattre.out.size);
1459 CHECK_EQUAL(getattre.out.alloc_size);
1460 CHECK_EQUAL(getattre.out.attrib);
1463 case RAW_FILEINFO_STANDARD:
1464 CHECK_TIMES_EQUAL(standard.out.create_time);
1465 CHECK_TIMES_EQUAL(standard.out.access_time);
1466 CHECK_TIMES_EQUAL(standard.out.write_time);
1467 CHECK_EQUAL(standard.out.size);
1468 CHECK_EQUAL(standard.out.alloc_size);
1469 CHECK_EQUAL(standard.out.attrib);
1472 case RAW_FILEINFO_EA_SIZE:
1473 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1474 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1475 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1476 CHECK_EQUAL(ea_size.out.size);
1477 CHECK_EQUAL(ea_size.out.alloc_size);
1478 CHECK_EQUAL(ea_size.out.attrib);
1479 CHECK_EQUAL(ea_size.out.ea_size);
1482 case RAW_FILEINFO_ALL_EAS:
1483 CHECK_EQUAL(all_eas.out.num_eas);
1484 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1485 CHECK_EQUAL(all_eas.out.eas[i].flags);
1486 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1487 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1491 case RAW_FILEINFO_IS_NAME_VALID:
1494 case RAW_FILEINFO_BASIC_INFO:
1495 case RAW_FILEINFO_BASIC_INFORMATION:
1496 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1497 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1498 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1499 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1500 CHECK_EQUAL(basic_info.out.attrib);
1503 case RAW_FILEINFO_STANDARD_INFO:
1504 case RAW_FILEINFO_STANDARD_INFORMATION:
1505 CHECK_EQUAL(standard_info.out.alloc_size);
1506 CHECK_EQUAL(standard_info.out.size);
1507 CHECK_EQUAL(standard_info.out.nlink);
1508 CHECK_EQUAL(standard_info.out.delete_pending);
1509 CHECK_EQUAL(standard_info.out.directory);
1512 case RAW_FILEINFO_EA_INFO:
1513 case RAW_FILEINFO_EA_INFORMATION:
1514 CHECK_EQUAL(ea_info.out.ea_size);
1517 case RAW_FILEINFO_NAME_INFO:
1518 case RAW_FILEINFO_NAME_INFORMATION:
1519 CHECK_WSTR_EQUAL(name_info.out.fname);
1522 case RAW_FILEINFO_ALL_INFO:
1523 case RAW_FILEINFO_ALL_INFORMATION:
1524 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1525 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1526 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1527 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1528 CHECK_EQUAL(all_info.out.attrib);
1529 CHECK_EQUAL(all_info.out.alloc_size);
1530 CHECK_EQUAL(all_info.out.size);
1531 CHECK_EQUAL(all_info.out.nlink);
1532 CHECK_EQUAL(all_info.out.delete_pending);
1533 CHECK_EQUAL(all_info.out.directory);
1534 CHECK_EQUAL(all_info.out.ea_size);
1535 CHECK_WSTR_EQUAL(all_info.out.fname);
1538 case RAW_FILEINFO_ALT_NAME_INFO:
1539 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1540 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1543 case RAW_FILEINFO_STREAM_INFO:
1544 case RAW_FILEINFO_STREAM_INFORMATION:
1545 CHECK_EQUAL(stream_info.out.num_streams);
1546 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1547 CHECK_EQUAL(stream_info.out.streams[i].size);
1548 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1549 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1553 case RAW_FILEINFO_COMPRESSION_INFO:
1554 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1555 CHECK_EQUAL(compression_info.out.compressed_size);
1556 CHECK_EQUAL(compression_info.out.format);
1557 CHECK_EQUAL(compression_info.out.unit_shift);
1558 CHECK_EQUAL(compression_info.out.chunk_shift);
1559 CHECK_EQUAL(compression_info.out.cluster_shift);
1562 case RAW_FILEINFO_INTERNAL_INFORMATION:
1563 CHECK_EQUAL(internal_information.out.file_id);
1566 case RAW_FILEINFO_ACCESS_INFORMATION:
1567 CHECK_EQUAL(access_information.out.access_flags);
1570 case RAW_FILEINFO_POSITION_INFORMATION:
1571 CHECK_EQUAL(position_information.out.position);
1574 case RAW_FILEINFO_MODE_INFORMATION:
1575 CHECK_EQUAL(mode_information.out.mode);
1578 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1579 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1582 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1583 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1584 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1585 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1586 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1587 CHECK_EQUAL(network_open_information.out.alloc_size);
1588 CHECK_EQUAL(network_open_information.out.size);
1589 CHECK_EQUAL(network_open_information.out.attrib);
1592 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1593 CHECK_EQUAL(attribute_tag_information.out.attrib);
1594 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1602 generate qpathinfo operations
1604 static BOOL handler_qpathinfo(int instance)
1606 union smb_fileinfo parm[NSERVERS];
1607 NTSTATUS status[NSERVERS];
1609 parm[0].generic.in.fname = gen_fname_open(instance);
1611 gen_fileinfo(instance, &parm[0]);
1614 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1616 return cmp_fileinfo(instance, parm, status);
1620 generate qfileinfo operations
1622 static BOOL handler_qfileinfo(int instance)
1624 union smb_fileinfo parm[NSERVERS];
1625 NTSTATUS status[NSERVERS];
1627 parm[0].generic.in.fnum = gen_fnum(instance);
1629 gen_fileinfo(instance, &parm[0]);
1632 GEN_SET_FNUM(generic.in.fnum);
1633 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1635 return cmp_fileinfo(instance, parm, status);
1640 generate a fileinfo query structure
1642 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1646 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1648 enum smb_setfileinfo_level level;
1652 /* disabled until win2003 can handle them ... */
1653 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1654 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1656 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1657 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1658 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1659 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1660 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1663 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1664 } while (ignore_pattern(levels[i].name));
1666 info->generic.level = levels[i].level;
1668 switch (info->generic.level) {
1669 case RAW_SFILEINFO_SETATTR:
1670 info->setattr.in.attrib = gen_attrib();
1671 info->setattr.in.write_time = gen_timet();
1673 case RAW_SFILEINFO_SETATTRE:
1674 info->setattre.in.create_time = gen_timet();
1675 info->setattre.in.access_time = gen_timet();
1676 info->setattre.in.write_time = gen_timet();
1678 case RAW_SFILEINFO_STANDARD:
1679 info->standard.in.create_time = gen_timet();
1680 info->standard.in.access_time = gen_timet();
1681 info->standard.in.write_time = gen_timet();
1683 case RAW_SFILEINFO_EA_SET:
1684 info->ea_set.in.ea = gen_ea_struct();
1686 case RAW_SFILEINFO_BASIC_INFO:
1687 case RAW_SFILEINFO_BASIC_INFORMATION:
1688 info->basic_info.in.create_time = gen_nttime();
1689 info->basic_info.in.access_time = gen_nttime();
1690 info->basic_info.in.write_time = gen_nttime();
1691 info->basic_info.in.change_time = gen_nttime();
1692 info->basic_info.in.attrib = gen_attrib();
1694 case RAW_SFILEINFO_DISPOSITION_INFO:
1695 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1696 info->disposition_info.in.delete_on_close = gen_bool();
1698 case RAW_SFILEINFO_ALLOCATION_INFO:
1699 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1700 info->allocation_info.in.alloc_size = gen_alloc_size();
1702 case RAW_SFILEINFO_END_OF_FILE_INFO:
1703 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1704 info->end_of_file_info.in.size = gen_offset();
1706 case RAW_SFILEINFO_RENAME_INFORMATION:
1707 info->rename_information.in.overwrite = gen_bool();
1708 info->rename_information.in.root_fid = gen_root_fid(instance);
1709 info->rename_information.in.new_name = gen_fname_open(instance);
1711 case RAW_SFILEINFO_POSITION_INFORMATION:
1712 info->position_information.in.position = gen_offset();
1714 case RAW_SFILEINFO_MODE_INFORMATION:
1715 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1721 generate setpathinfo operations
1723 static BOOL handler_spathinfo(int instance)
1725 union smb_setfileinfo parm[NSERVERS];
1726 NTSTATUS status[NSERVERS];
1728 parm[0].generic.file.fname = gen_fname_open(instance);
1730 gen_setfileinfo(instance, &parm[0]);
1734 /* a special case for the fid in a RENAME */
1735 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1736 parm[0].rename_information.in.root_fid != 0) {
1737 GEN_SET_FNUM(rename_information.in.root_fid);
1740 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1747 generate setfileinfo operations
1749 static BOOL handler_sfileinfo(int instance)
1751 union smb_setfileinfo parm[NSERVERS];
1752 NTSTATUS status[NSERVERS];
1754 parm[0].generic.file.fnum = gen_fnum(instance);
1756 gen_setfileinfo(instance, &parm[0]);
1759 GEN_SET_FNUM(generic.file.fnum);
1760 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1767 generate change notify operations
1769 static BOOL handler_notify(int instance)
1771 struct smb_notify parm[NSERVERS];
1774 parm[0].in.buffer_size = gen_io_count();
1775 parm[0].in.completion_filter = gen_bits_mask(0xFF);
1776 parm[0].in.fnum = gen_fnum(instance);
1777 parm[0].in.recursive = gen_bool();
1780 GEN_SET_FNUM(in.fnum);
1782 for (n=0;n<NSERVERS;n++) {
1783 struct smbcli_request *req;
1784 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1785 req->async.fn = async_notify;
1792 wipe any relevant files
1794 static void wipe_files(void)
1797 for (i=0;i<NSERVERS;i++) {
1798 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1800 printf("Failed to wipe tree on server %d\n", i);
1803 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1804 printf("Failed to create \\gentest - %s\n",
1805 smbcli_errstr(servers[i].cli[0]->tree));
1809 printf("Deleted %d files on server %d\n", n, i);
1815 dump the current seeds - useful for continuing a backtrack
1817 static void dump_seeds(void)
1822 if (!options.seeds_file) {
1825 f = fopen("seeds.tmp", "w");
1828 for (i=0;i<options.numops;i++) {
1829 fprintf(f, "%u\n", op_parms[i].seed);
1832 rename("seeds.tmp", options.seeds_file);
1838 the list of top-level operations that we will generate
1842 BOOL (*handler)(int instance);
1843 int count, success_count;
1845 {"OPEN", handler_open},
1846 {"OPENX", handler_openx},
1847 {"NTCREATEX", handler_ntcreatex},
1848 {"CLOSE", handler_close},
1849 {"UNLINK", handler_unlink},
1850 {"MKDIR", handler_mkdir},
1851 {"RMDIR", handler_rmdir},
1852 {"RENAME", handler_rename},
1853 {"NTRENAME", handler_ntrename},
1854 {"READX", handler_readx},
1855 {"WRITEX", handler_writex},
1856 {"CHKPATH", handler_chkpath},
1857 {"LOCKINGX", handler_lockingx},
1858 {"QPATHINFO", handler_qpathinfo},
1859 {"QFILEINFO", handler_qfileinfo},
1860 {"SPATHINFO", handler_spathinfo},
1861 {"SFILEINFO", handler_sfileinfo},
1862 {"NOTIFY", handler_notify},
1863 {"SEEK", handler_seek},
1868 run the test with the current set of op_parms parameters
1869 return the number of operations that completed successfully
1871 static int run_test(void)
1875 if (!connect_servers()) {
1876 printf("Failed to connect to servers\n");
1882 /* wipe any leftover files from old runs */
1885 /* reset the open handles array */
1886 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1887 num_open_handles = 0;
1889 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1890 gen_ops[i].count = 0;
1891 gen_ops[i].success_count = 0;
1894 for (op=0; op<options.numops; op++) {
1895 int instance, which_op;
1898 if (op_parms[op].disabled) continue;
1900 srandom(op_parms[op].seed);
1902 instance = gen_int_range(0, NINSTANCES-1);
1904 /* generate a non-ignored operation */
1906 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1907 } while (ignore_pattern(gen_ops[which_op].name));
1909 DEBUG(3,("Generating op %s on instance %d\n",
1910 gen_ops[which_op].name, instance));
1912 current_op.seed = op_parms[op].seed;
1913 current_op.opnum = op;
1914 current_op.name = gen_ops[which_op].name;
1915 current_op.status = NT_STATUS_OK;
1916 current_op.mem_ctx = talloc_init("%s", current_op.name);
1918 ret = gen_ops[which_op].handler(instance);
1920 talloc_destroy(current_op.mem_ctx);
1922 gen_ops[which_op].count++;
1923 if (NT_STATUS_IS_OK(current_op.status)) {
1924 gen_ops[which_op].success_count++;
1928 printf("Failed at operation %d - %s\n",
1929 op, gen_ops[which_op].name);
1933 if (op % 100 == 0) {
1938 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1939 printf("Op %-10s got %d/%d success\n",
1941 gen_ops[i].success_count,
1949 perform a backtracking analysis of the minimal set of operations
1950 to generate an error
1952 static void backtrack_analyze(void)
1956 chunk = options.numops / 2;
1961 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1964 chunk = MIN(chunk, options.numops / 2);
1966 /* mark this range as disabled */
1967 max = MIN(options.numops, base+chunk);
1968 for (i=base;i<max; i++) {
1969 op_parms[i].disabled = True;
1971 printf("Testing %d ops with %d-%d disabled\n",
1972 options.numops, base, max-1);
1974 printf("Completed %d of %d ops\n", ret, options.numops);
1975 for (i=base;i<max; i++) {
1976 op_parms[i].disabled = False;
1978 if (ret == options.numops) {
1979 /* this chunk is needed */
1981 } else if (ret < base) {
1982 printf("damn - inconsistent errors! found early error\n");
1983 options.numops = ret+1;
1986 /* it failed - this chunk isn't needed for a failure */
1987 memmove(&op_parms[base], &op_parms[max],
1988 sizeof(op_parms[0]) * (options.numops - max));
1989 options.numops = (ret+1) - (max - base);
1999 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2002 } while (chunk > 0);
2004 printf("Reduced to %d ops\n", options.numops);
2006 if (ret != options.numops - 1) {
2007 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2012 start the main gentest process
2014 static BOOL start_gentest(void)
2019 /* allocate the open_handles array */
2020 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2022 srandom(options.seed);
2023 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2025 /* generate the seeds - after this everything is deterministic */
2026 if (options.use_preset_seeds) {
2028 char **preset = file_lines_load(options.seeds_file, &numops);
2030 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2033 if (numops < options.numops) {
2034 options.numops = numops;
2036 for (op=0;op<options.numops;op++) {
2038 printf("Not enough seeds in %s\n", options.seeds_file);
2041 op_parms[op].seed = atoi(preset[op]);
2043 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2045 for (op=0; op<options.numops; op++) {
2046 op_parms[op].seed = random();
2052 if (ret != options.numops && options.analyze) {
2053 options.numops = ret+1;
2054 backtrack_analyze();
2055 } else if (options.analyze_always) {
2056 backtrack_analyze();
2057 } else if (options.analyze_continuous) {
2058 while (run_test() == options.numops) ;
2061 return ret == options.numops;
2065 static void usage(void)
2069 gentest2 //server1/share1 //server2/share2 [options..]\n\
2071 -U user%%pass (can be specified twice)\n\
2074 -a (show all ops)\n\
2075 -A backtrack to find minimal ops\n\
2076 -i FILE add a list of wildcard exclusions\n\
2077 -O enable oplocks\n\
2078 -S FILE set preset seeds file\n\
2079 -L use preset seeds\n\
2080 -F fast reconnect (just close files)\n\
2081 -C continuous analysis mode\n\
2082 -X analyse even when test OK\n\
2086 /****************************************************************************
2088 ****************************************************************************/
2089 int main(int argc, char *argv[])
2097 setup_logging("gentest", DEBUG_STDOUT);
2099 if (argc < 3 || argv[1][0] == '-') {
2104 setup_logging(argv[0], DEBUG_STDOUT);
2106 for (i=0;i<NSERVERS;i++) {
2107 const char *share = argv[1+i];
2108 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2109 printf("Invalid share name '%s'\n", share);
2117 lp_load(dyn_CONFIGFILE,True,False,False);
2120 options.seed = time(NULL);
2121 options.numops = 1000;
2122 options.max_open_handles = 20;
2123 options.seeds_file = "gentest_seeds.dat";
2125 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2128 i = servers[0].username?1:0;
2129 if (!split_username(optarg,
2130 &servers[i].username,
2131 &servers[i].password)) {
2132 printf("Must supply USER%%PASS\n");
2137 DEBUGLEVEL = atoi(optarg);
2138 setup_logging(NULL, DEBUG_STDOUT);
2141 options.seed = atoi(optarg);
2144 options.seeds_file = optarg;
2147 options.use_preset_seeds = True;
2150 options.fast_reconnect = True;
2153 options.numops = atoi(optarg);
2156 options.use_oplocks = True;
2159 options.showall = True;
2162 options.analyze = True;
2165 options.analyze_always = True;
2168 options.analyze_continuous = True;
2171 options.ignore_patterns = file_lines_load(optarg, NULL);
2177 printf("Unknown option %c (%d)\n", (char)opt, opt);
2182 if (!servers[0].username) {
2186 if (!servers[1].username) {
2187 servers[1].username = servers[0].username;
2188 servers[1].password = servers[0].password;
2191 printf("seed=%u\n", options.seed);
2193 ret = start_gentest();
2196 printf("gentest completed - no errors\n");
2198 printf("gentest failed\n");