Removes side effects from asserts in tests/
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 1 Mar 2013 21:39:31 +0000 (13:39 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 1 Mar 2013 21:39:31 +0000 (13:39 -0800)
We shouldn't have necessary work happen inside assert(), in case we
optimize it later.

Plus we now have potential error messages when pthread_create fails, if
errno was set properly, which it isn't yet.  That's something we need to
fix in pthread code, instead of printing profanities.

tests/dtls_test.c
tests/pthread_test.c

index 2130968..1087fb2 100644 (file)
@@ -49,7 +49,8 @@ int main(int argc, char** argv)
     pthread_key_create(&pthread_keys[i], dtls_dtor);
   }
   for (int i = 0; i < NR_TEST_THREADS; i++) {
-       assert(!pthread_create(&my_threads[i], NULL, &thread, NULL));
+       if (pthread_create(&my_threads[i], NULL, &thread, NULL))
+               perror("pth_create failed");
   }
   for (int i = 0; i < NR_TEST_THREADS; i++) {
        pthread_join(my_threads[i], &my_retvals[i]);
index 9c07536..76d325c 100644 (file)
@@ -80,7 +80,8 @@ int main(int argc, char** argv)
        /* create and join on yield */
        for (int i = 0; i < nr_yield_threads; i++) {
                printf_safe("[A] About to create thread %d\n", i);
-               assert(!pthread_create(&my_threads[i], NULL, &yield_thread, NULL));
+               if (pthread_create(&my_threads[i], NULL, &yield_thread, NULL))
+                       perror("pth_create failed");
        }
        if (gettimeofday(&start_tv, 0))
                perror("Start time error...");