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.
23 int nbench_line_count = 0;
24 static int timelimit = 300;
25 static const char *loadfile;
27 #define ival(s) strtol(s, NULL, 0)
29 /* run a test that simulates an approximate netbench client load */
30 static BOOL run_netbench(struct cli_state *cli, int client)
40 nb_setup(cli, client);
42 asprintf(&cname, "client%d", client);
44 f = fopen(loadfile, "r");
52 while (fgets(line, sizeof(line)-1, f)) {
55 if (end_timer() >= timelimit) {
61 line[strlen(line)-1] = 0;
63 all_string_sub(line,"client1", cname, sizeof(line));
67 i<19 && next_token(&p, params[i], " ", sizeof(fstring));
72 if (i < 2 || params[0][0] == '#') continue;
74 if (!strncmp(params[0],"SMB", 3)) {
75 printf("ERROR: You are using a dbench 1 load file\n");
79 if (strncmp(params[i-1], "NT_STATUS_", 10) != 0) {
80 printf("Badly formed status at line %d\n", nbench_line_count);
84 status = nt_status_string_to_code(params[i-1]);
86 DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));
88 if (!strcmp(params[0],"NTCreateX")) {
89 nb_createx(params[1], ival(params[2]), ival(params[3]),
90 ival(params[4]), status);
91 } else if (!strcmp(params[0],"Close")) {
92 nb_close(ival(params[1]), status);
93 } else if (!strcmp(params[0],"Rename")) {
94 nb_rename(params[1], params[2], status);
95 } else if (!strcmp(params[0],"Unlink")) {
96 nb_unlink(params[1], ival(params[2]), status);
97 } else if (!strcmp(params[0],"Deltree")) {
98 nb_deltree(params[1]);
99 } else if (!strcmp(params[0],"Rmdir")) {
100 nb_rmdir(params[1], status);
101 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
102 nb_qpathinfo(params[1], ival(params[2]), status);
103 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
104 nb_qfileinfo(ival(params[1]), ival(params[2]), status);
105 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
106 nb_qfsinfo(ival(params[1]), status);
107 } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) {
108 nb_sfileinfo(ival(params[1]), ival(params[2]), status);
109 } else if (!strcmp(params[0],"FIND_FIRST")) {
110 nb_findfirst(params[1], ival(params[2]),
111 ival(params[3]), ival(params[4]), status);
112 } else if (!strcmp(params[0],"WriteX")) {
113 nb_writex(ival(params[1]),
114 ival(params[2]), ival(params[3]), ival(params[4]),
116 } else if (!strcmp(params[0],"Write")) {
117 nb_write(ival(params[1]),
118 ival(params[2]), ival(params[3]), ival(params[4]),
120 } else if (!strcmp(params[0],"LockX")) {
121 nb_lockx(ival(params[1]),
122 ival(params[2]), ival(params[3]), status);
123 } else if (!strcmp(params[0],"UnlockX")) {
124 nb_unlockx(ival(params[1]),
125 ival(params[2]), ival(params[3]), status);
126 } else if (!strcmp(params[0],"ReadX")) {
127 nb_readx(ival(params[1]),
128 ival(params[2]), ival(params[3]), ival(params[4]),
130 } else if (!strcmp(params[0],"Flush")) {
131 nb_flush(ival(params[1]), status);
133 printf("[%d] Unknown operation %s\n", nbench_line_count, params[0]);
144 if (!torture_close_connection(cli)) {
152 /* run a test that simulates an approximate netbench client load */
153 BOOL torture_nbench(int dummy)
157 extern int torture_nprocs;
158 struct cli_state *cli;
161 p = lp_parm_string(-1, "torture", "timelimit");
166 loadfile = lp_parm_string(-1, "torture", "loadfile");
167 if (!loadfile || !*loadfile) {
168 loadfile = "client.txt";
171 if (!torture_open_connection(&cli)) {
176 nb_deltree("\\clients");
178 nbio_shmem(torture_nprocs);
180 printf("Running for %d seconds with load '%s'\n", timelimit, loadfile);
182 signal(SIGALRM, SIGNAL_CAST nb_alarm);
184 t = torture_create_procs(run_netbench, &correct);
187 printf("\nThroughput %g MB/sec\n",
188 1.0e-6 * nbio_total() / t);