Guest User

pubsub-duplicate.c

a guest
Jan 19th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.69 KB | None | 0 0
  1. /**
  2.  * @file testsPubSub.c
  3.  *
  4.  * @brief Implements tests for the PUB-SUB pattern.
  5.  */
  6.  
  7. #define _BSD_SOURCE // TODO: required for usleep()
  8.  
  9. /***********************************************************
  10.  * INCLUDES
  11.  ***********************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdint.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. #include <pthread.h>
  18. #include <signal.h>
  19. #include <unistd.h>
  20.  
  21. #include <zmq.h>
  22.  
  23. /***********************************************************
  24.  * SWITCHES
  25.  ***********************************************************/
  26.  
  27. /**
  28.  * Defines if debug output is generated. Output is generated
  29.  * on stderr. Possible values are:
  30.  *  - 0: no debug output
  31.  *  - 1: generate debug output
  32.  *
  33.  * @see DPRINTF()
  34.  */
  35. #define USE_DPRINTF 1
  36.  
  37. /**
  38.  * Defines which type of communication is used. Possible
  39.  * values are:
  40.  *  - 0: inproc (inter-thread communication)
  41.  *  - 1: ipc (inter-process communication)
  42.  *  - 2: tcp (TCP/IP sockets)
  43.  *
  44.  * @see ENDPOINT_FORMAT_STRING
  45.  */
  46. #define TYPE_SOCKET 1
  47.  
  48. /**
  49.  * The number of main loops are executed by the clients.
  50.  * Must be a positive number.
  51.  */
  52. #define COUNT_LOOPS 3
  53.  
  54. /**
  55.  * The number of endpoints used by some tests. That means
  56.  * both the number of servers and the number of clients
  57.  * generated for 1 to n, n to 1 or n to m tests. Must be
  58.  * a positive number.
  59.  * @see SERVER_MAX
  60.  * @see CLIENT_MAX
  61.  * @see REQUESTER_MAX
  62.  */
  63. #define COUNT_ENDPOINTS 3
  64.  
  65. /**
  66.  * The number of microseconds used to simulate a busy
  67.  * server and to delay the response messages. Must be zero
  68.  * for no delay or a positive number.
  69.  */
  70. #define SERVER_BUSY_MICROSECS (0 * 1000)
  71.  
  72. /**
  73.  * The number of microseconds used to delay server before
  74.  * closing a socket. Required, because subscibers will
  75.  * lose last messages. Must be zero for no delay
  76.  * or a positive number.
  77.  */
  78. #define SERVER_CLEANUP_MICROSECS (10 * 1000)
  79.  
  80. /**
  81.  * The number of microseconds used to delay server after
  82.  * creating a socket. Required, because subscibers will
  83.  * lose first messages. Must be zero for no delay
  84.  * or a positive number.
  85.  */
  86. #define CLIENT_STARTUP_MICROSECS (500 * 1000)
  87.  
  88. /***********************************************************
  89.  * COMMON DEFINITIONS
  90.  ***********************************************************/
  91.  
  92. #ifndef FALSE
  93. /**
  94.  * Standard value for false, if not defined already.
  95.  * @see TRUE
  96.  */
  97. #define FALSE 0
  98. #endif
  99.  
  100. #ifndef TRUE
  101. /**
  102.  * Standard value for true, if not defined already.
  103.  * @see FALSE
  104.  */
  105. #define TRUE (!FALSE)
  106. #endif
  107.  
  108. #if (TYPE_SOCKET == 0)
  109.   /**
  110.    * The format string used for inproc communication.
  111.    * @see TYPE_SOCKET
  112.    */
  113.   #define ENDPOINT_FORMAT_STRING "inproc://inproc-%d"
  114. #elif (TYPE_SOCKET == 1)
  115.   /**
  116.    * The format string used for ipc communication.
  117.    * @see TYPE_SOCKET
  118.    */
  119.   #define ENDPOINT_FORMAT_STRING "ipc://ipc-%d.ipc"
  120. #elif (TYPE_SOCKET == 2)
  121.   /**
  122.    * The format string used for tcp communication.
  123.    * @see TYPE_SOCKET
  124.    */
  125.   #define ENDPOINT_FORMAT_STRING "tcp://%s:%d"
  126. #else
  127.   #error Wrong value for socket type, must be in [0, 2]
  128. #endif
  129.  
  130. /**
  131.  * The maximum number of servers used by some tests. Some tests
  132.  * uses a single server and some test uses this maximum number
  133.  * of servers.
  134.  * @see COUNT_ENDPOINTS
  135.  */
  136. #define SERVER_MAX COUNT_ENDPOINTS
  137.  
  138. /**
  139.  * The maximum number of clients used by some tests. Some tests
  140.  * uses a single client and some test uses this maximum number
  141.  * of clients.
  142.  * @see SERVER_MAX
  143.  */
  144. #define CLIENT_MAX SERVER_MAX
  145.  
  146. /**
  147.  * The maximum number of concurrent requests fo a single client
  148.  * used by some tests. Some tests uses a single request and some
  149.  * test uses this maximum number of requests.
  150.  * @see SERVER_MAX
  151.  */
  152. #define REQUESTER_MAX SERVER_MAX
  153.  
  154. /***********************************************************
  155.  * HELPER MACROS
  156.  ***********************************************************/
  157.  
  158. /**
  159.  * Standard macro calculating the number of elements for
  160.  * an array.
  161.  */
  162. #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
  163.  
  164. /**
  165.  * Threadsafe replacement for CU_ASSERT_EQUAL().
  166.  */
  167. #define MY_ASSERT_EQUAL(actual, expected) { \
  168.   pthread_mutex_lock(&g_critical); \
  169.   if (actual != expected) errors += 1; \
  170.   pthread_mutex_unlock(&g_critical); \
  171. }
  172.  
  173. #if (USE_DPRINTF == 0)
  174.   /**
  175.    * The empty debug output macro.
  176.    * @see USE_DPRINTF
  177.    */
  178.   #define DPRINTF(...)
  179. #elif (USE_DPRINTF == 1)
  180.   /**
  181.    * The debug output macro to generate output on stderr.
  182.    * @see USE_DPRINTF
  183.    */
  184.   #define DPRINTF(...) fprintf(stderr, ##__VA_ARGS__)
  185. #else
  186.   #error Wrong value for debug output, must be in [0, 1]
  187. #endif
  188.  
  189. /***********************************************************
  190.  * HELPER FUNCTIONS
  191.  ***********************************************************/
  192.  
  193. /**
  194.  * Generates a string for the name of a communication
  195.  * endpoint. Used by servers.
  196.  *
  197.  * @param pBuffer buffer pointer used for the string
  198.  * @param size    size of the buffer
  199.  * @param index   index of the server
  200.  *
  201.  * @return pBuffer as the pointer to the resulting string
  202.  *
  203.  * @see endpointClient()
  204.  * @see TYPE_SOCKET
  205.  * @see ENDPOINT_FORMAT_STRING
  206.  */
  207. char *endpointServer(char *pBuffer, size_t size, int index) {
  208.   int ret;
  209.  
  210.   assert(pBuffer != NULL);
  211.  
  212. #if (TYPE_SOCKET != 2) /* not TCP */
  213.   ret = sprintf(pBuffer, ENDPOINT_FORMAT_STRING, index);
  214.   assert(ret >= 0);
  215.   assert(ret < (int) size);
  216. #else /* TCP */
  217.   ret = sprintf(pBuffer, ENDPOINT_FORMAT_STRING, "*", 5000 + index);
  218.   assert(ret >= 0);
  219.   assert(ret < (int) size);
  220. #endif
  221.  
  222.   return pBuffer;
  223. }
  224.  
  225. /**
  226.  * Generates a string for the name of a communication
  227.  * endpoint. Used by clients.
  228.  *
  229.  * @param pBuffer buffer pointer used for the string
  230.  * @param size    size of the buffer
  231.  * @param index   index of the server
  232.  *
  233.  * @return pBuffer as the pointer to the resulting string
  234.  *
  235.  * @see endpointServer()
  236.  * @see TYPE_SOCKET
  237.  * @see ENDPOINT_FORMAT_STRING
  238.  */
  239. char *endpointClient(char *pBuffer, size_t size, int index) {
  240.   int ret;
  241.  
  242.   assert(pBuffer != NULL);
  243.  
  244. #if (TYPE_SOCKET != 2) /* not TCP */
  245.   ret = sprintf(pBuffer, ENDPOINT_FORMAT_STRING, index);
  246.   assert(ret >= 0);
  247.   assert(ret < (int) size);
  248. #else /* TCP */
  249.   ret = sprintf(pBuffer, ENDPOINT_FORMAT_STRING, "localhost", 5000 + index);
  250.   assert(ret >= 0);
  251.   assert(ret < (int) size);
  252. #endif
  253.  
  254.   return pBuffer;
  255. }
  256. /**
  257.  * Sleeps a number of micro-seconds.
  258.  *
  259.  * @param usecs Microseconds to sleep
  260.  *
  261.  * @return native function return value, zero for success
  262.  */
  263.  
  264. int microsleep(int usecs) {
  265.   return usleep(usecs); // TODO: replace with nanosleep()
  266. }
  267.  
  268. /***********************************************************
  269.  * DATA
  270.  ***********************************************************/
  271.  
  272. pthread_mutex_t g_critical = PTHREAD_MUTEX_INITIALIZER;
  273. int errors = 0;
  274.  
  275. /***********************************************************
  276.  * DATA STRUCTURES
  277.  ***********************************************************/
  278.  
  279. /**
  280.  * Thread data structure for servers.
  281.  * @see threadServer()
  282.  */
  283. typedef struct THREAD_DATA_SERVER_T {
  284.   /** The 0MQ content handle, created outside the thread. */
  285.   void *zmqContext;
  286.   /** Index of the server thread as unique server ID. */
  287.   int threadIndex;
  288.   /** Number of total test loops. */
  289.   int loopCount;
  290.   /** Run flag used to startup the server. */
  291.   int bRun;
  292.   /** Original thread ID. */
  293.   pthread_t threadId;
  294. } THREAD_DATA_SERVER;
  295.  
  296. /**
  297.  * Thread data structure for clients.
  298.  * @see threadClient()
  299.  */
  300. typedef struct THREAD_DATA_CLIENT_T {
  301.   /** The 0MQ content handle, created outside the thread. */
  302.   void *zmqContext;
  303.   /** Index of the client thread as unique client ID. */
  304.   int threadIndex;
  305.   /** Number of predicted correct sequences. */
  306.   int seqCount;
  307.   /** Number of parallel publishers. */
  308.   int publisherCount;
  309.   /** Run flag used to shutdown the server when done. */
  310.   int bRun;
  311.   /** Original thread ID. */
  312.   pthread_t threadId;
  313. } THREAD_DATA_CLIENT;
  314.  
  315. /**
  316.  * The message structure used between clients and servers.
  317.  */
  318. typedef struct MESSAGE_T {
  319.   /**
  320.    * The index as an ID from the sending client. Required
  321.    * for the test.
  322.    */
  323.   int serverIndex;
  324.   /**
  325.    * A unique sequence number passed by a client
  326.    * to a server.
  327.    */
  328.   int sequence;
  329.   /**
  330.    * Some data to simulate big packages.
  331.    */
  332.   char szText[1000];
  333. } MESSAGE;
  334.  
  335. /***********************************************************
  336.  * THREADS - SERVER
  337.  ***********************************************************/
  338.  
  339. /**
  340.  * Server thread entry point.
  341.  *
  342.  * @param pArg pthread style argument pointer
  343.  *
  344.  * NULL is used as termination vaule.
  345.  *
  346.  * A pointer to a instance of a THREAD_DATA_SERVER
  347.  * data structure is passed to the server thread using the
  348.  * pArg parameter.
  349.  *
  350.  * @see THREAD_DATA_SERVER
  351.  * @see MESSAGE
  352.  * @see threadClient()
  353.  */
  354. static void *threadServer (void *pArg) {
  355.   THREAD_DATA_SERVER *pThreadData;
  356.   void *zmqSocket;
  357.   char text[40];
  358.   int ret;
  359.   zmq_msg_t zmqMsg;
  360.   MESSAGE msg;
  361.   int seq;
  362.   int i;
  363.  
  364.   /* Initialization */
  365.   assert(pArg != NULL);
  366.   pThreadData = (THREAD_DATA_SERVER *) pArg;
  367.  
  368.   /*  Sockets for publishing */
  369.   zmqSocket = zmq_socket(pThreadData->zmqContext, ZMQ_PUB);
  370.   assert(zmqSocket != NULL);
  371.   ret = zmq_bind(zmqSocket, endpointServer(text, sizeof(text), pThreadData->threadIndex));
  372.   assert(ret == 0);
  373.  
  374.   /* wait until runflag is set */
  375.   while (!pThreadData->bRun) {
  376.     microsleep(1 * 1000);
  377.   }
  378.  
  379.   seq = 0;
  380.  
  381.   for (i = 0; i < pThreadData->loopCount; i += 1) {
  382.     /* Initialize message for send */
  383.     memset(&msg, -1, sizeof(msg));
  384.     msg.serverIndex = pThreadData->threadIndex;
  385.     msg.sequence = seq;
  386.     sprintf(msg.szText, "%d-%d-%d", pThreadData->threadIndex, msg.serverIndex, msg.sequence);
  387.  
  388.     ret = zmq_msg_init_data(&zmqMsg, &msg, sizeof(msg), NULL, NULL);
  389.     assert(ret == 0);
  390.  
  391.     DPRINTF("Server[%d]: out-message = [%d, %d, %s]\n",
  392.       pThreadData->threadIndex, msg.serverIndex, msg.sequence, msg.szText);
  393.  
  394.     /* Send message */
  395.     ret = zmq_send(zmqSocket, &zmqMsg, 0);
  396.     assert(ret == 0);
  397.  
  398.     /* Close message resource */
  399.     ret = zmq_msg_close(&zmqMsg);
  400.     assert(ret == 0);
  401.  
  402.     seq += 1;
  403.  
  404.     /*  Do some 'work' */
  405. //    ret = microsleep (SERVER_BUSY_MICROSECS);
  406. //    assert(ret == 0);
  407.   }
  408.  
  409.   /* Final tests */
  410.   MY_ASSERT_EQUAL(seq, pThreadData->loopCount);
  411.  
  412.   if (seq != (pThreadData->loopCount)) {
  413.     DPRINTF("Client[%d]: sequence count = %d, assumed %d\n",
  414.       pThreadData->threadIndex, seq,
  415.       pThreadData->loopCount);
  416.   }
  417.  
  418.   /* Give clients time to receive all */
  419.   ret = microsleep (SERVER_CLEANUP_MICROSECS);
  420.   assert(ret == 0);
  421.  
  422.   /* Cleanup */
  423.   ret = zmq_close(zmqSocket);
  424.   assert(ret == 0);
  425.  
  426.   /* Terminate thread */
  427.   pthread_exit(NULL);
  428.   assert(0);
  429.   return NULL;
  430. }
  431.  
  432. /***********************************************************
  433.  * THREADS - CLIENT
  434.  ***********************************************************/
  435.  
  436. /**
  437.  * Client thread entry point.
  438.  *
  439.  * @param pArg pthread style argument pointer
  440.  *
  441.  * NULL is used as termination vaule.
  442.  *
  443.  * A pointer to a instance of a THREAD_DATA_CLIENT
  444.  * data structure is passed to the client thread using the
  445.  * pArg parameter.
  446.  *
  447.  * @see THREAD_DATA_CLIENT
  448.  * @see MESSAGE()
  449.  * @see threadServer()
  450.  */
  451. static void *threadClient (void *pArg) {
  452.   THREAD_DATA_CLIENT *pThreadData;
  453.   void *zmqSocket;
  454.   char text[80];
  455.   int i;
  456.   int ii;
  457.   int ret;
  458.   zmq_pollitem_t zmqPollItem;
  459.   zmq_msg_t zmqMsg;
  460.   MESSAGE msg;
  461.   int seq;
  462.   int assumedServerSeq[SERVER_MAX];
  463.   int countServerSeq[SERVER_MAX][COUNT_LOOPS];
  464.  
  465.   /* Initialization */
  466.   assert(pArg != NULL);
  467.   pThreadData = (THREAD_DATA_CLIENT *) pArg;
  468.   assert(pThreadData->publisherCount <= REQUESTER_MAX);
  469.   assert(pThreadData->seqCount <= COUNT_LOOPS);
  470.   memset(assumedServerSeq, 0, sizeof(assumedServerSeq));
  471.   memset(countServerSeq, 0, sizeof(countServerSeq));
  472.  
  473.   /*  Socket to all publishers */
  474.   zmqSocket = zmq_socket(pThreadData->zmqContext, ZMQ_SUB);
  475.   assert(zmqSocket != NULL);
  476.   ret = zmq_setsockopt (zmqSocket, ZMQ_SUBSCRIBE, "", 0);
  477.   assert(ret == 0);
  478.  
  479.   for (i = 0; i < pThreadData->publisherCount; i += 1) {
  480.     ret = zmq_connect(zmqSocket, endpointClient(text, sizeof(text), i));
  481.     assert(ret == 0);
  482.   }
  483.  
  484.   seq = 0;
  485.  
  486.   /* Prepare for polling */
  487.   zmqPollItem.socket = zmqSocket;
  488.   zmqPollItem.events = ZMQ_POLLIN;
  489.  
  490.   while (pThreadData->bRun) {
  491.     /* Poll for the next event */
  492.     ret = zmq_poll(&zmqPollItem, 1, 10 * 1000);
  493.     assert(ret >= 0);
  494.  
  495.     if (ret > 0)
  496.     {
  497.       assert(ret == 1);
  498.       assert(zmqPollItem.revents == ZMQ_POLLIN);
  499.  
  500.       /*  Read next message */
  501.       ret = zmq_msg_init(&zmqMsg);
  502.       assert(ret == 0);
  503.       ret = zmq_recv(zmqSocket, &zmqMsg, 0);
  504.       assert(ret == 0);
  505.  
  506.       /* Get message content */
  507.       assert(zmq_msg_size(&zmqMsg) == sizeof(msg));
  508.       memcpy(&msg, zmq_msg_data(&zmqMsg), sizeof(msg));
  509.  
  510.       /* Close message */
  511.       ret = zmq_msg_close(&zmqMsg);
  512.       assert(ret == 0);
  513.  
  514.       DPRINTF("Client[%d]: in-message = [%d, %d, %s]\n",
  515.         pThreadData->threadIndex, msg.serverIndex, msg.sequence, msg.szText);
  516.  
  517.       if (assumedServerSeq[msg.serverIndex] != msg.sequence) {
  518.         DPRINTF("Client[%d]: wrong message received; assumed: message [%d, %d], received: [%d, %d], %d times\n",
  519.                 pThreadData->threadIndex,
  520.                 msg.serverIndex, assumedServerSeq[msg.serverIndex],
  521.                 msg.serverIndex, msg.sequence,
  522.                 countServerSeq[msg.serverIndex][msg.sequence]);
  523.       }
  524.  
  525.       /* Check message */
  526.       MY_ASSERT_EQUAL(assumedServerSeq[msg.serverIndex], msg.sequence);
  527.       assumedServerSeq[msg.serverIndex] = msg.sequence + 1;
  528.  
  529.       /* Record sequence */
  530.       MY_ASSERT_EQUAL(countServerSeq[msg.serverIndex][msg.sequence], 0);
  531.       countServerSeq[msg.serverIndex][msg.sequence] += 1;
  532.       seq += 1;
  533.     }
  534.   }
  535.  
  536.   /* Final tests */
  537.   MY_ASSERT_EQUAL(seq, pThreadData->seqCount * pThreadData->publisherCount);
  538.  
  539.   for (i = 0; i < pThreadData->publisherCount; i += 1) {
  540.     for (ii = 0; ii < pThreadData->seqCount; ii += 1) {
  541.       MY_ASSERT_EQUAL(countServerSeq[i][ii], 1);
  542.  
  543.       if (countServerSeq[i][ii] != 1) {
  544.         DPRINTF("Client[%d]: wrong number of messages received for [%d][%d]; assumed 1, received: %d\n",
  545.                 pThreadData->threadIndex, i, ii, countServerSeq[i][ii]);
  546.       }
  547.     }
  548.   }
  549.  
  550.   if (seq != (pThreadData->seqCount * pThreadData->publisherCount)) {
  551.     DPRINTF("Client[%d]: sequence count = %d, assumed %d\n",
  552.       pThreadData->threadIndex, seq,
  553.       pThreadData->seqCount * pThreadData->publisherCount);
  554.   }
  555.  
  556.   /* Cleanup */
  557.   ret = zmq_close(zmqSocket);
  558.   assert(ret == 0);
  559.  
  560.   /* Terminate thread */
  561.   pthread_exit(NULL);
  562.   assert(0);
  563.   return NULL;
  564. }
  565.  
  566. /***********************************************************
  567.  * LOCAL TESTS
  568.  ***********************************************************/
  569.  
  570. /**
  571.  * Perform the test with configurable task numbers.
  572.  *
  573.  * @param clients Number of clients to start
  574.  * @param servers Number of servers to start
  575.  *
  576.  * The given number of servers are started at first. Then
  577.  * the given number of clients are configured to subscribe
  578.  * all publishers. Then we wait for all servers
  579.  * to terminate by theirself before we terminate the clients.
  580.  *
  581.  * This function is used by several tests for different setups.
  582.  *
  583.  * @note It is important to set up the publisher's
  584.  * endpoint first. At least for inproc endpoints subscriber's
  585.  * zmq_connect() will fail if the endpoint is not available.
  586.  */
  587. static void doit(unsigned int clients, unsigned int servers) {
  588.   void * zmqContext;
  589.   THREAD_DATA_SERVER dataServers[SERVER_MAX];
  590.   THREAD_DATA_CLIENT dataClients[CLIENT_MAX];
  591.   int ret;
  592.   unsigned int i;
  593.   void *threadResult;
  594.  
  595.   assert(clients <= ARRAY_SIZE(dataClients));
  596.   assert(servers <= ARRAY_SIZE(dataServers));
  597.  
  598.   /* Initialize */
  599.   zmqContext = zmq_init(1);
  600.   assert(zmqContext != NULL);
  601.  
  602.   /* Start clients */
  603.   for (i = 0; i < clients; i += 1) {
  604.     memset(&dataClients[i], 0, sizeof(dataClients[i]));
  605.     dataClients[i].zmqContext = zmqContext;
  606.     dataClients[i].threadIndex = i;
  607.     dataClients[i].seqCount = COUNT_LOOPS;
  608.     dataClients[i].publisherCount = servers;
  609.     dataClients[i].bRun = TRUE;
  610.     ret = pthread_create(&dataClients[i].threadId, NULL, threadClient, &dataClients[i]);
  611.     assert(ret == 0);
  612.   }
  613.  
  614.   /* Start servers */
  615.   for (i = 0; i < servers; i += 1) {
  616.     memset(&dataServers[i], 0, sizeof(dataServers[i]));
  617.  
  618.     dataServers[i].zmqContext = zmqContext;
  619.     dataServers[i].threadIndex = i;
  620.     dataServers[i].loopCount = COUNT_LOOPS;
  621.     dataServers[i].bRun = FALSE;
  622.     ret = pthread_create(&dataServers[i].threadId, NULL, threadServer, &dataServers[i]);
  623.     assert(ret == 0);
  624.   }
  625.  
  626.   /* Give clients time to initialize */
  627.   ret = microsleep (CLIENT_STARTUP_MICROSECS);
  628.   assert(ret == 0);
  629.  
  630.   /* Run servers */
  631.   for (i = 0; i < servers; i += 1) {
  632.     dataServers[i].bRun = TRUE;
  633.   }
  634.  
  635.   /* Wait for servers */
  636.   for (i = 0; i < servers; i += 1) {
  637.     ret = pthread_join(dataServers[i].threadId, &threadResult);
  638.     assert(ret == 0);
  639.     assert(threadResult == NULL);
  640.   }
  641.  
  642.   /* Stop clients */
  643.   for (i = 0; i < clients; i += 1) {
  644.     dataClients[i].bRun = FALSE;
  645.   }
  646.  
  647.   for (i = 0; i < clients; i += 1) {
  648.     ret = pthread_join(dataClients[i].threadId, &threadResult);
  649.     assert(ret == 0);
  650.     assert(threadResult == NULL);
  651.   }
  652.  
  653.   /* Cleanup */
  654.   ret = zmq_term(zmqContext);
  655.   assert(ret == 0);
  656. }
  657.  
  658. /**
  659.  * Test case for 1 client and 1 server.
  660.  */
  661. static void test1to1(void) {
  662.   doit(1, 1);
  663. }
  664.  
  665. /**
  666.  * Test case for 1 client and SERVER_MAX servers.
  667.  * @see SERVER_MAX
  668.  */
  669. static void test1toN(void) {
  670.   doit(1, SERVER_MAX);
  671. }
  672.  
  673. /**
  674.  * Test case for CLIENT_MAX clients and 1 server.
  675.  * @see CLIENT_MAX
  676.  */
  677. static void testNto1(void) {
  678.   doit(CLIENT_MAX, 1);
  679. }
  680.  
  681. /**
  682.  * Test case for CLIENT_MAX clients and SERVER_MAX servers.
  683.  * @see CLIENT_MAX
  684.  * @see SERVER_MAX
  685.  */
  686. static void testNtoN(void) {
  687.   doit(CLIENT_MAX, SERVER_MAX);
  688. }
  689.  
  690. /***********************************************************
  691.  * FUNCTIONS
  692.  ***********************************************************/
  693.  
  694. /**
  695.  * Application entry point.
  696.  * @param argc Number of command line entries
  697.  * @param argv List of command line entriy strings
  698.  */
  699. int main(int argc, char* argv[])
  700. {
  701.   DPRINTF("### test1to1 ###\n");
  702.   test1to1();
  703.   DPRINTF("### test1toN ###\n");
  704.   test1toN();
  705.   DPRINTF("### testNto1 ###\n");
  706.   testNto1();
  707.   DPRINTF("### testNtoN ###\n");
  708.   testNtoN();
  709.   DPRINTF("### Asserts failed: %d ###\n", errors);
  710. }
  711. /***********************************************************
  712.  * END OF FILE
  713.  ***********************************************************/
Advertisement
Add Comment
Please, Sign In to add comment