shithub: scc

Download patch

ref: 67b4a92153e09d3e2ad6a4cd26e64e7878054785
parent: aec67e43c52fcc1857d00d498d82189bbf0f680a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Sep 3 17:31:43 EDT 2018

[tests/libc] Add test 0008-longjmp

--- /dev/null
+++ b/tests/libc/execute/0008-longjmp.c
@@ -1,0 +1,45 @@
+#include <setjmp.h>
+#include <stdio.h>
+
+/*
+output:
+test 1
+i = 1, v = 2
+test 2
+i = 2, v = 3
+end:
+*/
+
+jmp_buf recover;
+
+void
+test(char *s, int val)
+{
+	puts(s);
+	longjmp(recover, val);
+}
+
+int
+main()
+{
+	static int i;
+	auto volatile int v;
+
+	i = 0;
+	v = 1;
+	if (!setjmp(recover)) {
+		i = 1;
+		v = 2;
+		test("test 1", 1);	
+	}
+	printf("i = %d, v = %d\n", i, v);
+
+	if (!setjmp(recover)) {
+		i = 2;
+		v = 3;
+		test("test 2", 0);
+	}
+	printf("i = %d, v = %d\n", i, v);
+
+	return 0;
+} 
--- a/tests/libc/execute/libc-tests.lst
+++ b/tests/libc/execute/libc-tests.lst
@@ -5,3 +5,4 @@
 0005-ctype
 0006-limits
 0007-signal
+0008-longjmp