diff options
Diffstat (limited to 'source3/tests')
-rw-r--r-- | source3/tests/os2_delete.c | 214 | ||||
-rw-r--r-- | source3/tests/shared_mmap.c | 68 |
2 files changed, 0 insertions, 282 deletions
diff --git a/source3/tests/os2_delete.c b/source3/tests/os2_delete.c deleted file mode 100644 index b3aaf67f41..0000000000 --- a/source3/tests/os2_delete.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - test readdir/unlink pattern that OS/2 uses - tridge@samba.org July 2005 -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <dirent.h> -#include <errno.h> -#include <string.h> -#include <fcntl.h> - -#define NUM_FILES 700 -#define READDIR_SIZE 100 -#define DELETE_SIZE 4 - -#define TESTDIR "test.dir" - -#define FAILED(d) (fprintf(stderr, "Failed for %s - %s\n", d, strerror(errno)), exit(1), 1) - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -static void cleanup(void) -{ - /* I'm a lazy bastard */ - system("rm -rf " TESTDIR); - mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir"); -} - -static void create_files() -{ - int i; - for (i=0;i<NUM_FILES;i++) { - char fname[40]; - sprintf(fname, TESTDIR "/test%u.txt", i); - close(open(fname, O_CREAT|O_RDWR, 0600)) == 0 || FAILED("close"); - } -} - -static int os2_delete(DIR *d) -{ - off_t offsets[READDIR_SIZE]; - int i, j; - struct dirent *de; - char names[READDIR_SIZE][30]; - - /* scan, remembering offsets */ - for (i=0, de=readdir(d); - de && i < READDIR_SIZE; - de=readdir(d), i++) { - offsets[i] = telldir(d); - strcpy(names[i], de->d_name); - } - - if (i == 0) { - return 0; - } - - /* delete the first few */ - for (j=0; j<MIN(i, DELETE_SIZE); j++) { - char fname[40]; - sprintf(fname, TESTDIR "/%s", names[j]); - unlink(fname) == 0 || FAILED("unlink"); - } - - /* seek to just after the deletion */ - seekdir(d, offsets[j-1]); - - /* return number deleted */ - return j; -} - -int main(void) -{ - int total_deleted = 0; - DIR *d; - struct dirent *de; - - cleanup(); - create_files(); - - d = opendir(TESTDIR); - - /* skip past . and .. */ - de = readdir(d); - strcmp(de->d_name, ".") == 0 || FAILED("match ."); - de = readdir(d); - strcmp(de->d_name, "..") == 0 || FAILED("match .."); - - while (1) { - int n = os2_delete(d); - if (n == 0) break; - total_deleted += n; - } - closedir(d); - - printf("Deleted %d files of %d\n", total_deleted, NUM_FILES); - - rmdir(TESTDIR) == 0 || FAILED("rmdir"); - - return 0; -} -/* - test readdir/unlink pattern that OS/2 uses - tridge@samba.org July 2005 -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <dirent.h> -#include <errno.h> -#include <string.h> -#include <fcntl.h> - -#define NUM_FILES 700 -#define READDIR_SIZE 100 -#define DELETE_SIZE 4 - -#define TESTDIR "test.dir" - -#define FAILED(d) (fprintf(stderr, "Failed for %s - %s\n", d, strerror(errno)), exit(1), 1) - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -static void cleanup(void) -{ - /* I'm a lazy bastard */ - system("rm -rf " TESTDIR); - mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir"); -} - -static void create_files() -{ - int i; - for (i=0;i<NUM_FILES;i++) { - char fname[40]; - sprintf(fname, TESTDIR "/test%u.txt", i); - close(open(fname, O_CREAT|O_RDWR, 0600)) == 0 || FAILED("close"); - } -} - -static int os2_delete(DIR *d) -{ - off_t offsets[READDIR_SIZE]; - int i, j; - struct dirent *de; - char names[READDIR_SIZE][30]; - - /* scan, remembering offsets */ - for (i=0, de=readdir(d); - de && i < READDIR_SIZE; - de=readdir(d), i++) { - offsets[i] = telldir(d); - strcpy(names[i], de->d_name); - } - - if (i == 0) { - return 0; - } - - /* delete the first few */ - for (j=0; j<MIN(i, DELETE_SIZE); j++) { - char fname[40]; - sprintf(fname, TESTDIR "/%s", names[j]); - unlink(fname) == 0 || FAILED("unlink"); - } - - /* seek to just after the deletion */ - seekdir(d, offsets[j-1]); - - /* return number deleted */ - return j; -} - -int main(void) -{ - int total_deleted = 0; - DIR *d; - struct dirent *de; - - cleanup(); - create_files(); - - d = opendir(TESTDIR); - - /* skip past . and .. */ - de = readdir(d); - strcmp(de->d_name, ".") == 0 || FAILED("match ."); - de = readdir(d); - strcmp(de->d_name, "..") == 0 || FAILED("match .."); - - while (1) { - int n = os2_delete(d); - if (n == 0) break; - total_deleted += n; - } - closedir(d); - - printf("Deleted %d files of %d\n", total_deleted, NUM_FILES); - - rmdir(TESTDIR) == 0 || FAILED("rmdir"); - - return 0; -} diff --git a/source3/tests/shared_mmap.c b/source3/tests/shared_mmap.c deleted file mode 100644 index fcef75d0d6..0000000000 --- a/source3/tests/shared_mmap.c +++ /dev/null @@ -1,68 +0,0 @@ -/* this tests whether we can use a shared writeable mmap on a file - - as needed for the mmap varient of FAST_SHARE_MODES */ - -#if defined(HAVE_UNISTD_H) -#include <unistd.h> -#endif -#include <sys/mman.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#define DATA "conftest.mmap" - -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif - -main() -{ - int *buf; - int i; - int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666); - int count=7; - - if (fd == -1) exit(1); - - for (i=0;i<10000;i++) { - write(fd,&i,sizeof(i)); - } - - close(fd); - - if (fork() == 0) { - fd = open(DATA,O_RDWR); - if (fd == -1) exit(1); - - buf = (int *)mmap(NULL, 10000*sizeof(int), - (PROT_READ | PROT_WRITE), - MAP_FILE | MAP_SHARED, - fd, 0); - - while (count-- && buf[9124] != 55732) sleep(1); - - if (count <= 0) exit(1); - - buf[1763] = 7268; - exit(0); - } - - fd = open(DATA,O_RDWR); - if (fd == -1) exit(1); - - buf = (int *)mmap(NULL, 10000*sizeof(int), - (PROT_READ | PROT_WRITE), - MAP_FILE | MAP_SHARED, - fd, 0); - - if (buf == (int *)-1) exit(1); - - buf[9124] = 55732; - - while (count-- && buf[1763] != 7268) sleep(1); - - unlink(DATA); - - if (count > 0) exit(0); - exit(1); -} |