]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-loop-block: don't spawn threads in case N_THREADS is 1
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Apr 2022 16:09:10 +0000 (18:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Apr 2022 16:55:58 +0000 (18:55 +0200)
Let's simplify things if we are only supposed to create a single thread.
Makes it easier to debug things with gdb.

src/test/test-loop-block.c

index 9c8c55bca29cea488ab5c6d5c0931ef42d65cb03..54f5d28da7a5e2f3153671519803d3cf095f160f 100644 (file)
@@ -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.");