Path: utzoo!attcan!uunet!mcvax!botter!star.cs.vu.nl!ast@cs.vu.nl From: ast@cs.vu.nl (Andy Tanenbaum) Newsgroups: comp.os.minix Subject: V1.3 posting # 15 - test1.c and test3.c Message-ID: <800@ast.cs.vu.nl> Date: 12 Jun 88 20:10:07 GMT Sender: ast@cs.vu.nl Reply-To: ast@cs.vu.nl (Andy Tanenbaum) Organization: VU Informatica, Amsterdam Lines: 259 I have fixed some bugs is test/test1.c and test/test3.c. Here they are. The other test*c files are unchanged. Andy Tanenbaum (ast@cs.vu.nl) : This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb echo Extracting 'test1.c' sed 's/^X//' > 'test1.c' << '+ END-OF-FILE ''test1.c' X#include "signal.h" X Xint glov, gct; Xextern int errno; Xint errct; X#define SIGNUM 10 X X X Xmain() X{ X int i; X X printf("Test 1 "); X X for (i = 0; i < 15; i++) { X test10(); X test11(); X } X if (errct == 0) X printf("ok\n"); X else X printf(" %d errors\n", errct); X exit(0); X} X Xtest10() X{ X int i, n, pid; X X n = 4; X for (i = 0; i < n; i++) { X if ( (pid=fork()) ) { X if (pid < 0) { printf("\nTest 1 fork failed\n"); exit(1);} X parent(); X } else X child(i); X } X} X Xparent() X{ X X int n; X X n = getpid(); X wait(&n); X} X Xchild(i) Xint i; X{ X int n; X X n = getpid(); X exit(i); X} X Xtest11() X{ X int i, k, func(); X X for (i = 0; i < 4; i++) { X glov = 0; X signal(SIGNUM, func); X if ( (k=fork())) { X if (k < 0){printf("Test 1 fork failed\n"); exit(1);} X parent1(k); X } else X child1(k); X } X} X X Xparent1(childpid) Xint childpid; X{ X X int n; X X for (n = 0; n < 5000; n++) ; X while (kill(childpid, SIGNUM) < 0) /* null statement */ ; X wait(&n); X} X Xfunc() X{ X glov++; X gct++; X} Xchild1(k) Xint k; X{ X while (glov == 0) ; X exit(gct); X} X X X Xe(n) Xint n; X{ X printf("\nError %d errno=%d ", n, errno); X perror(""); X errct++; X} X X + END-OF-FILE test1.c chmod 'u=rw,g=r,o=r' 'test1.c' set `wc -c 'test1.c'` count=$1 case $count in 1116) :;; *) echo 'Bad character count in ''test1.c' >&2 echo 'Count should be 1116' >&2 esac echo Extracting 'test3.c' sed 's/^X//' > 'test3.c' << '+ END-OF-FILE ''test3.c' X#include Xint is, array[4]; Xint parsigs, parpid, parcum; Xint sigct, cumsig, errct; X Xmain() X{ X int i; X X printf("Test 3 "); X for (i = 0; i < 9; i++) { X test91(); X test92(); X } X if (cumsig != 9) e(3); X if (errct == 0) X printf("ok\n"); X else X printf("%d errors\n", errct); X} X X Xtest90() X{ X extern catch(); X X int n, pid; X X parpid = getpid(); X signal(10, catch); X X if (pid = fork()) { X while(parsigs == 0) ; X if (kill(pid, 9) < 0) e(1); X wait(&n); X if (n != 9) e(2); X } else { X kill(parpid, 10); X pause(); X } X} X X Xcatch() X{ X parsigs++; X parcum++; X} X Xe(n) Xint n; X{ X printf("Error %d ",n); X errct++; X perror(""); X} X X Xtest91() X{ X int fd[2], n, sigpip(); X char buf[4]; X X sigct = 0; X signal(SIGPIPE, sigpip); X pipe(fd); X if (fork()) { X /* Parent */ X close(fd[0]); X while (sigct == 0) { X write(fd[1], buf,1); X } X wait(&n); X } else { X /* Child */ X close(fd[0]); X close(fd[1]); X exit(0); X } X} X Xsigpip() X{ X sigct++; X cumsig++; X} X X Xtest92() X{ X int pid, n; X X signal(SIGINT, SIG_DFL); X is = 0; X if ((array[is++]=fork()) > 0) { X if ((array[is++]=fork()) > 0) { X if ((array[is++]=fork()) > 0) { X if ((array[is++]=fork()) > 0) { X signal(SIGINT, SIG_IGN); X kill(array[0], SIGINT); X kill(array[1], SIGINT); X kill(array[2], SIGINT); X kill(array[3], SIGINT); X wait(&n); X wait(&n); X wait(&n); X wait(&n); X } else { X pause(); X } X } else { X pause(); X } X } else { X pause(); X } X } else { X pause(); X } X} + END-OF-FILE test3.c chmod 'u=rw,g=r,o=r' 'test3.c' set `wc -c 'test3.c'` count=$1 case $count in 1461) :;; *) echo 'Bad character count in ''test3.c' >&2 echo 'Count should be 1461' >&2 esac exit 0