r15087: Quick stress test that does more or less what the tool "iometer" does.
authorVolker Lendecke <vlendec@samba.org>
Fri, 14 Apr 2006 20:36:36 +0000 (20:36 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:04:07 +0000 (14:04 -0500)
Volker
(This used to be commit 6a08b192bec95cc0bbe017a2ce692afce63e047f)

source4/torture/basic/base.c

index 050c09229606e8c40f5be2992c7aed6543345d22..4358e60159fa9929c9d466ed19991c5d33da6300 100644 (file)
@@ -1438,6 +1438,92 @@ static BOOL run_xcopy(struct torture_context *torture)
        return correct;
 }
 
+static BOOL run_iometer(struct torture_context *torture)
+{
+       struct smbcli_state *cli;
+       const char *fname = "\\iobw.tst";
+       int fnum;
+       size_t filesize;
+       NTSTATUS status;
+       char buf[2048];
+       int ops;
+       BOOL result = False;
+
+       printf("Starting iometer test\n");
+
+       memset(buf, 0, sizeof(buf));
+
+       if (!torture_open_connection(&cli)) {
+               return False;
+       }
+
+       status = smbcli_getatr(cli->tree, fname, NULL, &filesize, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("smbcli_getatr failed: %s\n", nt_errstr(status));
+               goto done;
+       }
+
+       printf("size: %d\n", filesize);
+
+       filesize -= (sizeof(buf) - 1);
+
+       fnum = smbcli_nt_create_full(cli->tree, fname, 0x16,
+                                    0x2019f, 0, 0x3, 3, 0x42, 0x3);
+       if (fnum == -1) {
+               printf("open failed: %s\n", smbcli_errstr(cli->tree));
+               goto done;
+       }
+
+       ops = 0;
+
+       while (True) {
+               int i, num_reads, num_writes;
+
+               num_reads = random() % 10;
+               num_writes = random() % 3;
+
+               for (i=0; i<num_reads; i++) {
+                       ssize_t res;
+                       if (ops++ > torture_numops) {
+                               result = True;
+                               goto done;
+                       }
+                       res = smbcli_read(cli->tree, fnum, buf,
+                                         random() % filesize, sizeof(buf));
+                       if (res != sizeof(buf)) {
+                               printf("read failed: %s\n",
+                                      smbcli_errstr(cli->tree));
+                               goto done;
+                       }
+               }
+               for (i=0; i<num_writes; i++) {
+                       ssize_t res;
+                       if (ops++ > torture_numops) {
+                               result = True;
+                               goto done;
+                       }
+                       res = smbcli_write(cli->tree, fnum, 0, buf,
+                                         random() % filesize, sizeof(buf));
+                       if (res != sizeof(buf)) {
+                               printf("read failed: %s\n",
+                                      smbcli_errstr(cli->tree));
+                               goto done;
+                       }
+               }
+       }
+
+       result = True;
+ done:
+
+       if (!torture_close_connection(cli)) {
+               printf("close_connection failed: %s\n",
+                      smbcli_errstr(cli->tree));
+               return False;
+       }
+
+       return result;
+}
+
 /**
   tries variants of chkpath
  */
@@ -1554,6 +1640,7 @@ NTSTATUS torture_base_init(void)
        register_torture_op("BASE-OPEN", run_opentest, 0);
        register_torture_op("BASE-DEFER_OPEN", NULL, run_deferopen);
        register_torture_op("BASE-XCOPY", run_xcopy, 0);
+       register_torture_op("BASE-IOMETER", run_iometer, 0);
        register_torture_op("BASE-RENAME", torture_test_rename, 0);
        register_torture_op("BASE-DELETE", torture_test_delete, 0);
        register_torture_op("BASE-PROPERTIES", torture_test_properties, 0);