A regression test for clone(2).
This commit is contained in:
parent
da2e0bfb7c
commit
a018252ace
18
regress/lib/libc/clone/Makefile
Normal file
18
regress/lib/libc/clone/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# $NetBSD: Makefile,v 1.1 2001/07/17 23:58:30 thorpej Exp $
|
||||
|
||||
MKMAN=no
|
||||
|
||||
PROG= clonetest
|
||||
COPTS+=-g
|
||||
|
||||
WARNS?= 1
|
||||
|
||||
regress:
|
||||
@if ./clonetest; then \
|
||||
echo PASSED; \
|
||||
else \
|
||||
echo FAILED; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.include <bsd.prog.mk>
|
79
regress/lib/libc/clone/clonetest.c
Normal file
79
regress/lib/libc/clone/clonetest.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* $NetBSD: clonetest.c,v 1.1 2001/07/17 23:58:30 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Jason R. Thorpe, July 16, 2001.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/wait.h>
|
||||
#include <err.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int newclone(void *);
|
||||
|
||||
int main(int, char *[]);
|
||||
|
||||
#define STACKSIZE (8 * 1024)
|
||||
|
||||
#define FROBVAL 41973
|
||||
#define CHILDEXIT 0xa5
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
void *stack;
|
||||
__volatile int frobme = 0;
|
||||
pid_t pid;
|
||||
int stat;
|
||||
|
||||
stack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_PRIVATE|MAP_ANON, -1, (off_t) 0);
|
||||
if (stack == MAP_FAILED)
|
||||
err(1, "mmap stack");
|
||||
|
||||
/*
|
||||
* XXX FIX ME FOR UPWARD-GROWING STACK
|
||||
*/
|
||||
stack = (caddr_t) stack + STACKSIZE;
|
||||
|
||||
printf("parent: stack = %p\n", stack);
|
||||
fflush(stdout);
|
||||
|
||||
pid = __clone(newclone, stack,
|
||||
CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD,
|
||||
(void *) &frobme);
|
||||
if (pid == -1)
|
||||
err(1, "clone");
|
||||
|
||||
while (waitpid(pid, &stat, 0) != pid)
|
||||
/* spin */ ;
|
||||
|
||||
if (WIFEXITED(stat) == 0)
|
||||
errx(1, "child didn't exit\n");
|
||||
|
||||
printf("parent: childexit = 0x%x frobme = %d\n",
|
||||
WEXITSTATUS(stat), frobme);
|
||||
|
||||
if (WEXITSTATUS(stat) != CHILDEXIT || frobme != FROBVAL)
|
||||
exit(1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
newclone(void *arg)
|
||||
{
|
||||
int *frobp = arg;
|
||||
|
||||
printf("child: stack ~= %p\n", &frobp);
|
||||
fflush(stdout);
|
||||
|
||||
*frobp = FROBVAL;
|
||||
|
||||
return (CHILDEXIT);
|
||||
}
|
Loading…
Reference in New Issue
Block a user