2004-10-25 11:24:46 +04:00
/*
Unix SMB / CIFS implementation .
directory scanning tests
Copyright ( C ) Andrew Tridgell 2003
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-30 07:33:27 +03:00
# include "librpc/gen_ndr/ndr_security.h"
2004-10-25 11:24:46 +04:00
2004-11-02 15:15:17 +03:00
static void list_fn ( struct file_info * finfo , const char * name , void * state )
2004-10-25 11:24:46 +04:00
{
}
/*
test directory listing speed
*/
2004-10-28 17:40:50 +04:00
BOOL torture_dirtest1 ( void )
2004-10-25 11:24:46 +04:00
{
int i ;
struct smbcli_state * cli ;
int fnum ;
BOOL correct = True ;
extern int torture_numops ;
2004-11-03 13:09:48 +03:00
struct timeval tv ;
2004-10-25 11:24:46 +04:00
printf ( " starting dirtest1 \n " ) ;
if ( ! torture_open_connection ( & cli ) ) {
return False ;
}
printf ( " Creating %d random filenames \n " , torture_numops ) ;
srandom ( 0 ) ;
2004-11-03 13:09:48 +03:00
tv = timeval_current ( ) ;
2004-10-25 11:24:46 +04:00
for ( i = 0 ; i < torture_numops ; i + + ) {
char * fname ;
asprintf ( & fname , " \\ %x " , ( int ) random ( ) ) ;
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
if ( fnum = = - 1 ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to open %s \n " ,
__location__ , fname ) ;
2004-10-25 11:24:46 +04:00
return False ;
}
smbcli_close ( cli - > tree , fnum ) ;
free ( fname ) ;
}
printf ( " Matched %d \n " , smbcli_list ( cli - > tree , " a*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , smbcli_list ( cli - > tree , " b*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , smbcli_list ( cli - > tree , " xyzabc " , 0 , list_fn , NULL ) ) ;
2004-11-03 13:09:48 +03:00
printf ( " dirtest core %g seconds \n " , timeval_elapsed ( & tv ) ) ;
2004-10-25 11:24:46 +04:00
srandom ( 0 ) ;
for ( i = 0 ; i < torture_numops ; i + + ) {
char * fname ;
asprintf ( & fname , " \\ %x " , ( int ) random ( ) ) ;
smbcli_unlink ( cli - > tree , fname ) ;
free ( fname ) ;
}
if ( ! torture_close_connection ( cli ) ) {
correct = False ;
}
printf ( " finished dirtest1 \n " ) ;
return correct ;
}
2004-10-28 17:40:50 +04:00
BOOL torture_dirtest2 ( void )
2004-10-25 11:24:46 +04:00
{
int i ;
struct smbcli_state * cli ;
int fnum , num_seen ;
BOOL correct = True ;
extern int torture_entries ;
printf ( " starting dirtest2 \n " ) ;
if ( ! torture_open_connection ( & cli ) ) {
return False ;
}
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , " \\ LISTDIR " ) ) {
2004-10-25 11:24:46 +04:00
return False ;
}
printf ( " Creating %d files \n " , torture_entries ) ;
/* Create torture_entries files and torture_entries directories. */
for ( i = 0 ; i < torture_entries ; i + + ) {
char * fname ;
asprintf ( & fname , " \\ LISTDIR \\ f%d " , i ) ;
2004-11-30 07:33:27 +03:00
fnum = smbcli_nt_create_full ( cli - > tree , fname , 0 ,
SEC_RIGHTS_FULL_CONTROL ,
FILE_ATTRIBUTE_ARCHIVE ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-25 11:24:46 +04:00
if ( fnum = = - 1 ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to open %s, error=%s \n " ,
__location__ , fname , smbcli_errstr ( cli - > tree ) ) ;
2004-10-25 11:24:46 +04:00
return False ;
}
free ( fname ) ;
smbcli_close ( cli - > tree , fnum ) ;
}
for ( i = 0 ; i < torture_entries ; i + + ) {
char * fname ;
asprintf ( & fname , " \\ LISTDIR \\ d%d " , i ) ;
if ( NT_STATUS_IS_ERR ( smbcli_mkdir ( cli - > tree , fname ) ) ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to open %s, error=%s \n " ,
__location__ , fname , smbcli_errstr ( cli - > tree ) ) ;
2004-10-25 11:24:46 +04:00
return False ;
}
free ( fname ) ;
}
/* Now ensure that doing an old list sees both files and directories. */
num_seen = smbcli_list_old ( cli - > tree , " \\ LISTDIR \\ * " , FILE_ATTRIBUTE_DIRECTORY , list_fn , NULL ) ;
printf ( " num_seen = %d \n " , num_seen ) ;
/* We should see (torture_entries) each of files & directories + . and .. */
if ( num_seen ! = ( 2 * torture_entries ) + 2 ) {
correct = False ;
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) entry count mismatch, should be %d, was %d \n " ,
__location__ , ( 2 * torture_entries ) + 2 , num_seen ) ;
2004-10-25 11:24:46 +04:00
}
/* Ensure if we have the "must have" bits we only see the
* relevant entries .
*/
num_seen = smbcli_list_old ( cli - > tree , " \\ LISTDIR \\ * " , ( FILE_ATTRIBUTE_DIRECTORY < < 8 ) | FILE_ATTRIBUTE_DIRECTORY , list_fn , NULL ) ;
printf ( " num_seen = %d \n " , num_seen ) ;
if ( num_seen ! = torture_entries + 2 ) {
correct = False ;
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) entry count mismatch, should be %d, was %d \n " ,
__location__ , torture_entries + 2 , num_seen ) ;
2004-10-25 11:24:46 +04:00
}
num_seen = smbcli_list_old ( cli - > tree , " \\ LISTDIR \\ * " , ( FILE_ATTRIBUTE_ARCHIVE < < 8 ) | FILE_ATTRIBUTE_DIRECTORY , list_fn , NULL ) ;
printf ( " num_seen = %d \n " , num_seen ) ;
if ( num_seen ! = torture_entries ) {
correct = False ;
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) entry count mismatch, should be %d, was %d \n " ,
__location__ , torture_entries , num_seen ) ;
2004-10-25 11:24:46 +04:00
}
/* Delete everything. */
if ( smbcli_deltree ( cli - > tree , " \\ LISTDIR " ) = = - 1 ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to deltree %s, error=%s \n " , " \\ LISTDIR " ,
__location__ , smbcli_errstr ( cli - > tree ) ) ;
2004-10-25 11:24:46 +04:00
return False ;
}
#if 0
printf ( " Matched %d \n " , smbcli_list ( cli - > tree , " a*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , smbcli_list ( cli - > tree , " b*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , smbcli_list ( cli - > tree , " xyzabc " , 0 , list_fn , NULL ) ) ;
# endif
if ( ! torture_close_connection ( cli ) ) {
correct = False ;
}
printf ( " finished dirtest1 \n " ) ;
return correct ;
}