r20302: added support for 64 bit file offsets in NBENCH
[jra/samba/.git] / source4 / torture / nbench / nbench.c
index 43e9e0b4c581be4fc00b0065369b02c0736f06ee..f671a5b0dec0393959b648c7cbf5f785a1025a3e 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "libcli/libcli.h"
+#include "torture/ui.h"
 #include "torture/util.h"
 #include "torture/torture.h"
 #include "system/filesys.h"
@@ -31,13 +32,14 @@ int nbench_line_count = 0;
 static int timelimit = 600;
 static int warmup;
 static const char *loadfile;
+static int read_only;
 
-#define ival(s) strtol(s, NULL, 0)
+#define ival(s) strtoll(s, NULL, 0)
 
 /* run a test that simulates an approximate netbench client load */
-static BOOL run_netbench(struct smbcli_state *cli, int client)
+static BOOL run_netbench(struct torture_context *tctx, struct smbcli_state *cli, int client)
 {
-       extern int torture_nprocs;
+       int torture_nprocs = lp_parm_int(-1, "torture", "nprocs", 4);
        int i;
        pstring line;
        char *cname;
@@ -46,7 +48,7 @@ static BOOL run_netbench(struct smbcli_state *cli, int client)
        BOOL correct = True;
 
        if (torture_nprocs == 1) {
-               if (!torture_setup_dir(cli, "\\clients")) {
+               if (!read_only && !torture_setup_dir(cli, "\\clients")) {
                        return False;
                }
        }
@@ -97,15 +99,15 @@ again:
                                   ival(params[4]), status);
                } else if (!strcmp(params[0],"Close")) {
                        nb_close(ival(params[1]), status);
-               } else if (!strcmp(params[0],"Rename")) {
+               } else if (!read_only && !strcmp(params[0],"Rename")) {
                        nb_rename(params[1], params[2], status);
-               } else if (!strcmp(params[0],"Unlink")) {
+               } else if (!read_only && !strcmp(params[0],"Unlink")) {
                        nb_unlink(params[1], ival(params[2]), status);
-               } else if (!strcmp(params[0],"Deltree")) {
+               } else if (!read_only && !strcmp(params[0],"Deltree")) {
                        nb_deltree(params[1]);
-               } else if (!strcmp(params[0],"Rmdir")) {
+               } else if (!read_only && !strcmp(params[0],"Rmdir")) {
                        nb_rmdir(params[1], status);
-               } else if (!strcmp(params[0],"Mkdir")) {
+               } else if (!read_only && !strcmp(params[0],"Mkdir")) {
                        nb_mkdir(params[1], status);
                } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
                        nb_qpathinfo(params[1], ival(params[2]), status);
@@ -113,16 +115,16 @@ again:
                        nb_qfileinfo(ival(params[1]), ival(params[2]), status);
                } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
                        nb_qfsinfo(ival(params[1]), status);
-               } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) {
+               } else if (!read_only && !strcmp(params[0],"SET_FILE_INFORMATION")) {
                        nb_sfileinfo(ival(params[1]), ival(params[2]), status);
                } else if (!strcmp(params[0],"FIND_FIRST")) {
                        nb_findfirst(params[1], ival(params[2]), 
                                     ival(params[3]), ival(params[4]), status);
-               } else if (!strcmp(params[0],"WriteX")) {
+               } else if (!read_only && !strcmp(params[0],"WriteX")) {
                        nb_writex(ival(params[1]), 
                                  ival(params[2]), ival(params[3]), ival(params[4]),
                                  status);
-               } else if (!strcmp(params[0],"Write")) {
+               } else if (!read_only && !strcmp(params[0],"Write")) {
                        nb_write(ival(params[1]), 
                                 ival(params[2]), ival(params[3]), ival(params[4]),
                                 status);
@@ -155,7 +157,7 @@ again:
 done:
        fclose(f);
 
-       if (torture_nprocs == 1) {
+       if (!read_only && torture_nprocs == 1) {
                smbcli_deltree(cli->tree, "\\clients");
        }
        if (!torture_close_connection(cli)) {
@@ -167,31 +169,33 @@ done:
 
 
 /* run a test that simulates an approximate netbench client load */
-BOOL torture_nbench(void)
+BOOL torture_nbench(struct torture_context *torture)
 {
        BOOL correct = True;
-       extern int torture_nprocs;
+       int torture_nprocs = lp_parm_int(-1, "torture", "nprocs", 4);
        struct smbcli_state *cli;
        const char *p;
 
-       p = lp_parm_string(-1, "torture", "timelimit");
+       read_only = lp_parm_bool(-1, "torture", "readonly", False);
+
+       p = torture_setting_string(torture, "timelimit", NULL);
        if (p && *p) {
                timelimit = atoi(p);
        }
 
        warmup = timelimit / 20;
 
-       loadfile =  lp_parm_string(-1, "torture", "loadfile");
+       loadfile = torture_setting_string(torture, "loadfile", NULL);
        if (!loadfile || !*loadfile) {
                loadfile = "client.txt";
        }
 
        if (torture_nprocs > 1) {
-               if (!torture_open_connection(&cli)) {
+               if (!torture_open_connection(&cli, 0)) {
                        return False;
                }
 
-               if (!torture_setup_dir(cli, "\\clients")) {
+               if (!read_only && !torture_setup_dir(cli, "\\clients")) {
                        return False;
                }
        }
@@ -211,13 +215,28 @@ BOOL torture_nbench(void)
 
        signal(SIGALRM, nb_alarm);
        alarm(1);
-       torture_create_procs(run_netbench, &correct);
+       torture_create_procs(torture, run_netbench, &correct);
        alarm(0);
 
-       if (torture_nprocs > 1) {
+       if (!read_only && torture_nprocs > 1) {
                smbcli_deltree(cli->tree, "\\clients");
        }
 
        printf("\nThroughput %g MB/sec\n", nbio_result());
        return correct;
 }
+
+NTSTATUS torture_nbench_init(void)
+{
+       struct torture_suite *suite = torture_suite_create(
+                                                                               talloc_autofree_context(),
+                                                                               "BENCH");
+
+       torture_suite_add_simple_test(suite, "NBENCH", torture_nbench);
+
+       suite->description = talloc_strdup(suite, 
+                                                               "Benchmarks");
+
+       torture_register_suite(suite);
+       return NT_STATUS_OK;
+}