test_shutdown_stress_tipc.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "testutil.hpp"
4 #include "testutil_unity.hpp"
5 
6 #include <pthread.h>
7 
8 void setUp ()
9 {
10 }
11 
12 void tearDown ()
13 {
14 }
15 
16 #define THREAD_COUNT 100
17 
18 extern "C" {
19 static void *worker (void *ctx)
20 {
21  void *s = zmq_socket (ctx, ZMQ_SUB);
22  TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (s, "tipc://{5560,0}@0.0.0"));
23 
24  // Start closing the socket while the connecting process is underway.
26 
27  return NULL;
28 }
29 }
30 
32 {
33  void *s1;
34  int i;
35  int j;
36  pthread_t threads[THREAD_COUNT];
37 
38  for (j = 0; j != 10; j++) {
39  // Check the shutdown with many parallel I/O threads.
42 
44 
45  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s1, "tipc://{5560,0,0}"));
46 
47  for (i = 0; i != THREAD_COUNT; i++) {
49  pthread_create (&threads[i], NULL, worker, get_test_context ()));
50  }
51 
52  for (i = 0; i != THREAD_COUNT; i++) {
53  TEST_ASSERT_SUCCESS_RAW_ERRNO (pthread_join (threads[i], NULL));
54  }
55 
57 
59  }
60 }
61 
62 int main ()
63 {
64  if (!is_tipc_available ()) {
65  printf ("TIPC environment unavailable, skipping test\n");
66  return 77;
67  }
68 
69  UNITY_BEGIN ();
71  return UNITY_END ();
72 }
zmq_ctx_set
ZMQ_EXPORT int zmq_ctx_set(void *context_, int option_, int optval_)
Definition: zmq.cpp:156
NULL
NULL
Definition: test_security_zap.cpp:405
UNITY_END
return UNITY_END()
ZMQ_PUB
#define ZMQ_PUB
Definition: zmq.h:259
tearDown
void tearDown()
Definition: test_shutdown_stress_tipc.cpp:12
s
XmlRpcServer s
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
setup_test_context
void setup_test_context()
Definition: testutil_unity.cpp:179
teardown_test_context
void teardown_test_context()
Definition: testutil_unity.cpp:189
get_test_context
void * get_test_context()
Definition: testutil_unity.cpp:184
ZMQ_SUB
#define ZMQ_SUB
Definition: zmq.h:260
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
THREAD_COUNT
#define THREAD_COUNT
Definition: test_shutdown_stress_tipc.cpp:16
testutil_unity.hpp
setUp
void setUp()
Definition: test_shutdown_stress_tipc.cpp:8
TEST_ASSERT_SUCCESS_RAW_ERRNO
#define TEST_ASSERT_SUCCESS_RAW_ERRNO(expr)
Definition: testutil_unity.hpp:69
testutil.hpp
worker
static void * worker(void *ctx)
Definition: test_shutdown_stress_tipc.cpp:19
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
zmq_socket
ZMQ_EXPORT void * zmq_socket(void *, int type_)
Definition: zmq.cpp:230
is_tipc_available
int is_tipc_available()
Definition: testutil.cpp:283
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
zmq_close
ZMQ_EXPORT int zmq_close(void *s_)
Definition: zmq.cpp:241
i
int i
Definition: gmock-matchers_test.cc:764
UNITY_BEGIN
UNITY_BEGIN()
ZMQ_IO_THREADS
#define ZMQ_IO_THREADS
Definition: zmq.h:181
main
int main()
Definition: test_shutdown_stress_tipc.cpp:62
test_context_socket_close
void * test_context_socket_close(void *socket_)
Definition: testutil_unity.cpp:208
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47
test_shutdown_stress_tipc
void test_shutdown_stress_tipc()
Definition: test_shutdown_stress_tipc.cpp:31


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59