12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
19 #define NUM_THREADS 10
21 static void *thread_worker(void *arg)
25 (void) arg; /* unused */
27 for (i = 0; i < 1000; i++) {
30 s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
31 assert_return_code(s, errno);
39 static void test_threads_socket(void **state)
41 pthread_attr_t pthread_custom_attr;
42 pthread_t threads[NUM_THREADS];
45 (void) state; /* unused */
47 pthread_attr_init(&pthread_custom_attr);
49 for (i = 0; i < NUM_THREADS; i++) {
50 pthread_create(&threads[i],
56 for (i = 0; i < NUM_THREADS; i++) {
57 pthread_join(threads[i], NULL);
60 pthread_attr_destroy(&pthread_custom_attr);
66 const struct CMUnitTest thread_tests[] = {
67 cmocka_unit_test(test_threads_socket),
70 rc = cmocka_run_group_tests(thread_tests, NULL, NULL);