first public release of samba4 code
[bbaumbach/samba-autobuild/.git] / source4 / torture / gentest.c
1 /* 
2    Unix SMB/CIFS implementation.
3    generic testing tool
4    Copyright (C) Andrew Tridgell 2003
5    
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.
10    
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.
15    
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.
19 */
20
21 #include "includes.h"
22
23 #define NSERVERS 2
24 #define NINSTANCES 2
25
26 /* global options */
27 static struct gentest_options {
28         BOOL showall;
29         BOOL analyze;
30         BOOL analyze_always;
31         BOOL analyze_continuous;
32         uint_t max_open_handles;
33         uint_t seed;
34         uint_t numops;
35         BOOL use_oplocks;
36         char **ignore_patterns;
37         const char *seeds_file;
38         BOOL use_preset_seeds;
39         BOOL fast_reconnect;
40 } options;
41
42 /* mapping between open handles on the server and local handles */
43 static struct {
44         BOOL active;
45         uint_t instance;
46         uint_t server_fnum[NSERVERS];
47         const char *name;
48 } *open_handles;
49 static uint_t num_open_handles;
50
51 /* state information for the servers. We open NINSTANCES connections to
52    each server */
53 static struct {
54         struct cli_state *cli[NINSTANCES];
55         char *server_name;
56         char *share_name;
57         char *username;
58         char *password;
59 } servers[NSERVERS];
60
61 /* the seeds and flags for each operation */
62 static struct {
63         uint_t seed;
64         BOOL disabled;
65 } *op_parms;
66
67
68 /* oplock break info */
69 static struct {
70         BOOL got_break;
71         uint16 fnum;
72         uint16 handle;
73         uint8 level;
74         BOOL do_close;
75 } oplocks[NSERVERS][NINSTANCES];
76
77 /* change notify reply info */
78 static struct {
79         int notify_count;
80         NTSTATUS status;
81         struct smb_notify notify;
82 } notifies[NSERVERS][NINSTANCES];
83
84 /* info relevant to the current operation */
85 static struct {
86         const char *name;
87         uint_t seed;
88         NTSTATUS status;
89         uint_t opnum;
90         TALLOC_CTX *mem_ctx;
91 } current_op;
92
93
94
95 #define BAD_HANDLE 0xFFFE
96
97 static BOOL oplock_handler(struct cli_transport *transport, uint16 tid, uint16 fnum, uint8 level, void *private);
98 static void idle_func(struct cli_transport *transport, void *private);
99
100 /*
101   check if a string should be ignored. This is used as the basis
102   for all error ignore settings
103 */
104 static BOOL ignore_pattern(const char *str)
105 {
106         int i;
107         if (!options.ignore_patterns) return False;
108
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));
113                         return True;
114                 }
115         }
116         return False;
117 }
118
119 /***************************************************** 
120 connect to the servers
121 *******************************************************/
122 static BOOL connect_servers_fast(void)
123 {
124         int h, i;
125
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 (!cli_close(servers[i].cli[open_handles[h].instance],
131                                        open_handles[h].server_fnum[i])) {
132                                 return False;
133                         }
134                         open_handles[h].active = False;
135                 }
136         }
137
138         return True;
139 }
140
141
142
143
144 /***************************************************** 
145 connect to the servers
146 *******************************************************/
147 static BOOL connect_servers(void)
148 {
149         int i, j;
150
151         if (options.fast_reconnect && servers[0].cli[0]) {
152                 if (connect_servers_fast()) {
153                         return True;
154                 }
155         }
156
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                                 cli_tdis(servers[i].cli[j]);
162                                 cli_shutdown(servers[i].cli[j]);
163                                 servers[i].cli[j] = NULL;
164                         }
165                 }
166         }
167
168         for (i=0;i<NSERVERS;i++) {
169                 for (j=0;j<NINSTANCES;j++) {
170                         NTSTATUS status;
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 = cli_full_connection(&servers[i].cli[j],
175                                                      "gentest",
176                                                      servers[i].server_name, NULL, 
177                                                      servers[i].share_name, "?????", 
178                                                      servers[i].username, "",
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,
183                                        nt_errstr(status));
184                                 return False;
185                         }
186
187                         cli_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL);
188                         cli_transport_idle_handler(servers[i].cli[j]->transport, idle_func, 10, NULL);
189                 }
190         }
191
192         return True;
193 }
194
195 /*
196   work out the time skew between the servers - be conservative
197 */
198 static uint_t time_skew(void)
199 {
200         uint_t ret;
201         ret = ABS(servers[0].cli[0]->transport->negotiate.server_time -
202                   servers[1].cli[0]->transport->negotiate.server_time);
203         return ret + 300;
204 }
205
206 /*
207   turn an fnum for an instance into a handle
208 */
209 static uint_t fnum_to_handle(int server, int instance, uint16 fnum)
210 {
211         uint_t i;
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) {
216                         return i;
217                 }
218         }
219         printf("Invalid fnum %d in fnum_to_handle on server %d instance %d\n", 
220                fnum, server, instance);
221         return BAD_HANDLE;
222 }
223
224 /*
225   add some newly opened handles
226 */
227 static void gen_add_handle(int instance, const char *name, uint16 fnums[NSERVERS])
228 {
229         int i, h;
230         for (h=0;h<options.max_open_handles;h++) {
231                 if (!open_handles[h].active) break;
232         }
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 (!cli_close(servers[i].cli[open_handles[h].instance], 
238                                        open_handles[h].server_fnum[i])) {
239                                 printf("INTERNAL ERROR: Close failed when recovering handle! - %s\n",
240                                        cli_errstr(servers[i].cli[open_handles[h].instance]));
241                         }
242                 }
243                 printf("Recovered handle %d\n", h);
244                 num_open_handles--;
245         }
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;
251         }
252         num_open_handles++;
253
254         printf("OPEN num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n", 
255                num_open_handles, h, 
256                open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
257                name);
258 }
259
260 /*
261   remove a closed handle
262 */
263 static void gen_remove_handle(int instance, uint16 fnums[NSERVERS])
264 {
265         int h;
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;                 
270                         num_open_handles--;
271                         printf("CLOSE num_open_handles=%d h=%d s1=0x%x s2=0x%x (%s)\n", 
272                                num_open_handles, h, 
273                                open_handles[h].server_fnum[0], open_handles[h].server_fnum[1],
274                                open_handles[h].name);
275                         return;
276                 }
277         }
278         printf("Removing invalid handle!?\n");
279         exit(1);
280 }
281
282 /*
283   return True with 'chance' probability as a percentage
284 */
285 static BOOL gen_chance(uint_t chance)
286 {
287         return ((random() % 100) <= chance);
288 }
289
290 /*
291   map an internal handle number to a server fnum
292 */
293 static uint16 gen_lookup_fnum(int server, uint16 handle)
294 {
295         if (handle == BAD_HANDLE) return handle;
296         return open_handles[handle].server_fnum[server];
297 }
298
299 /*
300   return a file handle
301 */
302 static uint16 gen_fnum(int instance)
303 {
304         uint16 h;
305         int count = 0;
306
307         if (gen_chance(20)) return BAD_HANDLE;
308
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) {
313                         return h;
314                 }
315         }
316         return BAD_HANDLE;
317 }
318
319 /*
320   return a file handle, but skewed so we don't close the last
321   couple of handles too readily
322 */
323 static uint16 gen_fnum_close(int instance)
324 {
325         if (num_open_handles < 3) {
326                 if (gen_chance(80)) return BAD_HANDLE;
327         }
328
329         return gen_fnum(instance);
330 }
331
332 /*
333   generate an integer in a specified range
334 */
335 static int gen_int_range(uint_t min, uint_t max)
336 {
337         uint_t r = random();
338         return min + (r % (1+max-min));
339 }
340
341 /*
342   return a fnum for use as a root fid
343   be careful to call GEN_SET_FNUM() when you use this!
344 */
345 static uint16 gen_root_fid(int instance)
346 {
347         if (gen_chance(5)) return gen_fnum(instance);
348         return 0;
349 }
350
351 /*
352   generate a file offset
353 */
354 static int gen_offset(void)
355 {
356         if (gen_chance(20)) return 0;
357         return gen_int_range(0, 1024*1024);
358 }
359
360 /*
361   generate a io count
362 */
363 static int gen_io_count(void)
364 {
365         if (gen_chance(20)) return 0;
366         return gen_int_range(0, 4096);
367 }
368
369 /*
370   generate a filename
371 */
372 static const char *gen_fname(void)
373 {
374         const char *names[] = {"\\gentest\\gentest.dat", 
375                                "\\gentest\\foo", 
376                                "\\gentest\\foo2.sym", 
377                                "\\gentest\\foo3.dll", 
378                                "\\gentest\\foo4", 
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", 
385                                "\\gentest\\blah", 
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\\.", 
393 #if 0
394                                /* this causes problem with w2k3 */
395                                "\\gentest\\blah\\..", 
396 #endif
397                                "\\gentest\\a_very_long_name.bin", 
398                                "\\gentest\\x.y", 
399                                "\\gentest\\blah"};
400         int i;
401
402         do {
403                 i = gen_int_range(0, ARRAY_SIZE(names)-1);
404         } while (ignore_pattern(names[i]));
405
406         return names[i];
407 }
408
409 /*
410   generate a filename with a higher chance of choosing an already 
411   open file
412 */
413 static const char *gen_fname_open(int instance)
414 {
415         uint16 h;
416         h = gen_fnum(instance);
417         if (h == BAD_HANDLE) {
418                 return gen_fname();
419         }
420         return open_handles[h].name;
421 }
422
423 /*
424   generate a wildcard pattern
425 */
426 static const char *gen_pattern(void)
427 {
428         int i;
429         const char *names[] = {"\\gentest\\*.dat", 
430                                "\\gentest\\*", 
431                                "\\gentest\\*.*", 
432                                "\\gentest\\blah\\*.*", 
433                                "\\gentest\\blah\\*", 
434                                "\\gentest\\?"};
435
436         if (gen_chance(50)) return gen_fname();
437
438         do {
439                 i = gen_int_range(0, ARRAY_SIZE(names)-1);
440         } while (ignore_pattern(names[i]));
441
442         return names[i];
443 }
444
445 /*
446   generate a bitmask
447 */
448 static uint32 gen_bits_mask(uint_t mask)
449 {
450         uint_t ret = random();
451         return ret & mask;
452 }
453
454 /*
455   generate a bitmask with high probability of the first mask
456   and low of the second
457 */
458 static uint32 gen_bits_mask2(uint32 mask1, uint32 mask2)
459 {
460         if (gen_chance(10)) return gen_bits_mask(mask2);
461         return gen_bits_mask(mask1);
462 }
463
464 /*
465   generate a boolean
466 */
467 static BOOL gen_bool(void)
468 {
469         return gen_bits_mask2(0x1, 0xFF);
470 }
471
472 /*
473   return a lockingx lock mode
474 */
475 static uint16 gen_lock_mode(void)
476 {
477         if (gen_chance(5))  return gen_bits_mask(0xFFFF);
478         if (gen_chance(20)) return gen_bits_mask(0x1F);
479         return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES);
480 }
481
482 /*
483   generate a pid 
484 */
485 static uint16 gen_pid(void)
486 {
487         if (gen_chance(10)) return gen_bits_mask(0xFFFF);
488         return getpid();
489 }
490
491 /*
492   generate a lock count
493 */
494 static SMB_OFF_T gen_lock_count(void)
495 {
496         return gen_int_range(0, 3);
497 }
498
499 /*
500   generate a ntcreatex flags field
501 */
502 static uint32 gen_ntcreatex_flags(void)
503 {
504         if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED;
505         return gen_bits_mask2(0x1F, 0xFFFFFFFF);
506 }
507
508 /*
509   generate a NT access mask
510 */
511 static uint32 gen_access_mask(void)
512 {
513         if (gen_chance(50)) return SEC_RIGHT_MAXIMUM_ALLOWED;
514         if (gen_chance(20)) return GENERIC_RIGHTS_FILE_ALL_ACCESS;
515         return gen_bits_mask(0xFFFFFFFF);
516 }
517
518 /*
519   generate a ntcreatex create options bitfield
520 */
521 static uint32 gen_create_options(void)
522 {
523         if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
524         if (gen_chance(50)) return 0;
525         return gen_bits_mask(NTCREATEX_OPTIONS_DELETE_ON_CLOSE | NTCREATEX_OPTIONS_DIRECTORY);
526 }
527
528 /*
529   generate a ntcreatex open disposition
530 */
531 static uint32 gen_open_disp(void)
532 {
533         if (gen_chance(10)) return gen_bits_mask(0xFFFFFFFF);
534         return gen_int_range(0, 5);
535 }
536
537 /*
538   generate an openx open mode
539 */
540 static uint16 gen_openx_mode(void)
541 {
542         if (gen_chance(20)) return gen_bits_mask(0xFFFF);
543         if (gen_chance(20)) return gen_bits_mask(0xFF);
544         return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3);
545 }
546
547 /*
548   generate an openx flags field
549 */
550 static uint16 gen_openx_flags(void)
551 {
552         if (gen_chance(20)) return gen_bits_mask(0xFFFF);
553         return gen_bits_mask(0x7);
554 }
555
556 /*
557   generate an openx open function
558 */
559 static uint16 gen_openx_func(void)
560 {
561         if (gen_chance(20)) return gen_bits_mask(0xFFFF);
562         return gen_bits_mask(0x13);
563 }
564
565 /*
566   generate a file attrib combination
567 */
568 static uint32 gen_attrib(void)
569 {
570         if (gen_chance(20)) return gen_bits_mask(0xFFFFFFFF);
571         return gen_bits_mask(FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
572 }
573
574 /*
575   generate a unix timestamp
576 */
577 static time_t gen_timet(void)
578 {
579         if (gen_chance(30)) return 0;
580         return (time_t)random();
581 }
582
583 /*
584   generate a unix timestamp
585 */
586 static NTTIME gen_nttime(void)
587 {
588         NTTIME ret;
589         unix_to_nt_time(&ret, gen_timet());
590         return ret;
591 }
592
593 /*
594   generate a milliseconds protocol timeout
595 */
596 static uint32 gen_timeout(void)
597 {
598         if (gen_chance(98)) return 0;
599         return random() % 50;
600 }
601
602 /*
603   generate a file allocation size
604 */
605 static uint_t gen_alloc_size(void)
606 {
607         uint_t ret;
608
609         if (gen_chance(30)) return 0;
610
611         ret = random() % 4*1024*1024;
612         /* give a high chance of a round number */
613         if (gen_chance(60)) {
614                 ret &= ~(1024*1024 - 1);
615         }
616         return ret;
617 }
618
619 /*
620   generate an ea_struct
621 */
622 struct ea_struct gen_ea_struct(void)
623 {
624         struct ea_struct ea;
625         const char *names[] = {"EAONE", 
626                                "", 
627                                "FOO!", 
628                                " WITH SPACES ", 
629                                ".", 
630                                "AVERYLONGATTRIBUTENAME"};
631         const char *values[] = {"VALUE1", 
632                                "", 
633                                "NOT MUCH FOO", 
634                                " LEADING SPACES ", 
635                                ":", 
636                                "ASOMEWHATLONGERATTRIBUTEVALUE"};
637         int i;
638
639         do {
640                 i = gen_int_range(0, ARRAY_SIZE(names)-1);
641         } while (ignore_pattern(names[i]));
642
643         ea.name.s = names[i];
644
645         do {
646                 i = gen_int_range(0, ARRAY_SIZE(values)-1);
647         } while (ignore_pattern(values[i]));
648
649         ea.value = data_blob(values[i], strlen(values[i]));
650
651         if (gen_chance(10)) ea.flags = gen_bits_mask(0xFF);
652         ea.flags = 0;
653
654         return ea;
655 }
656
657
658 /*
659   this is called when a change notify reply comes in
660 */
661 static void async_notify(struct cli_request *req)
662 {
663         struct smb_notify notify;
664         NTSTATUS status;
665         int i, j;
666         uint16 tid;
667         struct cli_transport *transport = req->transport;
668
669         tid = SVAL(req->in.hdr, HDR_TID);
670
671         status = smb_raw_changenotify_recv(req, current_op.mem_ctx, &notify);
672         if (NT_STATUS_IS_OK(status)) {
673                 printf("notify tid=%d num_changes=%d action=%d name=%s\n", 
674                        tid, 
675                        notify.out.num_changes,
676                        notify.out.changes[0].action,
677                        notify.out.changes[0].name.s);
678         }
679
680         for (i=0;i<NSERVERS;i++) {
681                 for (j=0;j<NINSTANCES;j++) {
682                         if (transport == servers[i].cli[j]->transport &&
683                             tid == servers[i].cli[j]->tree->tid) {
684                                 notifies[i][j].notify_count++;
685                                 notifies[i][j].status = status;
686                                 notifies[i][j].notify = notify;
687                         }
688                 }
689         }
690 }
691
692 /*
693   the oplock handler will either ack the break or close the file
694 */
695 static BOOL oplock_handler(struct cli_transport *transport, uint16 tid, uint16 fnum, uint8 level, void *private)
696 {
697         union smb_close io;
698         NTSTATUS status;
699         int i, j;
700         BOOL do_close;
701         struct cli_tree *tree = NULL;
702
703         srandom(current_op.seed);
704         do_close = gen_chance(50);
705
706         for (i=0;i<NSERVERS;i++) {
707                 for (j=0;j<NINSTANCES;j++) {
708                         if (transport == servers[i].cli[j]->transport &&
709                             tid == servers[i].cli[j]->tree->tid) {
710                                 oplocks[i][j].got_break = True;
711                                 oplocks[i][j].fnum = fnum;
712                                 oplocks[i][j].handle = fnum_to_handle(i, j, fnum);
713                                 oplocks[i][j].level = level;
714                                 oplocks[i][j].do_close = do_close;
715                                 tree = servers[i].cli[j]->tree;
716                         }
717                 }
718         }
719
720         if (!tree) {
721                 printf("Oplock break not for one of our trees!?\n");
722                 return False;
723         }
724
725         if (!do_close) {
726                 printf("oplock ack fnum=%d\n", fnum);
727                 return cli_oplock_ack(tree, fnum, level == 1? 0x102 : 2);
728         }
729
730         printf("oplock close fnum=%d\n", fnum);
731
732         io.close.level = RAW_CLOSE_CLOSE;
733         io.close.in.fnum = fnum;
734         io.close.in.write_time = 0;
735         status = smb_raw_close(tree, &io);
736
737         if (!NT_STATUS_IS_OK(status)) {
738                 printf("WARNING: close failed in oplock_handler_close - %s\n", nt_errstr(status));
739         }
740         return True;
741 }
742
743
744 /*
745   the idle function tries to cope with getting an oplock break on a connection, and
746   an operation on another connection blocking until that break is acked
747   we check for operations on all transports in the idle function
748 */
749 static void idle_func(struct cli_transport *transport, void *private)
750 {
751         int i, j;
752         for (i=0;i<NSERVERS;i++) {
753                 for (j=0;j<NINSTANCES;j++) {
754                         if (servers[i].cli[j] &&
755                             transport != servers[i].cli[j]->transport &&
756                             cli_transport_pending(servers[i].cli[j]->transport)) {
757                                 if (!cli_request_receive_next(servers[i].cli[j]->transport)) {
758                                         printf("Connection to server %d instance %d died!\n",
759                                                i, j);
760                                         exit(1);
761                                 }
762                         }
763                 }
764         }
765
766 }
767
768
769 /*
770   compare NTSTATUS, using checking ignored patterns
771 */
772 static BOOL compare_status(NTSTATUS status1, NTSTATUS status2)
773 {
774         if (NT_STATUS_EQUAL(status1, status2)) return True;
775
776         /* one code being an error and the other OK is always an error */
777         if (NT_STATUS_IS_OK(status1) || NT_STATUS_IS_OK(status2)) return False;
778
779         /* if we are ignoring one of the status codes then consider this a match */
780         if (ignore_pattern(nt_errstr(status1)) ||
781             ignore_pattern(nt_errstr(status2))) {
782                 return True;
783         }
784         return False;
785 }
786
787
788 /*
789   check for pending packets on all connections
790 */
791 static void check_pending(void)
792 {
793         int i, j;
794
795         msleep(20);
796
797         for (j=0;j<NINSTANCES;j++) {
798                 for (i=0;i<NSERVERS;i++) {
799                         if (cli_transport_pending(servers[i].cli[j]->transport)) {
800                                 if (!cli_request_receive_next(servers[i].cli[j]->transport)) {
801                                         printf("Connection to server %d instance %d died!\n",
802                                                i, j);
803                                         exit(1);                                        
804                                 }
805                         }
806                 }
807         }       
808 }
809
810 /*
811   check that the same oplock breaks have been received by all instances
812 */
813 static BOOL check_oplocks(const char *call)
814 {
815         int i, j;
816         int tries = 0;
817
818 again:
819         check_pending();
820
821         for (j=0;j<NINSTANCES;j++) {
822                 for (i=1;i<NSERVERS;i++) {
823                         if (oplocks[0][j].got_break != oplocks[i][j].got_break ||
824                             oplocks[0][j].handle != oplocks[i][j].handle ||
825                             oplocks[0][j].level != oplocks[i][j].level) {
826                                 if (tries++ < 10) goto again;
827                                 printf("oplock break inconsistent - %d/%d/%d vs %d/%d/%d\n",
828                                        oplocks[0][j].got_break, 
829                                        oplocks[0][j].handle, 
830                                        oplocks[0][j].level, 
831                                        oplocks[i][j].got_break, 
832                                        oplocks[i][j].handle, 
833                                        oplocks[i][j].level);
834                                 return False;
835                         }
836                 }
837         }
838
839         /* if we got a break and closed then remove the handle */
840         for (j=0;j<NINSTANCES;j++) {
841                 if (oplocks[0][j].got_break &&
842                     oplocks[0][j].do_close) {
843                         uint16 fnums[NSERVERS];
844                         for (i=0;i<NSERVERS;i++) {
845                                 fnums[i] = oplocks[i][j].fnum;
846                         }
847                         gen_remove_handle(j, fnums);
848                         break;
849                 }
850         }       
851         return True;
852 }
853
854
855 /*
856   check that the same change notify info has been received by all instances
857 */
858 static BOOL check_notifies(const char *call)
859 {
860         int i, j;
861         int tries = 0;
862
863 again:
864         check_pending();
865
866         for (j=0;j<NINSTANCES;j++) {
867                 for (i=1;i<NSERVERS;i++) {
868                         int n;
869                         struct smb_notify not1, not2;
870
871                         if (notifies[0][j].notify_count != notifies[i][j].notify_count) {
872                                 if (tries++ < 10) goto again;
873                                 printf("Notify count inconsistent %d %d\n",
874                                        notifies[0][j].notify_count,
875                                        notifies[i][j].notify_count);
876                                 return False;
877                         }
878
879                         if (notifies[0][j].notify_count == 0) continue;
880
881                         if (!NT_STATUS_EQUAL(notifies[0][j].status,
882                                              notifies[i][j].status)) {
883                                 printf("Notify status mismatch - %s - %s\n",
884                                        nt_errstr(notifies[0][j].status),
885                                        nt_errstr(notifies[i][j].status));
886                                 return False;
887                         }
888
889                         if (!NT_STATUS_IS_OK(notifies[0][j].status)) {
890                                 continue;
891                         }
892
893                         not1 = notifies[0][j].notify;
894                         not2 = notifies[i][j].notify;
895
896                         for (n=0;n<not1.out.num_changes;n++) {
897                                 if (not1.out.changes[n].action != 
898                                     not2.out.changes[n].action) {
899                                         printf("Notify action %d inconsistent %d %d\n", n,
900                                                not1.out.changes[n].action,
901                                                not2.out.changes[n].action);
902                                         return False;
903                                 }
904                                 if (strcmp(not1.out.changes[n].name.s,
905                                            not2.out.changes[n].name.s)) {
906                                         printf("Notify name %d inconsistent %s %s\n", n,
907                                                not1.out.changes[n].name.s,
908                                                not2.out.changes[n].name.s);
909                                         return False;
910                                 }
911                                 if (not1.out.changes[n].name.private_length !=
912                                     not2.out.changes[n].name.private_length) {
913                                         printf("Notify name length %d inconsistent %d %d\n", n,
914                                                not1.out.changes[n].name.private_length,
915                                                not2.out.changes[n].name.private_length);
916                                         return False;
917                                 }
918                         }
919                 }
920         }
921
922         ZERO_STRUCT(notifies);
923
924         return True;
925 }
926
927
928 #define GEN_COPY_PARM do { \
929         int i; \
930         for (i=1;i<NSERVERS;i++) { \
931                 parm[i] = parm[0]; \
932         } \
933 } while (0)
934
935 #define GEN_CALL(call) do { \
936         int i; \
937         ZERO_STRUCT(oplocks); \
938         ZERO_STRUCT(notifies); \
939         for (i=0;i<NSERVERS;i++) { \
940                 struct cli_tree *tree = servers[i].cli[instance]->tree; \
941                 status[i] = call; \
942         } \
943         current_op.status = status[0]; \
944         for (i=1;i<NSERVERS;i++) { \
945                 if (!compare_status(status[i], status[0])) { \
946                         printf("status different in %s - %s %s\n", #call, \
947                                nt_errstr(status[0]), nt_errstr(status[i])); \
948                         return False; \
949                 } \
950         } \
951         if (!check_oplocks(#call)) return False; \
952         if (!check_notifies(#call)) return False; \
953         if (!NT_STATUS_IS_OK(status[0])) { \
954                 return True; \
955         } \
956 } while(0)
957
958 #define ADD_HANDLE(name, field) do { \
959         uint16 fnums[NSERVERS]; \
960         int i; \
961         for (i=0;i<NSERVERS;i++) { \
962                 fnums[i] = parm[i].field; \
963         } \
964         gen_add_handle(instance, name, fnums); \
965 } while(0)
966
967 #define REMOVE_HANDLE(field) do { \
968         uint16 fnums[NSERVERS]; \
969         int i; \
970         for (i=0;i<NSERVERS;i++) { \
971                 fnums[i] = parm[i].field; \
972         } \
973         gen_remove_handle(instance, fnums); \
974 } while(0)
975
976 #define GEN_SET_FNUM(field) do { \
977         int i; \
978         for (i=0;i<NSERVERS;i++) { \
979                 parm[i].field = gen_lookup_fnum(i, parm[i].field); \
980         } \
981 } while(0)
982
983 #define CHECK_EQUAL(field) do { \
984         if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \
985                 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
986                        (int)parm[0].field, (int)parm[1].field); \
987                 return False; \
988         } \
989 } while(0)
990
991 #define CHECK_WSTR_EQUAL(field) do { \
992         if (strcmp(parm[0].field.s, parm[1].field.s) != 0 && !ignore_pattern(#field)) { \
993                 printf("Mismatch in %s - %s %s\n", #field, \
994                        parm[0].field.s, parm[1].field.s); \
995                 return False; \
996         } \
997         CHECK_EQUAL(field.private_length); \
998 } while(0)
999
1000 #define CHECK_BLOB_EQUAL(field) do { \
1001         if (memcmp(parm[0].field.data, parm[1].field.data, parm[0].field.length) != 0 && !ignore_pattern(#field)) { \
1002                 printf("Mismatch in %s\n", #field); \
1003                 return False; \
1004         } \
1005         CHECK_EQUAL(field.length); \
1006 } while(0)
1007
1008 #define CHECK_TIMES_EQUAL(field) do { \
1009         if (ABS(parm[0].field - parm[1].field) > time_skew() && \
1010             !ignore_pattern(#field)) { \
1011                 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1012                        (int)parm[0].field, (int)parm[1].field); \
1013                 return False; \
1014         } \
1015 } while(0)
1016
1017 #define CHECK_NTTIMES_EQUAL(field) do { \
1018         if (ABS(nt_time_to_unix(&parm[0].field) - \
1019                 nt_time_to_unix(&parm[1].field)) > time_skew() && \
1020             !ignore_pattern(#field)) { \
1021                 printf("Mismatch in %s - 0x%x 0x%x\n", #field, \
1022                        (int)nt_time_to_unix(&parm[0].field), \
1023                        (int)nt_time_to_unix(&parm[1].field)); \
1024                 return False; \
1025         } \
1026 } while(0)
1027
1028 /*
1029   generate openx operations
1030 */
1031 static BOOL handler_openx(int instance)
1032 {
1033         union smb_open parm[NSERVERS];
1034         NTSTATUS status[NSERVERS];
1035
1036         parm[0].openx.level = RAW_OPEN_OPENX;
1037         parm[0].openx.in.flags = gen_openx_flags();
1038         parm[0].openx.in.open_mode = gen_openx_mode();
1039         parm[0].openx.in.search_attrs = gen_attrib();
1040         parm[0].openx.in.file_attrs = gen_attrib();
1041         parm[0].openx.in.write_time = gen_timet();
1042         parm[0].openx.in.open_func = gen_openx_func();
1043         parm[0].openx.in.size = gen_io_count();
1044         parm[0].openx.in.timeout = gen_timeout();
1045         parm[0].openx.in.fname = gen_fname_open(instance);
1046
1047         if (!options.use_oplocks) {
1048                 /* mask out oplocks */
1049                 parm[0].openx.in.flags &= ~(OPENX_FLAGS_REQUEST_OPLOCK|
1050                                             OPENX_FLAGS_REQUEST_BATCH_OPLOCK);
1051         }
1052         
1053         GEN_COPY_PARM;
1054         GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1055
1056         CHECK_EQUAL(openx.out.attrib);
1057         CHECK_EQUAL(openx.out.size);
1058         CHECK_EQUAL(openx.out.access);
1059         CHECK_EQUAL(openx.out.ftype);
1060         CHECK_EQUAL(openx.out.devstate);
1061         CHECK_EQUAL(openx.out.action);
1062         CHECK_EQUAL(openx.out.access_mask);
1063         CHECK_EQUAL(openx.out.unknown);
1064         CHECK_TIMES_EQUAL(openx.out.write_time);
1065
1066         /* open creates a new file handle */
1067         ADD_HANDLE(parm[0].openx.in.fname, openx.out.fnum);
1068
1069         return True;
1070 }
1071
1072
1073 /*
1074   generate ntcreatex operations
1075 */
1076 static BOOL handler_ntcreatex(int instance)
1077 {
1078         union smb_open parm[NSERVERS];
1079         NTSTATUS status[NSERVERS];
1080
1081         parm[0].ntcreatex.level = RAW_OPEN_NTCREATEX;
1082         parm[0].ntcreatex.in.flags = gen_ntcreatex_flags();
1083         parm[0].ntcreatex.in.root_fid = gen_root_fid(instance);
1084         parm[0].ntcreatex.in.access_mask = gen_access_mask();
1085         parm[0].ntcreatex.in.alloc_size = gen_alloc_size();
1086         parm[0].ntcreatex.in.file_attr = gen_attrib();
1087         parm[0].ntcreatex.in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF);
1088         parm[0].ntcreatex.in.open_disposition = gen_open_disp();
1089         parm[0].ntcreatex.in.create_options = gen_create_options();
1090         parm[0].ntcreatex.in.impersonation = gen_bits_mask2(0, 0xFFFFFFFF);
1091         parm[0].ntcreatex.in.security_flags = gen_bits_mask2(0, 0xFF);
1092         parm[0].ntcreatex.in.fname = gen_fname_open(instance);
1093
1094         if (!options.use_oplocks) {
1095                 /* mask out oplocks */
1096                 parm[0].ntcreatex.in.flags &= ~(NTCREATEX_FLAGS_REQUEST_OPLOCK|
1097                                                 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK);
1098         }
1099         
1100         GEN_COPY_PARM;
1101         if (parm[0].ntcreatex.in.root_fid != 0) {
1102                 GEN_SET_FNUM(ntcreatex.in.root_fid);
1103         }
1104         GEN_CALL(smb_raw_open(tree, current_op.mem_ctx, &parm[i]));
1105
1106         CHECK_EQUAL(ntcreatex.out.oplock_level);
1107         CHECK_EQUAL(ntcreatex.out.create_action);
1108         CHECK_NTTIMES_EQUAL(ntcreatex.out.create_time);
1109         CHECK_NTTIMES_EQUAL(ntcreatex.out.access_time);
1110         CHECK_NTTIMES_EQUAL(ntcreatex.out.write_time);
1111         CHECK_NTTIMES_EQUAL(ntcreatex.out.change_time);
1112         CHECK_EQUAL(ntcreatex.out.attrib);
1113         CHECK_EQUAL(ntcreatex.out.alloc_size);
1114         CHECK_EQUAL(ntcreatex.out.size);
1115         CHECK_EQUAL(ntcreatex.out.file_type);
1116         CHECK_EQUAL(ntcreatex.out.ipc_state);
1117         CHECK_EQUAL(ntcreatex.out.is_directory);
1118
1119         /* ntcreatex creates a new file handle */
1120         ADD_HANDLE(parm[0].ntcreatex.in.fname, ntcreatex.out.fnum);
1121
1122         return True;
1123 }
1124
1125 /*
1126   generate close operations
1127 */
1128 static BOOL handler_close(int instance)
1129 {
1130         union smb_close parm[NSERVERS];
1131         NTSTATUS status[NSERVERS];
1132
1133         parm[0].close.level = RAW_CLOSE_CLOSE;
1134         parm[0].close.in.fnum = gen_fnum_close(instance);
1135         parm[0].close.in.write_time = gen_timet();
1136
1137         GEN_COPY_PARM;
1138         GEN_SET_FNUM(close.in.fnum);
1139         GEN_CALL(smb_raw_close(tree, &parm[i]));
1140
1141         REMOVE_HANDLE(close.in.fnum);
1142
1143         return True;
1144 }
1145
1146 /*
1147   generate unlink operations
1148 */
1149 static BOOL handler_unlink(int instance)
1150 {
1151         struct smb_unlink parm[NSERVERS];
1152         NTSTATUS status[NSERVERS];
1153
1154         parm[0].in.pattern = gen_pattern();
1155         parm[0].in.attrib = gen_attrib();
1156
1157         GEN_COPY_PARM;
1158         GEN_CALL(smb_raw_unlink(tree, &parm[i]));
1159
1160         return True;
1161 }
1162
1163 /*
1164   generate chkpath operations
1165 */
1166 static BOOL handler_chkpath(int instance)
1167 {
1168         struct smb_chkpath parm[NSERVERS];
1169         NTSTATUS status[NSERVERS];
1170
1171         parm[0].in.path = gen_fname_open(instance);
1172
1173         GEN_COPY_PARM;
1174         GEN_CALL(smb_raw_chkpath(tree, &parm[i]));
1175
1176         return True;
1177 }
1178
1179 /*
1180   generate mkdir operations
1181 */
1182 static BOOL handler_mkdir(int instance)
1183 {
1184         union smb_mkdir parm[NSERVERS];
1185         NTSTATUS status[NSERVERS];
1186
1187         parm[0].mkdir.level = RAW_MKDIR_MKDIR;
1188         parm[0].mkdir.in.path = gen_fname_open(instance);
1189
1190         GEN_COPY_PARM;
1191         GEN_CALL(smb_raw_mkdir(tree, &parm[i]));
1192
1193         return True;
1194 }
1195
1196 /*
1197   generate rmdir operations
1198 */
1199 static BOOL handler_rmdir(int instance)
1200 {
1201         struct smb_rmdir parm[NSERVERS];
1202         NTSTATUS status[NSERVERS];
1203
1204         parm[0].in.path = gen_fname_open(instance);
1205
1206         GEN_COPY_PARM;
1207         GEN_CALL(smb_raw_rmdir(tree, &parm[i]));
1208
1209         return True;
1210 }
1211
1212 /*
1213   generate rename operations
1214 */
1215 static BOOL handler_rename(int instance)
1216 {
1217         struct smb_rename parm[NSERVERS];
1218         NTSTATUS status[NSERVERS];
1219
1220         parm[0].in.pattern1 = gen_pattern();
1221         parm[0].in.pattern2 = gen_pattern();
1222         parm[0].in.attrib = gen_attrib();
1223
1224         GEN_COPY_PARM;
1225         GEN_CALL(smb_raw_rename(tree, &parm[i]));
1226
1227         return True;
1228 }
1229
1230
1231 /*
1232   generate readx operations
1233 */
1234 static BOOL handler_readx(int instance)
1235 {
1236         union smb_read parm[NSERVERS];
1237         NTSTATUS status[NSERVERS];
1238
1239         parm[0].readx.level = RAW_READ_READX;
1240         parm[0].readx.in.fnum = gen_fnum(instance);
1241         parm[0].readx.in.offset = gen_offset();
1242         parm[0].readx.in.mincnt = gen_io_count();
1243         parm[0].readx.in.maxcnt = gen_io_count();
1244         parm[0].readx.in.remaining = gen_io_count();
1245         parm[0].readx.out.data = talloc(current_op.mem_ctx,
1246                                         MAX(parm[0].readx.in.mincnt, parm[0].readx.in.maxcnt));
1247
1248         GEN_COPY_PARM;
1249         GEN_SET_FNUM(readx.in.fnum);
1250         GEN_CALL(smb_raw_read(tree, &parm[i]));
1251
1252         CHECK_EQUAL(readx.out.remaining);
1253         CHECK_EQUAL(readx.out.compaction_mode);
1254         CHECK_EQUAL(readx.out.nread);
1255
1256         return True;
1257 }
1258
1259 /*
1260   generate writex operations
1261 */
1262 static BOOL handler_writex(int instance)
1263 {
1264         union smb_write parm[NSERVERS];
1265         NTSTATUS status[NSERVERS];
1266
1267         parm[0].writex.level = RAW_WRITE_WRITEX;
1268         parm[0].writex.in.fnum = gen_fnum(instance);
1269         parm[0].writex.in.offset = gen_offset();
1270         parm[0].writex.in.wmode = gen_bits_mask(0xFFFF);
1271         parm[0].writex.in.remaining = gen_io_count();
1272         parm[0].writex.in.count = gen_io_count();
1273         parm[0].writex.in.data = talloc_zero(current_op.mem_ctx, parm[0].writex.in.count);
1274
1275         GEN_COPY_PARM;
1276         GEN_SET_FNUM(writex.in.fnum);
1277         GEN_CALL(smb_raw_write(tree, &parm[i]));
1278
1279         CHECK_EQUAL(writex.out.nwritten);
1280         CHECK_EQUAL(writex.out.remaining);
1281
1282         return True;
1283 }
1284
1285 /*
1286   generate lockingx operations
1287 */
1288 static BOOL handler_lockingx(int instance)
1289 {
1290         union smb_lock parm[NSERVERS];
1291         NTSTATUS status[NSERVERS];
1292         int n, nlocks;
1293
1294         parm[0].lockx.level = RAW_LOCK_LOCKX;
1295         parm[0].lockx.in.fnum = gen_fnum(instance);
1296         parm[0].lockx.in.mode = gen_lock_mode();
1297         parm[0].lockx.in.timeout = gen_timeout();
1298         do {
1299                 /* make sure we don't accidentially generate an oplock
1300                    break ack - otherwise the server can just block forever */
1301                 parm[0].lockx.in.ulock_cnt = gen_lock_count();
1302                 parm[0].lockx.in.lock_cnt = gen_lock_count();
1303                 nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt;
1304         } while (nlocks == 0);
1305
1306         if (nlocks > 0) {
1307                 parm[0].lockx.in.locks = talloc(current_op.mem_ctx,
1308                                                 sizeof(parm[0].lockx.in.locks[0]) * nlocks);
1309                 for (n=0;n<nlocks;n++) {
1310                         parm[0].lockx.in.locks[n].pid = gen_pid();
1311                         parm[0].lockx.in.locks[n].offset = gen_offset();
1312                         parm[0].lockx.in.locks[n].count = gen_io_count();
1313                 }
1314         }
1315
1316         GEN_COPY_PARM;
1317         GEN_SET_FNUM(lockx.in.fnum);
1318         GEN_CALL(smb_raw_lock(tree, &parm[i]));
1319
1320         return True;
1321 }
1322
1323 /*
1324   generate a fileinfo query structure
1325 */
1326 static void gen_fileinfo(int instance, union smb_fileinfo *info)
1327 {
1328         int i;
1329         #define LVL(v) {RAW_FILEINFO_ ## v, "RAW_FILEINFO_" #v}
1330         struct {
1331                 enum fileinfo_level level;
1332                 const char *name;
1333         }  levels[] = {
1334                 LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD),
1335                 LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID),
1336                 LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO),
1337                 LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO),
1338                 LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION),
1339                 LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION),
1340                 LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION),
1341                 LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION),
1342                 LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION),
1343                 LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION)
1344         };
1345         do {
1346                 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1347         } while (ignore_pattern(levels[i].name));
1348
1349         info->generic.level = levels[i].level;
1350 }
1351
1352 /*
1353   compare returned fileinfo structures
1354 */
1355 static BOOL cmp_fileinfo(int instance, 
1356                          union smb_fileinfo parm[NSERVERS],
1357                          NTSTATUS status[NSERVERS])
1358 {
1359         int i;
1360
1361         switch (parm[0].generic.level) {
1362         case RAW_FILEINFO_GENERIC:
1363                 return False;
1364
1365         case RAW_FILEINFO_GETATTR:
1366                 CHECK_EQUAL(getattr.out.attrib);
1367                 CHECK_EQUAL(getattr.out.size);
1368                 CHECK_TIMES_EQUAL(getattr.out.write_time);
1369                 break;
1370
1371         case RAW_FILEINFO_GETATTRE:
1372                 CHECK_TIMES_EQUAL(getattre.out.create_time);
1373                 CHECK_TIMES_EQUAL(getattre.out.access_time);
1374                 CHECK_TIMES_EQUAL(getattre.out.write_time);
1375                 CHECK_EQUAL(getattre.out.size);
1376                 CHECK_EQUAL(getattre.out.alloc_size);
1377                 CHECK_EQUAL(getattre.out.attrib);
1378                 break;
1379
1380         case RAW_FILEINFO_STANDARD:
1381                 CHECK_TIMES_EQUAL(standard.out.create_time);
1382                 CHECK_TIMES_EQUAL(standard.out.access_time);
1383                 CHECK_TIMES_EQUAL(standard.out.write_time);
1384                 CHECK_EQUAL(standard.out.size);
1385                 CHECK_EQUAL(standard.out.alloc_size);
1386                 CHECK_EQUAL(standard.out.attrib);
1387                 break;
1388
1389         case RAW_FILEINFO_EA_SIZE:
1390                 CHECK_TIMES_EQUAL(ea_size.out.create_time);
1391                 CHECK_TIMES_EQUAL(ea_size.out.access_time);
1392                 CHECK_TIMES_EQUAL(ea_size.out.write_time);
1393                 CHECK_EQUAL(ea_size.out.size);
1394                 CHECK_EQUAL(ea_size.out.alloc_size);
1395                 CHECK_EQUAL(ea_size.out.attrib);
1396                 CHECK_EQUAL(ea_size.out.ea_size);
1397                 break;
1398
1399         case RAW_FILEINFO_ALL_EAS:
1400                 CHECK_EQUAL(all_eas.out.num_eas);
1401                 for (i=0;i<parm[0].all_eas.out.num_eas;i++) {
1402                         CHECK_EQUAL(all_eas.out.eas[i].flags);
1403                         CHECK_WSTR_EQUAL(all_eas.out.eas[i].name);
1404                         CHECK_BLOB_EQUAL(all_eas.out.eas[i].value);
1405                 }
1406                 break;
1407
1408         case RAW_FILEINFO_IS_NAME_VALID:
1409                 break;
1410                 
1411         case RAW_FILEINFO_BASIC_INFO:
1412         case RAW_FILEINFO_BASIC_INFORMATION:
1413                 CHECK_NTTIMES_EQUAL(basic_info.out.create_time);
1414                 CHECK_NTTIMES_EQUAL(basic_info.out.access_time);
1415                 CHECK_NTTIMES_EQUAL(basic_info.out.write_time);
1416                 CHECK_NTTIMES_EQUAL(basic_info.out.change_time);
1417                 CHECK_EQUAL(basic_info.out.attrib);
1418                 break;
1419
1420         case RAW_FILEINFO_STANDARD_INFO:
1421         case RAW_FILEINFO_STANDARD_INFORMATION:
1422                 CHECK_EQUAL(standard_info.out.alloc_size);
1423                 CHECK_EQUAL(standard_info.out.size);
1424                 CHECK_EQUAL(standard_info.out.nlink);
1425                 CHECK_EQUAL(standard_info.out.delete_pending);
1426                 CHECK_EQUAL(standard_info.out.directory);
1427                 break;
1428
1429         case RAW_FILEINFO_EA_INFO:
1430         case RAW_FILEINFO_EA_INFORMATION:
1431                 CHECK_EQUAL(ea_info.out.ea_size);
1432                 break;
1433
1434         case RAW_FILEINFO_NAME_INFO:
1435         case RAW_FILEINFO_NAME_INFORMATION:
1436                 CHECK_WSTR_EQUAL(name_info.out.fname);
1437                 break;
1438
1439         case RAW_FILEINFO_ALL_INFO:
1440         case RAW_FILEINFO_ALL_INFORMATION:
1441                 CHECK_NTTIMES_EQUAL(all_info.out.create_time);
1442                 CHECK_NTTIMES_EQUAL(all_info.out.access_time);
1443                 CHECK_NTTIMES_EQUAL(all_info.out.write_time);
1444                 CHECK_NTTIMES_EQUAL(all_info.out.change_time);
1445                 CHECK_EQUAL(all_info.out.attrib);
1446                 CHECK_EQUAL(all_info.out.alloc_size);
1447                 CHECK_EQUAL(all_info.out.size);
1448                 CHECK_EQUAL(all_info.out.nlink);
1449                 CHECK_EQUAL(all_info.out.delete_pending);
1450                 CHECK_EQUAL(all_info.out.directory);
1451                 CHECK_EQUAL(all_info.out.ea_size);
1452                 CHECK_WSTR_EQUAL(all_info.out.fname);
1453                 break;
1454
1455         case RAW_FILEINFO_ALT_NAME_INFO:
1456         case RAW_FILEINFO_ALT_NAME_INFORMATION:
1457                 CHECK_WSTR_EQUAL(alt_name_info.out.fname);
1458                 break;
1459
1460         case RAW_FILEINFO_STREAM_INFO:
1461         case RAW_FILEINFO_STREAM_INFORMATION:
1462                 CHECK_EQUAL(stream_info.out.num_streams);
1463                 for (i=0;i<parm[0].stream_info.out.num_streams;i++) {
1464                         CHECK_EQUAL(stream_info.out.streams[i].size);
1465                         CHECK_EQUAL(stream_info.out.streams[i].alloc_size);
1466                         CHECK_WSTR_EQUAL(stream_info.out.streams[i].stream_name);
1467                 }
1468                 break;
1469
1470         case RAW_FILEINFO_COMPRESSION_INFO:
1471         case RAW_FILEINFO_COMPRESSION_INFORMATION:
1472                 CHECK_EQUAL(compression_info.out.compressed_size);
1473                 CHECK_EQUAL(compression_info.out.format);
1474                 CHECK_EQUAL(compression_info.out.unit_shift);
1475                 CHECK_EQUAL(compression_info.out.chunk_shift);
1476                 CHECK_EQUAL(compression_info.out.cluster_shift);
1477                 break;
1478
1479         case RAW_FILEINFO_INTERNAL_INFORMATION:
1480                 CHECK_EQUAL(internal_information.out.device);
1481                 CHECK_EQUAL(internal_information.out.inode);
1482                 break;
1483
1484         case RAW_FILEINFO_ACCESS_INFORMATION:
1485                 CHECK_EQUAL(access_information.out.access_flags);
1486                 break;
1487
1488         case RAW_FILEINFO_POSITION_INFORMATION:
1489                 CHECK_EQUAL(position_information.out.position);
1490                 break;
1491
1492         case RAW_FILEINFO_MODE_INFORMATION:
1493                 CHECK_EQUAL(mode_information.out.mode);
1494                 break;
1495
1496         case RAW_FILEINFO_ALIGNMENT_INFORMATION:
1497                 CHECK_EQUAL(alignment_information.out.alignment_requirement);
1498                 break;
1499
1500         case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
1501                 CHECK_NTTIMES_EQUAL(network_open_information.out.create_time);
1502                 CHECK_NTTIMES_EQUAL(network_open_information.out.access_time);
1503                 CHECK_NTTIMES_EQUAL(network_open_information.out.write_time);
1504                 CHECK_NTTIMES_EQUAL(network_open_information.out.change_time);
1505                 CHECK_EQUAL(network_open_information.out.alloc_size);
1506                 CHECK_EQUAL(network_open_information.out.size);
1507                 CHECK_EQUAL(network_open_information.out.attrib);
1508                 break;
1509
1510         case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
1511                 CHECK_EQUAL(attribute_tag_information.out.attrib);
1512                 CHECK_EQUAL(attribute_tag_information.out.reparse_tag);
1513                 break;
1514         }
1515
1516         return True;
1517 }
1518
1519 /*
1520   generate qpathinfo operations
1521 */
1522 static BOOL handler_qpathinfo(int instance)
1523 {
1524         union smb_fileinfo parm[NSERVERS];
1525         NTSTATUS status[NSERVERS];
1526
1527         parm[0].generic.in.fname = gen_fname_open(instance);
1528
1529         gen_fileinfo(instance, &parm[0]);
1530
1531         GEN_COPY_PARM;
1532         GEN_CALL(smb_raw_pathinfo(tree, current_op.mem_ctx, &parm[i]));
1533
1534         return cmp_fileinfo(instance, parm, status);
1535 }
1536
1537 /*
1538   generate qfileinfo operations
1539 */
1540 static BOOL handler_qfileinfo(int instance)
1541 {
1542         union smb_fileinfo parm[NSERVERS];
1543         NTSTATUS status[NSERVERS];
1544
1545         parm[0].generic.in.fnum = gen_fnum(instance);
1546
1547         gen_fileinfo(instance, &parm[0]);
1548
1549         GEN_COPY_PARM;
1550         GEN_SET_FNUM(generic.in.fnum);
1551         GEN_CALL(smb_raw_fileinfo(tree, current_op.mem_ctx, &parm[i]));
1552
1553         return cmp_fileinfo(instance, parm, status);
1554 }
1555
1556
1557 /*
1558   generate a fileinfo query structure
1559 */
1560 static void gen_setfileinfo(int instance, union smb_setfileinfo *info)
1561 {
1562         int i;
1563         #undef LVL
1564         #define LVL(v) {RAW_SFILEINFO_ ## v, "RAW_SFILEINFO_" #v}
1565         struct {
1566                 enum setfileinfo_level level;
1567                 const char *name;
1568         }  levels[] = {
1569 #if 0
1570                 /* disabled until win2003 can handle them ... */
1571                 LVL(EA_SET), LVL(BASIC_INFO), LVL(DISPOSITION_INFO), 
1572                 LVL(STANDARD), LVL(ALLOCATION_INFO), LVL(END_OF_FILE_INFO), 
1573 #endif
1574                 LVL(SETATTR), LVL(SETATTRE), LVL(BASIC_INFORMATION),
1575                 LVL(RENAME_INFORMATION), LVL(DISPOSITION_INFORMATION), 
1576                 LVL(POSITION_INFORMATION), LVL(MODE_INFORMATION),
1577                 LVL(ALLOCATION_INFORMATION), LVL(END_OF_FILE_INFORMATION), 
1578                 LVL(1023), LVL(1025), LVL(1029), LVL(1032), LVL(1039), LVL(1040)
1579         };
1580         do {
1581                 i = gen_int_range(0, ARRAY_SIZE(levels)-1);
1582         } while (ignore_pattern(levels[i].name));
1583
1584         info->generic.level = levels[i].level;
1585
1586         switch (info->generic.level) {
1587         case RAW_SFILEINFO_SETATTR:
1588                 info->setattr.in.attrib = gen_attrib();
1589                 info->setattr.in.write_time = gen_timet();
1590                 break;
1591         case RAW_SFILEINFO_SETATTRE:
1592                 info->setattre.in.create_time = gen_timet();
1593                 info->setattre.in.access_time = gen_timet();
1594                 info->setattre.in.write_time = gen_timet();
1595                 break;
1596         case RAW_SFILEINFO_STANDARD:
1597                 info->standard.in.create_time = gen_timet();
1598                 info->standard.in.access_time = gen_timet();
1599                 info->standard.in.write_time = gen_timet();
1600                 break;
1601         case RAW_SFILEINFO_EA_SET:
1602                 info->ea_set.in.ea = gen_ea_struct();
1603                 break;
1604         case RAW_SFILEINFO_BASIC_INFO:
1605         case RAW_SFILEINFO_BASIC_INFORMATION:
1606                 info->basic_info.in.create_time = gen_nttime();
1607                 info->basic_info.in.access_time = gen_nttime();
1608                 info->basic_info.in.write_time = gen_nttime();
1609                 info->basic_info.in.change_time = gen_nttime();
1610                 info->basic_info.in.attrib = gen_attrib();
1611                 break;
1612         case RAW_SFILEINFO_DISPOSITION_INFO:
1613         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
1614                 info->disposition_info.in.delete_on_close = gen_bool();
1615                 break;
1616         case RAW_SFILEINFO_ALLOCATION_INFO:
1617         case RAW_SFILEINFO_ALLOCATION_INFORMATION:
1618                 info->allocation_info.in.alloc_size = gen_alloc_size();
1619                 break;
1620         case RAW_SFILEINFO_END_OF_FILE_INFO:
1621         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
1622                 info->end_of_file_info.in.size = gen_offset();
1623                 break;
1624         case RAW_SFILEINFO_RENAME_INFORMATION:
1625                 info->rename_information.in.overwrite = gen_bool();
1626                 info->rename_information.in.root_fid = gen_root_fid(instance);
1627                 info->rename_information.in.new_name = gen_fname_open(instance);
1628                 break;
1629         case RAW_SFILEINFO_POSITION_INFORMATION:
1630                 info->position_information.in.position = gen_offset();
1631                 break;
1632         case RAW_SFILEINFO_MODE_INFORMATION:
1633                 info->mode_information.in.mode = gen_bits_mask(0xFFFFFFFF);
1634                 break;
1635         }
1636 }
1637
1638 /*
1639   generate setpathinfo operations
1640 */
1641 static BOOL handler_spathinfo(int instance)
1642 {
1643         union smb_setfileinfo parm[NSERVERS];
1644         NTSTATUS status[NSERVERS];
1645
1646         parm[0].generic.file.fname = gen_fname_open(instance);
1647
1648         gen_setfileinfo(instance, &parm[0]);
1649
1650         GEN_COPY_PARM;
1651
1652         /* a special case for the fid in a RENAME */
1653         if (parm[0].generic.level == RAW_SFILEINFO_RENAME_INFORMATION &&
1654             parm[0].rename_information.in.root_fid != 0) {
1655                 GEN_SET_FNUM(rename_information.in.root_fid);
1656         }
1657
1658         GEN_CALL(smb_raw_setpathinfo(tree, &parm[i]));
1659
1660         return True;
1661 }
1662
1663
1664 /*
1665   generate setfileinfo operations
1666 */
1667 static BOOL handler_sfileinfo(int instance)
1668 {
1669         union smb_setfileinfo parm[NSERVERS];
1670         NTSTATUS status[NSERVERS];
1671
1672         parm[0].generic.file.fnum = gen_fnum(instance);
1673
1674         gen_setfileinfo(instance, &parm[0]);
1675
1676         GEN_COPY_PARM;
1677         GEN_SET_FNUM(generic.file.fnum);
1678         GEN_CALL(smb_raw_setfileinfo(tree, &parm[i]));
1679
1680         return True;
1681 }
1682
1683
1684 /*
1685   generate change notify operations
1686 */
1687 static BOOL handler_notify(int instance)
1688 {
1689         struct smb_notify parm[NSERVERS];
1690         int n;
1691
1692         parm[0].in.buffer_size = gen_io_count();
1693         parm[0].in.completion_filter = gen_bits_mask(0xFF);
1694         parm[0].in.fnum = gen_fnum(instance);
1695         parm[0].in.recursive = gen_bool();
1696
1697         GEN_COPY_PARM;
1698         GEN_SET_FNUM(in.fnum);
1699
1700         for (n=0;n<NSERVERS;n++) {
1701                 struct cli_request *req;
1702                 req = smb_raw_changenotify_send(servers[n].cli[instance]->tree, &parm[n]);
1703                 req->async.fn = async_notify;
1704         }
1705
1706         return True;
1707 }
1708
1709 /*
1710   wipe any relevant files
1711 */
1712 static void wipe_files(void)
1713 {
1714         int i;
1715         for (i=0;i<NSERVERS;i++) {
1716                 int n = cli_deltree(servers[i].cli[0], "\\gentest");
1717                 if (n == -1) {
1718                         printf("Failed to wipe tree on server %d\n", i);
1719                         exit(1);
1720                 }
1721                 if (!cli_mkdir(servers[i].cli[0], "\\gentest")) {
1722                         printf("Failed to create \\gentest - %s\n",
1723                                cli_errstr(servers[i].cli[0]));
1724                         exit(1);
1725                 }
1726                 if (n > 0) {
1727                         printf("Deleted %d files on server %d\n", n, i);
1728                 }
1729         }
1730 }
1731
1732 /*
1733   dump the current seeds - useful for continuing a backtrack
1734 */
1735 static void dump_seeds(void)
1736 {
1737         int i;
1738         FILE *f;
1739
1740         if (!options.seeds_file) {
1741                 return;
1742         }
1743         f = fopen("seeds.tmp", "w");
1744         if (!f) return;
1745
1746         for (i=0;i<options.numops;i++) {
1747                 fprintf(f, "%u\n", op_parms[i].seed);
1748         }
1749         fclose(f);
1750         rename("seeds.tmp", options.seeds_file);
1751 }
1752
1753
1754
1755 /*
1756   the list of top-level operations that we will generate
1757 */
1758 static struct {
1759         const char *name;
1760         BOOL (*handler)(int instance);
1761         int count, success_count;
1762 } gen_ops[] = {
1763         {"OPENX",      handler_openx},
1764         {"NTCREATEX",  handler_ntcreatex},
1765         {"CLOSE",      handler_close},
1766         {"UNLINK",     handler_unlink},
1767         {"MKDIR",      handler_mkdir},
1768         {"RMDIR",      handler_rmdir},
1769         {"RENAME",     handler_rename},
1770         {"READX",      handler_readx},
1771         {"WRITEX",     handler_writex},
1772         {"CHKPATH",    handler_chkpath},
1773         {"LOCKINGX",   handler_lockingx},
1774         {"QPATHINFO",  handler_qpathinfo},
1775         {"QFILEINFO",  handler_qfileinfo},
1776         {"SPATHINFO",  handler_spathinfo},
1777         {"SFILEINFO",  handler_sfileinfo},
1778         {"NOTIFY",     handler_notify},
1779 };
1780
1781
1782 /*
1783   run the test with the current set of op_parms parameters
1784   return the number of operations that completed successfully
1785 */
1786 static int run_test(void)
1787 {
1788         int op, i;
1789
1790         if (!connect_servers()) {
1791                 printf("Failed to connect to servers\n");
1792                 exit(1);
1793         }
1794
1795         dump_seeds();
1796
1797         /* wipe any leftover files from old runs */
1798         wipe_files();
1799
1800         /* reset the open handles array */
1801         memset(open_handles, 0, options.max_open_handles * sizeof(open_handles[0]));
1802         num_open_handles = 0;
1803
1804         for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1805                 gen_ops[i].count = 0;
1806                 gen_ops[i].success_count = 0;
1807         }
1808
1809         for (op=0; op<options.numops; op++) {
1810                 int instance, which_op;
1811                 BOOL ret;
1812
1813                 if (op_parms[op].disabled) continue;
1814
1815                 srandom(op_parms[op].seed);
1816
1817                 instance = gen_int_range(0, NINSTANCES-1);
1818
1819                 /* generate a non-ignored operation */
1820                 do {
1821                         which_op = gen_int_range(0, ARRAY_SIZE(gen_ops)-1);
1822                 } while (ignore_pattern(gen_ops[which_op].name));
1823
1824                 DEBUG(3,("Generating op %s on instance %d\n",
1825                          gen_ops[which_op].name, instance));
1826
1827                 current_op.seed = op_parms[op].seed;
1828                 current_op.opnum = op;
1829                 current_op.name = gen_ops[which_op].name;
1830                 current_op.status = NT_STATUS_OK;
1831                 current_op.mem_ctx = talloc_init(current_op.name);
1832
1833                 ret = gen_ops[which_op].handler(instance);
1834
1835                 talloc_destroy(current_op.mem_ctx);
1836
1837                 gen_ops[which_op].count++;
1838                 if (NT_STATUS_IS_OK(current_op.status)) {
1839                         gen_ops[which_op].success_count++;                      
1840                 }
1841
1842                 if (!ret) {
1843                         printf("Failed at operation %d - %s\n",
1844                                op, gen_ops[which_op].name);
1845                         return op;
1846                 }
1847
1848                 if (op % 100 == 0) {
1849                         printf("%d\n", op);
1850                 }
1851         }
1852
1853         for (i=0;i<ARRAY_SIZE(gen_ops);i++) {
1854                 printf("Op %-10s got %d/%d success\n", 
1855                        gen_ops[i].name,
1856                        gen_ops[i].success_count,
1857                        gen_ops[i].count);
1858         }
1859
1860         return op;
1861 }
1862
1863 /* 
1864    perform a backtracking analysis of the minimal set of operations
1865    to generate an error
1866 */
1867 static void backtrack_analyze(void)
1868 {
1869         int chunk, ret;
1870
1871         chunk = options.numops / 2;
1872
1873         do {
1874                 int base;
1875                 for (base=0; 
1876                      chunk > 0 && base+chunk < options.numops && options.numops > 1; ) {
1877                         int i, max;
1878
1879                         chunk = MIN(chunk, options.numops / 2);
1880
1881                         /* mark this range as disabled */
1882                         max = MIN(options.numops, base+chunk);
1883                         for (i=base;i<max; i++) {
1884                                 op_parms[i].disabled = True;
1885                         }
1886                         printf("Testing %d ops with %d-%d disabled\n", 
1887                                options.numops, base, max-1);
1888                         ret = run_test();
1889                         printf("Completed %d of %d ops\n", ret, options.numops);
1890                         for (i=base;i<max; i++) {
1891                                 op_parms[i].disabled = False;
1892                         }
1893                         if (ret == options.numops) {
1894                                 /* this chunk is needed */
1895                                 base += chunk;
1896                         } else if (ret < base) {
1897                                 printf("damn - inconsistent errors! found early error\n");
1898                                 options.numops = ret+1;
1899                                 base = 0;
1900                         } else {
1901                                 /* it failed - this chunk isn't needed for a failure */
1902                                 memmove(&op_parms[base], &op_parms[max], 
1903                                         sizeof(op_parms[0]) * (options.numops - max));
1904                                 options.numops = (ret+1) - (max - base);
1905                         }
1906                 }
1907
1908                 if (chunk == 2) {
1909                         chunk = 1;
1910                 } else {
1911                         chunk *= 0.4;
1912                 }
1913
1914                 if (options.analyze_continuous && chunk == 0 && options.numops != 1) {
1915                         chunk = 1;
1916                 }
1917         } while (chunk > 0);
1918
1919         printf("Reduced to %d ops\n", options.numops);
1920         ret = run_test();
1921         if (ret != options.numops - 1) {
1922                 printf("Inconsistent result? ret=%d numops=%d\n", ret, options.numops);
1923         }
1924 }
1925
1926 /* 
1927    start the main gentest process
1928 */
1929 static BOOL start_gentest(void)
1930 {
1931         int op;
1932         int ret;
1933
1934         /* allocate the open_handles array */
1935         open_handles = calloc(options.max_open_handles, sizeof(open_handles[0]));
1936
1937         srandom(options.seed);
1938         op_parms = calloc(options.numops, sizeof(op_parms[0]));
1939
1940         /* generate the seeds - after this everything is deterministic */
1941         if (options.use_preset_seeds) {
1942                 int numops;
1943                 char **preset = file_lines_load(options.seeds_file, &numops);
1944                 if (!preset) {
1945                         printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
1946                         exit(1);
1947                 }
1948                 if (numops < options.numops) {
1949                         options.numops = numops;
1950                 }
1951                 for (op=0;op<options.numops;op++) {
1952                         if (!preset[op]) {
1953                                 printf("Not enough seeds in %s\n", options.seeds_file);
1954                                 exit(1);
1955                         }
1956                         op_parms[op].seed = atoi(preset[op]);
1957                 }
1958                 printf("Loaded %d seeds from %s\n", options.numops, options.seeds_file);
1959         } else {
1960                 for (op=0; op<options.numops; op++) {
1961                         op_parms[op].seed = random();
1962                 }
1963         }
1964
1965         ret = run_test();
1966
1967         if (ret != options.numops && options.analyze) {
1968                 options.numops = ret+1;
1969                 backtrack_analyze();
1970         } else if (options.analyze_always) {
1971                 backtrack_analyze();
1972         } else if (options.analyze_continuous) {
1973                 while (run_test() == options.numops) ;
1974         }
1975
1976         return ret == options.numops;
1977 }
1978
1979
1980 static void usage(void)
1981 {
1982         printf(
1983 "Usage:\n\
1984   gentest2 //server1/share1 //server2/share2 [options..]\n\
1985   options:\n\
1986         -U user%%pass        (must be specified twice)\n\
1987         -s seed\n\
1988         -o numops\n\
1989         -a            (show all ops)\n\
1990         -A            backtrack to find minimal ops\n\
1991         -i FILE       add a list of wildcard exclusions\n\
1992         -O            enable oplocks\n\
1993         -S FILE       set preset seeds file\n\
1994         -L            use preset seeds\n\
1995         -F            fast reconnect (just close files)\n\
1996         -C            continuous analysis mode\n\
1997         -X            analyse even when test OK\n\
1998 ");
1999 }
2000
2001 /****************************************************************************
2002   main program
2003 ****************************************************************************/
2004  int main(int argc, char *argv[])
2005 {
2006         int opt;
2007         int i;
2008         BOOL ret;
2009
2010         setlinebuf(stdout);
2011
2012         setup_logging("gentest", DEBUG_STDOUT);
2013
2014         if (argc < 3 || argv[1][0] == '-') {
2015                 usage();
2016                 exit(1);
2017         }
2018
2019         setup_logging(argv[0],True);
2020
2021         for (i=0;i<NSERVERS;i++) {
2022                 const char *share = argv[1+i];
2023                 if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
2024                         printf("Invalid share name '%s'\n", share);
2025                         return -1;
2026                 }
2027         }
2028
2029         argc -= NSERVERS;
2030         argv += NSERVERS;
2031
2032         lp_load(dyn_CONFIGFILE,True,False,False);
2033         load_interfaces();
2034
2035         options.seed = time(NULL);
2036         options.numops = 1000;
2037         options.max_open_handles = 20;
2038         options.seeds_file = "gentest_seeds.dat";
2039
2040         while ((opt = getopt(argc, argv, "U:s:o:ad:i:AOhS:LFXC")) != EOF) {
2041                 switch (opt) {
2042                 case 'U':
2043                         i = servers[0].username?1:0;
2044                         if (!split_username(optarg, 
2045                                             &servers[i].username, 
2046                                             &servers[i].password)) {
2047                                 printf("Must supply USER%%PASS\n");
2048                                 return -1;
2049                         }
2050                         break;
2051                 case 'd':
2052                         DEBUGLEVEL = atoi(optarg);
2053                         setup_logging(NULL,True);
2054                         break;
2055                 case 's':
2056                         options.seed = atoi(optarg);
2057                         break;
2058                 case 'S':
2059                         options.seeds_file = optarg;
2060                         break;
2061                 case 'L':
2062                         options.use_preset_seeds = True;
2063                         break;
2064                 case 'F':
2065                         options.fast_reconnect = True;
2066                         break;
2067                 case 'o':
2068                         options.numops = atoi(optarg);
2069                         break;
2070                 case 'O':
2071                         options.use_oplocks = True;
2072                         break;
2073                 case 'a':
2074                         options.showall = True;
2075                         break;
2076                 case 'A':
2077                         options.analyze = True;
2078                         break;
2079                 case 'X':
2080                         options.analyze_always = True;
2081                         break;
2082                 case 'C':
2083                         options.analyze_continuous = True;
2084                         break;
2085                 case 'i':
2086                         options.ignore_patterns = file_lines_load(optarg, NULL);
2087                         break;
2088                 case 'h':
2089                         usage();
2090                         exit(1);
2091                 default:
2092                         printf("Unknown option %c (%d)\n", (char)opt, opt);
2093                         exit(1);
2094                 }
2095         }
2096
2097         if (!servers[0].username || !servers[1].username) {
2098                 usage();
2099                 return -1;
2100         }
2101
2102         printf("seed=%u\n", options.seed);
2103
2104         ret = start_gentest();
2105
2106         if (ret) {
2107                 printf("gentest completed - no errors\n");
2108         } else {
2109                 printf("gentest failed\n");
2110         }
2111
2112         return ret?0:-1;
2113 }