testutil.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. Copyright (c) 2007-2019 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #include "testutil.hpp"
  25. #include "testutil_unity.hpp"
  26. #include <stdarg.h>
  27. #include <string.h>
  28. #if defined _WIN32
  29. #include "../src/windows.hpp"
  30. #if defined _MSC_VER
  31. #if defined ZMQ_HAVE_IPC
  32. #include <direct.h>
  33. #include <afunix.h>
  34. #endif
  35. #include <crtdbg.h>
  36. #pragma warning(disable : 4996)
  37. // iphlpapi is needed for if_nametoindex (not on Windows XP)
  38. #if _WIN32_WINNT > _WIN32_WINNT_WINXP
  39. #pragma comment(lib, "iphlpapi")
  40. #endif
  41. #endif
  42. #else
  43. #include <pthread.h>
  44. #include <unistd.h>
  45. #include <signal.h>
  46. #include <stdlib.h>
  47. #include <grp.h>
  48. #include <sys/wait.h>
  49. #include <sys/socket.h>
  50. #include <sys/types.h>
  51. #include <netinet/in.h>
  52. #include <arpa/inet.h>
  53. #include <net/if.h>
  54. #include <netdb.h>
  55. #include <sys/un.h>
  56. #include <dirent.h>
  57. #if defined(ZMQ_HAVE_AIX)
  58. #include <sys/types.h>
  59. #include <sys/socketvar.h>
  60. #endif
  61. #endif
  62. const char *SEQ_END = (const char *) 1;
  63. const char bounce_content[] = "12345678ABCDEFGH12345678abcdefgh";
  64. static void send_bounce_msg (void *socket_)
  65. {
  66. send_string_expect_success (socket_, bounce_content, ZMQ_SNDMORE);
  67. send_string_expect_success (socket_, bounce_content, 0);
  68. }
  69. static void recv_bounce_msg (void *socket_)
  70. {
  71. recv_string_expect_success (socket_, bounce_content, 0);
  72. int rcvmore;
  73. size_t sz = sizeof (rcvmore);
  74. TEST_ASSERT_SUCCESS_ERRNO (
  75. zmq_getsockopt (socket_, ZMQ_RCVMORE, &rcvmore, &sz));
  76. TEST_ASSERT_TRUE (rcvmore);
  77. recv_string_expect_success (socket_, bounce_content, 0);
  78. TEST_ASSERT_SUCCESS_ERRNO (
  79. zmq_getsockopt (socket_, ZMQ_RCVMORE, &rcvmore, &sz));
  80. TEST_ASSERT_FALSE (rcvmore);
  81. }
  82. void bounce (void *server_, void *client_)
  83. {
  84. // Send message from client to server
  85. send_bounce_msg (client_);
  86. // Receive message at server side and
  87. // check that message is still the same
  88. recv_bounce_msg (server_);
  89. // Send two parts back to client
  90. send_bounce_msg (server_);
  91. // Receive the two parts at the client side
  92. recv_bounce_msg (client_);
  93. }
  94. static void send_bounce_msg_may_fail (void *socket_)
  95. {
  96. int timeout = 250;
  97. TEST_ASSERT_SUCCESS_ERRNO (
  98. zmq_setsockopt (socket_, ZMQ_SNDTIMEO, &timeout, sizeof (int)));
  99. int rc = zmq_send (socket_, bounce_content, 32, ZMQ_SNDMORE);
  100. TEST_ASSERT_TRUE ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
  101. rc = zmq_send (socket_, bounce_content, 32, 0);
  102. TEST_ASSERT_TRUE ((rc == 32) || ((rc == -1) && (errno == EAGAIN)));
  103. }
  104. static void recv_bounce_msg_fail (void *socket_)
  105. {
  106. int timeout = 250;
  107. char buffer[32];
  108. TEST_ASSERT_SUCCESS_ERRNO (
  109. zmq_setsockopt (socket_, ZMQ_RCVTIMEO, &timeout, sizeof (int)));
  110. TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (socket_, buffer, 32, 0));
  111. }
  112. void expect_bounce_fail (void *server_, void *client_)
  113. {
  114. // Send message from client to server
  115. send_bounce_msg_may_fail (client_);
  116. // Receive message at server side (should not succeed)
  117. recv_bounce_msg_fail (server_);
  118. // Send message from server to client to test other direction
  119. // If connection failed, send may block, without a timeout
  120. send_bounce_msg_may_fail (server_);
  121. // Receive message at client side (should not succeed)
  122. recv_bounce_msg_fail (client_);
  123. }
  124. char *s_recv (void *socket_)
  125. {
  126. char buffer[256];
  127. int size = zmq_recv (socket_, buffer, 255, 0);
  128. if (size == -1)
  129. return NULL;
  130. if (size > 255)
  131. size = 255;
  132. buffer[size] = 0;
  133. return strdup (buffer);
  134. }
  135. void s_send_seq (void *socket_, ...)
  136. {
  137. va_list ap;
  138. va_start (ap, socket_);
  139. const char *data = va_arg (ap, const char *);
  140. while (true) {
  141. const char *prev = data;
  142. data = va_arg (ap, const char *);
  143. bool end = data == SEQ_END;
  144. if (!prev) {
  145. TEST_ASSERT_SUCCESS_ERRNO (
  146. zmq_send (socket_, 0, 0, end ? 0 : ZMQ_SNDMORE));
  147. } else {
  148. TEST_ASSERT_SUCCESS_ERRNO (zmq_send (
  149. socket_, prev, strlen (prev) + 1, end ? 0 : ZMQ_SNDMORE));
  150. }
  151. if (end)
  152. break;
  153. }
  154. va_end (ap);
  155. }
  156. void s_recv_seq (void *socket_, ...)
  157. {
  158. zmq_msg_t msg;
  159. zmq_msg_init (&msg);
  160. int more;
  161. size_t more_size = sizeof (more);
  162. va_list ap;
  163. va_start (ap, socket_);
  164. const char *data = va_arg (ap, const char *);
  165. while (true) {
  166. TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, socket_, 0));
  167. if (!data)
  168. TEST_ASSERT_EQUAL_INT (0, zmq_msg_size (&msg));
  169. else
  170. TEST_ASSERT_EQUAL_STRING (data, (const char *) zmq_msg_data (&msg));
  171. data = va_arg (ap, const char *);
  172. bool end = data == SEQ_END;
  173. TEST_ASSERT_SUCCESS_ERRNO (
  174. zmq_getsockopt (socket_, ZMQ_RCVMORE, &more, &more_size));
  175. TEST_ASSERT_TRUE (!more == end);
  176. if (end)
  177. break;
  178. }
  179. va_end (ap);
  180. zmq_msg_close (&msg);
  181. }
  182. void close_zero_linger (void *socket_)
  183. {
  184. int linger = 0;
  185. int rc = zmq_setsockopt (socket_, ZMQ_LINGER, &linger, sizeof (linger));
  186. TEST_ASSERT_TRUE (rc == 0 || errno == ETERM);
  187. TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket_));
  188. }
  189. void setup_test_environment (int timeout_seconds_)
  190. {
  191. #if defined _WIN32
  192. #if defined _MSC_VER
  193. _set_abort_behavior (0, _WRITE_ABORT_MSG);
  194. _CrtSetReportMode (_CRT_ASSERT, _CRTDBG_MODE_FILE);
  195. _CrtSetReportFile (_CRT_ASSERT, _CRTDBG_FILE_STDERR);
  196. #endif
  197. #else
  198. #if defined ZMQ_HAVE_CYGWIN
  199. // abort test after 121 seconds
  200. alarm (121);
  201. #else
  202. #if !defined ZMQ_DISABLE_TEST_TIMEOUT
  203. // abort test after timeout_seconds_ seconds
  204. alarm (timeout_seconds_);
  205. #endif
  206. #endif
  207. #endif
  208. #if defined __MVS__
  209. // z/OS UNIX System Services: Ignore SIGPIPE during test runs, as a
  210. // workaround for no SO_NOGSIGPIPE socket option.
  211. signal (SIGPIPE, SIG_IGN);
  212. #endif
  213. }
  214. void msleep (int milliseconds_)
  215. {
  216. #ifdef ZMQ_HAVE_WINDOWS
  217. Sleep (milliseconds_);
  218. #else
  219. usleep (static_cast<useconds_t> (milliseconds_) * 1000);
  220. #endif
  221. }
  222. int is_ipv6_available ()
  223. {
  224. #if defined(ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
  225. return 0;
  226. #else
  227. int rc, ipv6 = 1;
  228. struct sockaddr_in6 test_addr;
  229. memset (&test_addr, 0, sizeof (test_addr));
  230. test_addr.sin6_family = AF_INET6;
  231. inet_pton (AF_INET6, "::1", &(test_addr.sin6_addr));
  232. fd_t fd = socket (AF_INET6, SOCK_STREAM, IPPROTO_IP);
  233. if (fd == retired_fd)
  234. ipv6 = 0;
  235. else {
  236. #ifdef ZMQ_HAVE_WINDOWS
  237. setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const char *) &ipv6,
  238. sizeof (int));
  239. rc = setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const char *) &ipv6,
  240. sizeof (int));
  241. if (rc == SOCKET_ERROR)
  242. ipv6 = 0;
  243. else {
  244. rc = bind (fd, (struct sockaddr *) &test_addr, sizeof (test_addr));
  245. if (rc == SOCKET_ERROR)
  246. ipv6 = 0;
  247. }
  248. #else
  249. setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &ipv6, sizeof (int));
  250. rc = setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6, sizeof (int));
  251. if (rc != 0)
  252. ipv6 = 0;
  253. else {
  254. rc = bind (fd, reinterpret_cast<struct sockaddr *> (&test_addr),
  255. sizeof (test_addr));
  256. if (rc != 0)
  257. ipv6 = 0;
  258. }
  259. #endif
  260. close (fd);
  261. }
  262. return ipv6;
  263. #endif // _WIN32_WINNT < 0x0600
  264. }
  265. int is_tipc_available ()
  266. {
  267. #ifndef ZMQ_HAVE_TIPC
  268. return 0;
  269. #else
  270. int tipc = 0;
  271. void *ctx = zmq_init (1);
  272. TEST_ASSERT_NOT_NULL (ctx);
  273. void *rep = zmq_socket (ctx, ZMQ_REP);
  274. TEST_ASSERT_NOT_NULL (rep);
  275. tipc = zmq_bind (rep, "tipc://{5560,0,0}");
  276. zmq_close (rep);
  277. zmq_ctx_term (ctx);
  278. return tipc == 0;
  279. #endif // ZMQ_HAVE_TIPC
  280. }
  281. int test_inet_pton (int af_, const char *src_, void *dst_)
  282. {
  283. #if defined(ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
  284. if (af_ == AF_INET) {
  285. struct in_addr *ip4addr = (struct in_addr *) dst_;
  286. ip4addr->s_addr = inet_addr (src_);
  287. // INADDR_NONE is -1 which is also a valid representation for IP
  288. // 255.255.255.255
  289. if (ip4addr->s_addr == INADDR_NONE
  290. && strcmp (src_, "255.255.255.255") != 0) {
  291. return 0;
  292. }
  293. // Success
  294. return 1;
  295. } else {
  296. // Not supported.
  297. return 0;
  298. }
  299. #else
  300. return inet_pton (af_, src_, dst_);
  301. #endif
  302. }
  303. sockaddr_in bind_bsd_socket (int socket_)
  304. {
  305. struct sockaddr_in saddr;
  306. memset (&saddr, 0, sizeof (saddr));
  307. saddr.sin_family = AF_INET;
  308. saddr.sin_addr.s_addr = INADDR_ANY;
  309. #if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
  310. saddr.sin_port = 0;
  311. #else
  312. saddr.sin_port = htons (PORT_6);
  313. #endif
  314. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  315. bind (socket_, (struct sockaddr *) &saddr, sizeof (saddr)));
  316. #if !defined(_WIN32_WINNT) || (_WIN32_WINNT >= 0x0600)
  317. socklen_t saddr_len = sizeof (saddr);
  318. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  319. getsockname (socket_, (struct sockaddr *) &saddr, &saddr_len));
  320. #endif
  321. return saddr;
  322. }
  323. fd_t connect_socket (const char *endpoint_, const int af_, const int protocol_)
  324. {
  325. struct sockaddr_storage addr;
  326. // OSX is very opinionated and wants the size to match the AF family type
  327. socklen_t addr_len;
  328. const fd_t s_pre = socket (af_, SOCK_STREAM,
  329. protocol_ == IPPROTO_UDP
  330. ? IPPROTO_UDP
  331. : protocol_ == IPPROTO_TCP ? IPPROTO_TCP : 0);
  332. TEST_ASSERT_NOT_EQUAL (-1, s_pre);
  333. if (af_ == AF_INET || af_ == AF_INET6) {
  334. const char *port = strrchr (endpoint_, ':') + 1;
  335. char address[MAX_SOCKET_STRING];
  336. // getaddrinfo does not like [x:y::z]
  337. if (*strchr (endpoint_, '/') + 2 == '[') {
  338. strcpy (address, strchr (endpoint_, '[') + 1);
  339. address[strlen (address) - strlen (port) - 2] = '\0';
  340. } else {
  341. strcpy (address, strchr (endpoint_, '/') + 2);
  342. address[strlen (address) - strlen (port) - 1] = '\0';
  343. }
  344. struct addrinfo *in, hint;
  345. memset (&hint, 0, sizeof (struct addrinfo));
  346. hint.ai_flags = AI_NUMERICSERV;
  347. hint.ai_family = af_;
  348. hint.ai_socktype = protocol_ == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
  349. hint.ai_protocol = protocol_ == IPPROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP;
  350. TEST_ASSERT_SUCCESS_RAW_ZERO_ERRNO (
  351. getaddrinfo (address, port, &hint, &in));
  352. TEST_ASSERT_NOT_NULL (in);
  353. memcpy (&addr, in->ai_addr, in->ai_addrlen);
  354. addr_len = (socklen_t) in->ai_addrlen;
  355. freeaddrinfo (in);
  356. } else {
  357. #if defined(ZMQ_HAVE_IPC)
  358. // Cannot cast addr as gcc 4.4 will fail with strict aliasing errors
  359. (*(struct sockaddr_un *) &addr).sun_family = AF_UNIX;
  360. strcpy ((*(struct sockaddr_un *) &addr).sun_path, endpoint_);
  361. addr_len = sizeof (struct sockaddr_un);
  362. #else
  363. return retired_fd;
  364. #endif
  365. }
  366. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  367. connect (s_pre, (struct sockaddr *) &addr, addr_len));
  368. return s_pre;
  369. }
  370. fd_t bind_socket_resolve_port (const char *address_,
  371. const char *port_,
  372. char *my_endpoint_,
  373. const int af_,
  374. const int protocol_)
  375. {
  376. struct sockaddr_storage addr;
  377. // OSX is very opinionated and wants the size to match the AF family type
  378. socklen_t addr_len;
  379. const fd_t s_pre = socket (af_, SOCK_STREAM,
  380. protocol_ == IPPROTO_UDP
  381. ? IPPROTO_UDP
  382. : protocol_ == IPPROTO_TCP ? IPPROTO_TCP : 0);
  383. TEST_ASSERT_NOT_EQUAL (-1, s_pre);
  384. if (af_ == AF_INET || af_ == AF_INET6) {
  385. #ifdef ZMQ_HAVE_WINDOWS
  386. const char flag = '\1';
  387. #elif defined ZMQ_HAVE_VXWORKS
  388. char flag = '\1';
  389. #else
  390. int flag = 1;
  391. #endif
  392. struct addrinfo *in, hint;
  393. memset (&hint, 0, sizeof (struct addrinfo));
  394. hint.ai_flags = AI_NUMERICSERV;
  395. hint.ai_family = af_;
  396. hint.ai_socktype = protocol_ == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
  397. hint.ai_protocol = protocol_ == IPPROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP;
  398. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  399. setsockopt (s_pre, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)));
  400. TEST_ASSERT_SUCCESS_RAW_ZERO_ERRNO (
  401. getaddrinfo (address_, port_, &hint, &in));
  402. TEST_ASSERT_NOT_NULL (in);
  403. memcpy (&addr, in->ai_addr, in->ai_addrlen);
  404. addr_len = (socklen_t) in->ai_addrlen;
  405. freeaddrinfo (in);
  406. } else {
  407. #if defined(ZMQ_HAVE_IPC)
  408. // Cannot cast addr as gcc 4.4 will fail with strict aliasing errors
  409. (*(struct sockaddr_un *) &addr).sun_family = AF_UNIX;
  410. addr_len = sizeof (struct sockaddr_un);
  411. #if defined ZMQ_HAVE_WINDOWS
  412. char buffer[MAX_PATH] = "";
  413. TEST_ASSERT_SUCCESS_RAW_ERRNO (tmpnam_s (buffer));
  414. TEST_ASSERT_SUCCESS_RAW_ERRNO (_mkdir (buffer));
  415. strcat (buffer, "/ipc");
  416. #else
  417. char buffer[PATH_MAX] = "";
  418. strcpy (buffer, "tmpXXXXXX");
  419. #ifdef HAVE_MKDTEMP
  420. TEST_ASSERT_TRUE (mkdtemp (buffer));
  421. strcat (buffer, "/socket");
  422. #else
  423. int fd = mkstemp (buffer);
  424. TEST_ASSERT_TRUE (fd != -1);
  425. close (fd);
  426. #endif
  427. #endif
  428. strcpy ((*(struct sockaddr_un *) &addr).sun_path, buffer);
  429. memcpy (my_endpoint_, "ipc://", 7);
  430. strcat (my_endpoint_, buffer);
  431. // TODO check return value of unlink
  432. unlink (buffer);
  433. #else
  434. return retired_fd;
  435. #endif
  436. }
  437. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  438. bind (s_pre, (struct sockaddr *) &addr, addr_len));
  439. TEST_ASSERT_SUCCESS_RAW_ERRNO (listen (s_pre, SOMAXCONN));
  440. if (af_ == AF_INET || af_ == AF_INET6) {
  441. addr_len = sizeof (struct sockaddr_storage);
  442. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  443. getsockname (s_pre, (struct sockaddr *) &addr, &addr_len));
  444. sprintf (my_endpoint_, "%s://%s:%u",
  445. protocol_ == IPPROTO_TCP
  446. ? "tcp"
  447. : protocol_ == IPPROTO_UDP
  448. ? "udp"
  449. : protocol_ == IPPROTO_WSS ? "wss" : "ws",
  450. address_,
  451. af_ == AF_INET
  452. ? ntohs ((*(struct sockaddr_in *) &addr).sin_port)
  453. : ntohs ((*(struct sockaddr_in6 *) &addr).sin6_port));
  454. }
  455. return s_pre;
  456. }
  457. bool streq (const char *lhs_, const char *rhs_)
  458. {
  459. return strcmp (lhs_, rhs_) == 0;
  460. }
  461. bool strneq (const char *lhs_, const char *rhs_)
  462. {
  463. return strcmp (lhs_, rhs_) != 0;
  464. }
  465. #if defined _WIN32
  466. int fuzzer_corpus_encode (const char *dirname,
  467. uint8_t ***data,
  468. size_t **len,
  469. size_t *num_cases)
  470. {
  471. (void) dirname;
  472. (void) data;
  473. (void) len;
  474. (void) num_cases;
  475. return -1;
  476. }
  477. #else
  478. int fuzzer_corpus_encode (const char *dirname,
  479. uint8_t ***data,
  480. size_t **len,
  481. size_t *num_cases)
  482. {
  483. TEST_ASSERT_NOT_NULL (dirname);
  484. TEST_ASSERT_NOT_NULL (data);
  485. TEST_ASSERT_NOT_NULL (len);
  486. struct dirent *ent;
  487. DIR *dir = opendir (dirname);
  488. if (!dir)
  489. return -1;
  490. *len = NULL;
  491. *data = NULL;
  492. *num_cases = 0;
  493. while ((ent = readdir (dir)) != NULL) {
  494. if (!strcmp (ent->d_name, ".") || !strcmp (ent->d_name, ".."))
  495. continue;
  496. char *filename =
  497. (char *) malloc (strlen (dirname) + strlen (ent->d_name) + 2);
  498. TEST_ASSERT_NOT_NULL (filename);
  499. strcpy (filename, dirname);
  500. strcat (filename, "/");
  501. strcat (filename, ent->d_name);
  502. FILE *f = fopen (filename, "r");
  503. free (filename);
  504. if (!f)
  505. continue;
  506. fseek (f, 0, SEEK_END);
  507. size_t file_len = ftell (f);
  508. fseek (f, 0, SEEK_SET);
  509. if (file_len == 0) {
  510. fclose (f);
  511. continue;
  512. }
  513. *len = (size_t *) realloc (*len, (*num_cases + 1) * sizeof (size_t));
  514. TEST_ASSERT_NOT_NULL (*len);
  515. *(*len + *num_cases) = file_len;
  516. *data =
  517. (uint8_t **) realloc (*data, (*num_cases + 1) * sizeof (uint8_t *));
  518. TEST_ASSERT_NOT_NULL (*data);
  519. *(*data + *num_cases) =
  520. (uint8_t *) malloc (file_len * sizeof (uint8_t));
  521. TEST_ASSERT_NOT_NULL (*(*data + *num_cases));
  522. size_t read_bytes = 0;
  523. read_bytes = fread (*(*data + *num_cases), 1, file_len, f);
  524. TEST_ASSERT_EQUAL (file_len, read_bytes);
  525. (*num_cases)++;
  526. fclose (f);
  527. }
  528. closedir (dir);
  529. return 0;
  530. }
  531. #endif