diff options
author | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 15:34:30 -0500 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 15:34:30 -0500 |
commit | e5a951325a6cac8567af3a66de6d2df577508ae4 (patch) | |
tree | 34da9fe59f3c2d7f8edb072144443a9704197831 /source3/tests | |
parent | 57482469b32645250e92a7ffd003aeeb4a42235e (diff) | |
download | samba-e5a951325a6cac8567af3a66de6d2df577508ae4.tar.gz samba-e5a951325a6cac8567af3a66de6d2df577508ae4.tar.xz samba-e5a951325a6cac8567af3a66de6d2df577508ae4.zip |
[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
(This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab)
Diffstat (limited to 'source3/tests')
-rw-r--r-- | source3/tests/crypttest.c | 6 | ||||
-rw-r--r-- | source3/tests/fcntl_lock.c | 10 | ||||
-rw-r--r-- | source3/tests/fcntl_lock64.c | 12 | ||||
-rw-r--r-- | source3/tests/ftruncate.c | 4 | ||||
-rw-r--r-- | source3/tests/getgroups.c | 14 | ||||
-rw-r--r-- | source3/tests/os2_delete.c | 214 | ||||
-rw-r--r-- | source3/tests/shared_mmap.c | 16 | ||||
-rw-r--r-- | source3/tests/summary.c | 1 | ||||
-rw-r--r-- | source3/tests/trivial.c | 1 | ||||
-rw-r--r-- | source3/tests/unixsock.c | 21 |
10 files changed, 250 insertions, 49 deletions
diff --git a/source3/tests/crypttest.c b/source3/tests/crypttest.c index ee5a23235ed..0e500d54817 100644 --- a/source3/tests/crypttest.c +++ b/source3/tests/crypttest.c @@ -813,7 +813,7 @@ main() if((strcmp(c_out1, expected_out) != 0) && (strcmp(c_out2, expected_out) == 0)) - return 1; + exit(1); #ifdef HAVE_BIGCRYPT /* @@ -842,10 +842,10 @@ main() if((strcmp(big_c_out1, big_expected_out) != 0) && (strcmp(big_c_out2, big_expected_out) == 0)) - return 1; + exit(1); } #endif - return 0; + exit(0); } diff --git a/source3/tests/fcntl_lock.c b/source3/tests/fcntl_lock.c index 728f94b6122..3dc12a38973 100644 --- a/source3/tests/fcntl_lock.c +++ b/source3/tests/fcntl_lock.c @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) if (fd == -1) { fprintf(stderr,"ERROR: failed to open %s (errno=%d)\n", DATA, (int)errno); - return 1; + exit(1); } lock.l_type = F_WRLCK; @@ -74,9 +74,9 @@ int main(int argc, char *argv[]) if ((ret == -1) || (lock.l_type == F_UNLCK)) { fprintf(stderr,"ERROR: lock test failed (ret=%d errno=%d)\n", ret, (int)errno); - return 1; + exit(1); } else { - return 0; + exit(0); } } @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) if (fd == -1) { fprintf(stderr,"ERROR: failed to open %s (errno=%d)\n", DATA, (int)errno); - return 1; + exit(1); } lock.l_type = F_WRLCK; @@ -117,5 +117,5 @@ int main(int argc, char *argv[]) status); } - return status; + exit(status); } diff --git a/source3/tests/fcntl_lock64.c b/source3/tests/fcntl_lock64.c index b218fa9282e..e5ecd88fd04 100644 --- a/source3/tests/fcntl_lock64.c +++ b/source3/tests/fcntl_lock64.c @@ -16,10 +16,6 @@ #include <sys/fcntl.h> #endif -#ifdef HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif - #include <errno.h> static int sys_waitpid(pid_t pid,int *status,int options) @@ -44,7 +40,7 @@ int main(int argc, char *argv[]) sleep(2); fd = open64(DATA, O_RDONLY); - if (fd == -1) return 1; + if (fd == -1) exit(1); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; @@ -60,10 +56,10 @@ int main(int argc, char *argv[]) if ((ret == -1) || (lock.l_type == F_UNLCK)) { /* printf("No lock conflict\n"); */ - return 1; + exit(1); } else { /* printf("lock conflict\n"); */ - return 0; + exit(0); } } @@ -96,5 +92,5 @@ int main(int argc, char *argv[]) unlink(DATA); - return status; + exit(status); } diff --git a/source3/tests/ftruncate.c b/source3/tests/ftruncate.c index 700d5c8ce54..93282782eed 100644 --- a/source3/tests/ftruncate.c +++ b/source3/tests/ftruncate.c @@ -21,7 +21,7 @@ main() unlink(DATA); if (lseek(fd, 0, SEEK_END) == LEN) { - return 0; + exit(0); } - return 1; + exit(1); } diff --git a/source3/tests/getgroups.c b/source3/tests/getgroups.c index c73cd21650d..343fd5a184f 100644 --- a/source3/tests/getgroups.c +++ b/source3/tests/getgroups.c @@ -11,10 +11,6 @@ #include <unistd.h> #endif -#if defined(HAVE_STDLIB_H) -#include <stdlib.h> -#endif - #include <sys/types.h> #include <stdio.h> #include <unistd.h> @@ -30,7 +26,7 @@ main() if (sizeof(gid_t) == sizeof(int)) { fprintf(stderr,"gid_t and int are the same size\n"); - return 1; + exit(1); } if (ngroups <= 0) @@ -48,7 +44,7 @@ main() if (ngroups == 0) { printf("WARNING: can't determine getgroups return type\n"); - return 1; + exit(1); } cgroups = (char *)igroups; @@ -56,15 +52,15 @@ main() if (ngroups == 1 && cgroups[2] == 0x42 && cgroups[3] == 0x42) { fprintf(stderr,"getgroups returns gid_t\n"); - return 1; + exit(1); } for (i=0;i<ngroups;i++) { if (igroups[i] == 0x42424242) { fprintf(stderr,"getgroups returns gid_t\n"); - return 1; + exit(1); } } - return 0; + exit(0); } diff --git a/source3/tests/os2_delete.c b/source3/tests/os2_delete.c new file mode 100644 index 00000000000..b3aaf67f418 --- /dev/null +++ b/source3/tests/os2_delete.c @@ -0,0 +1,214 @@ +/* + 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 index 6af9ba0b394..fcef75d0d61 100644 --- a/source3/tests/shared_mmap.c +++ b/source3/tests/shared_mmap.c @@ -22,7 +22,7 @@ main() int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666); int count=7; - if (fd == -1) return 1; + if (fd == -1) exit(1); for (i=0;i<10000;i++) { write(fd,&i,sizeof(i)); @@ -32,7 +32,7 @@ main() if (fork() == 0) { fd = open(DATA,O_RDWR); - if (fd == -1) return 1; + if (fd == -1) exit(1); buf = (int *)mmap(NULL, 10000*sizeof(int), (PROT_READ | PROT_WRITE), @@ -41,21 +41,21 @@ main() while (count-- && buf[9124] != 55732) sleep(1); - if (count <= 0) return 1; + if (count <= 0) exit(1); buf[1763] = 7268; - return 0; + exit(0); } fd = open(DATA,O_RDWR); - if (fd == -1) return 1; + 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) return 1; + if (buf == (int *)-1) exit(1); buf[9124] = 55732; @@ -63,6 +63,6 @@ main() unlink(DATA); - if (count > 0) return 0; - return 1; + if (count > 0) exit(0); + exit(1); } diff --git a/source3/tests/summary.c b/source3/tests/summary.c index c3da22f1708..8fcde7bd998 100644 --- a/source3/tests/summary.c +++ b/source3/tests/summary.c @@ -1,4 +1,3 @@ -#include <stdlib.h> #include <stdio.h> main() diff --git a/source3/tests/trivial.c b/source3/tests/trivial.c index ae368a13980..2723637a0ff 100644 --- a/source3/tests/trivial.c +++ b/source3/tests/trivial.c @@ -1,4 +1,3 @@ -#include <stdlib.h> main() { exit(0); diff --git a/source3/tests/unixsock.c b/source3/tests/unixsock.c index ba384ae3626..f2765d68f67 100644 --- a/source3/tests/unixsock.c +++ b/source3/tests/unixsock.c @@ -1,5 +1,4 @@ -/* - * -*- c-file-style: "linux" -*- +/* -*- c-file-style: "linux" -*- * * Try creating a Unix-domain socket, opening it, and reading from it. * The POSIX name for these is AF_LOCAL/PF_LOCAL. @@ -9,17 +8,15 @@ * on which they are broken under some conditions, such as RedHat 7.0 * (unpatched). We can't build WinBind there at the moment. * - * Martin Pool <mbp@samba.org>, June 2000. - */ + * Coding standard says to always use exit() for this, not return, so + * we do. + * + * Martin Pool <mbp@samba.org>, June 2000. */ /* TODO: Look for AF_LOCAL (most standard), AF_UNIX, and AF_FILE. */ #include <stdio.h> -#if defined(HAVE_UNISTD_H) -#include <unistd.h> -#endif - #ifdef HAVE_SYS_SOCKET_H # include <sys/socket.h> #endif @@ -51,7 +48,7 @@ static int bind_socket(char const *filename) /* Create the socket. */ if ((sock_fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { perror ("socket(PF_LOCAL, SOCK_STREAM)"); - return 1; + exit(1); } /* Bind a name to the socket. */ @@ -70,7 +67,7 @@ static int bind_socket(char const *filename) if (bind(sock_fd, (struct sockaddr *) &name, size) < 0) { perror ("bind"); - return 1; + exit(1); } return sock_fd; @@ -87,10 +84,10 @@ int main(void) alarm(15); /* secs */ if ((sock_fd = bind_socket(filename)) < 0) - return 1; + exit(1); /* the socket will be deleted when autoconf cleans up these files. */ - return 0; + exit(0); } |