diff options
Diffstat (limited to 'source3/tests')
-rw-r--r-- | source3/tests/README | 10 | ||||
-rw-r--r-- | source3/tests/fcntl_lock.c | 78 | ||||
-rw-r--r-- | source3/tests/ftruncate.c | 24 | ||||
-rw-r--r-- | source3/tests/shared_mmap.c | 66 | ||||
-rw-r--r-- | source3/tests/sysv_ipc.c | 66 | ||||
-rw-r--r-- | source3/tests/trapdoor.c | 25 |
6 files changed, 269 insertions, 0 deletions
diff --git a/source3/tests/README b/source3/tests/README new file mode 100644 index 0000000000..cf1be8b00a --- /dev/null +++ b/source3/tests/README @@ -0,0 +1,10 @@ +This directory contains autoconf test programs that are too large to +comfortably fit in configure.in. + +These programs should test one feature of the OS and exit(0) if it +works or exit(1) if it doesn't work (do _not_ use return) + +The programs should be kept simple and to the point. Beautiful/fast +code is not necessary + + diff --git a/source3/tests/fcntl_lock.c b/source3/tests/fcntl_lock.c new file mode 100644 index 0000000000..c54479434e --- /dev/null +++ b/source3/tests/fcntl_lock.c @@ -0,0 +1,78 @@ +/* test whether fcntl locking works on this system */ + +#include <stdio.h> +#include <stdlib.h> + +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif + +#ifdef HAVE_SYS_FCNTL_H +#include <sys/fcntl.h> +#endif + +#include <errno.h> + +static int sys_waitpid(pid_t pid,int *status,int options) +{ +#ifdef HAVE_WAITPID + return waitpid(pid,status,options); +#else /* USE_WAITPID */ + return wait4(pid, status, options, NULL); +#endif /* USE_WAITPID */ +} + +#define DATA "conftest.fcntl" + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +/* lock a byte range in a open file */ +int main(int argc, char *argv[]) +{ + struct flock lock; + int fd, pid, ret, status=1; + + if (!(pid=fork())) { + sleep(2); + fd = open(DATA, O_RDONLY); + + if (fd == -1) exit(1); + + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 4; + lock.l_pid = getpid(); + + lock.l_type = F_WRLCK; + + /* check if a lock applies */ + ret = fcntl(fd,F_GETLK,&lock); + + if ((ret == -1) || + (lock.l_type == F_UNLCK)) { + exit(1); + } else { + exit(0); + } + } + + fd = open(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600); + + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 4; + lock.l_pid = getpid(); + + /* set a 4 byte write lock */ + fcntl(fd,F_SETLK,&lock); + + sys_waitpid(pid, &status, 0); + + unlink(DATA); + + exit(status); +} diff --git a/source3/tests/ftruncate.c b/source3/tests/ftruncate.c new file mode 100644 index 0000000000..8d5e8942e3 --- /dev/null +++ b/source3/tests/ftruncate.c @@ -0,0 +1,24 @@ +/* test whether ftruncte() can extend a file */ + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#define DATA "conftest.trunc" +#define LEN 7663 + +main() +{ + int *buf; + int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666); + + ftruncate(fd, LEN); + + unlink(DATA); + + if (lseek(fd, 0, SEEK_END) == LEN) { + exit(0); + } + exit(1); +} diff --git a/source3/tests/shared_mmap.c b/source3/tests/shared_mmap.c new file mode 100644 index 0000000000..fb8a2a32d5 --- /dev/null +++ b/source3/tests/shared_mmap.c @@ -0,0 +1,66 @@ +/* this tests whether we can use a shared writeable mmap on a file - + as needed for the mmap varient of FAST_SHARE_MODES */ + +#include <unistd.h> +#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, pid; + 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); +} diff --git a/source3/tests/sysv_ipc.c b/source3/tests/sysv_ipc.c new file mode 100644 index 0000000000..2374174e8f --- /dev/null +++ b/source3/tests/sysv_ipc.c @@ -0,0 +1,66 @@ +/* this tests whether we can use a sysv shared memory segment + as needed for the sysv varient of FAST_SHARE_MODES */ + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#define KEY 0x963796 +#define SIZE (32*1024) + +main() +{ + int id; + int *buf; + int count=7; + +#ifdef LINUX + if (sizeof(struct shmid_ds) == 52) { + printf("WARNING: You probably have a broken set of glibc2 include files - disabling sysv shared memory\n"); + exit(1); + } +#endif + + id = shmget(KEY, 0, 0); + if (id != -1) { + if (shmctl(id, IPC_RMID, 0) != 0) exit(1); + } + + if (fork() == 0) { + /* uggh - need locking */ + sleep(2); + + /* get an existing area */ + id = shmget(KEY, 0, 0); + if (id == -1) exit(1); + + buf = (int *)shmat(id, 0, 0); + if (buf == (int *)-1) exit(1); + + + while (count-- && buf[6124] != 55732) sleep(1); + + if (count <= 0) exit(1); + + buf[1763] = 7268; + exit(0); + } + + id = shmget(KEY, SIZE, IPC_CREAT | IPC_EXCL | 0600); + if (id == -1) exit(1); + + buf = (int *)shmat(id, 0, 0); + + if (buf == (int *)-1) exit(1); + + buf[6124] = 55732; + + while (count-- && buf[1763] != 7268) sleep(1); + + shmctl(id, IPC_RMID, 0); + + if (count <= 0) exit(1); + exit(0); +} diff --git a/source3/tests/trapdoor.c b/source3/tests/trapdoor.c new file mode 100644 index 0000000000..83e10d0613 --- /dev/null +++ b/source3/tests/trapdoor.c @@ -0,0 +1,25 @@ +/* test for a trapdoor uid system */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> + +main() +{ + if (getuid() != 0) { + fprintf(stderr,"ERROR: This test must be run as root - assuming non-trapdoor system\n"); + exit(0); + } + + if (seteuid(1) != 0) exit(1); + if (geteuid() != 1) exit(1); + if (seteuid(0) != 0) exit(1); + if (geteuid() != 0) exit(1); + + if (setegid(1) != 0) exit(1); + if (getegid() != 1) exit(1); + if (setegid(0) != 0) exit(1); + if (getegid() != 0) exit(1); + + exit(0); +} |