Skip to contentSkip to conversation

tests/tcg/multiarch/testthread.c: Add pthread_cancel test

PATCH In review Taylor Simpson 2 participants 2 messages Jan 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tests/tcg/multiarch/testthread.c: Add pthread_cancel test

---
 tests/tcg/multiarch/testthread.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
tests/tcg/multiarch/testthread.c +22 -0
index 810ba5d..0da1f61 100644
@@ -50,8 +50,30 @@ void test_pthread(void)
     printf("End of pthread test.\n");
 }
 
+void *thread3_func(void *arg)
+{
+    usleep(3 * 1000);
+    return 0;
+}
+
+void test_cancel(void)
+{
+    pthread_t thread;
+    void *res;
+
+    pthread_create(&thread, 0, thread3_func, NULL);
+    pthread_cancel(thread);
+    pthread_join(thread, &res);
+    if (res != PTHREAD_CANCELED) {
+        puts("ERROR: thread not cancelled");
+        exit(EXIT_FAILURE);
+    }
+    printf("End of pthread_cancel test.\n");
+}
+
 int main(int argc, char **argv)
 {
     test_pthread();
+    test_cancel();
     return 0;
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Taylor Simpson

What's the motivation for adding this test? Did we have a bug we fixed which this would be the regression test for? Some other reason why it seems like a good test case? This is the sort of thing that it's useful to put in the commit message...

thanks
-- PMM