test1.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*******************************************************************************
  2. * Copyright (c) 2014 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial API and implementation and/or initial documentation
  15. *******************************************************************************/
  16. #include "MQTTPacket.h"
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #if !defined(_WINDOWS)
  21. #include <sys/time.h>
  22. #include <sys/socket.h>
  23. #include <unistd.h>
  24. #include <errno.h>
  25. #else
  26. #include <winsock2.h>
  27. #include <ws2tcpip.h>
  28. #define MAXHOSTNAMELEN 256
  29. #define EAGAIN WSAEWOULDBLOCK
  30. #define EINTR WSAEINTR
  31. #define EINPROGRESS WSAEINPROGRESS
  32. #define EWOULDBLOCK WSAEWOULDBLOCK
  33. #define ENOTCONN WSAENOTCONN
  34. #define ECONNRESET WSAECONNRESET
  35. #endif
  36. #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
  37. struct Options
  38. {
  39. char* connection; /**< connection to system under test. */
  40. char** haconnections;
  41. int hacount;
  42. int verbose;
  43. int test_no;
  44. } options =
  45. {
  46. "tcp://m2m.eclipse.org:1883",
  47. NULL,
  48. 0,
  49. 0,
  50. 0,
  51. };
  52. void usage()
  53. {
  54. }
  55. void getopts(int argc, char** argv)
  56. {
  57. int count = 1;
  58. while (count < argc)
  59. {
  60. if (strcmp(argv[count], "--test_no") == 0)
  61. {
  62. if (++count < argc)
  63. options.test_no = atoi(argv[count]);
  64. else
  65. usage();
  66. }
  67. else if (strcmp(argv[count], "--connection") == 0)
  68. {
  69. if (++count < argc)
  70. {
  71. options.connection = argv[count];
  72. printf("\nSetting connection to %s\n", options.connection);
  73. }
  74. else
  75. usage();
  76. }
  77. else if (strcmp(argv[count], "--haconnections") == 0)
  78. {
  79. if (++count < argc)
  80. {
  81. char* tok = strtok(argv[count], " ");
  82. options.hacount = 0;
  83. options.haconnections = malloc(sizeof(char*) * 5);
  84. while (tok)
  85. {
  86. options.haconnections[options.hacount] = malloc(strlen(tok) + 1);
  87. strcpy(options.haconnections[options.hacount], tok);
  88. options.hacount++;
  89. tok = strtok(NULL, " ");
  90. }
  91. }
  92. else
  93. usage();
  94. }
  95. else if (strcmp(argv[count], "--verbose") == 0)
  96. {
  97. options.verbose = 1;
  98. printf("\nSetting verbose on\n");
  99. }
  100. count++;
  101. }
  102. }
  103. #define LOGA_DEBUG 0
  104. #define LOGA_INFO 1
  105. #include <stdarg.h>
  106. #include <time.h>
  107. #include <sys/timeb.h>
  108. void MyLog(int LOGA_level, char* format, ...)
  109. {
  110. static char msg_buf[256];
  111. va_list args;
  112. struct timeb ts;
  113. struct tm *timeinfo;
  114. if (LOGA_level == LOGA_DEBUG && options.verbose == 0)
  115. return;
  116. ftime(&ts);
  117. timeinfo = localtime(&ts.time);
  118. strftime(msg_buf, 80, "%Y%m%d %H%M%S", timeinfo);
  119. sprintf(&msg_buf[strlen(msg_buf)], ".%.3hu ", ts.millitm);
  120. va_start(args, format);
  121. vsnprintf(&msg_buf[strlen(msg_buf)], sizeof(msg_buf) - strlen(msg_buf), format, args);
  122. va_end(args);
  123. printf("%s\n", msg_buf);
  124. fflush(stdout);
  125. }
  126. #if defined(WIN32) || defined(_WINDOWS)
  127. #define mqsleep(A) Sleep(1000*A)
  128. #define START_TIME_TYPE DWORD
  129. static DWORD start_time = 0;
  130. START_TIME_TYPE start_clock(void)
  131. {
  132. return GetTickCount();
  133. }
  134. #elif defined(AIX)
  135. #define mqsleep sleep
  136. #define START_TIME_TYPE struct timespec
  137. START_TIME_TYPE start_clock(void)
  138. {
  139. static struct timespec start;
  140. clock_gettime(CLOCK_REALTIME, &start);
  141. return start;
  142. }
  143. #else
  144. #define mqsleep sleep
  145. #define START_TIME_TYPE struct timeval
  146. /* TODO - unused - remove? static struct timeval start_time; */
  147. START_TIME_TYPE start_clock(void)
  148. {
  149. struct timeval start_time;
  150. gettimeofday(&start_time, NULL);
  151. return start_time;
  152. }
  153. #endif
  154. #if defined(WIN32)
  155. long elapsed(START_TIME_TYPE start_time)
  156. {
  157. return GetTickCount() - start_time;
  158. }
  159. #elif defined(AIX)
  160. #define assert(a)
  161. long elapsed(struct timespec start)
  162. {
  163. struct timespec now, res;
  164. clock_gettime(CLOCK_REALTIME, &now);
  165. ntimersub(now, start, res);
  166. return (res.tv_sec)*1000L + (res.tv_nsec)/1000000L;
  167. }
  168. #else
  169. long elapsed(START_TIME_TYPE start_time)
  170. {
  171. struct timeval now, res;
  172. gettimeofday(&now, NULL);
  173. timersub(&now, &start_time, &res);
  174. return (res.tv_sec)*1000 + (res.tv_usec)/1000;
  175. }
  176. #endif
  177. #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
  178. #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
  179. int tests = 0;
  180. int failures = 0;
  181. FILE* xml;
  182. START_TIME_TYPE global_start_time;
  183. char output[3000];
  184. char* cur_output = output;
  185. void write_test_result()
  186. {
  187. long duration = elapsed(global_start_time);
  188. fprintf(xml, " time=\"%ld.%.3ld\" >\n", duration / 1000, duration % 1000);
  189. if (cur_output != output)
  190. {
  191. fprintf(xml, "%s", output);
  192. cur_output = output;
  193. }
  194. fprintf(xml, "</testcase>\n");
  195. }
  196. void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
  197. {
  198. ++tests;
  199. if (!value)
  200. {
  201. va_list args;
  202. ++failures;
  203. printf("Assertion failed, file %s, line %d, description: %s\n", filename, lineno, description);
  204. va_start(args, format);
  205. vprintf(format, args);
  206. va_end(args);
  207. cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
  208. description, filename, lineno);
  209. }
  210. else
  211. MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
  212. }
  213. #define min(a, b) ((a < b) ? a : b)
  214. int checkMQTTStrings(MQTTString a, MQTTString b)
  215. {
  216. if (!a.lenstring.data)
  217. {
  218. a.lenstring.data = a.cstring;
  219. if (a.cstring)
  220. a.lenstring.len = strlen(a.cstring);
  221. }
  222. if (!b.lenstring.data)
  223. {
  224. b.lenstring.data = b.cstring;
  225. if (b.cstring)
  226. b.lenstring.len = strlen(b.cstring);
  227. }
  228. return memcmp(a.lenstring.data, b.lenstring.data, min(a.lenstring.len, b.lenstring.len)) == 0;
  229. }
  230. int checkConnectPackets(MQTTPacket_connectData* before, MQTTPacket_connectData* after)
  231. {
  232. int rc = 0;
  233. int start_failures = failures;
  234. assert("struct_ids should be the same",
  235. memcmp(before->struct_id, after->struct_id, 4) == 0, "struct_ids were different %.4s\n", after->struct_id);
  236. assert("struct_versions should be the same",
  237. before->struct_version == after->struct_version, "struct_versions were different\n", rc);
  238. assert("MQTT versions should be the same",
  239. before->MQTTVersion == after->MQTTVersion, "MQTT versions were different\n", rc);
  240. assert("ClientIDs should be the same",
  241. checkMQTTStrings(before->clientID, after->clientID), "ClientIDs were different\n", rc);
  242. assert("keepAliveIntervals should be the same",
  243. before->keepAliveInterval == after->keepAliveInterval, "keepAliveIntervals were different %d\n", after->keepAliveInterval);
  244. assert("cleansessions should be the same",
  245. before->cleansession == after->cleansession, "cleansessions were different\n", rc);
  246. assert("willFlags should be the same",
  247. before->willFlag == after->willFlag, "willFlags were different\n", rc);
  248. if (before->willFlag)
  249. {
  250. assert("will struct_ids should be the same",
  251. memcmp(before->will.struct_id, after->will.struct_id, 4) == 0, "will struct_ids were different %.4s\n", after->struct_id);
  252. assert("will struct_versions should be the same",
  253. before->will.struct_version == after->will.struct_version, "will struct_versions were different\n", rc);
  254. assert("topic names should be the same",
  255. checkMQTTStrings(before->will.topicName, after->will.topicName), "topic names were different\n", rc);
  256. assert("messages should be the same",
  257. checkMQTTStrings(before->will.message, after->will.message), "messages were different\n", rc);
  258. assert("retained flags should be the same",
  259. before->will.retained == after->will.retained, "retained flags were different\n", rc);
  260. assert("will qos should be the same",
  261. before->will.qos == after->will.qos, "will qos were different\n", rc);
  262. }
  263. assert("usernames should be the same",
  264. checkMQTTStrings(before->clientID, after->clientID), "usernames were different\n", rc);
  265. assert("passwords should be the same",
  266. checkMQTTStrings(before->password, after->password), "passwords were different\n", rc);
  267. return failures == start_failures;
  268. }
  269. int test1(struct Options options)
  270. {
  271. MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
  272. MQTTPacket_connectData data_after = MQTTPacket_connectData_initializer;
  273. int rc = 0;
  274. unsigned char buf[100];
  275. int buflen = sizeof(buf);
  276. fprintf(xml, "<testcase classname=\"test1\" name=\"de/serialization\"");
  277. global_start_time = start_clock();
  278. failures = 0;
  279. MyLog(LOGA_INFO, "Starting test 1 - serialization of connect and back");
  280. data.clientID.cstring = "me";
  281. data.keepAliveInterval = 20;
  282. data.cleansession = 1;
  283. data.username.cstring = "testuser";
  284. data.password.cstring = "testpassword";
  285. data.willFlag = 1;
  286. data.will.message.cstring = "will message";
  287. data.will.qos = 1;
  288. data.will.retained = 0;
  289. data.will.topicName.cstring = "will topic";
  290. rc = MQTTSerialize_connect(buf, buflen, &data);
  291. assert("good rc from serialize connect", rc > 0, "rc was %d\n", rc);
  292. rc = MQTTDeserialize_connect(&data_after, buf, buflen);
  293. assert("good rc from deserialize connect", rc == 1, "rc was %d\n", rc);
  294. /* data after should be the same as data before */
  295. rc = checkConnectPackets(&data, &data_after);
  296. assert("packets should be the same", rc == 1, "packets were different\n", rc);
  297. /* exit: */
  298. MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
  299. (failures == 0) ? "passed" : "failed", tests, failures);
  300. write_test_result();
  301. return failures;
  302. }
  303. int test2(struct Options options)
  304. {
  305. int rc = 0;
  306. unsigned char buf[100];
  307. int buflen = sizeof(buf);
  308. unsigned char dup = 0;
  309. int qos = 2;
  310. unsigned char retained = 0;
  311. unsigned short msgid = 23;
  312. MQTTString topicString = MQTTString_initializer;
  313. unsigned char *payload = (unsigned char*)"kkhkhkjkj jkjjk jk jk ";
  314. int payloadlen = strlen((char*)payload);
  315. unsigned char dup2 = 1;
  316. int qos2 = 1;
  317. unsigned char retained2 = 1;
  318. unsigned short msgid2 = 3243;
  319. MQTTString topicString2 = MQTTString_initializer;
  320. unsigned char *payload2 = NULL;
  321. int payloadlen2 = 0;
  322. fprintf(xml, "<testcase classname=\"test1\" name=\"de/serialization\"");
  323. global_start_time = start_clock();
  324. failures = 0;
  325. MyLog(LOGA_INFO, "Starting test 2 - serialization of publish and back");
  326. topicString.cstring = "mytopic";
  327. rc = MQTTSerialize_publish(buf, buflen, dup, qos, retained, msgid, topicString,
  328. payload, payloadlen);
  329. assert("good rc from serialize publish", rc > 0, "rc was %d\n", rc);
  330. rc = MQTTDeserialize_publish(&dup2, &qos2, &retained2, &msgid2, &topicString2,
  331. &payload2, &payloadlen2, buf, buflen);
  332. assert("good rc from deserialize publish", rc == 1, "rc was %d\n", rc);
  333. /* data after should be the same as data before */
  334. assert("dups should be the same", dup == dup2, "dups were different %d\n", dup2);
  335. assert("qoss should be the same", qos == qos2, "qoss were different %d\n", qos2);
  336. assert("retaineds should be the same", retained == retained2, "retaineds were different %d\n", retained2);
  337. assert("msgids should be the same", msgid == msgid2, "msgids were different %d\n", msgid2);
  338. assert("topics should be the same",
  339. checkMQTTStrings(topicString, topicString2), "topics were different %s\n", ""); //topicString2);
  340. assert("payload lengths should be the same",
  341. payloadlen == payloadlen2, "payload lengths were different %d\n", payloadlen2);
  342. assert("payloads should be the same",
  343. memcmp(payload, payload2, payloadlen) == 0, "payloads were different %s\n", "");
  344. /*exit:*/
  345. MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
  346. (failures == 0) ? "passed" : "failed", tests, failures);
  347. write_test_result();
  348. return failures;
  349. }
  350. int test3(struct Options options)
  351. {
  352. int i = 0;
  353. int rc = 0;
  354. unsigned char buf[100];
  355. int buflen = sizeof(buf);
  356. #define TOPIC_COUNT 2
  357. unsigned char dup = 0;
  358. unsigned short msgid = 23;
  359. int count = TOPIC_COUNT;
  360. MQTTString topicStrings[TOPIC_COUNT] = { MQTTString_initializer, MQTTString_initializer };
  361. int req_qoss[TOPIC_COUNT] = {2, 1};
  362. unsigned char dup2 = 1;
  363. unsigned short msgid2 = 2223;
  364. int count2 = 0;
  365. MQTTString topicStrings2[TOPIC_COUNT] = { MQTTString_initializer, MQTTString_initializer };
  366. int req_qoss2[TOPIC_COUNT] = {0, 0};
  367. fprintf(xml, "<testcase classname=\"test1\" name=\"de/serialization\"");
  368. global_start_time = start_clock();
  369. failures = 0;
  370. MyLog(LOGA_INFO, "Starting test 2 - serialization of subscribe and back");
  371. topicStrings[0].cstring = "mytopic";
  372. topicStrings[1].cstring = "mytopic2";
  373. rc = MQTTSerialize_subscribe(buf, buflen, dup, msgid, count, topicStrings, req_qoss);
  374. assert("good rc from serialize subscribe", rc > 0, "rc was %d\n", rc);
  375. rc = MQTTDeserialize_subscribe(&dup2, &msgid2, 2, &count2, topicStrings2, req_qoss2, buf, buflen);
  376. assert("good rc from deserialize subscribe", rc == 1, "rc was %d\n", rc);
  377. /* data after should be the same as data before */
  378. assert("dups should be the same", dup == dup2, "dups were different %d\n", dup2);
  379. assert("msgids should be the same", msgid == msgid2, "msgids were different %d\n", msgid2);
  380. assert("count should be the same", count == count2, "counts were different %d\n", count2);
  381. for (i = 0; i < count2; ++i)
  382. {
  383. assert("topics should be the same",
  384. checkMQTTStrings(topicStrings[i], topicStrings2[i]), "topics were different %s\n", "");
  385. assert("qoss should be the same", req_qoss[i] == req_qoss2[i], "qoss were different %d\n", req_qoss2[i]);
  386. }
  387. /*exit:*/
  388. MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
  389. (failures == 0) ? "passed" : "failed", tests, failures);
  390. write_test_result();
  391. return failures;
  392. }
  393. int test4(struct Options options)
  394. {
  395. int i = 0;
  396. int rc = 0;
  397. unsigned char buf[100];
  398. int buflen = sizeof(buf);
  399. #define TOPIC_COUNT 2
  400. int msgid = 23;
  401. int count = TOPIC_COUNT;
  402. int granted_qoss[TOPIC_COUNT] = {2, 1};
  403. unsigned short msgid2 = 2223;
  404. int count2 = 0;
  405. int granted_qoss2[TOPIC_COUNT] = {0, 0};
  406. fprintf(xml, "<testcase classname=\"test1\" name=\"de/serialization\"");
  407. global_start_time = start_clock();
  408. failures = 0;
  409. MyLog(LOGA_INFO, "Starting test 4 - serialization of suback and back");
  410. rc = MQTTSerialize_suback(buf, buflen, msgid, count, granted_qoss);
  411. assert("good rc from serialize suback", rc > 0, "rc was %d\n", rc);
  412. rc = MQTTDeserialize_suback(&msgid2, 2, &count2, granted_qoss2, buf, buflen);
  413. assert("good rc from deserialize suback", rc == 1, "rc was %d\n", rc);
  414. /* data after should be the same as data before */
  415. assert("msgids should be the same", msgid == msgid2, "msgids were different %d\n", msgid2);
  416. assert("count should be the same", count == count2, "counts were different %d\n", count2);
  417. for (i = 0; i < count2; ++i)
  418. assert("qoss should be the same", granted_qoss[i] == granted_qoss2[i], "qoss were different %d\n", granted_qoss2[i]);
  419. /* exit: */
  420. MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.",
  421. (failures == 0) ? "passed" : "failed", tests, failures);
  422. write_test_result();
  423. return failures;
  424. }
  425. int test5(struct Options options)
  426. {
  427. int i = 0;
  428. int rc = 0;
  429. unsigned char buf[100];
  430. int buflen = sizeof(buf);
  431. #define TOPIC_COUNT 2
  432. unsigned char dup = 0;
  433. unsigned short msgid = 23;
  434. int count = TOPIC_COUNT;
  435. MQTTString topicStrings[TOPIC_COUNT] = { MQTTString_initializer, MQTTString_initializer };
  436. unsigned char dup2 = 1;
  437. unsigned short msgid2 = 2223;
  438. int count2 = 0;
  439. MQTTString topicStrings2[TOPIC_COUNT] = { MQTTString_initializer, MQTTString_initializer };
  440. fprintf(xml, "<testcase classname=\"test1\" name=\"de/serialization\"");
  441. global_start_time = start_clock();
  442. failures = 0;
  443. MyLog(LOGA_INFO, "Starting test 2 - serialization of unsubscribe and back");
  444. topicStrings[0].cstring = "mytopic";
  445. topicStrings[1].cstring = "mytopic2";
  446. rc = MQTTSerialize_unsubscribe(buf, buflen, dup, msgid, count, topicStrings);
  447. assert("good rc from serialize unsubscribe", rc > 0, "rc was %d\n", rc);
  448. rc = MQTTDeserialize_unsubscribe(&dup2, &msgid2, 2, &count2, topicStrings2, buf, buflen);
  449. assert("good rc from deserialize unsubscribe", rc == 1, "rc was %d\n", rc);
  450. /* data after should be the same as data before */
  451. assert("dups should be the same", dup == dup2, "dups were different %d\n", dup2);
  452. assert("msgids should be the same", msgid == msgid2, "msgids were different %d\n", msgid2);
  453. assert("count should be the same", count == count2, "counts were different %d\n", count2);
  454. for (i = 0; i < count2; ++i)
  455. assert("topics should be the same",
  456. checkMQTTStrings(topicStrings[i], topicStrings2[i]), "topics were different %s\n", "");
  457. /* exit: */
  458. MyLog(LOGA_INFO, "TEST5: test %s. %d tests run, %d failures.",
  459. (failures == 0) ? "passed" : "failed", tests, failures);
  460. write_test_result();
  461. return failures;
  462. }
  463. int test6(struct Options options)
  464. {
  465. int rc = 0;
  466. unsigned char buf[100];
  467. int buflen = sizeof(buf);
  468. unsigned char sessionPresent = 1;
  469. unsigned char connack_rc = 77;
  470. unsigned char sessionPresent2 = 0;
  471. unsigned char connack_rc2 = 0;
  472. fprintf(xml, "<testcase classname=\"test1\" name=\"de/serialization\"");
  473. global_start_time = start_clock();
  474. failures = 0;
  475. MyLog(LOGA_INFO, "Starting test 2 - serialization of connack and back");
  476. rc = MQTTSerialize_connack(buf, buflen, connack_rc, sessionPresent);
  477. assert("good rc from serialize connack", rc > 0, "rc was %d\n", rc);
  478. rc = MQTTDeserialize_connack(&sessionPresent2, &connack_rc2, buf, buflen);
  479. assert("good rc from deserialize connack", rc == 1, "rc was %d\n", rc);
  480. /* data after should be the same as data before */
  481. assert("connack rcs should be the same", connack_rc == connack_rc2, "connack rcs were different %d\n", connack_rc2);
  482. assert("session present flags should be the same", sessionPresent == sessionPresent2,
  483. "session present flags were different %d\n", sessionPresent2);
  484. /* exit: */
  485. MyLog(LOGA_INFO, "TEST6: test %s. %d tests run, %d failures.",
  486. (failures == 0) ? "passed" : "failed", tests, failures);
  487. write_test_result();
  488. return failures;
  489. }
  490. int main(int argc, char** argv)
  491. {
  492. int rc = 0;
  493. int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6};
  494. xml = fopen("TEST-test1.xml", "w");
  495. fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));
  496. getopts(argc, argv);
  497. if (options.test_no == 0)
  498. { /* run all the tests */
  499. for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
  500. rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
  501. }
  502. else
  503. rc = tests[options.test_no](options); /* run just the selected test */
  504. if (rc == 0)
  505. MyLog(LOGA_INFO, "verdict pass");
  506. else
  507. MyLog(LOGA_INFO, "verdict fail");
  508. fprintf(xml, "</testsuite>\n");
  509. fclose(xml);
  510. return rc;
  511. }