summaryrefslogtreecommitdiff
path: root/source3/tests
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-07-29 03:08:05 +0000
committerAndrew Tridgell <tridge@samba.org>1998-07-29 03:08:05 +0000
commit64578c0589a3a741f81fb55c16eeb882128da00b (patch)
tree8b650156e44e4d39af8625185d857a88789b8074 /source3/tests
parentc48b3fce6be6d5d952cbcda0ddae223dda5a576f (diff)
downloadsamba-64578c0589a3a741f81fb55c16eeb882128da00b.tar.gz
samba-64578c0589a3a741f81fb55c16eeb882128da00b.tar.bz2
samba-64578c0589a3a741f81fb55c16eeb882128da00b.zip
merge from the autoconf2 branch to the main branch
(This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21)
Diffstat (limited to 'source3/tests')
-rw-r--r--source3/tests/README10
-rw-r--r--source3/tests/fcntl_lock.c78
-rw-r--r--source3/tests/ftruncate.c24
-rw-r--r--source3/tests/shared_mmap.c66
-rw-r--r--source3/tests/sysv_ipc.c66
-rw-r--r--source3/tests/trapdoor.c25
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);
+}