2 Unix SMB/CIFS implementation.
3 SMB torture tester - NBENCH test
4 Copyright (C) Andrew Tridgell 1997-2004
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.
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.
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.
22 #include "torture/torture.h"
23 #include "libcli/libcli.h"
24 #include "system/filesys.h"
27 int nbench_line_count = 0;
28 static int timelimit = 600;
30 static const char *loadfile;
32 #define ival(s) strtol(s, NULL, 0)
34 /* run a test that simulates an approximate netbench client load */
35 static BOOL run_netbench(struct smbcli_state *cli, int client)
37 extern int torture_nprocs;
45 if (torture_nprocs == 1) {
46 if (!torture_setup_dir(cli, "\\clients")) {
51 nb_setup(cli, client);
53 asprintf(&cname, "client%d", client+1);
55 f = fopen(loadfile, "r");
63 while (fgets(line, sizeof(line)-1, f)) {
68 line[strlen(line)-1] = 0;
70 all_string_sub(line,"client1", cname, sizeof(line));
72 params = str_list_make_shell(NULL, line, " ");
73 i = str_list_length(params);
75 if (i < 2 || params[0][0] == '#') continue;
77 if (!strncmp(params[0],"SMB", 3)) {
78 printf("ERROR: You are using a dbench 1 load file\n");
82 if (strncmp(params[i-1], "NT_STATUS_", 10) != 0) {
83 printf("Badly formed status at line %d\n", nbench_line_count);
88 status = nt_status_string_to_code(params[i-1]);
90 DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));
92 if (!strcmp(params[0],"NTCreateX")) {
93 nb_createx(params[1], ival(params[2]), ival(params[3]),
94 ival(params[4]), status);
95 } else if (!strcmp(params[0],"Close")) {
96 nb_close(ival(params[1]), status);
97 } else if (!strcmp(params[0],"Rename")) {
98 nb_rename(params[1], params[2], status);
99 } else if (!strcmp(params[0],"Unlink")) {
100 nb_unlink(params[1], ival(params[2]), status);
101 } else if (!strcmp(params[0],"Deltree")) {
102 nb_deltree(params[1]);
103 } else if (!strcmp(params[0],"Rmdir")) {
104 nb_rmdir(params[1], status);
105 } else if (!strcmp(params[0],"Mkdir")) {
106 nb_mkdir(params[1], status);
107 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
108 nb_qpathinfo(params[1], ival(params[2]), status);
109 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
110 nb_qfileinfo(ival(params[1]), ival(params[2]), status);
111 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
112 nb_qfsinfo(ival(params[1]), status);
113 } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) {
114 nb_sfileinfo(ival(params[1]), ival(params[2]), status);
115 } else if (!strcmp(params[0],"FIND_FIRST")) {
116 nb_findfirst(params[1], ival(params[2]),
117 ival(params[3]), ival(params[4]), status);
118 } else if (!strcmp(params[0],"WriteX")) {
119 nb_writex(ival(params[1]),
120 ival(params[2]), ival(params[3]), ival(params[4]),
122 } else if (!strcmp(params[0],"Write")) {
123 nb_write(ival(params[1]),
124 ival(params[2]), ival(params[3]), ival(params[4]),
126 } else if (!strcmp(params[0],"LockX")) {
127 nb_lockx(ival(params[1]),
128 ival(params[2]), ival(params[3]), status);
129 } else if (!strcmp(params[0],"UnlockX")) {
130 nb_unlockx(ival(params[1]),
131 ival(params[2]), ival(params[3]), status);
132 } else if (!strcmp(params[0],"ReadX")) {
133 nb_readx(ival(params[1]),
134 ival(params[2]), ival(params[3]), ival(params[4]),
136 } else if (!strcmp(params[0],"Flush")) {
137 nb_flush(ival(params[1]), status);
138 } else if (!strcmp(params[0],"Sleep")) {
139 nb_sleep(ival(params[1]), status);
141 printf("[%d] Unknown operation %s\n", nbench_line_count, params[0]);
146 if (nb_tick()) goto done;
155 if (torture_nprocs == 1) {
156 smbcli_deltree(cli->tree, "\\clients");
158 if (!torture_close_connection(cli)) {
166 /* run a test that simulates an approximate netbench client load */
167 BOOL torture_nbench(void)
170 extern int torture_nprocs;
171 struct smbcli_state *cli;
174 p = lp_parm_string(-1, "torture", "timelimit");
179 warmup = timelimit / 20;
181 loadfile = lp_parm_string(-1, "torture", "loadfile");
182 if (!loadfile || !*loadfile) {
183 loadfile = "client.txt";
186 if (torture_nprocs > 1) {
187 if (!torture_open_connection(&cli)) {
191 if (!torture_setup_dir(cli, "\\clients")) {
196 nbio_shmem(torture_nprocs, timelimit, warmup);
198 printf("Running for %d seconds with load '%s' and warmup %d secs\n",
199 timelimit, loadfile, warmup);
201 /* we need to reset SIGCHLD here as the name resolution
202 library may have changed it. We rely on correct signals
203 from childs in the main torture code which reaps
204 children. This is why smbtorture BENCH-NBENCH was sometimes
206 signal(SIGCHLD, SIG_DFL);
209 signal(SIGALRM, nb_alarm);
211 torture_create_procs(run_netbench, &correct);
214 if (torture_nprocs > 1) {
215 smbcli_deltree(cli->tree, "\\clients");
218 printf("\nThroughput %g MB/sec\n", nbio_result());