2 Unix SMB/CIFS implementation.
4 directory scanning tests
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static void list_fn(file_info *finfo, const char *name, void *state)
31 test directory listing speed
33 BOOL torture_dirtest1(void)
36 struct smbcli_state *cli;
40 extern int torture_numops;
42 printf("starting dirtest1\n");
44 if (!torture_open_connection(&cli)) {
48 printf("Creating %d random filenames\n", torture_numops);
51 for (i=0;i<torture_numops;i++) {
53 asprintf(&fname, "\\%x", (int)random());
54 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
56 fprintf(stderr,"(%s) Failed to open %s\n",
60 smbcli_close(cli->tree, fnum);
66 printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
67 printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
68 printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
70 printf("dirtest core %g seconds\n", end_timer() - t1);
73 for (i=0;i<torture_numops;i++) {
75 asprintf(&fname, "\\%x", (int)random());
76 smbcli_unlink(cli->tree, fname);
80 if (!torture_close_connection(cli)) {
84 printf("finished dirtest1\n");
89 BOOL torture_dirtest2(void)
92 struct smbcli_state *cli;
95 extern int torture_entries;
97 printf("starting dirtest2\n");
99 if (!torture_open_connection(&cli)) {
103 if (smbcli_deltree(cli->tree, "\\LISTDIR") == -1) {
104 fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", smbcli_errstr(cli->tree));
107 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\LISTDIR"))) {
108 fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", smbcli_errstr(cli->tree));
112 printf("Creating %d files\n", torture_entries);
114 /* Create torture_entries files and torture_entries directories. */
115 for (i=0;i<torture_entries;i++) {
117 asprintf(&fname, "\\LISTDIR\\f%d", i);
118 fnum = smbcli_nt_create_full(cli->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
119 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
121 fprintf(stderr,"(%s) Failed to open %s, error=%s\n",
122 __location__, fname, smbcli_errstr(cli->tree));
126 smbcli_close(cli->tree, fnum);
128 for (i=0;i<torture_entries;i++) {
130 asprintf(&fname, "\\LISTDIR\\d%d", i);
131 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
132 fprintf(stderr,"(%s) Failed to open %s, error=%s\n",
133 __location__, fname, smbcli_errstr(cli->tree));
139 /* Now ensure that doing an old list sees both files and directories. */
140 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
141 printf("num_seen = %d\n", num_seen );
142 /* We should see (torture_entries) each of files & directories + . and .. */
143 if (num_seen != (2*torture_entries)+2) {
145 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
146 __location__, (2*torture_entries)+2, num_seen);
150 /* Ensure if we have the "must have" bits we only see the
153 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
154 printf("num_seen = %d\n", num_seen );
155 if (num_seen != torture_entries+2) {
157 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
158 __location__, torture_entries+2, num_seen);
161 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
162 printf("num_seen = %d\n", num_seen );
163 if (num_seen != torture_entries) {
165 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
166 __location__, torture_entries, num_seen);
169 /* Delete everything. */
170 if (smbcli_deltree(cli->tree, "\\LISTDIR") == -1) {
171 fprintf(stderr,"(%s) Failed to deltree %s, error=%s\n", "\\LISTDIR",
172 __location__, smbcli_errstr(cli->tree));
177 printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
178 printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
179 printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
182 if (!torture_close_connection(cli)) {
186 printf("finished dirtest1\n");