Browse Source

Add in a setjmp test from David Schleef

Eric Andersen 24 years ago
parent
commit
162b5c1c0a
2 changed files with 57 additions and 0 deletions
  1. 22 0
      test/setjmp/Makefile
  2. 35 0
      test/setjmp/setjmp_test.c

+ 22 - 0
test/setjmp/Makefile

@@ -0,0 +1,22 @@
+TESTDIR=../
+include $(TESTDIR)/Rules.mak
+
+
+TARGETS=setjmp_test
+all: $(TARGETS)
+
+setjmp_test: setjmp_test.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(TESTCC)
+	-@ echo "-------"
+	-@ echo " "
+	-@ echo "Compiling vs uClibc: "
+	-@ echo " "
+	$(TESTCC) $(CFLAGS) -c $< -o $@.o
+	$(TESTCC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
+	$(STRIPTOOL) -x -R .note -R .comment $@
+	-./$@
+	-@ echo " "
+
+clean:
+	rm -f *.[oa] *~ core $(TARGETS)
+
+

+ 35 - 0
test/setjmp/setjmp_test.c

@@ -0,0 +1,35 @@
+
+#include <stdio.h>
+#include <setjmp.h>
+#include <unistd.h>
+
+
+jmp_buf jb;
+int tries=0;
+
+int main(int argc,char *argv[])
+{
+	int ret;
+
+	printf("calling setjmp, should return with 0\n");
+
+	ret = setjmp(jb);
+	
+	printf("setjmp returned %d\n",ret);
+
+	if(!ret){
+		if(tries++>4){
+			printf("Hmmm... in loop, must be broken.\n");
+			return 0;
+		}
+		printf("now calling longjmp, setjmp should return with 1\n");
+
+		longjmp(jb,1);
+
+		printf("returned from longjmp, must be broken\n");
+		return 0;
+	}
+
+	return 0;
+}
+