Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libc/harness/test_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@
return 1;
}

if (signalPost(getpid(), atoi(argv[1]), SIGUSR1) != -EINVAL) {
fprintf(stderr, "signalPost didn't return EINVAL, thread still running in exec'd process!\n");
if (sys_tkill(getpid(), atoi(argv[1]), SIGUSR1) != -EINVAL) {

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8r52-mps3an536-qemu)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m4-stm32l4x6-nucleo)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8m33-mcxn94x-frdm)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zturn)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-grfpga-artya7)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-generic-qemu)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]

Check failure on line 192 in libc/harness/test_exec.c

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr716-mimas)

implicit declaration of function 'sys_tkill' [-Wimplicit-function-declaration]
fprintf(stderr, "sys_tkill didn't return EINVAL, thread still running in exec'd process!\n");
return 1;
}
}
Expand Down
49 changes: 49 additions & 0 deletions libc/pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ static void *test_threadCleanup4(void *arg)
}


static void *test_threadCleanupCancel(void *arg)
{
int *val = (int *)arg;

pthread_cleanup_push(test_cleanupHandler1, val);
pthread_cleanup_push(test_cleanupHandler2, val);

pthread_mutex_lock(&thread_args.count_lock);
thread_args.count = 1;
pthread_cond_signal(&thread_args.count_nonzero); /* Signal that the thread is ready */
pthread_mutex_unlock(&thread_args.count_lock);

for (;;) {
sleep(1); /* Cancellation point */
}

pthread_cleanup_pop(0);
pthread_cleanup_pop(0);

return NULL;
}


TEST_GROUP(test_pthread_cond);
TEST_GROUP(test_pthread_cleanup);

Expand Down Expand Up @@ -379,6 +402,31 @@ TEST(test_pthread_cleanup, pthread_cleanup_push_pop_exec_pthread_exit)
}


TEST(test_pthread_cleanup, pthread_cleanup_push_pthread_cancel)
{
pthread_t thread;
int val = 42;

TEST_ASSERT_EQUAL(0, pthread_mutex_init(&thread_args.count_lock, NULL));
TEST_ASSERT_EQUAL(0, pthread_cond_init(&thread_args.count_nonzero, NULL));
thread_args.count = 0;

TEST_ASSERT_EQUAL_INT(0, pthread_create(&thread, NULL, test_threadCleanupCancel, &val));

pthread_mutex_lock(&thread_args.count_lock);
while (thread_args.count == 0) {
/* Wait for thread to enter the loop */
pthread_cond_wait(&thread_args.count_nonzero, &thread_args.count_lock);
}
pthread_mutex_unlock(&thread_args.count_lock);

TEST_ASSERT_EQUAL_INT(0, pthread_cancel(thread));
TEST_ASSERT_EQUAL_INT(0, pthread_join(thread, NULL));

TEST_ASSERT_EQUAL(42 * 3 * 2, val);
}


TEST_GROUP_RUNNER(test_pthread_cond)
{
RUN_TEST_CASE(test_pthread_cond, pthread_cond_init);
Expand All @@ -399,4 +447,5 @@ TEST_GROUP_RUNNER(test_pthread_cleanup)
RUN_TEST_CASE(test_pthread_cleanup, pthread_cleanup_push_pop_no_exec);
RUN_TEST_CASE(test_pthread_cleanup, pthread_cleanup_push_pop_exec);
RUN_TEST_CASE(test_pthread_cleanup, pthread_cleanup_push_pop_exec_pthread_exit);
RUN_TEST_CASE(test_pthread_cleanup, pthread_cleanup_push_pthread_cancel);
}
Loading
Loading