Pārlūkot izejas kodu

[LibOS/regression] Add futex-timeout test

Before PR #554, futex() syscall incorrectly failed
if user-supplied timeout expired (also see PR #438).
This patch adds test on futex() with timeout.
Dmitrii Kuvaiskii 6 gadi atpakaļ
vecāks
revīzija
402020f8da

+ 9 - 0
LibOS/shim/test/regression/30_futex.py

@@ -11,3 +11,12 @@ regression.add_check(name="Futex Wake Test",
 
 rv = regression.run_checks()
 if rv: sys.exit(rv)
+
+# Running futex-timeout
+regression = Regression(loader, "futex-timeout")
+
+regression.add_check(name="Futex Timeout Test",
+    check=lambda res: "futex correctly timed out" in res[0].out)
+
+rv = regression.run_checks()
+if rv: sys.exit(rv)

+ 24 - 0
LibOS/shim/test/regression/futex-timeout.c

@@ -0,0 +1,24 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <linux/futex.h>
+#include <sys/time.h>
+#include <errno.h>
+
+int main (int argc, const char** argv) {
+    int myfutex = 0;
+    int ret;
+
+    struct timespec t = {
+        .tv_sec = 1,
+        .tv_nsec = 0
+    };
+
+    puts("invoke futex syscall with 1-second timeout");
+    ret = syscall(SYS_futex, &myfutex, FUTEX_WAIT, 0, &t, NULL, 0);
+    if (ret == -1 && errno == ETIMEDOUT) {
+        puts("futex correctly timed out");
+    }
+
+    return 0;
+}