[comp.os.minix] V1.3 posting # 15 - test1.c and test3.c

ast@cs.vu.nl (Andy Tanenbaum) (06/13/88)

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 <signal.h>
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

bunda@cs.utexas.edu (John Bunda) (06/16/88)

This reminded me of a problem that I had with test5 when I first
got 1.2 running on my IBM PC (vanilla everything).  using the
shell script to run the tests, test5 would hang and never come back.
i was able to interrupt it.  it was repeatable.  I then ran test5
directly (not using the script), and it passed, and thereafter would
work using the script.  I talked to someone else who had a similar
problem.  Since I've had too many other things going, I haven't looked
into it.

John


-- 
................................................................
John Bunda            UT CS Dept.      The proof is trivial, and
bunda@cs.utexas.edu   Austin, Texas    left as an exercise.

roskos@csed-1.IDA.ORG (Eric Roskos) (06/24/88)

> Test 5 would hang and never come back.

I reported a bug with this about 6 months ago, when I first tried running the
tests on version 1.2.  The problem was caused by the wrong field name being
used in one of the messages being passed between mm and the clock task.  If
I remember correctly, it is because line 6706 uses m_sig.PROC_NR (which is
field m2_i2) and line 3156 uses m_ptr->CLOCK_PROC_NR, which is field
m6_i1.  This caused all alarm signals to get sent to the wrong process.
I don't have the diff listing any more, but I think I just changed line 
6706 to m_sig.CLOCK_PROC_NR and it fixed it.  It took a couple of days to
track it down.
-- 
Eric Roskos, IDA (...daitc!csed-1!roskos, or csed-1!roskos@DAITC.ARPA, or
		     Roskos@DOCKMASTER.ARPA)

"... should have risen as noiselessly as the sun out of the sea, and
     we sailors have found ourselves steering between the tropics as if
     the broad day had lasted forever.  You know how the sun comes up 
     from the sea when you stand on the cliff, and doesn't startle you,
     but every thing, and you too are helping it."