r3586: Fix some of the issues with the module init functions.
[bbaumbach/samba-autobuild/.git] / source4 / torture / torture.c
index d969a514045ff6946da4440624a3e78801af6c8c..883fe4b017ac9b0572642eaf04899bc2a97de10f 100644 (file)
 */
 
 #include "includes.h"
+#include "dynconfig.h"
+#include "client.h"
+#include "lib/cmdline/popt_common.h"
+#include "libcli/raw/libcliraw.h"
+#include "system/time.h"
+#include "system/wait.h"
+#include "ioctl.h"
 
 int torture_nprocs=4;
 int torture_numops=100;
 int torture_entries=1000;
 int torture_failures=1;
+int torture_seed=0;
 static int procnum; /* records process count number when forking */
 static struct smbcli_state *current_cli;
 static BOOL use_oplocks;
@@ -359,7 +367,6 @@ static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
        ssize_t sent = 0;
        BOOL correct = True;
 
-       srandom(1);
        for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
        {
                SIVAL(buf, i, sys_random());
@@ -529,7 +536,7 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
        return correct;
 }
 
-static BOOL run_readwritetest(int dummy)
+static BOOL run_readwritetest(void)
 {
        struct smbcli_state *cli1, *cli2;
        BOOL test1, test2 = True;
@@ -577,7 +584,7 @@ static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
   this checks to see if a secondary tconx can use open files from an
   earlier tconx
  */
-static BOOL run_tcon_test(int dummy)
+static BOOL run_tcon_test(void)
 {
        struct smbcli_state *cli;
        const char *fname = "\\tcontest.tmp";
@@ -732,7 +739,7 @@ static BOOL tcon_devtest(struct smbcli_state *cli,
 /*
  checks for correct tconX support
  */
-static BOOL run_tcon_devtype_test(int dummy)
+static BOOL run_tcon_devtype_test(void)
 {
        struct smbcli_state *cli1 = NULL;
        BOOL retry;
@@ -800,7 +807,7 @@ static BOOL run_tcon_devtype_test(int dummy)
 test whether fnums and tids open on one VC are available on another (a major
 security hole)
 */
-static BOOL run_fdpasstest(int dummy)
+static BOOL run_fdpasstest(void)
 {
        struct smbcli_state *cli1, *cli2;
        const char *fname = "\\fdpass.tst";
@@ -856,59 +863,6 @@ static BOOL run_fdpasstest(int dummy)
 }
 
 
-/*
-  This test checks that 
-
-  1) the server does not allow an unlink on a file that is open
-*/
-static BOOL run_unlinktest(int dummy)
-{
-       struct smbcli_state *cli;
-       const char *fname = "\\unlink.tst";
-       int fnum;
-       BOOL correct = True;
-
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       printf("starting unlink test\n");
-
-       smbcli_unlink(cli->tree, fname);
-
-       cli->session->pid = 1;
-
-       printf("Opening a file\n");
-
-       fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -1) {
-               printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
-               return False;
-       }
-
-       printf("Unlinking a open file\n");
-
-       if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
-               printf("error: server allowed unlink on an open file\n");
-               correct = False;
-       } else {
-               correct = check_error(__location__, cli, ERRDOS, ERRbadshare, 
-                                     NT_STATUS_SHARING_VIOLATION);
-       }
-
-       smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
-
-       if (!torture_close_connection(cli)) {
-               correct = False;
-       }
-
-       printf("unlink test finished\n");
-       
-       return correct;
-}
-
-
 /*
 test the timing of deferred open requests
 */
@@ -930,22 +884,19 @@ static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
                int fnum = -1;
 
                do {
-                       struct timeval tv_start, tv_end;
-                       GetTimeOfDay(&tv_start);
+                       struct timeval tv;
+                       tv = timeval_current();
                        fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
                                FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
                                NTCREATEX_DISP_OPEN_IF, 0, 0);
                        if (fnum != -1) {
                                break;
                        }
-                       GetTimeOfDay(&tv_end);
                        if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
-                               /* Sharing violation errors need to be 1 second apart. */
-                               int64_t tdif = usec_time_diff(&tv_end, &tv_start);
-                               if (tdif < 500000 || tdif > 1500000) {
-                                       fprintf(stderr,"Timing incorrect %lld.%lld for share violation\n",
-                                               tdif / (int64_t)1000000, 
-                                               tdif % (int64_t)1000000);
+                               double e = timeval_elapsed(&tv);
+                               if (e < 0.5 || e > 1.5) {
+                                       fprintf(stderr,"Timing incorrect %.2f violation\n",
+                                               e);
                                }
                        }
                } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
@@ -1080,7 +1031,7 @@ static BOOL run_maxfidtest(struct smbcli_state *cli, int dummy)
 }
 
 /* send smb negprot commands, not reading the response */
-static BOOL run_negprot_nowait(int dummy)
+static BOOL run_negprot_nowait(void)
 {
        int i;
        struct smbcli_state *cli, *cli2;
@@ -1144,7 +1095,7 @@ static BOOL run_negprot_nowait(int dummy)
 /*
   This checks how the getatr calls works
 */
-static BOOL run_attrtest(int dummy)
+static BOOL run_attrtest(void)
 {
        struct smbcli_state *cli;
        int fnum;
@@ -1215,7 +1166,7 @@ static BOOL run_attrtest(int dummy)
 /*
   This checks a couple of trans2 calls
 */
-static BOOL run_trans2test(int dummy)
+static BOOL run_trans2test(void)
 {
        struct smbcli_state *cli;
        int fnum;
@@ -1352,7 +1303,7 @@ static BOOL run_trans2test(int dummy)
 /*
   print out server properties
  */
-static BOOL run_properties(int dummy)
+static BOOL run_properties(void)
 {
        struct smbcli_state *cli;
        BOOL correct = True;
@@ -1398,7 +1349,7 @@ static BOOL run_properties(int dummy)
 /*
   Test ntcreate calls made by xcopy
  */
-static BOOL run_xcopy(int dummy)
+static BOOL run_xcopy(void)
 {
        struct smbcli_state *cli1;
        const char *fname = "\\test.txt";
@@ -1441,7 +1392,7 @@ static BOOL run_xcopy(int dummy)
 /*
   see how many RPC pipes we can open at once
 */
-static BOOL run_pipe_number(int dummy)
+static BOOL run_pipe_number(void)
 {
        struct smbcli_state *cli1;
        const char *pipe_name = "\\WKSSVC";
@@ -1479,7 +1430,7 @@ static BOOL run_pipe_number(int dummy)
   used for testing performance when there are N idle users
   already connected
  */
- static BOOL torture_holdcon(int dummy)
+ static BOOL torture_holdcon(void)
 {
        int i;
        struct smbcli_state **cli;
@@ -1529,7 +1480,7 @@ static BOOL run_pipe_number(int dummy)
   Try with a wrong vuid and check error message.
  */
 
-static BOOL run_vuidtest(int dummy)
+static BOOL run_vuidtest(void)
 {
        struct smbcli_state *cli;
        const char *fname = "\\vuid.tst";
@@ -1595,7 +1546,7 @@ static BOOL run_vuidtest(int dummy)
 /*
   Test open mode returns on read-only files.
  */
- static BOOL run_opentest(int dummy)
+ static BOOL run_opentest(void)
 {
        static struct smbcli_state *cli1;
        static struct smbcli_state *cli2;
@@ -2085,7 +2036,7 @@ error_test80:
 /*
   sees what IOCTLs are supported
  */
-BOOL torture_ioctl_test(int dummy)
+BOOL torture_ioctl_test(void)
 {
        struct smbcli_state *cli;
        uint16_t device, function;
@@ -2141,7 +2092,7 @@ BOOL torture_ioctl_test(int dummy)
 /*
   tries variants of chkpath
  */
-BOOL torture_chkpath_test(int dummy)
+BOOL torture_chkpath_test(void)
 {
        struct smbcli_state *cli;
        int fnum;
@@ -2247,7 +2198,7 @@ static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
 
 
 
-static void sigcont(void)
+static void sigcont(int sig)
 {
 }
 
@@ -2262,6 +2213,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
        char **unc_list = NULL;
        const char *p;
        int num_unc_names = 0;
+       struct timeval tv;
 
        synccount = 0;
 
@@ -2293,7 +2245,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
                child_status_out[i] = True;
        }
 
-       start_timer();
+       tv = timeval_current();
 
        for (i=0;i<torture_nprocs;i++) {
                procnum = i;
@@ -2357,18 +2309,18 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
                }
                if (synccount == torture_nprocs) break;
                msleep(100);
-       } while (end_timer() < start_time_limit);
+       } while (timeval_elapsed(&tv) < start_time_limit);
 
        if (synccount != torture_nprocs) {
                printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
                *result = False;
-               return end_timer();
+               return timeval_elapsed(&tv);
        }
 
        printf("Starting %d clients\n", torture_nprocs);
 
        /* start the client load */
-       start_timer();
+       tv = timeval_current();
        for (i=0;i<torture_nprocs;i++) {
                child_status[i] = 0;
        }
@@ -2378,7 +2330,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
        for (i=0;i<torture_nprocs;i++) {
                int ret;
-               while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
+               while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
                if (ret == -1 || WEXITSTATUS(status) != 0) {
                        *result = False;
                }
@@ -2391,15 +2343,15 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
                        *result = False;
                }
        }
-       return end_timer();
+       return timeval_elapsed(&tv);
 }
 
 #define FLAG_MULTIPROC 1
 
 static struct {
        const char *name;
-       BOOL (*fn)(int);
-       uint_t flags;
+       BOOL (*fn)(void);
+       BOOL (*multi_fn)(struct smbcli_state *, int );
 } torture_ops[] = {
        /* base tests */
        {"BASE-FDPASS", run_fdpasstest, 0},
@@ -2410,7 +2362,7 @@ static struct {
        {"BASE-LOCK5",  torture_locktest5,  0},
        {"BASE-LOCK6",  torture_locktest6,  0},
        {"BASE-LOCK7",  torture_locktest7,  0},
-       {"BASE-UNLINK", run_unlinktest, 0},
+       {"BASE-UNLINK", torture_unlinktest, 0},
        {"BASE-ATTR",   run_attrtest,   0},
        {"BASE-TRANS2", run_trans2test, 0},
        {"BASE-NEGNOWAIT", run_negprot_nowait, 0},
@@ -2419,13 +2371,15 @@ static struct {
        {"BASE-DENY1",  torture_denytest1, 0},
        {"BASE-DENY2",  torture_denytest2, 0},
        {"BASE-DENY3",  torture_denytest3, 0},
+       {"BASE-NTDENY1",  NULL, torture_ntdenytest1},
+       {"BASE-NTDENY2",  torture_ntdenytest2, 0},
        {"BASE-TCON",  run_tcon_test, 0},
        {"BASE-TCONDEV",  run_tcon_devtype_test, 0},
        {"BASE-VUID", run_vuidtest, 0},
        {"BASE-RW1",  run_readwritetest, 0},
-       {"BASE-RW2",  run_readwritemulti, FLAG_MULTIPROC},
+       {"BASE-RW2",  NULL, run_readwritemulti},
        {"BASE-OPEN", run_opentest, 0},
-       {"BASE-DEFER_OPEN", run_deferopen, FLAG_MULTIPROC},
+       {"BASE-DEFER_OPEN", NULL, run_deferopen},
        {"BASE-XCOPY", run_xcopy, 0},
        {"BASE-RENAME", torture_test_rename, 0},
        {"BASE-DELETE", torture_test_delete, 0},
@@ -2439,7 +2393,7 @@ static struct {
        /* benchmarking tests */
        {"BENCH-HOLDCON",  torture_holdcon, 0},
        {"BENCH-NBENCH",  torture_nbench, 0},
-       {"BENCH-TORTURE",run_torture,    FLAG_MULTIPROC},
+       {"BENCH-TORTURE", NULL, run_torture},
 
        /* RAW smb tests */
        {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
@@ -2469,7 +2423,7 @@ static struct {
        {"SCAN-NTTRANS", torture_nttrans_scan, 0},
        {"SCAN-ALIASES", torture_trans2_aliases, 0},
        {"SCAN-SMB", torture_smb_scan, 0},
-       {"SCAN-MAXFID", run_maxfidtest, FLAG_MULTIPROC},
+       {"SCAN-MAXFID", NULL, run_maxfidtest},
        {"SCAN-UTABLE", torture_utable, 0},
        {"SCAN-CASETABLE", torture_casetable, 0},
        {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
@@ -2491,6 +2445,7 @@ static struct {
         {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
         {"RPC-WINREG", torture_rpc_winreg, 0},
         {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
+        {"RPC-REMACT", torture_rpc_remact, 0},
         {"RPC-MGMT", torture_rpc_mgmt, 0},
         {"RPC-SCANNER", torture_rpc_scanner, 0},
         {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
@@ -2498,6 +2453,9 @@ static struct {
        {"RPC-MULTIBIND", torture_multi_bind, 0},
        {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
 
+       /* Distributed COM testers */
+       {"DCOM-SIMPLE", torture_dcom_simple, 0},
+
        /* local (no server) testers */
        {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
        {"LOCAL-ICONV", torture_local_iconv, 0},
@@ -2537,21 +2495,22 @@ static BOOL run_test(const char *name)
                        matched = True;
                        init_iconv();
                        printf("Running %s\n", torture_ops[i].name);
-                       if (torture_ops[i].flags & FLAG_MULTIPROC) {
+                       if (torture_ops[i].multi_fn) {
                                BOOL result;
-                               t = torture_create_procs(torture_ops[i].fn, &result);
+                               t = torture_create_procs(torture_ops[i].multi_fn, 
+                                                        &result);
                                if (!result) { 
                                        ret = False;
                                        printf("TEST %s FAILED!\n", torture_ops[i].name);
                                }
                                         
                        } else {
-                               start_timer();
-                               if (!torture_ops[i].fn(0)) {
+                               struct timeval tv = timeval_current();
+                               if (!torture_ops[i].fn()) {
                                        ret = False;
                                        printf("TEST %s FAILED!\n", torture_ops[i].name);
                                }
-                               t = end_timer();
+                               t = timeval_elapsed(&tv);
                        }
                        printf("%s took %g secs\n\n", torture_ops[i].name, t);
                }
@@ -2654,7 +2613,7 @@ static BOOL is_binding_string(const char *binding_string)
        struct poptOption long_options[] = {
                POPT_AUTOHELP
                {"smb-ports",   'p', POPT_ARG_STRING, NULL,             0,      "SMB ports",    NULL},
-               {"seed",          0, POPT_ARG_STRING, NULL,             0,      "seed",         NULL},
+               {"seed",          0, POPT_ARG_INT,  &torture_seed,      0,      "seed",         NULL},
                {"num-progs",     0, POPT_ARG_INT,  &torture_nprocs,    0,      "num progs",    NULL},
                {"num-ops",       0, POPT_ARG_INT,  &torture_numops,    0,      "num ops",      NULL},
                {"entries",       0, POPT_ARG_INT,  &torture_entries,   0,      "entries",      NULL},
@@ -2673,6 +2632,8 @@ static BOOL is_binding_string(const char *binding_string)
                POPT_TABLEEND
        };
 
+       smbtorture_init_subsystems;
+
        setup_logging("smbtorture", DEBUG_STDOUT);
 
 #ifdef HAVE_SETBUFFER
@@ -2711,9 +2672,13 @@ static BOOL is_binding_string(const char *binding_string)
 
        lp_load(dyn_CONFIGFILE,True,False,False);
        load_interfaces();
-       srandom(time(NULL));
+       if (torture_seed == 0) {
+               torture_seed = time(NULL);
+       } 
+       printf("Using seed %d\n", torture_seed);
+       srandom(torture_seed);
 
-       argv_new = (const char **)poptGetArgs(pc);
+       argv_new = discard_const_p(char *, poptGetArgs(pc));
 
        argc_new = argc;
        for (i=0; i<argc; i++) {
@@ -2741,6 +2706,7 @@ static BOOL is_binding_string(const char *binding_string)
                char *host = NULL, *share = NULL;
 
                if (!parse_unc(argv_new[1], &host, &share)) {
+                       d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
                        usage(pc);
                }