summaryrefslogtreecommitdiff
path: root/src/test/test-loop-block.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-04-05 18:09:10 +0200
committerLennart Poettering <lennart@poettering.net>2022-04-07 18:55:58 +0200
commitda9ae8ea6c3d1c05ec171e4472669c61b43b65d8 (patch)
treea83d9f1a9f8db32c2cb5f15324f0f62d9c0139fb /src/test/test-loop-block.c
parent7ffc7f3fcc86260417a7b09bd40f9c517da371df (diff)
downloadsystemd-da9ae8ea6c3d1c05ec171e4472669c61b43b65d8.tar.gz
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.
Diffstat (limited to 'src/test/test-loop-block.c')
-rw-r--r--src/test/test-loop-block.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c
index 9c8c55bca2..54f5d28da7 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.");