By Hans-Christian Egtvedt (hans-christian.egtvedt AT atmel.com):
strace.c: suppress "warning: unused static" message by adding #ifdef's around a variable .gitignore: trivial test/*.c: cleanup (suppress warnings, much better style).
This commit is contained in:
parent
4dedd561d6
commit
8ed5727642
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
*~
|
||||
*.o
|
||||
.deps
|
||||
.libs
|
||||
.*.swp
|
||||
|
||||
Makefile
|
||||
Makefile.in
|
||||
|
3
strace.c
3
strace.c
@ -108,8 +108,9 @@ int not_failing_only = 0;
|
||||
static int exit_code = 0;
|
||||
static int strace_child = 0;
|
||||
static int ptrace_stop_sig = SIGTRAP;
|
||||
#if defined LINUX && (defined PTRACE_SETOPTIONS || defined PT_SETOPTIONS)
|
||||
static bool ptrace_opts_set;
|
||||
|
||||
#endif
|
||||
static char *username = NULL;
|
||||
uid_t run_uid;
|
||||
gid_t run_gid;
|
||||
|
@ -13,47 +13,48 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static void *start0 (void *arg)
|
||||
static void *start0(void *arg)
|
||||
{
|
||||
pause ();
|
||||
/* NOTREACHED */
|
||||
assert (0);
|
||||
pause();
|
||||
/* NOTREACHED */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t thread0;
|
||||
int i;
|
||||
pid_t child, got_pid;
|
||||
int status;
|
||||
pthread_t thread0;
|
||||
pid_t child, got_pid;
|
||||
int status;
|
||||
int i;
|
||||
|
||||
child = fork ();
|
||||
switch (child)
|
||||
{
|
||||
case -1:
|
||||
assert (0);
|
||||
case 0:
|
||||
i = pthread_create (&thread0, NULL, start0, NULL);
|
||||
assert (i == 0);
|
||||
/* The thread must be initialized, it becomes thread-child of this
|
||||
process-child (child of a child of the toplevel process). */
|
||||
sleep (1);
|
||||
/* Here the child TCB cannot be deallocated as there still exist
|
||||
* children (the thread child in START0). */
|
||||
exit (42);
|
||||
/* NOTREACHED */
|
||||
assert (0);
|
||||
default:
|
||||
/* We must not be waiting in WAITPID when the child double-exits. */
|
||||
sleep (2);
|
||||
/* PID must be -1. */
|
||||
got_pid = waitpid (-1, &status, 0);
|
||||
assert (got_pid == child);
|
||||
assert (WIFEXITED (status));
|
||||
assert (WEXITSTATUS (status) == 42);
|
||||
puts ("OK");
|
||||
exit (0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
assert (0);
|
||||
child = fork();
|
||||
|
||||
switch(child) {
|
||||
case -1:
|
||||
assert(0);
|
||||
case 0:
|
||||
i = pthread_create(&thread0, NULL, start0, NULL);
|
||||
assert(i == 0);
|
||||
/* The thread must be initialized, it becomes thread-child of this
|
||||
process-child (child of a child of the toplevel process). */
|
||||
sleep(1);
|
||||
/* Here the child TCB cannot be deallocated as there still exist
|
||||
* children (the thread child in START0). */
|
||||
exit(42);
|
||||
/* NOTREACHED */
|
||||
assert(0);
|
||||
default:
|
||||
/* We must not be waiting in WAITPID when the child double-exits. */
|
||||
sleep(2);
|
||||
/* PID must be -1. */
|
||||
got_pid = waitpid(-1, &status, 0);
|
||||
assert(got_pid == child);
|
||||
assert(WIFEXITED(status));
|
||||
assert(WEXITSTATUS(status) == 42);
|
||||
puts("OK");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* NOTREACHED */
|
||||
assert(0);
|
||||
}
|
||||
|
13
test/clone.c
13
test/clone.c
@ -1,15 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sched.h>
|
||||
|
||||
int child(void* arg) {
|
||||
write(1, "clone\n", 6);
|
||||
return 0;
|
||||
int child(void* arg)
|
||||
{
|
||||
write(1, "clone\n", 6);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char stack[4096];
|
||||
char stack[4096];
|
||||
clone(child, stack+4000, CLONE_VM|CLONE_FS|CLONE_FILES, NULL);
|
||||
write(1, "original\n", 9);
|
||||
exit(0);
|
||||
|
10
test/fork.c
10
test/fork.c
@ -1,10 +1,14 @@
|
||||
main()
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (fork() == 0)
|
||||
if (fork() == 0) {
|
||||
write(1, "child\n", 6);
|
||||
else {
|
||||
} else {
|
||||
wait(0);
|
||||
write(1, "parent\n", 7);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -13,52 +13,52 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static void *start0 (void *arg)
|
||||
static void *start0(void *arg)
|
||||
{
|
||||
sleep (1);
|
||||
|
||||
exit (42);
|
||||
sleep(1);
|
||||
exit(42);
|
||||
}
|
||||
|
||||
static void *start1 (void *arg)
|
||||
static void *start1(void *arg)
|
||||
{
|
||||
pause ();
|
||||
/* NOTREACHED */
|
||||
assert (0);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
pthread_t thread0;
|
||||
pthread_t thread1;
|
||||
int i;
|
||||
pid_t child, got_pid;
|
||||
int status;
|
||||
|
||||
sleep (2);
|
||||
|
||||
child = fork ();
|
||||
switch (child)
|
||||
{
|
||||
case -1:
|
||||
abort ();
|
||||
case 0:
|
||||
i = pthread_create (&thread0, NULL, start0, NULL);
|
||||
assert (i == 0);
|
||||
i = pthread_create (&thread1, NULL, start1, NULL);
|
||||
assert (i == 0);
|
||||
pause ();
|
||||
pause();
|
||||
/* NOTREACHED */
|
||||
assert (0);
|
||||
break;
|
||||
default:
|
||||
got_pid = waitpid (child, &status, 0);
|
||||
assert (got_pid == child);
|
||||
assert (WIFEXITED (status));
|
||||
assert (WEXITSTATUS (status) == 42);
|
||||
puts ("OK");
|
||||
exit (0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
abort ();
|
||||
assert(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t thread0;
|
||||
pthread_t thread1;
|
||||
pid_t child, got_pid;
|
||||
int status;
|
||||
int i;
|
||||
|
||||
sleep(2);
|
||||
|
||||
child = fork();
|
||||
|
||||
switch(child) {
|
||||
case -1:
|
||||
abort();
|
||||
case 0:
|
||||
i = pthread_create(&thread0, NULL, start0, NULL);
|
||||
assert(i == 0);
|
||||
i = pthread_create(&thread1, NULL, start1, NULL);
|
||||
assert(i == 0);
|
||||
pause();
|
||||
/* NOTREACHED */
|
||||
assert(0);
|
||||
break;
|
||||
default:
|
||||
got_pid = waitpid(child, &status, 0);
|
||||
assert(got_pid == child);
|
||||
assert(WIFEXITED(status));
|
||||
assert(WEXITSTATUS(status) == 42);
|
||||
puts("OK");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* NOTREACHED */
|
||||
abort();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ static void *sub_thd(void *c)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
pthread_t *thd;
|
||||
@ -28,10 +28,12 @@ int main(int argc, char **argv)
|
||||
|
||||
thd = malloc(num_threads * sizeof(thd[0]));
|
||||
fprintf(stderr, "test start, num_threads:%d...\n", num_threads);
|
||||
|
||||
for (i = 0; i < num_threads; i++) {
|
||||
pthread_create(&thd[i], NULL, sub_thd, NULL);
|
||||
fprintf(stderr, "after pthread_create\n");
|
||||
}
|
||||
|
||||
/* Exit. This kills all threads */
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <sys/procfs.h>
|
||||
#include <sys/stropts.h>
|
||||
#include <poll.h>
|
||||
main()
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int pid;
|
||||
char proc[32];
|
||||
@ -14,17 +16,24 @@ main()
|
||||
pause();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sprintf(proc, "/proc/%d", pid);
|
||||
|
||||
if ((pfp = fopen(proc, "r+")) == NULL)
|
||||
goto fail;
|
||||
|
||||
if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
|
||||
goto fail;
|
||||
|
||||
pfd.fd = fileno(pfp);
|
||||
pfd.events = POLLPRI;
|
||||
|
||||
if (poll(&pfd, 1, 0) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(pfd.revents & POLLPRI))
|
||||
goto fail;
|
||||
|
||||
kill(pid, SIGKILL);
|
||||
exit(0);
|
||||
fail:
|
||||
|
11
test/sfd.c
11
test/sfd.c
@ -1,6 +1,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
main(int argc, char *argv[])
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int pid = atoi(argv[1]);
|
||||
int sfd;
|
||||
@ -11,22 +12,28 @@ main(int argc, char *argv[])
|
||||
int signal, blocked, ignore, caught;
|
||||
|
||||
sprintf(sname, "/proc/%d/stat", pid);
|
||||
|
||||
if ((sfd = open(sname, O_RDONLY)) == -1) {
|
||||
perror(sname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
i = read(sfd, buf, 1024);
|
||||
buf[i] = '\0';
|
||||
|
||||
for (i = 0, s = buf; i < 30; i++) {
|
||||
while (*++s != ' ') {
|
||||
if (!*s)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
|
||||
fprintf(stderr, "/proc/pid/stat format error\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
16
test/sig.c
16
test/sig.c
@ -1,16 +1,18 @@
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
main()
|
||||
|
||||
void interrupt()
|
||||
{
|
||||
write(2, "xyzzy\n", 6);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buf[1024];
|
||||
void interrupt();
|
||||
|
||||
signal(SIGINT, interrupt);
|
||||
read(0, buf, 1024);
|
||||
write(2, "qwerty\n", 7);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
interrupt()
|
||||
{
|
||||
write(2, "xyzzy\n", 6);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
/* This test is not yet added to Makefile */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
static const struct sockaddr sa;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int loops;
|
||||
int pid;
|
||||
@ -24,7 +26,10 @@ int main(int argc, char **argv)
|
||||
|
||||
while (--loops >= 0) {
|
||||
pid = fork();
|
||||
if (pid < 0) _exit(1);
|
||||
|
||||
if (pid < 0)
|
||||
exit(1);
|
||||
|
||||
if (!pid) {
|
||||
/* child */
|
||||
int child = getpid();
|
||||
@ -32,12 +37,16 @@ int main(int argc, char **argv)
|
||||
loops = 99;
|
||||
while (--loops) {
|
||||
pid = fork();
|
||||
if (pid < 0) _exit(1);
|
||||
|
||||
if (pid < 0)
|
||||
exit(1);
|
||||
|
||||
if (!pid) {
|
||||
/* grandchild: kill child */
|
||||
kill(child, SIGKILL);
|
||||
_exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Add various syscalls you want to test here.
|
||||
* strace will decode them and suddenly find
|
||||
* process disappearing.
|
||||
@ -47,16 +56,23 @@ int main(int argc, char **argv)
|
||||
* decode syscall number before process dies.
|
||||
*/
|
||||
switch (loops & 1) {
|
||||
case 0: /* empty */ break;
|
||||
case 1: sendto(-1, "Hello cruel world", 17, 0, &sa, sizeof(sa)); break;
|
||||
case 0:
|
||||
break; /* intentional empty */
|
||||
case 1:
|
||||
sendto(-1, "Hello cruel world", 17, 0, &sa, sizeof(sa));
|
||||
break;
|
||||
}
|
||||
|
||||
/* kill grandchild */
|
||||
kill(pid, SIGKILL);
|
||||
}
|
||||
_exit(0);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* parent */
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,28 +6,33 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *c = (char*)0x94000000;
|
||||
int fd;
|
||||
open( "/tmp/delme", O_RDWR );
|
||||
mmap( c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0 );
|
||||
*c = 0;
|
||||
if (fork()) {
|
||||
while(1) {
|
||||
strcpy( c, "/etc/passwd" );
|
||||
strcpy( c, "/etc/shadow" );
|
||||
}
|
||||
} else
|
||||
while (1)
|
||||
if ((fd=open( c, 0 ))!=-1)
|
||||
close(fd);
|
||||
return 0;
|
||||
/* XXX: x86 specific stuff? */
|
||||
char *c = (char*) 0x94000000;
|
||||
int fd;
|
||||
|
||||
open("/tmp/delme", O_RDWR);
|
||||
mmap(c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0);
|
||||
*c = 0;
|
||||
|
||||
if (fork()) {
|
||||
while(1) {
|
||||
strcpy(c, "/etc/passwd");
|
||||
strcpy(c, "/etc/shadow");
|
||||
}
|
||||
} else {
|
||||
while (1)
|
||||
if ((fd = open(c, 0)) != -1)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
10
test/vfork.c
10
test/vfork.c
@ -1,10 +1,14 @@
|
||||
main()
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (vfork() == 0)
|
||||
if (vfork() == 0) {
|
||||
write(1, "child\n", 6);
|
||||
else {
|
||||
} else {
|
||||
wait(0);
|
||||
write(1, "parent\n", 7);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user