MAINTAINERS: List rusty and tridge as maintainers for talloc.
[Samba.git] / source4 / torture / basic / dir.c
blob2024f4c30c1081f8ac7b7a35fe6d86cdb3856c7b
1 /*
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/libcli.h"
24 #include "torture/util.h"
25 #include "system/filesys.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(struct torture_context *tctx,
36 struct smbcli_state *cli)
38 int i;
39 int fnum;
40 bool correct = true;
41 extern int torture_numops;
42 struct timeval tv;
44 torture_comment(tctx, "Creating %d random filenames\n", torture_numops);
46 srandom(0);
47 tv = timeval_current();
48 for (i=0;i<torture_numops;i++) {
49 char *fname;
50 asprintf(&fname, "\\%x", (int)random());
51 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
52 if (fnum == -1) {
53 fprintf(stderr,"(%s) Failed to open %s\n",
54 __location__, fname);
55 return false;
57 smbcli_close(cli->tree, fnum);
58 free(fname);
61 torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
62 torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
63 torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
65 torture_comment(tctx, "dirtest core %g seconds\n", timeval_elapsed(&tv));
67 srandom(0);
68 for (i=0;i<torture_numops;i++) {
69 char *fname;
70 asprintf(&fname, "\\%x", (int)random());
71 smbcli_unlink(cli->tree, fname);
72 free(fname);
75 return correct;
78 bool torture_dirtest2(struct torture_context *tctx,
79 struct smbcli_state *cli)
81 int i;
82 int fnum, num_seen;
83 bool correct = true;
84 extern int torture_entries;
86 if (!torture_setup_dir(cli, "\\LISTDIR")) {
87 return false;
90 torture_comment(tctx, "Creating %d files\n", torture_entries);
92 /* Create torture_entries files and torture_entries directories. */
93 for (i=0;i<torture_entries;i++) {
94 char *fname;
95 asprintf(&fname, "\\LISTDIR\\f%d", i);
96 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
97 SEC_RIGHTS_FILE_ALL,
98 FILE_ATTRIBUTE_ARCHIVE,
99 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
100 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
101 if (fnum == -1) {
102 fprintf(stderr,"(%s) Failed to open %s, error=%s\n",
103 __location__, fname, smbcli_errstr(cli->tree));
104 return false;
106 free(fname);
107 smbcli_close(cli->tree, fnum);
109 for (i=0;i<torture_entries;i++) {
110 char *fname;
111 asprintf(&fname, "\\LISTDIR\\d%d", i);
112 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) {
113 fprintf(stderr,"(%s) Failed to open %s, error=%s\n",
114 __location__, fname, smbcli_errstr(cli->tree));
115 return false;
117 free(fname);
120 /* Now ensure that doing an old list sees both files and directories. */
121 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
122 torture_comment(tctx, "num_seen = %d\n", num_seen );
123 /* We should see (torture_entries) each of files & directories + . and .. */
124 if (num_seen != (2*torture_entries)+2) {
125 correct = false;
126 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
127 __location__, (2*torture_entries)+2, num_seen);
131 /* Ensure if we have the "must have" bits we only see the
132 * relevant entries.
134 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
135 torture_comment(tctx, "num_seen = %d\n", num_seen );
136 if (num_seen != torture_entries+2) {
137 correct = false;
138 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
139 __location__, torture_entries+2, num_seen);
142 num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
143 torture_comment(tctx, "num_seen = %d\n", num_seen );
144 if (num_seen != torture_entries) {
145 correct = false;
146 fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n",
147 __location__, torture_entries, num_seen);
150 /* Delete everything. */
151 if (smbcli_deltree(cli->tree, "\\LISTDIR") == -1) {
152 fprintf(stderr,"(%s) Failed to deltree %s, error=%s\n", "\\LISTDIR",
153 __location__, smbcli_errstr(cli->tree));
154 return false;
157 #if 0
158 torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL));
159 torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL));
160 torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL));
161 #endif
163 return correct;