rename configs to match
[oweals/gnunet.git] / src / transport / test_transport_api_limited_sockets.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2010 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 /**
21  * @file transport/test_transport_api_limited_sockets.c
22  * @brief base test case for transport implementations
23  *
24  * This test case serves as a base for tcp, udp, and udp-nat
25  * transport test cases.  Based on the executable being run
26  * the correct test case will be performed.  Conservation of
27  * C code apparently.
28  */
29 #include "platform.h"
30 #include "gnunet_transport_service.h"
31 #include "transport-testing.h"
32
33 /**
34  * How long until we give up on transmitting the message?
35  */
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
37
38 #define MAX_FILES 50
39
40
41 #if HAVE_SETRLIMIT
42
43 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
44
45
46 static void
47 notify_receive (void *cls,
48                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
49                 const struct GNUNET_PeerIdentity *sender,
50                 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
51 {
52   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
53               "Received message of type %d from peer %s!\n",
54               ntohs (message->header.type),
55               GNUNET_i2s (sender));
56   if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE ==
57        ntohs (message->header.type)) &&
58       (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) ==
59        ntohs (message->header.size)))
60   {
61     ccc->global_ret = GNUNET_OK;
62   }
63   else
64   {
65     GNUNET_break (0);
66   }
67   GNUNET_SCHEDULER_shutdown ();
68 }
69
70
71 int
72 main (int argc, char *argv[])
73 {
74   struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
75     .num_messages = 1
76   };
77   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
78     .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
79     .connect_continuation_cls = &sc,
80     .config_file = "test_transport_api_data.conf",
81     .rec = &notify_receive,
82     .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
83     .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
84     .timeout = TIMEOUT,
85     .global_ret = GNUNET_SYSERR
86   };
87   struct rlimit r_file_old;
88   struct rlimit r_file_new;
89   int res;
90
91   sc.ccc = &my_ccc;
92   res = getrlimit (RLIMIT_NOFILE,
93                    &r_file_old);
94   r_file_new.rlim_cur = MAX_FILES;
95   r_file_new.rlim_max = r_file_old.rlim_max;
96   res = setrlimit (RLIMIT_NOFILE,
97                    &r_file_new);
98   if (0 != res)
99   {
100     fprintf (stderr,
101              "Setting limit failed: %s\n",
102              strerror (errno));
103     return 77;
104   }
105
106   ccc = &my_ccc;
107   ccc->global_ret = GNUNET_SYSERR;
108   if (GNUNET_OK !=
109       GNUNET_TRANSPORT_TESTING_main (2,
110                                      &GNUNET_TRANSPORT_TESTING_connect_check,
111                                      ccc))
112     return 1;
113   return 0;
114 }
115
116
117 #else
118 /* cannot setrlimit */
119
120
121 int
122 main (int argc, char *argv[])
123 {
124   fprintf (stderr,
125            "Cannot run test on this system\n");
126   return 77;
127 }
128
129
130 #endif
131
132 /* end of test_transport_api_limited_sockets.c */