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.
22 #include "system/time.h"
24 #include "libcli/raw/libcliraw.h"
30 static struct gentest_options {
34 BOOL analyze_continuous;
35 uint_t max_open_handles;
39 char **ignore_patterns;
40 const char *seeds_file;
41 BOOL use_preset_seeds;
45 /* mapping between open handles on the server and local handles */
49 uint_t server_fnum[NSERVERS];
52 static uint_t num_open_handles;
54 /* state information for the servers. We open NINSTANCES connections to
57 struct smbcli_state *cli[NINSTANCES];
64 /* the seeds and flags for each operation */
71 /* oplock break info */
78 } oplocks[NSERVERS][NINSTANCES];
80 /* change notify reply info */
84 struct smb_notify notify;
85 } notifies[NSERVERS][NINSTANCES];
87 /* info relevant to the current operation */
98 #define BAD_HANDLE 0xFFFE
100 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private);
101 static void idle_func(struct smbcli_transport *transport, void *private);
104 check if a string should be ignored. This is used as the basis
105 for all error ignore settings
107 static BOOL ignore_pattern(const char *str)
110 if (!options.ignore_patterns) return False;
112 for (i=0;options.ignore_patterns[i];i++) {
113 if (strcmp(options.ignore_patterns[i], str) == 0 ||
114 gen_fnmatch(options.ignore_patterns[i], str) == 0) {
115 DEBUG(2,("Ignoring '%s'\n", str));
122 /*****************************************************
123 connect to the servers
124 *******************************************************/
125 static BOOL connect_servers_fast(void)
129 /* close all open files */
130 for (h=0;h<options.max_open_handles;h++) {
131 if (!open_handles[h].active) continue;
132 for (i=0;i<NSERVERS;i++) {
133 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
134 open_handles[h].server_fnum[i])))) {
137 open_handles[h].active = False;
147 /*****************************************************
148 connect to the servers
149 *******************************************************/
150 static BOOL connect_servers(void)
154 if (options.fast_reconnect && servers[0].cli[0]) {
155 if (connect_servers_fast()) {
160 /* close any existing connections */
161 for (i=0;i<NSERVERS;i++) {
162 for (j=0;j<NINSTANCES;j++) {
163 if (servers[i].cli[j]) {
164 smbcli_tdis(servers[i].cli[j]);
165 smbcli_shutdown(servers[i].cli[j]);
166 servers[i].cli[j] = NULL;
171 for (i=0;i<NSERVERS;i++) {
172 for (j=0;j<NINSTANCES;j++) {
174 printf("Connecting to \\\\%s\\%s as %s - instance %d\n",
175 servers[i].server_name, servers[i].share_name,
176 servers[i].username, j);
177 status = smbcli_full_connection(NULL, &servers[i].cli[j],
179 servers[i].server_name, NULL,
180 servers[i].share_name, "?????",
181 servers[i].username, lp_workgroup(),
182 servers[i].password, 0, NULL);
183 if (!NT_STATUS_IS_OK(status)) {
184 printf("Failed to connect to \\\\%s\\%s - %s\n",
185 servers[i].server_name, servers[i].share_name,
190 smbcli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
191 smbcli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 1, NULL);
199 work out the time skew between the servers - be conservative
201 static uint_t time_skew(void)
204 ret = ABS(servers[0].cli[0]->transport->negotiate.server_time -
205 servers[1].cli[0]->transport->negotiate.server_time);
210 turn an fnum for an instance into a handle
212 static uint_t fnum_to_handle(int server, int instance, uint16_t fnum)
215 for (i=0;i<options.max_open_handles;i++) {
216 if (!open_handles[i].active ||
217 instance != open_handles[i].instance) continue;
218 if (open_handles[i].server_fnum[server] == fnum) {
222 printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n",
223 fnum, server, instance);
228 add some newly opened handles
230 static void gen_add_handle(int instance, const char *name, uint16_t fnums[NSERVERS])
233 for (h=0;h<options.max_open_handles;h++) {
234 if (!open_handles[h].active) break;
236 if (h == options.max_open_handles) {
237 /* we have to force close a random handle */
238 h = random() % options.max_open_handles;
239 for (i=0;i<NSERVERS;i++) {
240 if (NT_STATUS_IS_ERR((smbcli_close(servers[i].cli[open_handles[h].instance]->tree,
241 open_handles[h].server_fnum[i])))) {
242 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
243 smbcli_errstr(servers[i].cli[open_handles[h].instance]->tree));
246 printf("Recovered handle %d\n", h);
249 for (i=0;i<NSERVERS;i++) {
250 open_handles[h].server_fnum[i] = fnums[i];
251 open_handles[h].instance = instance;
252 open_handles[h].active = True;
253 open_handles[h].name = name;
257 printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
259 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
264 remove a closed handle
266 static void gen_remove_handle(int instance, uint16_t fnums[NSERVERS])
269 for (h=0;h<options.max_open_handles;h++) {
270 if (instance == open_handles[h].instance &&
271 open_handles[h].server_fnum[0] == fnums[0]) {
272 open_handles[h].active = False;
274 printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n",
276 open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
277 open_handles[h].name);
281 printf("Removing invalid handle!?\n");
286 return True with 'chance' probability as a percentage
288 static BOOL gen_chance(uint_t chance)
290 return ((random() % 100) <= chance);
294 map an internal handle number to a server fnum
296 static uint16_t gen_lookup_fnum(int server, uint16_t handle)
298 if (handle == BAD_HANDLE) return handle;
299 return open_handles[handle].server_fnum[server];
305 static uint16_t gen_fnum(int instance)
310 if (gen_chance(20)) return BAD_HANDLE;
312 while (num_open_handles > 0 && count++ < 10*options.max_open_handles) {
313 h = random() % options.max_open_handles;
314 if (open_handles[h].active &&
315 open_handles[h].instance == instance) {
323 return a file handle, but skewed so we don't close the last
324 couple of handles too readily
326 static uint16_t gen_fnum_close(int instance)
328 if (num_open_handles < 3) {
329 if (gen_chance(80)) return BAD_HANDLE;
332 return gen_fnum(instance);
336 generate an integer in a specified range
338 static int gen_int_range(uint_t min, uint_t max)
341 return min + (r % (1+max-min));
345 return a fnum for use as a root fid
346 be careful to call GEN_SET_FNUM() when you use this!
348 static uint16_t gen_root_fid(int instance)
350 if (gen_chance(5)) return gen_fnum(instance);
355 generate a file offset
357 static int gen_offset(void)
359 if (gen_chance(20)) return 0;
360 return gen_int_range(0, 1024*1024);
366 static int gen_io_count(void)
368 if (gen_chance(20)) return 0;
369 return gen_int_range(0, 4096);
375 static const char *gen_fname(void)
377 const char *names[] = {"\\gentest\\gentest.dat",
379 "\\gentest\\foo2.sym",
380 "\\gentest\\foo3.dll",
382 "\\gentest\\foo4:teststream1",
383 "\\gentest\\foo4:teststream2",
384 "\\gentest\\foo5.exe",
385 "\\gentest\\foo5.exe:teststream3",
386 "\\gentest\\foo5.exe:teststream4",
387 "\\gentest\\foo6.com",
389 "\\gentest\\blah\\blergh.txt",
390 "\\gentest\\blah\\blergh2",
391 "\\gentest\\blah\\blergh3.txt",
392 "\\gentest\\blah\\blergh4",
393 "\\gentest\\blah\\blergh5.txt",
394 "\\gentest\\blah\\blergh5",
395 "\\gentest\\blah\\.",
397 /* this causes problem with w2k3 */
398 "\\gentest\\blah\\..",
400 "\\gentest\\a_very_long_name.bin",
406 i = gen_int_range(0, ARRAY_SIZE(names)-1);
407 } while (ignore_pattern(names[i]));
413 generate a filename with a higher chance of choosing an already
416 static const char *gen_fname_open(int instance)
419 h = gen_fnum(instance);
420 if (h == BAD_HANDLE) {
423 return open_handles[h].name;
427 generate a wildcard pattern
429 static const char *gen_pattern(void)
432 const char *names[] = {"\\gentest\\*.dat",
435 "\\gentest\\blah\\*.*",
436 "\\gentest\\blah\\*",
439 if (gen_chance(50)) return gen_fname();
442 i = gen_int_range(0, ARRAY_SIZE(names)-1);
443 } while (ignore_pattern(names[i]));
451 static uint32_t gen_bits_mask(uint_t mask)
453 uint_t ret = random();
458 generate a bitmask with high probability of the first mask
459 and low of the second
461 static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2)
463 if (gen_chance(10)) return gen_bits_mask(mask2);
464 return gen_bits_mask(mask1);
470 static BOOL gen_bool(void)
472 return gen_bits_mask2(0x1, 0xFF);
476 generate ntrename flags
478 static uint16_t gen_rename_flags(void)
480 if (gen_chance(30)) return RENAME_FLAG_RENAME;
481 if (gen_chance(30)) return RENAME_FLAG_HARD_LINK;
482 if (gen_chance(30)) return RENAME_FLAG_COPY;
483 return gen_bits_mask(0xFFFF);
488 return a lockingx lock mode
490 static uint16_t gen_lock_mode(void)
492 if (gen_chance(5)) return gen_bits_mask(0xFFFF);
493 if (gen_chance(20)) return gen_bits_mask(0x1F);
494 return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
500 static uint16_t gen_pid(void)
502 if (gen_chance(10)) return gen_bits_mask(0xFFFF);
507 generate a lock count
509 static off_t gen_lock_count(void)
511 return gen_int_range(0, 3);
515 generate a ntcreatex flags field
517 static uint32_t gen_ntcreatex_flags(void)
519 if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
520 return gen_bits_mask2(0x1F, 0xFFFFFFFF);
524 generate a NT access mask
526 static uint32_t gen_access_mask(void)
528 if (gen_chance(50)) return SEC_RIGHT_MAXIMUM_ALLOWED;
529 if (gen_chance(20)) return GENERIC_RIGHTS_FILE_ALL_ACCESS;
530 return gen_bits_mask(0xFFFFFFFF);
534 generate a ntcreatex create options bitfield
536 static uint32_t gen_create_options(void)
538 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
539 if (gen_chance(50)) return 0;
540 return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
544 generate a ntcreatex open disposition
546 static uint32_t gen_open_disp(void)
548 if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
549 return gen_int_range(0, 5);
553 generate an openx open mode
555 static uint16_t gen_openx_mode(void)
557 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
558 if (gen_chance(20)) return gen_bits_mask(0xFF);
559 return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
563 generate an openx flags field
565 static uint16_t gen_openx_flags(void)
567 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
568 return gen_bits_mask(0x7);
572 generate an openx open function
574 static uint16_t gen_openx_func(void)
576 if (gen_chance(20)) return gen_bits_mask(0xFFFF);
577 return gen_bits_mask(0x13);
581 generate a file attrib combination
583 static uint32_t gen_attrib(void)
585 if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
586 return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
590 generate a unix timestamp
592 static time_t gen_timet(void)
594 if (gen_chance(30)) return 0;
595 return (time_t)random();
599 generate a unix timestamp
601 static NTTIME gen_nttime(void)
604 unix_to_nt_time(&ret, gen_timet());
609 generate a milliseconds protocol timeout
611 static uint32_t gen_timeout(void)
613 if (gen_chance(98)) return 0;
614 return random() % 50;
618 generate a file allocation size
620 static uint_t gen_alloc_size(void)
624 if (gen_chance(30)) return 0;
626 ret = random() % 4*1024*1024;
627 /* give a high chance of a round number */
628 if (gen_chance(60)) {
629 ret &= ~(1024*1024 - 1);
635 generate an ea_struct
637 static struct ea_struct gen_ea_struct(void)
640 const char *names[] = {"EAONE",
645 "AVERYLONGATTRIBUTENAME"};
646 const char *values[] = {"VALUE1",
651 "ASOMEWHATLONGERATTRIBUTEVALUE"};
655 i = gen_int_range(0, ARRAY_SIZE(names)-1);
656 } while (ignore_pattern(names[i]));
658 ea.name.s = names[i];
661 i = gen_int_range(0, ARRAY_SIZE(values)-1);
662 } while (ignore_pattern(values[i]));
664 ea.value = data_blob(values[i], strlen(values[i]));
666 if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
674 this is called when a change notify reply comes in
676 static void async_notify(struct smbcli_request *req)
678 struct smb_notify notify;
682 struct smbcli_transport *transport = req->transport;
684 tid = SVAL(req->in.hdr, HDR_TID);
686 status = smb_raw_changenotify_recv(req, current_op.mem_ctx, ¬ify);
687 if (NT_STATUS_IS_OK(status)) {
688 printf("notify tid=%d num_changes=%d action=%d name=%s\n",
690 notify.out.num_changes,
691 notify.out.changes[0].action,
692 notify.out.changes[0].name.s);
695 for (i=0;i<NSERVERS;i++) {
696 for (j=0;j<NINSTANCES;j++) {
697 if (transport == servers[i].cli[j]->transport &&
698 tid == servers[i].cli[j]->tree->tid) {
699 notifies[i][j].notify_count++;
700 notifies[i][j].status = status;
701 notifies[i][j].notify = notify;
708 the oplock handler will either ack the break or close the file
710 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
716 struct smbcli_tree *tree = NULL;
718 srandom(current_op.seed);
719 do_close = gen_chance(50);
721 for (i=0;i<NSERVERS;i++) {
722 for (j=0;j<NINSTANCES;j++) {
723 if (transport == servers[i].cli[j]->transport &&
724 tid == servers[i].cli[j]->tree->tid) {
725 oplocks[i][j].got_break = True;
726 oplocks[i][j].fnum = fnum;
727 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
728 oplocks[i][j].level = level;
729 oplocks[i][j].do_close = do_close;
730 tree = servers[i].cli[j]->tree;
736 printf("Oplock break not for one of our trees!?\n");
741 printf("oplock ack fnum=%d\n", fnum);
742 return smbcli_oplock_ack(tree, fnum, level);
745 printf("oplock close fnum=%d\n", fnum);
747 io.close.level = RAW_CLOSE_CLOSE;
748 io.close.in.fnum = fnum;
749 io.close.in.write_time = 0;
750 status = smb_raw_close(tree, &io);
752 if (!NT_STATUS_IS_OK(status)) {
753 printf("WARNING: close failed in oplock_handler_close - %s\n", nt_errstr(status));
760 the idle function tries to cope with getting an oplock break on a connection, and
761 an operation on another connection blocking until that break is acked
762 we check for operations on all transports in the idle function
764 static void idle_func(struct smbcli_transport *transport, void *private)
767 for (i=0;i<NSERVERS;i++) {
768 for (j=0;j<NINSTANCES;j++) {
769 if (servers[i].cli[j] &&
770 transport != servers[i].cli[j]->transport) {
771 smbcli_transport_process(servers[i].cli[j]->transport);
780 compare NTSTATUS, using checking ignored patterns
782 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
784 if (NT_STATUS_EQUAL(status1, status2)) return True;
786 /* one code being an error and the other OK is always an error */
787 if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
789 /* if we are ignoring one of the status codes then consider this a match */
790 if (ignore_pattern(nt_errstr(status1)) ||
791 ignore_pattern(nt_errstr(status2))) {
799 check for pending packets on all connections
801 static void check_pending(void)
807 for (j=0;j<NINSTANCES;j++) {
808 for (i=0;i<NSERVERS;i++) {
809 smbcli_transport_process(servers[i].cli[j]->transport);
815 check that the same oplock breaks have been received by all instances
817 static BOOL check_oplocks(const char *call)
825 for (j=0;j<NINSTANCES;j++) {
826 for (i=1;i<NSERVERS;i++) {
827 if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
828 oplocks[0][j].handle != oplocks[i][j].handle ||
829 oplocks[0][j].level != oplocks[i][j].level) {
830 if (tries++ < 10) goto again;
831 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
832 oplocks[0][j].got_break,
833 oplocks[0][j].handle,
835 oplocks[i][j].got_break,
836 oplocks[i][j].handle,
837 oplocks[i][j].level);
843 /* if we got a break and closed then remove the handle */
844 for (j=0;j<NINSTANCES;j++) {
845 if (oplocks[0][j].got_break &&
846 oplocks[0][j].do_close) {
847 uint16_t fnums[NSERVERS];
848 for (i=0;i<NSERVERS;i++) {
849 fnums[i] = oplocks[i][j].fnum;
851 gen_remove_handle(j, fnums);
860 check that the same change notify info has been received by all instances
862 static BOOL check_notifies(const char *call)
870 for (j=0;j<NINSTANCES;j++) {
871 for (i=1;i<NSERVERS;i++) {
873 struct smb_notify not1, not2;
875 if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
876 if (tries++ < 10) goto again;
877 printf("Notify count inconsistent %d %d\n",
878 notifies[0][j].notify_count,
879 notifies[i][j].notify_count);
883 if (notifies[0][j].notify_count == 0) continue;
885 if (!NT_STATUS_EQUAL(notifies[0][j].status,
886 notifies[i][j].status)) {
887 printf("Notify status mismatch - %s - %s\n",
888 nt_errstr(notifies[0][j].status),
889 nt_errstr(notifies[i][j].status));
893 if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
897 not1 = notifies[0][j].notify;
898 not2 = notifies[i][j].notify;
900 for (n=0;n<not1.out.num_changes;n++) {
901 if (not1.out.changes[n].action !=
902 not2.out.changes[n].action) {
903 printf("Notify action %d inconsistent %d %d\n", n,
904 not1.out.changes[n].action,
905 not2.out.changes[n].action);
908 if (strcmp(not1.out.changes[n].name.s,
909 not2.out.changes[n].name.s)) {
910 printf("Notify name %d inconsistent %s %s\n", n,
911 not1.out.changes[n].name.s,
912 not2.out.changes[n].name.s);
915 if (not1.out.changes[n].name.private_length !=
916 not2.out.changes[n].name.private_length) {
917 printf("Notify name length %d inconsistent %d %d\n", n,
918 not1.out.changes[n].name.private_length,
919 not2.out.changes[n].name.private_length);
926 ZERO_STRUCT(notifies);
932 #define GEN_COPY_PARM do { \
934 for (i=1;i<NSERVERS;i++) { \
939 #define GEN_CALL(call) do { \
941 ZERO_STRUCT(oplocks); \
942 ZERO_STRUCT(notifies); \
943 for (i=0;i<NSERVERS;i++) { \
944 struct smbcli_tree *tree = servers[i].cli[instance]->tree; \
947 current_op.status = status[0]; \
948 for (i=1;i<NSERVERS;i++) { \
949 if (!compare_status(status[i], status[0])) { \
950 printf("status different in %s - %s %s\n", #call, \
951 nt_errstr(status[0]), nt_errstr(status[i])); \
955 if (!check_oplocks(#call)) return False; \
956 if (!check_notifies(#call)) return False; \
957 if (!NT_STATUS_IS_OK(status[0])) { \
962 #define ADD_HANDLE(name, field) do { \
963 uint16_t fnums[NSERVERS]; \
965 for (i=0;i<NSERVERS;i++) { \
966 fnums[i] = parm[i].field; \
968 gen_add_handle(instance, name, fnums); \
971 #define REMOVE_HANDLE(field) do { \
972 uint16_t fnums[NSERVERS]; \
974 for (i=0;i<NSERVERS;i++) { \
975 fnums[i] = parm[i].field; \
977 gen_remove_handle(instance, fnums); \
980 #define GEN_SET_FNUM(field) do { \
982 for (i=0;i<NSERVERS;i++) { \
983 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
987 #define CHECK_EQUAL(field) do { \
988 if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
989 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
990 (int)parm[0].field, (int)parm[1].field); \
995 #define CHECK_WSTR_EQUAL(field) do { \
996 if ((!parm[0].field.s && parm[1].field.s) || (parm[0].field.s && !parm[1].field.s)) { \
997 printf("%s is NULL!\n", #field); \
1000 if (parm[0].field.s && strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
1001 printf("Mismatch in %s - %s %s\n", #field, \
1002 parm[0].field.s, parm[1].field.s); \
1005 CHECK_EQUAL(field.private_length); \
1008 #define CHECK_BLOB_EQUAL(field) do { \
1009 if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1010 printf("Mismatch in %s\n", #field); \
1013 CHECK_EQUAL(field.length); \
1016 #define CHECK_TIMES_EQUAL(field) do { \
1017 if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1018 !ignore_pattern(#field)) { \
1019 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1020 (int)parm[0].field, (int)parm[1].field); \
1025 #define CHECK_NTTIMES_EQUAL(field) do { \
1026 if (ABS(nt_time_to_unix(parm[0].field) - \
1027 nt_time_to_unix(parm[1].field)) > time_skew() && \
1028 !ignore_pattern(#field)) { \
1029 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1030 (int)nt_time_to_unix(parm[0].field), \
1031 (int)nt_time_to_unix(parm[1].field)); \
1037 generate openx operations
1039 static BOOL handler_openx(int instance)
1041 union smb_open parm[NSERVERS];
1042 NTSTATUS status[NSERVERS];
1044 parm[0].openx.level = RAW_OPEN_OPENX;
1045 parm[0].openx.in.flags = gen_openx_flags();
1046 parm[0].openx.in.open_mode = gen_openx_mode();
1047 parm[0].openx.in.search_attrs = gen_attrib();
1048 parm[0].openx.in.file_attrs = gen_attrib();
1049 parm[0].openx.in.write_time = gen_timet();
1050 parm[0].openx.in.open_func = gen_openx_func();
1051 parm[0].openx.in.size = gen_io_count();
1052 parm[0].openx.in.timeout = gen_timeout();
1053 parm[0].openx.in.fname = gen_fname_open(instance);
1055 if (!options.use_oplocks) {
1056 /* mask out oplocks */
1057 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1058 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1062 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1064 CHECK_EQUAL(openx.out.attrib);
1065 CHECK_EQUAL(openx.out.size);
1066 CHECK_EQUAL(openx.out.access);
1067 CHECK_EQUAL(openx.out.ftype);
1068 CHECK_EQUAL(openx.out.devstate);
1069 CHECK_EQUAL(openx.out.action);
1070 CHECK_EQUAL(openx.out.access_mask);
1071 CHECK_EQUAL(openx.out.unknown);
1072 CHECK_TIMES_EQUAL(openx.out.write_time);
1074 /* open creates a new file handle */
1075 ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum);
1082 generate open operations
1084 static BOOL handler_open(int instance)
1086 union smb_open parm[NSERVERS];
1087 NTSTATUS status[NSERVERS];
1089 parm[0].openold.level = RAW_OPEN_OPEN;
1090 parm[0].openold.in.flags = gen_bits_mask2(0xF, 0xFFFF);
1091 parm[0].openold.in.search_attrs = gen_attrib();
1092 parm[0].openold.in.fname = gen_fname_open(instance);
1094 if (!options.use_oplocks) {
1095 /* mask out oplocks */
1096 parm[0].openold.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1097 OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1101 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1103 CHECK_EQUAL(openold.out.attrib);
1104 CHECK_TIMES_EQUAL(openold.out.write_time);
1105 CHECK_EQUAL(openold.out.size);
1106 CHECK_EQUAL(openold.out.rmode);
1108 /* open creates a new file handle */
1109 ADD_HANDLE(parm[0].openold.in.fname, openold.out.fnum);
1116 generate ntcreatex operations
1118 static BOOL handler_ntcreatex(int instance)
1120 union smb_open parm[NSERVERS];
1121 NTSTATUS status[NSERVERS];
1123 parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1124 parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1125 parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1126 parm[0].ntcreatex.in.access_mask = gen_access_mask();
1127 parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1128 parm[0].ntcreatex.in.file_attr = gen_attrib();
1129 parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1130 parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1131 parm[0].ntcreatex.in.create_options = gen_create_options();
1132 parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1133 parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1134 parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1136 if (!options.use_oplocks) {
1137 /* mask out oplocks */
1138 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1139 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1143 if (parm[0].ntcreatex.in.root_fid != 0) {
1144 GEN_SET_FNUM(ntcreatex.in.root_fid);
1146 GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1148 CHECK_EQUAL(ntcreatex.out.oplock_level);
1149 CHECK_EQUAL(ntcreatex.out.create_action);
1150 CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1151 CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1152 CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1153 CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1154 CHECK_EQUAL(ntcreatex.out.attrib);
1155 CHECK_EQUAL(ntcreatex.out.alloc_size);
1156 CHECK_EQUAL(ntcreatex.out.size);
1157 CHECK_EQUAL(ntcreatex.out.file_type);
1158 CHECK_EQUAL(ntcreatex.out.ipc_state);
1159 CHECK_EQUAL(ntcreatex.out.is_directory);
1161 /* ntcreatex creates a new file handle */
1162 ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum);
1168 generate close operations
1170 static BOOL handler_close(int instance)
1172 union smb_close parm[NSERVERS];
1173 NTSTATUS status[NSERVERS];
1175 parm[0].close.level = RAW_CLOSE_CLOSE;
1176 parm[0].close.in.fnum = gen_fnum_close(instance);
1177 parm[0].close.in.write_time = gen_timet();
1180 GEN_SET_FNUM(close.in.fnum);
1181 GEN_CALL(smb_raw_close(tree, &parm[i]));
1183 REMOVE_HANDLE(close.in.fnum);
1189 generate unlink operations
1191 static BOOL handler_unlink(int instance)
1193 struct smb_unlink parm[NSERVERS];
1194 NTSTATUS status[NSERVERS];
1196 parm[0].in.pattern = gen_pattern();
1197 parm[0].in.attrib = gen_attrib();
1200 GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1206 generate chkpath operations
1208 static BOOL handler_chkpath(int instance)
1210 struct smb_chkpath parm[NSERVERS];
1211 NTSTATUS status[NSERVERS];
1213 parm[0].in.path = gen_fname_open(instance);
1216 GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1222 generate mkdir operations
1224 static BOOL handler_mkdir(int instance)
1226 union smb_mkdir parm[NSERVERS];
1227 NTSTATUS status[NSERVERS];
1229 parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1230 parm[0].mkdir.in.path = gen_fname_open(instance);
1233 GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1239 generate rmdir operations
1241 static BOOL handler_rmdir(int instance)
1243 struct smb_rmdir parm[NSERVERS];
1244 NTSTATUS status[NSERVERS];
1246 parm[0].in.path = gen_fname_open(instance);
1249 GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1255 generate rename operations
1257 static BOOL handler_rename(int instance)
1259 union smb_rename parm[NSERVERS];
1260 NTSTATUS status[NSERVERS];
1262 parm[0].generic.level = RAW_RENAME_RENAME;
1263 parm[0].rename.in.pattern1 = gen_pattern();
1264 parm[0].rename.in.pattern2 = gen_pattern();
1265 parm[0].rename.in.attrib = gen_attrib();
1268 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1274 generate ntrename operations
1276 static BOOL handler_ntrename(int instance)
1278 union smb_rename parm[NSERVERS];
1279 NTSTATUS status[NSERVERS];
1281 parm[0].generic.level = RAW_RENAME_NTRENAME;
1282 parm[0].ntrename.in.old_name = gen_fname();
1283 parm[0].ntrename.in.new_name = gen_fname();
1284 parm[0].ntrename.in.attrib = gen_attrib();
1285 parm[0].ntrename.in.cluster_size = gen_bits_mask2(0, 0xFFFFFFF);
1286 parm[0].ntrename.in.flags = gen_rename_flags();
1289 GEN_CALL(smb_raw_rename(tree, &parm[i]));
1296 generate seek operations
1298 static BOOL handler_seek(int instance)
1300 struct smb_seek parm[NSERVERS];
1301 NTSTATUS status[NSERVERS];
1303 parm[0].in.fnum = gen_fnum(instance);
1304 parm[0].in.mode = gen_bits_mask2(0x3, 0xFFFF);
1305 parm[0].in.offset = gen_offset();
1308 GEN_SET_FNUM(in.fnum);
1309 GEN_CALL(smb_raw_seek(tree, &parm[i]));
1311 CHECK_EQUAL(out.offset);
1318 generate readx operations
1320 static BOOL handler_readx(int instance)
1322 union smb_read parm[NSERVERS];
1323 NTSTATUS status[NSERVERS];
1325 parm[0].readx.level = RAW_READ_READX;
1326 parm[0].readx.in.fnum = gen_fnum(instance);
1327 parm[0].readx.in.offset = gen_offset();
1328 parm[0].readx.in.mincnt = gen_io_count();
1329 parm[0].readx.in.maxcnt = gen_io_count();
1330 parm[0].readx.in.remaining = gen_io_count();
1331 parm[0].readx.out.data = talloc(current_op.mem_ctx,
1332 MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1335 GEN_SET_FNUM(readx.in.fnum);
1336 GEN_CALL(smb_raw_read(tree, &parm[i]));
1338 CHECK_EQUAL(readx.out.remaining);
1339 CHECK_EQUAL(readx.out.compaction_mode);
1340 CHECK_EQUAL(readx.out.nread);
1346 generate writex operations
1348 static BOOL handler_writex(int instance)
1350 union smb_write parm[NSERVERS];
1351 NTSTATUS status[NSERVERS];
1353 parm[0].writex.level = RAW_WRITE_WRITEX;
1354 parm[0].writex.in.fnum = gen_fnum(instance);
1355 parm[0].writex.in.offset = gen_offset();
1356 parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1357 parm[0].writex.in.remaining = gen_io_count();
1358 parm[0].writex.in.count = gen_io_count();
1359 parm[0].writex.in.data = talloc_zero(current_op.mem_ctx, parm[0].writex.in.count);
1362 GEN_SET_FNUM(writex.in.fnum);
1363 GEN_CALL(smb_raw_write(tree, &parm[i]));
1365 CHECK_EQUAL(writex.out.nwritten);
1366 CHECK_EQUAL(writex.out.remaining);
1372 generate lockingx operations
1374 static BOOL handler_lockingx(int instance)
1376 union smb_lock parm[NSERVERS];
1377 NTSTATUS status[NSERVERS];
1380 parm[0].lockx.level = RAW_LOCK_LOCKX;
1381 parm[0].lockx.in.fnum = gen_fnum(instance);
1382 parm[0].lockx.in.mode = gen_lock_mode();
1383 parm[0].lockx.in.timeout = gen_timeout();
1385 /* make sure we don't accidentially generate an oplock
1386 break ack - otherwise the server can just block forever */
1387 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1388 parm[0].lockx.in.lock_cnt = gen_lock_count();
1389 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1390 } while (nlocks == 0);
1393 parm[0].lockx.in.locks = talloc(current_op.mem_ctx,
1394 sizeof(parm[0].lockx.in.locks[0]) * nlocks);
1395 for (n=0;n<nlocks;n++) {
1396 parm[0].lockx.in.locks[n].pid = gen_pid();
1397 parm[0].lockx.in.locks[n].offset = gen_offset();
1398 parm[0].lockx.in.locks[n].count = gen_io_count();
1403 GEN_SET_FNUM(lockx.in.fnum);
1404 GEN_CALL(smb_raw_lock(tree, &parm[i]));
1410 generate a fileinfo query structure
1412 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1415 #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1417 enum smb_fileinfo_level level;
1420 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1421 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1422 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1423 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1424 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1425 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1426 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1427 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1428 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1429 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1432 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1433 } while (ignore_pattern(levels[i].name));
1435 info->generic.level = levels[i].level;
1439 compare returned fileinfo structures
1441 static BOOL cmp_fileinfo(int instance,
1442 union smb_fileinfo parm[NSERVERS],
1443 NTSTATUS status[NSERVERS])
1447 switch (parm[0].generic.level) {
1448 case RAW_FILEINFO_GENERIC:
1451 case RAW_FILEINFO_GETATTR:
1452 CHECK_EQUAL(getattr.out.attrib);
1453 CHECK_EQUAL(getattr.out.size);
1454 CHECK_TIMES_EQUAL(getattr.out.write_time);
1457 case RAW_FILEINFO_GETATTRE:
1458 CHECK_TIMES_EQUAL(getattre.out.create_time);
1459 CHECK_TIMES_EQUAL(getattre.out.access_time);
1460 CHECK_TIMES_EQUAL(getattre.out.write_time);
1461 CHECK_EQUAL(getattre.out.size);
1462 CHECK_EQUAL(getattre.out.alloc_size);
1463 CHECK_EQUAL(getattre.out.attrib);
1466 case RAW_FILEINFO_STANDARD:
1467 CHECK_TIMES_EQUAL(standard.out.create_time);
1468 CHECK_TIMES_EQUAL(standard.out.access_time);
1469 CHECK_TIMES_EQUAL(standard.out.write_time);
1470 CHECK_EQUAL(standard.out.size);
1471 CHECK_EQUAL(standard.out.alloc_size);
1472 CHECK_EQUAL(standard.out.attrib);
1475 case RAW_FILEINFO_EA_SIZE:
1476 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1477 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1478 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1479 CHECK_EQUAL(ea_size.out.size);
1480 CHECK_EQUAL(ea_size.out.alloc_size);
1481 CHECK_EQUAL(ea_size.out.attrib);
1482 CHECK_EQUAL(ea_size.out.ea_size);
1485 case RAW_FILEINFO_ALL_EAS:
1486 CHECK_EQUAL(all_eas.out.num_eas);
1487 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1488 CHECK_EQUAL(all_eas.out.eas[i].flags);
1489 CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1490 CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1494 case RAW_FILEINFO_IS_NAME_VALID:
1497 case RAW_FILEINFO_BASIC_INFO:
1498 case RAW_FILEINFO_BASIC_INFORMATION:
1499 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1500 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1501 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1502 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1503 CHECK_EQUAL(basic_info.out.attrib);
1506 case RAW_FILEINFO_STANDARD_INFO:
1507 case RAW_FILEINFO_STANDARD_INFORMATION:
1508 CHECK_EQUAL(standard_info.out.alloc_size);
1509 CHECK_EQUAL(standard_info.out.size);
1510 CHECK_EQUAL(standard_info.out.nlink);
1511 CHECK_EQUAL(standard_info.out.delete_pending);
1512 CHECK_EQUAL(standard_info.out.directory);
1515 case RAW_FILEINFO_EA_INFO:
1516 case RAW_FILEINFO_EA_INFORMATION:
1517 CHECK_EQUAL(ea_info.out.ea_size);
1520 case RAW_FILEINFO_NAME_INFO:
1521 case RAW_FILEINFO_NAME_INFORMATION:
1522 CHECK_WSTR_EQUAL(name_info.out.fname);
1525 case RAW_FILEINFO_ALL_INFO:
1526 case RAW_FILEINFO_ALL_INFORMATION:
1527 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1528 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1529 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1530 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1531 CHECK_EQUAL(all_info.out.attrib);
1532 CHECK_EQUAL(all_info.out.alloc_size);
1533 CHECK_EQUAL(all_info.out.size);
1534 CHECK_EQUAL(all_info.out.nlink);
1535 CHECK_EQUAL(all_info.out.delete_pending);
1536 CHECK_EQUAL(all_info.out.directory);
1537 CHECK_EQUAL(all_info.out.ea_size);
1538 CHECK_WSTR_EQUAL(all_info.out.fname);
1541 case RAW_FILEINFO_ALT_NAME_INFO:
1542 case RAW_FILEINFO_ALT_NAME_INFORMATION:
1543 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1546 case RAW_FILEINFO_STREAM_INFO:
1547 case RAW_FILEINFO_STREAM_INFORMATION:
1548 CHECK_EQUAL(stream_info.out.num_streams);
1549 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1550 CHECK_EQUAL(stream_info.out.streams[i].size);
1551 CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1552 CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1556 case RAW_FILEINFO_COMPRESSION_INFO:
1557 case RAW_FILEINFO_COMPRESSION_INFORMATION:
1558 CHECK_EQUAL(compression_info.out.compressed_size);
1559 CHECK_EQUAL(compression_info.out.format);
1560 CHECK_EQUAL(compression_info.out.unit_shift);
1561 CHECK_EQUAL(compression_info.out.chunk_shift);
1562 CHECK_EQUAL(compression_info.out.cluster_shift);
1565 case RAW_FILEINFO_INTERNAL_INFORMATION:
1566 CHECK_EQUAL(internal_information.out.file_id);
1569 case RAW_FILEINFO_ACCESS_INFORMATION:
1570 CHECK_EQUAL(access_information.out.access_flags);
1573 case RAW_FILEINFO_POSITION_INFORMATION:
1574 CHECK_EQUAL(position_information.out.position);
1577 case RAW_FILEINFO_MODE_INFORMATION:
1578 CHECK_EQUAL(mode_information.out.mode);
1581 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1582 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1585 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1586 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1587 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1588 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1589 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1590 CHECK_EQUAL(network_open_information.out.alloc_size);
1591 CHECK_EQUAL(network_open_information.out.size);
1592 CHECK_EQUAL(network_open_information.out.attrib);
1595 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1596 CHECK_EQUAL(attribute_tag_information.out.attrib);
1597 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1605 generate qpathinfo operations
1607 static BOOL handler_qpathinfo(int instance)
1609 union smb_fileinfo parm[NSERVERS];
1610 NTSTATUS status[NSERVERS];
1612 parm[0].generic.in.fname = gen_fname_open(instance);
1614 gen_fileinfo(instance, &parm[0]);
1617 GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1619 return cmp_fileinfo(instance, parm, status);
1623 generate qfileinfo operations
1625 static BOOL handler_qfileinfo(int instance)
1627 union smb_fileinfo parm[NSERVERS];
1628 NTSTATUS status[NSERVERS];
1630 parm[0].generic.in.fnum = gen_fnum(instance);
1632 gen_fileinfo(instance, &parm[0]);
1635 GEN_SET_FNUM(generic.in.fnum);
1636 GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1638 return cmp_fileinfo(instance, parm, status);
1643 generate a fileinfo query structure
1645 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1649 #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1651 enum smb_setfileinfo_level level;
1655 /* disabled until win2003 can handle them ... */
1656 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO),
1657 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO),
1659 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1660 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION),
1661 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1662 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION),
1663 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1666 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1667 } while (ignore_pattern(levels[i].name));
1669 info->generic.level = levels[i].level;
1671 switch (info->generic.level) {
1672 case RAW_SFILEINFO_SETATTR:
1673 info->setattr.in.attrib = gen_attrib();
1674 info->setattr.in.write_time = gen_timet();
1676 case RAW_SFILEINFO_SETATTRE:
1677 info->setattre.in.create_time = gen_timet();
1678 info->setattre.in.access_time = gen_timet();
1679 info->setattre.in.write_time = gen_timet();
1681 case RAW_SFILEINFO_STANDARD:
1682 info->standard.in.create_time = gen_timet();
1683 info->standard.in.access_time = gen_timet();
1684 info->standard.in.write_time = gen_timet();
1686 case RAW_SFILEINFO_EA_SET:
1687 info->ea_set.in.ea = gen_ea_struct();
1689 case RAW_SFILEINFO_BASIC_INFO:
1690 case RAW_SFILEINFO_BASIC_INFORMATION:
1691 info->basic_info.in.create_time = gen_nttime();
1692 info->basic_info.in.access_time = gen_nttime();
1693 info->basic_info.in.write_time = gen_nttime();
1694 info->basic_info.in.change_time = gen_nttime();
1695 info->basic_info.in.attrib = gen_attrib();
1697 case RAW_SFILEINFO_DISPOSITION_INFO:
1698 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1699 info->disposition_info.in.delete_on_close = gen_bool();
1701 case RAW_SFILEINFO_ALLOCATION_INFO:
1702 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1703 info->allocation_info.in.alloc_size = gen_alloc_size();
1705 case RAW_SFILEINFO_END_OF_FILE_INFO:
1706 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1707 info->end_of_file_info.in.size = gen_offset();
1709 case RAW_SFILEINFO_RENAME_INFORMATION:
1710 info->rename_information.in.overwrite = gen_bool();
1711 info->rename_information.in.root_fid = gen_root_fid(instance);
1712 info->rename_information.in.new_name = gen_fname_open(instance);
1714 case RAW_SFILEINFO_POSITION_INFORMATION:
1715 info->position_information.in.position = gen_offset();
1717 case RAW_SFILEINFO_MODE_INFORMATION:
1718 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1724 generate setpathinfo operations
1726 static BOOL handler_spathinfo(int instance)
1728 union smb_setfileinfo parm[NSERVERS];
1729 NTSTATUS status[NSERVERS];
1731 parm[0].generic.file.fname = gen_fname_open(instance);
1733 gen_setfileinfo(instance, &parm[0]);
1737 /* a special case for the fid in a RENAME */
1738 if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1739 parm[0].rename_information.in.root_fid != 0) {
1740 GEN_SET_FNUM(rename_information.in.root_fid);
1743 GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1750 generate setfileinfo operations
1752 static BOOL handler_sfileinfo(int instance)
1754 union smb_setfileinfo parm[NSERVERS];
1755 NTSTATUS status[NSERVERS];
1757 parm[0].generic.file.fnum = gen_fnum(instance);
1759 gen_setfileinfo(instance, &parm[0]);
1762 GEN_SET_FNUM(generic.file.fnum);
1763 GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1770 generate change notify operations
1772 static BOOL handler_notify(int instance)
1774 struct smb_notify parm[NSERVERS];
1777 parm[0].in.buffer_size = gen_io_count();
1778 parm[0].in.completion_filter = gen_bits_mask(0xFF);
1779 parm[0].in.fnum = gen_fnum(instance);
1780 parm[0].in.recursive = gen_bool();
1783 GEN_SET_FNUM(in.fnum);
1785 for (n=0;n<NSERVERS;n++) {
1786 struct smbcli_request *req;
1787 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1788 req->async.fn = async_notify;
1795 wipe any relevant files
1797 static void wipe_files(void)
1800 for (i=0;i<NSERVERS;i++) {
1801 int n = smbcli_deltree(servers[i].cli[0]->tree, "\\gentest");
1803 printf("Failed to wipe tree on server %d\n", i);
1806 if (NT_STATUS_IS_ERR(smbcli_mkdir(servers[i].cli[0]->tree, "\\gentest"))) {
1807 printf("Failed to create \\gentest - %s\n",
1808 smbcli_errstr(servers[i].cli[0]->tree));
1812 printf("Deleted %d files on server %d\n", n, i);
1818 dump the current seeds - useful for continuing a backtrack
1820 static void dump_seeds(void)
1825 if (!options.seeds_file) {
1828 f = fopen("seeds.tmp", "w");
1831 for (i=0;i<options.numops;i++) {
1832 fprintf(f, "%u\n", op_parms[i].seed);
1835 rename("seeds.tmp", options.seeds_file);
1841 the list of top-level operations that we will generate
1845 BOOL (*handler)(int instance);
1846 int count, success_count;
1848 {"OPEN", handler_open},
1849 {"OPENX", handler_openx},
1850 {"NTCREATEX", handler_ntcreatex},
1851 {"CLOSE", handler_close},
1852 {"UNLINK", handler_unlink},
1853 {"MKDIR", handler_mkdir},
1854 {"RMDIR", handler_rmdir},
1855 {"RENAME", handler_rename},
1856 {"NTRENAME", handler_ntrename},
1857 {"READX", handler_readx},
1858 {"WRITEX", handler_writex},
1859 {"CHKPATH", handler_chkpath},
1860 {"LOCKINGX", handler_lockingx},
1861 {"QPATHINFO", handler_qpathinfo},
1862 {"QFILEINFO", handler_qfileinfo},
1863 {"SPATHINFO", handler_spathinfo},
1864 {"SFILEINFO", handler_sfileinfo},
1865 {"NOTIFY", handler_notify},
1866 {"SEEK", handler_seek},
1871 run the test with the current set of op_parms parameters
1872 return the number of operations that completed successfully
1874 static int run_test(void)
1878 if (!connect_servers()) {
1879 printf("Failed to connect to servers\n");
1885 /* wipe any leftover files from old runs */
1888 /* reset the open handles array */
1889 memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1890 num_open_handles = 0;
1892 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1893 gen_ops[i].count = 0;
1894 gen_ops[i].success_count = 0;
1897 for (op=0; op<options.numops; op++) {
1898 int instance, which_op;
1901 if (op_parms[op].disabled) continue;
1903 srandom(op_parms[op].seed);
1905 instance = gen_int_range(0, NINSTANCES-1);
1907 /* generate a non-ignored operation */
1909 which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1910 } while (ignore_pattern(gen_ops[which_op].name));
1912 DEBUG(3,("Generating op %s on instance %d\n",
1913 gen_ops[which_op].name, instance));
1915 current_op.seed = op_parms[op].seed;
1916 current_op.opnum = op;
1917 current_op.name = gen_ops[which_op].name;
1918 current_op.status = NT_STATUS_OK;
1919 current_op.mem_ctx = talloc_init("%s", current_op.name);
1921 ret = gen_ops[which_op].handler(instance);
1923 talloc_destroy(current_op.mem_ctx);
1925 gen_ops[which_op].count++;
1926 if (NT_STATUS_IS_OK(current_op.status)) {
1927 gen_ops[which_op].success_count++;
1931 printf("Failed at operation %d - %s\n",
1932 op, gen_ops[which_op].name);
1936 if (op % 100 == 0) {
1941 for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1942 printf("Op %-10s got %d/%d success\n",
1944 gen_ops[i].success_count,
1952 perform a backtracking analysis of the minimal set of operations
1953 to generate an error
1955 static void backtrack_analyze(void)
1959 chunk = options.numops / 2;
1964 chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1967 chunk = MIN(chunk, options.numops / 2);
1969 /* mark this range as disabled */
1970 max = MIN(options.numops, base+chunk);
1971 for (i=base;i<max; i++) {
1972 op_parms[i].disabled = True;
1974 printf("Testing %d ops with %d-%d disabled\n",
1975 options.numops, base, max-1);
1977 printf("Completed %d of %d ops\n", ret, options.numops);
1978 for (i=base;i<max; i++) {
1979 op_parms[i].disabled = False;
1981 if (ret == options.numops) {
1982 /* this chunk is needed */
1984 } else if (ret < base) {
1985 printf("damn - inconsistent errors! found early error\n");
1986 options.numops = ret+1;
1989 /* it failed - this chunk isn't needed for a failure */
1990 memmove(&op_parms[base], &op_parms[max],
1991 sizeof(op_parms[0]) * (options.numops - max));
1992 options.numops = (ret+1) - (max - base);
2002 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
2005 } while (chunk > 0);
2007 printf("Reduced to %d ops\n", options.numops);
2009 if (ret != options.numops - 1) {
2010 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
2015 start the main gentest process
2017 static BOOL start_gentest(void)
2022 /* allocate the open_handles array */
2023 open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
2025 srandom(options.seed);
2026 op_parms = calloc(options.numops, sizeof(op_parms[0]));
2028 /* generate the seeds - after this everything is deterministic */
2029 if (options.use_preset_seeds) {
2031 char **preset = file_lines_load(options.seeds_file, &numops);
2033 printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
2036 if (numops < options.numops) {
2037 options.numops = numops;
2039 for (op=0;op<options.numops;op++) {
2041 printf("Not enough seeds in %s\n", options.seeds_file);
2044 op_parms[op].seed = atoi(preset[op]);
2046 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
2048 for (op=0; op<options.numops; op++) {
2049 op_parms[op].seed = random();
2055 if (ret != options.numops && options.analyze) {
2056 options.numops = ret+1;
2057 backtrack_analyze();
2058 } else if (options.analyze_always) {
2059 backtrack_analyze();
2060 } else if (options.analyze_continuous) {
2061 while (run_test() == options.numops) ;
2064 return ret == options.numops;
2068 static void usage(void)
2072 gentest2 //server1/share1 //server2/share2 [options..]\n\
2074 -U user%%pass (can be specified twice)\n\
2077 -a (show all ops)\n\
2078 -A backtrack to find minimal ops\n\
2079 -i FILE add a list of wildcard exclusions\n\
2080 -O enable oplocks\n\
2081 -S FILE set preset seeds file\n\
2082 -L use preset seeds\n\
2083 -F fast reconnect (just close files)\n\
2084 -C continuous analysis mode\n\
2085 -X analyse even when test OK\n\
2089 /****************************************************************************
2091 ****************************************************************************/
2092 int main(int argc, char *argv[])
2100 setup_logging("gentest", DEBUG_STDOUT);
2102 if (argc < 3 || argv[1][0] == '-') {
2107 setup_logging(argv[0], DEBUG_STDOUT);
2109 for (i=0;i<NSERVERS;i++) {
2110 const char *share = argv[1+i];
2111 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2112 printf("Invalid share name '%s'\n", share);
2120 lp_load(dyn_CONFIGFILE,True,False,False);
2123 options.seed = time(NULL);
2124 options.numops = 1000;
2125 options.max_open_handles = 20;
2126 options.seeds_file = "gentest_seeds.dat";
2128 while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2131 i = servers[0].username?1:0;
2132 if (!split_username(optarg,
2133 &servers[i].username,
2134 &servers[i].password)) {
2135 printf("Must supply USER%%PASS\n");
2140 DEBUGLEVEL = atoi(optarg);
2141 setup_logging(NULL, DEBUG_STDOUT);
2144 options.seed = atoi(optarg);
2147 options.seeds_file = optarg;
2150 options.use_preset_seeds = True;
2153 options.fast_reconnect = True;
2156 options.numops = atoi(optarg);
2159 options.use_oplocks = True;
2162 options.showall = True;
2165 options.analyze = True;
2168 options.analyze_always = True;
2171 options.analyze_continuous = True;
2174 options.ignore_patterns = file_lines_load(optarg, NULL);
2180 printf("Unknown option %c (%d)\n", (char)opt, opt);
2185 if (!servers[0].username) {
2189 if (!servers[1].username) {
2190 servers[1].username = servers[0].username;
2191 servers[1].password = servers[0].password;
2194 printf("seed=%u\n", options.seed);
2196 ret = start_gentest();
2199 printf("gentest completed - no errors\n");
2201 printf("gentest failed\n");