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.
24 #include "system/filesys.h"
25 #include "librpc/gen_ndr/ndr_security.h"
27 static void list_fn(struct clilist_file_info *finfo, const char *name, void *state)
33 test directory listing speed
35 BOOL torture_dirtest1(void)
38 struct smbcli_state *cli;
41 extern int torture_numops;
44 printf("starting dirtest1\n");
46 if (!torture_open_connection(&cli)) {
50 printf("Creating %d random filenames\n", torture_numops);
53 tv = timeval_current();
54 for (i=0;i<torture_numops;i++) {
56 asprintf(&fname, "\\%x", (int)random());
57 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
59 fprintf(stderr,"(%s) Failed to open %s\n",
63 smbcli_close(cli->tree, fnum);
67 printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
68 printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
69 printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
71 printf("dirtest core %g seconds\n", timeval_elapsed(&tv));
74 for (i=0;i<torture_numops;i++) {
76 asprintf(&fname, "\\%x", (int)random());
77 smbcli_unlink(cli->tree, fname);
81 if (!torture_close_connection(cli)) {
85 printf("finished dirtest1\n");
90 BOOL torture_dirtest2(void)
93 struct smbcli_state *cli;
96 extern int torture_entries;
98 printf("starting dirtest2\n");
100 if (!torture_open_connection(&cli)) {
104 if (!torture_setup_dir(cli, "\\LISTDIR")) {
108 printf("Creating %d files\n", torture_entries);
110 /* Create torture_entries files and torture_entries directories. */
111 for (i=0;i<torture_entries;i++) {
113 asprintf(&fname, "\\LISTDIR\\f%d", i);
114 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
116 FILE_ATTRIBUTE_ARCHIVE,
117 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
118 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
120 fprintf(stderr,"(%s) Failed to open %s, error=%s\n",
121 __location__, fname, smbcli_errstr(cli->tree));
125 smbcli_close(cli->tree, fnum);
127 for (i=0;i<torture_entries;i++) {
129 asprintf(&fname, "\\LISTDIR\\d%d", i);
130 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
131 fprintf(stderr,"(%s) Failed to open %s, error=%s\n",
132 __location__, fname, smbcli_errstr(cli->tree));
138 /* Now ensure that doing an old list sees both files and directories. */
139 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
140 printf("num_seen = %d\n", num_seen );
141 /* We should see (torture_entries) each of files & directories + . and .. */
142 if (num_seen != (2*torture_entries)+2) {
144 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
145 __location__, (2*torture_entries)+2, num_seen);
149 /* Ensure if we have the "must have" bits we only see the
152 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
153 printf("num_seen = %d\n", num_seen );
154 if (num_seen != torture_entries+2) {
156 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
157 __location__, torture_entries+2, num_seen);
160 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
161 printf("num_seen = %d\n", num_seen );
162 if (num_seen != torture_entries) {
164 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
165 __location__, torture_entries, num_seen);
168 /* Delete everything. */
169 if (smbcli_deltree(cli->tree, "\\LISTDIR") == -1) {
170 fprintf(stderr,"(%s) Failed to deltree %s, error=%s\n", "\\LISTDIR",
171 __location__, smbcli_errstr(cli->tree));
176 printf("Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
177 printf("Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
178 printf("Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
181 if (!torture_close_connection(cli)) {
185 printf("finished dirtest1\n");