Update release-README after completing the 2.43 release.
[binutils-gdb.git] / sim / testsuite / cris / c / clone1.c
blob9c4cca42545e09587dcd5ffb0929a0af5eaf959b
1 /*
2 #progos: linux
3 #output: got: a\nthen: bc\nexit: 0\n
4 */
6 /* This is a very limited subset of what ex1.c does; we just check that
7 thread creation (clone syscall) and pipe writes and reads work. */
9 #include <stddef.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sched.h>
14 #include <signal.h>
15 #include <sys/types.h>
16 #include <sys/wait.h>
18 int pip[2];
20 int
21 process (void *arg)
23 char *s = arg;
24 if (write (pip[1], s+2, 1) != 1) abort ();
25 if (write (pip[1], s+1, 1) != 1) abort ();
26 if (write (pip[1], s, 1) != 1) abort ();
27 return 0;
30 int
31 main (void)
33 int retcode;
34 int pid;
35 int st;
36 long stack[16384];
37 char buf[10] = {0};
39 retcode = pipe (pip);
41 if (retcode != 0)
43 fprintf (stderr, "Bad pipe %d\n", retcode);
44 abort ();
47 pid = clone (process, (char *) stack + sizeof (stack) - 64,
48 (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
49 | SIGCHLD, "cba");
50 if (pid <= 0)
52 fprintf (stderr, "Bad clone %d\n", pid);
53 abort ();
56 if ((retcode = read (pip[0], buf, 1)) != 1)
58 fprintf (stderr, "Bad read 1: %d\n", retcode);
59 abort ();
61 printf ("got: %c\n", buf[0]);
62 retcode = read (pip[0], buf, 2);
63 if (retcode == 1)
65 retcode = read (pip[0], buf+1, 1);
66 if (retcode != 1)
68 fprintf (stderr, "Bad read 1.5: %d\n", retcode);
69 abort ();
71 retcode = 2;
73 if (retcode != 2)
75 fprintf (stderr, "Bad read 2: %d\n", retcode);
76 abort ();
79 printf ("then: %s\n", buf);
80 retcode = wait4 (-1, &st, WNOHANG | __WCLONE, NULL);
82 if (retcode != pid || !WIFEXITED (st))
84 fprintf (stderr, "Bad wait %d %x\n", retcode, st);
85 abort ();
88 printf ("exit: %d\n", WEXITSTATUS (st));
89 return 0;