This test fails on aarch64 until we fix broken 
setjmp/longjmp/sigsetjmp/siglongjmp
for aarch64.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 modules/tests/Makefile |  2 +-
 tests/tst-setjmp.cc    | 59 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 tests/tst-setjmp.cc

diff --git a/modules/tests/Makefile b/modules/tests/Makefile
index d18bac5d..be59f427 100644
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -177,7 +177,7 @@ tests := tst-pthread.so misc-ramdisk.so tst-vblk.so 
tst-bsd-evh.so \
        tst-sigaltstack.so tst-fread.so tst-tcp-cork.so tst-tcp-v6.so \
        tst-calloc.so tst-crypt.so tst-non-fpic.so tst-small-malloc.so \
        tst-getopt.so tst-getopt-pie.so tst-non-pie.so tst-semaphore.so \
-       tst-elf-init.so tst-realloc.so
+       tst-elf-init.so tst-realloc.so tst-setjmp.so
 #      libstatic-thread-variable.so tst-static-thread-variable.so \
 
 #TODO For now let us disable these tests for aarch64 until
diff --git a/tests/tst-setjmp.cc b/tests/tst-setjmp.cc
new file mode 100644
index 00000000..932f5621
--- /dev/null
+++ b/tests/tst-setjmp.cc
@@ -0,0 +1,59 @@
+#include <fenv.h>
+#include <__fenv.h>
+#include <signal.h>
+#include <assert.h>
+#include <setjmp.h>
+#include <math.h>
+
+#include <iostream>
+
+static int tests = 0, fails = 0;
+
+#define expect(actual, expected) do_expect(actual, expected, #actual, 
#expected, __FILE__, __LINE__)
+template<typename T>
+bool do_expect(T actual, T expected, const char *actuals, const char 
*expecteds, const char *file, int line)
+{
+    ++tests;
+    if (actual != expected) {
+        fails++;
+        std::cout << "FAIL: " << file << ":" << line << ": For " << actuals <<
+                ", expected " << expecteds << ", saw " << actual << ".\n";
+        return false;
+    }
+    return true;
+}
+
+//This is a simple test that verifies that setjmp/longjmp/sigsetjmp/siglongjmp
+//flow control works correctly.
+
+static jmp_buf env;
+bool setjmp_check() {
+    if (setjmp(env)) {
+        std::cout << "Back from longjmp()!\n";
+        return true;
+    }
+    std::cout << "After setjmp()!\n";
+    longjmp(env, 1);
+    return false;
+}
+
+static sigjmp_buf sig_env;
+bool sigsetjmp_check(int savesigs) {
+    if (sigsetjmp(sig_env, savesigs)) {
+        std::cout << "Back from siglongjmp()!\n";
+        return true;
+    }
+    std::cout << "After sigsetjmp()!\n";
+    siglongjmp(sig_env, 1);
+    return false;
+}
+
+int main(int argc, char **argv)
+{
+    expect(setjmp_check(), true);
+    expect(sigsetjmp_check(0), true);
+    expect(sigsetjmp_check(1), true);
+
+    std::cout << "SUMMARY: " << tests << " tests, " << fails << " failures\n";
+    return fails == 0 ? 0 : 1;
+}
-- 
2.26.2

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20201007163630.345711-1-jwkozaczuk%40gmail.com.

Reply via email to