From: Lennart Poettering Date: Tue, 5 Apr 2022 16:09:10 +0000 (+0200) Subject: test-loop-block: don't spawn threads in case N_THREADS is 1 X-Git-Tag: v251-rc2~165^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da9ae8ea6c3d1c05ec171e4472669c61b43b65d8;p=thirdparty%2Fsystemd.git test-loop-block: don't spawn threads in case N_THREADS is 1 Let's simplify things if we are only supposed to create a single thread. Makes it easier to debug things with gdb. --- diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c index 9c8c55bca29..54f5d28da7a 100644 --- a/src/test/test-loop-block.c +++ b/src/test/test-loop-block.c @@ -228,20 +228,26 @@ int main(int argc, char *argv[]) { slow_tests_enabled() ? 5 * USEC_PER_SEC : 1 * USEC_PER_SEC); - for (unsigned i = 0; i < N_THREADS; i++) - assert_se(pthread_create(threads + i, NULL, thread_func, FD_TO_PTR(fd)) == 0); + assert_cc(N_THREADS > 0); + + if (N_THREADS > 1) + for (unsigned i = 0; i < N_THREADS; i++) + assert_se(pthread_create(threads + i, NULL, thread_func, FD_TO_PTR(fd)) == 0); log_notice("All threads started now."); - for (unsigned i = 0; i < N_THREADS; i++) { - log_notice("Joining thread #%u.", i); + if (N_THREADS == 1) + assert_se(thread_func(FD_TO_PTR(fd)) == NULL); + else + for (unsigned i = 0; i < N_THREADS; i++) { + log_notice("Joining thread #%u.", i); - void *k; - assert_se(pthread_join(threads[i], &k) == 0); - assert_se(k == NULL); + void *k; + assert_se(pthread_join(threads[i], &k) == 0); + assert_se(k == NULL); - log_notice("Joined thread #%u.", i); - } + log_notice("Joined thread #%u.", i); + } log_notice("Threads are all terminated now.");