| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
directory scanning tests |
| 5 |
|
| 6 |
Copyright (C) Andrew Tridgell 2003 |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "includes.h" |
| 23 |
#include "libcli/libcli.h" |
| 24 |
#include "torture/util.h" |
| 25 |
#include "system/filesys.h" |
| 26 |
#include "torture/basic/proto.h" |
| 27 |
|
| 28 |
static void list_fn(struct clilist_file_info *finfo, const char *name, void *state) |
| 29 |
{ |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
/* |
| 34 |
test directory listing speed |
| 35 |
*/ |
| 36 |
bool torture_dirtest1(struct torture_context *tctx, |
| 37 |
struct smbcli_state *cli) |
| 38 |
{ |
| 39 |
int i; |
| 40 |
int fnum; |
| 41 |
bool correct = true; |
| 42 |
extern int torture_numops; |
| 43 |
struct timeval tv; |
| 44 |
int ret; |
| 45 |
|
| 46 |
torture_comment(tctx, "Creating %d random filenames\n", torture_numops); |
| 47 |
|
| 48 |
srandom(0); |
| 49 |
tv = timeval_current(); |
| 50 |
for (i=0;i<torture_numops;i++) { |
| 51 |
char *fname; |
| 52 |
ret = asprintf(&fname, "\\%x", (int)random()); |
| 53 |
torture_assert(tctx, ret != -1, "asprintf failed"); |
| 54 |
fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); |
| 55 |
if (fnum == -1) { |
| 56 |
fprintf(stderr,"(%s) Failed to open %s\n", |
| 57 |
__location__, fname); |
| 58 |
return false; |
| 59 |
} |
| 60 |
smbcli_close(cli->tree, fnum); |
| 61 |
free(fname); |
| 62 |
} |
| 63 |
|
| 64 |
torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); |
| 65 |
torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); |
| 66 |
torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); |
| 67 |
|
| 68 |
torture_comment(tctx, "dirtest core %g seconds\n", timeval_elapsed(&tv)); |
| 69 |
|
| 70 |
srandom(0); |
| 71 |
for (i=0;i<torture_numops;i++) { |
| 72 |
char *fname; |
| 73 |
ret = asprintf(&fname, "\\%x", (int)random()); |
| 74 |
torture_assert(tctx, ret != -1, "asprintf failed"); |
| 75 |
smbcli_unlink(cli->tree, fname); |
| 76 |
free(fname); |
| 77 |
} |
| 78 |
|
| 79 |
return correct; |
| 80 |
} |
| 81 |
|
| 82 |
bool torture_dirtest2(struct torture_context *tctx, |
| 83 |
struct smbcli_state *cli) |
| 84 |
{ |
| 85 |
int i; |
| 86 |
int fnum, num_seen; |
| 87 |
bool correct = true; |
| 88 |
extern int torture_entries; |
| 89 |
int ret; |
| 90 |
|
| 91 |
if (!torture_setup_dir(cli, "\\LISTDIR")) { |
| 92 |
return false; |
| 93 |
} |
| 94 |
|
| 95 |
torture_comment(tctx, "Creating %d files\n", torture_entries); |
| 96 |
|
| 97 |
/* Create torture_entries files and torture_entries directories. */ |
| 98 |
for (i=0;i<torture_entries;i++) { |
| 99 |
char *fname; |
| 100 |
ret = asprintf(&fname, "\\LISTDIR\\f%d", i); |
| 101 |
torture_assert(tctx, ret != -1, "asprintf failed"); |
| 102 |
fnum = smbcli_nt_create_full(cli->tree, fname, 0, |
| 103 |
SEC_RIGHTS_FILE_ALL, |
| 104 |
FILE_ATTRIBUTE_ARCHIVE, |
| 105 |
NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, |
| 106 |
NTCREATEX_DISP_OVERWRITE_IF, 0, 0); |
| 107 |
if (fnum == -1) { |
| 108 |
fprintf(stderr,"(%s) Failed to open %s, error=%s\n", |
| 109 |
__location__, fname, smbcli_errstr(cli->tree)); |
| 110 |
return false; |
| 111 |
} |
| 112 |
free(fname); |
| 113 |
smbcli_close(cli->tree, fnum); |
| 114 |
} |
| 115 |
for (i=0;i<torture_entries;i++) { |
| 116 |
char *fname; |
| 117 |
ret = asprintf(&fname, "\\LISTDIR\\d%d", i); |
| 118 |
torture_assert(tctx, ret != -1, "asprintf failed"); |
| 119 |
if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, fname))) { |
| 120 |
fprintf(stderr,"(%s) Failed to open %s, error=%s\n", |
| 121 |
__location__, fname, smbcli_errstr(cli->tree)); |
| 122 |
return false; |
| 123 |
} |
| 124 |
free(fname); |
| 125 |
} |
| 126 |
|
| 127 |
/* Now ensure that doing an old list sees both files and directories. */ |
| 128 |
num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); |
| 129 |
torture_comment(tctx, "num_seen = %d\n", num_seen ); |
| 130 |
/* We should see (torture_entries) each of files & directories + . and .. */ |
| 131 |
if (num_seen != (2*torture_entries)+2) { |
| 132 |
correct = false; |
| 133 |
fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", |
| 134 |
__location__, (2*torture_entries)+2, num_seen); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
/* Ensure if we have the "must have" bits we only see the |
| 139 |
* relevant entries. |
| 140 |
*/ |
| 141 |
num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); |
| 142 |
torture_comment(tctx, "num_seen = %d\n", num_seen ); |
| 143 |
if (num_seen != torture_entries+2) { |
| 144 |
correct = false; |
| 145 |
fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", |
| 146 |
__location__, torture_entries+2, num_seen); |
| 147 |
} |
| 148 |
|
| 149 |
num_seen = smbcli_list_old(cli->tree, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL); |
| 150 |
torture_comment(tctx, "num_seen = %d\n", num_seen ); |
| 151 |
if (num_seen != torture_entries) { |
| 152 |
correct = false; |
| 153 |
fprintf(stderr,"(%s) entry count mismatch, should be %d, was %d\n", |
| 154 |
__location__, torture_entries, num_seen); |
| 155 |
} |
| 156 |
|
| 157 |
/* Delete everything. */ |
| 158 |
if (smbcli_deltree(cli->tree, "\\LISTDIR") == -1) { |
| 159 |
fprintf(stderr,"(%s) Failed to deltree %s, error=%s\n", "\\LISTDIR", |
| 160 |
__location__, smbcli_errstr(cli->tree)); |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
#if 0 |
| 165 |
torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); |
| 166 |
torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); |
| 167 |
torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); |
| 168 |
#endif |
| 169 |
|
| 170 |
return correct; |
| 171 |
} |