Browse Source

regression testing for longjmp and libthread, both kind of messy at this point, yet useful.

Change-Id: Ie6efc97c21a105f5f57ebf6646c3168219a0104a
Aki Nyrhinen 8 years ago
parent
commit
fb59738e42
3 changed files with 111 additions and 2 deletions
  1. 48 0
      sys/src/regress/longjmp.c
  2. 3 2
      sys/src/regress/regress.json
  3. 60 0
      sys/src/regress/thread.c

+ 48 - 0
sys/src/regress/longjmp.c

@@ -0,0 +1,48 @@
+
+#include <u.h>
+#include <libc.h>
+
+enum {
+	Njmps = 10000
+};
+
+void foo(void);
+
+int
+main(void)
+{
+	int i, njmp;
+	int fail = 0;
+	jmp_buf label;
+
+	njmp = 0;
+	while((njmp = setjmp(label)) < Njmps)
+		longjmp(label, njmp+1);
+
+	for(i = 0; i < nelem(label); i++)
+		fprint(2, "label[%d] = %p\n", i, label[i]);
+	fprint(2, "main: %p foo: %p\n", main, foo);
+
+	if(njmp != Njmps)
+		fail++;
+	if(label[JMPBUFPC] < main)
+		fail++;
+	if(label[JMPBUFPC] > foo)
+		fail++;
+	if(label[JMPBUFSP] > &label[nelem(label)])
+		fail++;
+	if(label[JMPBUFSP] < 0x7fffffd00000)
+		fail++;
+
+	if(fail == 0){
+		print("PASS\n");
+		exits("PASS");
+	}
+	print("FAIL\n");
+	exits("FAIL");
+}
+
+void
+foo(void)
+{
+}

+ 3 - 2
sys/src/regress/regress.json

@@ -5,8 +5,9 @@
     "SourceFilesCmd": [
 	"iphash.c",
 	"privates.c",
-	"fork.c"
-
+	"fork.c",
+	"thread.c",
+	"longjmp.c"
     ],
     "Install": "/$ARCH/bin/regress"
 }

+ 60 - 0
sys/src/regress/thread.c

@@ -0,0 +1,60 @@
+
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+
+enum
+{
+	STACK = 2048,
+};
+
+void
+clockproc(void *arg)
+{
+	int t;
+	Channel *c;
+
+	c = arg;
+	for(t=0;; t++){
+		sleep(100);
+		sendul(c, t);
+	}
+}
+
+
+void
+threadmain(int argc, char *argv[])
+{
+	int tick, tock;
+	Alt a[] = {
+		{nil, &tick, CHANRCV},
+		{nil, &tock, CHANRCV},
+		{nil, nil, CHANEND},
+	};
+
+	fprint(2, "threadmain hi!\n");
+
+	a[0].c = chancreate(sizeof tick, 0);
+	a[1].c = chancreate(sizeof tock, 0);
+
+	proccreate(clockproc, a[0].c, STACK);
+	proccreate(clockproc, a[1].c, STACK);
+
+	tick = 0;
+	tock = 0;
+	while(tick < 10 || tock < 10){
+		switch(alt(a)){
+		case 0:
+			fprint(2, "tick %d\n", tick);
+			break;
+		case 1:
+			fprint(2, "tock %d\n", tock);
+			break;
+		default:
+			sysfatal("can't happen");
+		}
+	}
+
+	print("PASS\n");
+	exits("PASS");
+}