Print the vuid in BENCH-SESSSETUP
[nivanova/samba-autobuild/.git] / source3 / torture / torture.c
index 904fb5c26252c0af35de3cc99e0be72d58c799b1..63942da2e5b72cd441a04b49c71eaec6ed71ae12 100644 (file)
@@ -28,6 +28,7 @@ static const char *sockops="TCP_NODELAY";
 static int nprocs=1;
 static int port_to_use=0;
 int torture_numops=100;
+int torture_blocksize=1024*1024;
 static int procnum; /* records process count number when forking */
 static struct cli_state *current_cli;
 static fstring randomfname;
@@ -158,7 +159,7 @@ static struct cli_state *open_nbt_connection(void)
        make_nmb_name(&calling, myname, 0x0);
        make_nmb_name(&called , host, 0x20);
 
-        zero_addr(&ss);
+        zero_sockaddr(&ss);
 
        if (!(c = cli_initialise())) {
                printf("Failed initialize cli_struct to connect with %s\n", host);
@@ -2346,7 +2347,7 @@ static bool run_negprot_nowait(int dummy)
        }
 
        for (i=0;i<50000;i++) {
-               cli_negprot_send(cli);
+               cli_negprot_sendsync(cli);
        }
 
        if (!torture_close_connection(cli)) {
@@ -4726,6 +4727,7 @@ static bool run_error_map_extract(int dummy) {
        
        static struct cli_state *c_dos;
        static struct cli_state *c_nt;
+       NTSTATUS status;
 
        uint32 error;
 
@@ -4744,8 +4746,11 @@ static bool run_error_map_extract(int dummy) {
 
        c_nt->use_spnego = False;
 
-       if (!cli_negprot(c_nt)) {
-               printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
+       status = cli_negprot(c_nt);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("%s rejected the NT-error negprot (%s)\n", host,
+                      nt_errstr(status));
                cli_shutdown(c_nt);
                return False;
        }
@@ -4765,8 +4770,10 @@ static bool run_error_map_extract(int dummy) {
        c_dos->use_spnego = False;
        c_dos->force_dos_errors = True;
 
-       if (!cli_negprot(c_dos)) {
-               printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
+       status = cli_negprot(c_dos);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("%s rejected the DOS-error negprot (%s)\n", host,
+                      nt_errstr(status));
                cli_shutdown(c_dos);
                return False;
        }
@@ -4832,17 +4839,21 @@ static bool run_error_map_extract(int dummy) {
 static bool run_sesssetup_bench(int dummy)
 {
        static struct cli_state *c;
+       const char *fname = "\\file.dat";
+       int fnum;
        NTSTATUS status;
        int i;
 
-       if (!(c = open_nbt_connection())) {
+       if (!torture_open_connection(&c, 0)) {
                return false;
        }
 
-       if (!cli_negprot(c)) {
-               printf("%s rejected the NT-error negprot (%s)\n", host,
-                      cli_errstr(c));
-               cli_shutdown(c);
+       fnum = cli_nt_create_full(
+               c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+               FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+               FILE_DELETE_ON_CLOSE, 0);
+       if (fnum == -1) {
+               d_printf("open %s failed: %s\n", fname, cli_errstr(c));
                return false;
        }
 
@@ -4858,6 +4869,8 @@ static bool run_sesssetup_bench(int dummy)
                        return false;
                }
 
+               d_printf("\r%d   ", (int)c->vuid);
+
                if (!cli_ulogoff(c)) {
                        d_printf("(%s) cli_ulogoff failed: %s\n",
                                 __location__, cli_errstr(c));
@@ -4920,6 +4933,23 @@ static void chain1_read_completion(struct async_req *req)
        TALLOC_FREE(req);
 }
 
+static void chain1_write_completion(struct async_req *req)
+{
+       NTSTATUS status;
+       size_t written;
+
+       status = cli_write_andx_recv(req, &written);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(req);
+               d_printf("cli_write_andx_recv returned %s\n",
+                        nt_errstr(status));
+               return;
+       }
+
+       d_printf("wrote %d bytes\n", (int)written);
+       TALLOC_FREE(req);
+}
+
 static void chain1_close_completion(struct async_req *req)
 {
        NTSTATUS status;
@@ -4938,6 +4968,7 @@ static bool run_chain1(int dummy)
        struct event_context *evt = event_context_init(NULL);
        struct async_req *reqs[4];
        bool done = false;
+       const char *text = "hallo";
 
        printf("starting chain1 test\n");
        if (!torture_open_connection(&cli1, 0)) {
@@ -4950,8 +4981,9 @@ static bool run_chain1(int dummy)
        reqs[0] = cli_open_send(talloc_tos(), evt, cli1, "\\test",
                                O_CREAT|O_RDWR, 0);
        reqs[0]->async.fn = chain1_open_completion;
-       reqs[1] = cli_read_andx_send(talloc_tos(), evt, cli1, 0, 0, 10);
-       reqs[1]->async.fn = chain1_read_completion;
+       reqs[1] = cli_write_andx_send(talloc_tos(), evt, cli1, 0, 0,
+                                     (uint8_t *)text, 0, strlen(text));
+       reqs[1]->async.fn = chain1_write_completion;
        reqs[2] = cli_read_andx_send(talloc_tos(), evt, cli1, 0, 1, 10);
        reqs[2]->async.fn = chain1_read_completion;
        reqs[3] = cli_close_send(talloc_tos(), evt, cli1, 0);
@@ -4967,6 +4999,81 @@ static bool run_chain1(int dummy)
        return True;
 }
 
+static size_t null_source(uint8_t *buf, size_t n, void *priv)
+{
+       size_t *to_pull = (size_t *)priv;
+       size_t thistime = *to_pull;
+
+       thistime = MIN(thistime, n);
+       if (thistime == 0) {
+               return 0;
+       }
+
+       memset(buf, 0, thistime);
+       *to_pull -= thistime;
+       return thistime;
+}
+
+static bool run_windows_write(int dummy)
+{
+       struct cli_state *cli1;
+       int fnum;
+       int i;
+       bool ret = false;
+       const char *fname = "\\writetest.txt";
+       double seconds;
+       double kbytes;
+
+       printf("starting windows_write test\n");
+       if (!torture_open_connection(&cli1, 0)) {
+               return False;
+       }
+
+       fnum = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+       if (fnum == -1) {
+               printf("open failed (%s)\n", cli_errstr(cli1));
+               return False;
+       }
+
+       cli_sockopt(cli1, sockops);
+
+       start_timer();
+
+       for (i=0; i<torture_numops; i++) {
+               char c = 0;
+               off_t start = i * torture_blocksize;
+               NTSTATUS status;
+               size_t to_pull = torture_blocksize - 1;
+
+               if (cli_write(cli1, fnum, 0, &c,
+                             start + torture_blocksize - 1, 1) != 1) {
+                       printf("cli_write failed: %s\n", cli_errstr(cli1));
+                       goto fail;
+               }
+
+               status = cli_push(cli1, fnum, 0, i * torture_blocksize, torture_blocksize,
+                                 null_source, &to_pull);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("cli_push returned: %s\n", nt_errstr(status));
+                       goto fail;
+               }
+       }
+
+       seconds = end_timer();
+       kbytes = (double)torture_blocksize * torture_numops;
+       kbytes /= 1024;
+
+       printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes,
+              (double)seconds, (int)(kbytes/seconds));
+
+       ret = true;
+ fail:
+       cli_close(cli1, fnum);
+       cli_unlink(cli1, fname);
+       torture_close_connection(cli1);
+       return ret;
+}
+
 static bool run_cli_echo(int dummy)
 {
        struct cli_state *cli;
@@ -5291,6 +5398,11 @@ static bool run_local_memcache(int dummy)
        DATA_BLOB d1, d2, d3;
        DATA_BLOB v1, v2, v3;
 
+       TALLOC_CTX *mem_ctx;
+       char *str1, *str2;
+       size_t size1, size2;
+       bool ret = false;
+
        cache = memcache_init(NULL, 100);
 
        if (cache == NULL) {
@@ -5342,7 +5454,33 @@ static bool run_local_memcache(int dummy)
        }
 
        TALLOC_FREE(cache);
-       return true;
+
+       cache = memcache_init(NULL, 0);
+
+       mem_ctx = talloc_init("foo");
+
+       str1 = talloc_strdup(mem_ctx, "string1");
+       str2 = talloc_strdup(mem_ctx, "string2");
+
+       memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
+                           data_blob_string_const("torture"), &str1);
+       size1 = talloc_total_size(cache);
+
+       memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
+                           data_blob_string_const("torture"), &str2);
+       size2 = talloc_total_size(cache);
+
+       printf("size1=%d, size2=%d\n", (int)size1, (int)size2);
+
+       if (size2 > size1) {
+               printf("memcache leaks memory!\n");
+               goto fail;
+       }
+
+       ret = true;
+ fail:
+       TALLOC_FREE(cache);
+       return ret;
 }
 
 static double create_procs(bool (*fn)(int), bool *result)
@@ -5497,6 +5635,7 @@ static struct {
        { "EATEST", run_eatest, 0},
        { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
        { "CHAIN1", run_chain1, 0},
+       { "WINDOWS-WRITE", run_windows_write, 0},
        { "CLI_ECHO", run_cli_echo, 0},
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
@@ -5655,7 +5794,7 @@ static void usage(void)
 
        fstrcpy(workgroup, lp_workgroup());
 
-       while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:")) != EOF) {
+       while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aec:ks:b:B:")) != EOF) {
                switch (opt) {
                case 'p':
                        port_to_use = atoi(optarg);
@@ -5718,6 +5857,9 @@ static void usage(void)
                        fstrcpy(multishare_conn_fname, optarg);
                        use_multishare_conn = True;
                        break;
+               case 'B':
+                       torture_blocksize = atoi(optarg);
+                       break;
                default:
                        printf("Unknown option %c (%d)\n", (char)opt, opt);
                        usage();