1
0

test.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /***********************************************************************
  2. **
  3. ** Filename : test.c
  4. ** Project : Unit Test
  5. ** Subsystem :
  6. ** Module : Basic routines for performing a Unit Test
  7. ** Document :
  8. **
  9. *************************************************************************
  10. **
  11. ** Brief Description
  12. ** =================
  13. **
  14. ** Functions to provide a nice, consistent Unit Test infrastructure.
  15. **
  16. **
  17. *************************************************************************
  18. **
  19. ** Change History
  20. ** --------------
  21. **
  22. ** 20-Jun-2005 Graeme McKerrell Populated lub_test_stop_here() t ensure it is reached when a
  23. ** optimising compiler is used.
  24. ** 7-Dec-2004 Graeme McKerrell Updated to use the "lub_test_" prefix
  25. ** rather than "unittest_"
  26. ** 4 Mar 2004 Graeme McKerrell Ported for use in Garibaldi
  27. ** 4 Oct 2002 Graeme McKerrell updated to use central interface
  28. ** definition
  29. ** 18-Mar-2002 Graeme McKerrell Added unitest_stop_here() support
  30. ** 16-Mar-2002 Graeme McKerrell LINTed...
  31. ** 14 Nov 2000 Brett B. Bonner created
  32. **
  33. *************************************************************************
  34. **
  35. ** Copyright (C) 3Com Corporation. All Rights Reserved.
  36. **
  37. \************************************************************************/
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <stdarg.h>
  41. #include <stdlib.h>
  42. /*lint -esym(534,vsprintf) */
  43. /*lint -esym(632,va_list,__va_list) */
  44. /*lint -esym(633,va_list,__gnuc_va_list) */
  45. #include "lub/test.h"
  46. /* Where to direct output (bitmasks) */
  47. #define LUB_TEST_LOGTOFILE 0x1
  48. #define LUB_TEST_LOGTOSTDOUT 0x2
  49. /* Termination Mode */
  50. typedef enum {
  51. ContinueOnFail,
  52. StopOnFail
  53. } TerminationMode;
  54. /* local variables */
  55. static char unitTestName[80];
  56. static char seqDescr[80];
  57. static FILE *logp = NULL;
  58. static lub_test_verbosity_t verbosity = LUB_TEST_NORMAL;
  59. static int outputTo;
  60. static lub_test_status_t unitTestStatus = LUB_TEST_PASS;
  61. static int seqNum = 0;
  62. static int testNum = 0;
  63. static int failureCount = 0;
  64. static int testCount = 0;
  65. static TerminationMode termMode = ContinueOnFail;
  66. /* local functions */
  67. static void testLogNoIndent(lub_test_verbosity_t level, const char *format,
  68. ...);
  69. static void printUsage(void);
  70. /* definitions */
  71. #define LOGGING_TO_FILE ((outputTo & LUB_TEST_LOGTOFILE) != 0)
  72. #define LOGGING_TO_STDOUT ((outputTo & LUB_TEST_LOGTOSTDOUT) != 0)
  73. /*
  74. * This is provided as a debug aid.
  75. */
  76. void lub_test_stop_here(void)
  77. {
  78. /* If any test fails, the unit test fails */
  79. unitTestStatus = LUB_TEST_FAIL;
  80. failureCount++;
  81. if (termMode == StopOnFail) {
  82. lub_test_end();
  83. exit(1);
  84. }
  85. }
  86. static lub_test_status_t checkStatus(lub_test_status_t value)
  87. {
  88. /* Test number gets incremented automatically... */
  89. testNum++;
  90. testCount++; /* update total number of tests performed */
  91. if (LUB_TEST_FAIL == value) {
  92. lub_test_stop_here();
  93. }
  94. return value;
  95. }
  96. /*******************************************************
  97. * unit-test-level functions
  98. ********************************************************/
  99. /* NAME: unitTestLog
  100. PURPOSE: Log output to file and/or stdout, verbosity-filtered
  101. ARGS: level - priority of this message.
  102. Will be logged only if priority equals or exceeds
  103. the current lub_test_verbosity_t level.
  104. format, args - printf-style format and parameters
  105. RETURN: none
  106. */
  107. static void unitTestLog(lub_test_verbosity_t level, const char *format, ...)
  108. {
  109. va_list args;
  110. char string[320]; /* ought to be big enough; that's 4 lines */
  111. /* Turn format,args into a string */
  112. va_start(args, format);
  113. vsprintf(string, format, args);
  114. va_end(args);
  115. /* output to selected destination if lub_test_verbosity_t equals or exceeds
  116. current setting. */
  117. if (level <= verbosity) {
  118. if (LOGGING_TO_FILE) {
  119. if (NULL != logp) {
  120. fprintf(logp, "%s\n", string);
  121. } else {
  122. fprintf(stderr,
  123. "ERROR: Trying to log to file, but no logfile is open!\n");
  124. }
  125. }
  126. if (LOGGING_TO_STDOUT) {
  127. fprintf(stdout, "%s\n", string);
  128. }
  129. }
  130. }
  131. /* NAME: TestStartLog
  132. PURPOSE: Sets up logging destination(s) and opens logfile.
  133. ARGS: whereToLog - where output gets directed to
  134. Bitmask of lub_test_LOGTOFILE, lub_test_LOGTOSTDOUT
  135. logfile - file name to open.
  136. Use NULL if not logging to file.
  137. RETURN: BOOL_FALSE == failure
  138. BOOL_TRUE == success
  139. */
  140. static int TestStartLog(int whereToLog, const char *logFile)
  141. {
  142. bool_t status = BOOL_TRUE;
  143. /* Where are we logging? */
  144. outputTo = whereToLog;
  145. /* open log file */
  146. if (LOGGING_TO_FILE && (strlen(logFile) < 1)) {
  147. status = BOOL_FALSE;
  148. fprintf(stderr, "ERROR: No logfile name specified.\n");
  149. }
  150. if (LOGGING_TO_FILE && status) {
  151. if ((logp = fopen(logFile, "w")) == NULL) {
  152. status = BOOL_FALSE;
  153. fprintf(stderr,
  154. "ERROR: could not open log file '%s'.\n",
  155. logFile);
  156. }
  157. }
  158. return status;
  159. }
  160. /* NAME: lub_test_begin
  161. PURPOSE: Starts unit test.
  162. ARGS: format,args - Specification of unit test name
  163. RETURN: none
  164. */
  165. void lub_test_begin(const char *name, ...)
  166. {
  167. va_list args;
  168. /* Process varargs list into unit test name string */
  169. va_start(args, name);
  170. vsprintf(unitTestName, name, args);
  171. va_end(args);
  172. unitTestLog(LUB_TEST_NORMAL, "BEGIN: Testing '%s'.", unitTestName);
  173. /* reset counters */
  174. seqNum = testNum = testCount = failureCount = 0;
  175. }
  176. /* NAME: lub_test_get_status
  177. PURPOSE: Reports current unit test status
  178. ARGS: none
  179. RETURN: Status code - TESTPASS/TESTFAIL
  180. */
  181. lub_test_status_t lub_test_get_status(void)
  182. {
  183. return unitTestStatus;
  184. }
  185. /* NAME: lub_test_failure_count
  186. PURPOSE: Reports current number of test failures
  187. ARGS: none
  188. RETURN: Count of failures
  189. */
  190. int lub_test_failure_count(void)
  191. {
  192. return failureCount;
  193. }
  194. /* NAME: lub_test_end
  195. PURPOSE: Ends test. Closes log file.
  196. ARGS: none
  197. RETURN: none
  198. */
  199. void lub_test_end(void)
  200. {
  201. char result[40];
  202. if (unitTestStatus == LUB_TEST_PASS) {
  203. sprintf(result, "PASSED (%d tests)", testCount);
  204. } else {
  205. if (failureCount == 1) {
  206. sprintf(result, "FAILED (%d failure, %d tests)",
  207. failureCount, testCount);
  208. } else {
  209. sprintf(result, "FAILED (%d failures, %d tests)",
  210. failureCount, testCount);
  211. }
  212. }
  213. if ((termMode == ContinueOnFail) || (unitTestStatus == LUB_TEST_PASS)) {
  214. /* ran to end - either due to continue-on-fail, or because
  215. everything passed */
  216. unitTestLog(LUB_TEST_TERSE, "END: Test '%s' %s.\n",
  217. unitTestName, result);
  218. } else {
  219. /* stopped on first failure */
  220. unitTestLog(LUB_TEST_TERSE,
  221. "END: Test '%s': STOPPED AT FIRST FAILURE.\n",
  222. unitTestName);
  223. }
  224. if (LOGGING_TO_FILE) {
  225. fclose(logp);
  226. }
  227. }
  228. /* NAME: printUsage
  229. PURPOSE: Prints usage message
  230. ARGS: none
  231. RETURN: none
  232. */
  233. static void printUsage(void)
  234. {
  235. printf("Usage:\n");
  236. printf
  237. ("-terse, -normal, -verbose : set lub_test_verbosity_t level (default: normal)\n");
  238. printf
  239. ("-stoponfail, -continueonfail : set behavior upon failure (default: continue)\n");
  240. printf
  241. ("-logfile [FILENAME] : log to FILENAME (default: 'test.log')\n");
  242. printf("-nologfile : disable logging to file \n");
  243. printf
  244. ("-stdout, -nostdout : enable/disable logging to STDOUT\n");
  245. printf("-usage, -help : print these options and exit\n");
  246. printf("\nAll arguments are optional. Defaults are equivalent to: \n");
  247. printf(" -normal -continueonfail -logfile test.log -stdout\n");
  248. }
  249. /* NAME: lub_test_parse_command_line
  250. PURPOSE: Parses command-line arguments & sets unit test options.
  251. ARGS: argc, argv - as passed to main()
  252. RETURN: none (will exit if there is an error)
  253. */
  254. void lub_test_parse_command_line(int argc, const char *const *argv)
  255. {
  256. bool_t status = BOOL_TRUE;
  257. int logDest = 0;
  258. static char defaultFile[] = "test.log";
  259. char *logFile;
  260. bool_t logFileAllocatedFromHeap = BOOL_FALSE;
  261. /* variables used to detect conflicting options */
  262. int verbset = 0;
  263. int failset = 0;
  264. int logfset = 0;
  265. int stdset = 0;
  266. /* Set logFile to defaultFile so there is always a valid filename.
  267. Also set logging destination to both STDOUT and FILE.
  268. These will be changed later if user specifies something else. */
  269. logFile = defaultFile;
  270. logDest = (LUB_TEST_LOGTOFILE | LUB_TEST_LOGTOSTDOUT);
  271. /* Loop through the command line arguments. */
  272. while (--argc > 0) {
  273. /* Usage/Help */
  274. if ((strstr(argv[argc], "-usage") != NULL) ||
  275. (strstr(argv[argc], "-help") != NULL)) {
  276. printUsage();
  277. exit(0);
  278. }
  279. /* lub_test_verbosity_t Levels */
  280. else if (strstr(argv[argc], "-terse") != NULL) {
  281. verbosity = LUB_TEST_TERSE;
  282. verbset++;
  283. } else if (strstr(argv[argc], "-normal") != NULL) {
  284. verbosity = LUB_TEST_NORMAL;
  285. verbset++;
  286. } else if (strstr(argv[argc], "-verbose") != NULL) {
  287. verbosity = LUB_TEST_VERBOSE;
  288. verbset++;
  289. }
  290. /* Failure behavior */
  291. else if (strstr(argv[argc], "-stoponfail") != NULL) {
  292. termMode = StopOnFail;
  293. failset++;
  294. } else if (strstr(argv[argc], "-continueonfail") != NULL) {
  295. termMode = ContinueOnFail;
  296. failset++;
  297. }
  298. /* Log file options */
  299. else if (strstr(argv[argc], "-logfile") != NULL) {
  300. logDest |= LUB_TEST_LOGTOFILE;
  301. /* Was a log file name specified?
  302. We assume it's a file name if it doesn't start with '-' */
  303. if (strstr(argv[argc + 1], "-") != argv[argc + 1]) {
  304. /* Yes, got a filename */
  305. logFile =
  306. (char *)malloc(strlen(argv[argc + 1]) + 1);
  307. if (NULL == logFile) {
  308. status = BOOL_FALSE;
  309. fprintf(stderr,
  310. "unitTestParseCL: ERROR: Memory allocation problem.\n");
  311. } else {
  312. /* all is well, go ahead and copy the string */
  313. strcpy(logFile, argv[argc + 1]);
  314. }
  315. logFileAllocatedFromHeap = BOOL_TRUE;
  316. }
  317. logfset++;
  318. } else if (strstr(argv[argc], "-nologfile") != NULL) {
  319. logDest &= ~LUB_TEST_LOGTOFILE;
  320. logfset++;
  321. }
  322. /* Stdout options */
  323. else if (strstr(argv[argc], "-stdout") != NULL) {
  324. logDest |= LUB_TEST_LOGTOSTDOUT;
  325. stdset++;
  326. } else if (strstr(argv[argc], "-nostdout") != NULL) {
  327. logDest &= ~LUB_TEST_LOGTOSTDOUT;
  328. stdset++;
  329. }
  330. /* Unhandled arguments */
  331. else {
  332. /* If the next argument down in the list is '-logfile', then
  333. this is the logfile name; don't complain. */
  334. if (strstr(argv[argc - 1], "-logfile") == NULL) {
  335. /* This is an unrecognized option.
  336. Don't bother setting status and forcing an exit; just ignore it. */
  337. fprintf(stderr,
  338. "Unrecognized argument: '%s', ignoring it...\n",
  339. argv[argc]);
  340. }
  341. }
  342. }
  343. /* See if there is a logging destination */
  344. if (logDest == 0) {
  345. fprintf(stderr,
  346. "WARNING: No logging is enabled to either stdout or a logfile; expect no output.\n");
  347. }
  348. /* Make sure there were no conflicting options */
  349. if (verbset > 1) {
  350. fprintf(stderr,
  351. "ERROR: conflicting lub_test_verbosity_t options specified.\n");
  352. fprintf(stderr,
  353. " Specify only ONE of -terse, -normal, -verbose\n");
  354. status = BOOL_FALSE;
  355. }
  356. if (failset > 1) {
  357. fprintf(stderr,
  358. "ERROR: conflicting Failure Mode options specified.\n");
  359. fprintf(stderr,
  360. " Specify only ONE of -stoponfail, -continueonfail\n");
  361. status = BOOL_FALSE;
  362. }
  363. if (logfset > 1) {
  364. fprintf(stderr,
  365. "ERROR: conflicting Logfile options specified.\n");
  366. fprintf(stderr,
  367. " Specify only ONE of -logfile, -nologfile\n");
  368. status = BOOL_FALSE;
  369. }
  370. if (stdset > 1) {
  371. fprintf(stderr,
  372. "ERROR: conflicting Stdout options specified.\n");
  373. fprintf(stderr,
  374. " Specify only ONE of -stdout, -nostdout\n");
  375. status = BOOL_FALSE;
  376. }
  377. /* Set up log file, if things are OK so far */
  378. if (status && !TestStartLog(logDest, logFile)) {
  379. status = BOOL_FALSE;
  380. }
  381. if (logFileAllocatedFromHeap) {
  382. /*lint -e673 Possibly inappropriate deallocation (free) for 'static' data */
  383. free(logFile);
  384. /*lint +e673 */
  385. }
  386. if (BOOL_FALSE == status) {
  387. fprintf(stderr, "Something bad has occurred. Aborting...\n");
  388. exit(1);
  389. }
  390. }
  391. /*******************************************************
  392. * sequence level functions
  393. ********************************************************/
  394. /* NAME: lub_test_seq_begin
  395. PURPOSE: Starts a new test sequence.
  396. ARGS: num - sequence number, must be different than last one
  397. format, args - printf-style name for the sequence
  398. RETURN: none
  399. */
  400. void lub_test_seq_begin(int num, const char *seqName, ...)
  401. {
  402. va_list args;
  403. /* Get sequence name */
  404. va_start(args, seqName);
  405. vsprintf(seqDescr, seqName, args);
  406. va_end(args);
  407. /* Start new sequence number */
  408. if (num == seqNum) {
  409. seqNum++;
  410. unitTestLog(LUB_TEST_TERSE,
  411. "seq_start: duplicate sequence number. Using next available sequence number (%d).\n",
  412. seqNum);
  413. } else {
  414. seqNum = num;
  415. }
  416. /* Reset test number */
  417. testNum = 0;
  418. /* Log beginning of sequence */
  419. lub_test_seq_log(LUB_TEST_NORMAL, "*** Sequence '%s' begins ***",
  420. seqDescr);
  421. }
  422. /* NAME: lub_test_seq_end
  423. PURPOSE: Ends current test sequence
  424. ARGS: none
  425. RETURN: none
  426. */
  427. void lub_test_seq_end(void)
  428. {
  429. lub_test_seq_log(LUB_TEST_NORMAL,
  430. "----------------------------------------"
  431. "--------------------");
  432. }
  433. /* NAME: lub_test_seq_log
  434. PURPOSE: Log output to file and/or stdout, verbosity-filtered and
  435. formatted as a "sequence-level" message
  436. ARGS: level - priority of this message.
  437. Will be logged only if priority equals or exceeds
  438. the current lub_test_verbosity_t level.
  439. format, args - printf-style format and parameters
  440. RETURN: none
  441. */
  442. void lub_test_seq_log(lub_test_verbosity_t level, const char *format, ...)
  443. {
  444. va_list args;
  445. char string[160];
  446. /* Turn format,args into a string */
  447. va_start(args, format);
  448. vsprintf(string, format, args);
  449. va_end(args);
  450. unitTestLog(level, "%03d : %s", seqNum, string);
  451. }
  452. /*******************************************************
  453. * test level functions
  454. ********************************************************/
  455. /* NAME: lub_test_check
  456. PURPOSE: True/False test of an expression. If True, test passes.
  457. ARGS: expr - expression to evaluate.
  458. format, args - Printf-style format/parameters describing test.
  459. RETURN: Status code - PASS or FAIL
  460. */
  461. lub_test_status_t lub_test_check(bool_t expr, const char *testName, ...)
  462. {
  463. va_list args;
  464. char testDescr[80];
  465. lub_test_status_t testStatus;
  466. char result[5];
  467. lub_test_verbosity_t verb;
  468. /* evaluate expression */
  469. testStatus = expr ? LUB_TEST_PASS : LUB_TEST_FAIL;
  470. /* extract description as a string */
  471. va_start(args, testName);
  472. vsprintf(testDescr, testName, args);
  473. va_end(args);
  474. /* log results */
  475. if (testStatus == LUB_TEST_PASS) {
  476. verb = LUB_TEST_NORMAL;
  477. sprintf(result, "pass");
  478. } else {
  479. verb = LUB_TEST_TERSE;
  480. sprintf(result, "FAIL");
  481. }
  482. testLogNoIndent(verb, "[%s] %s", result, testDescr);
  483. return checkStatus(testStatus);
  484. }
  485. /* NAME: lub_test_check_int
  486. PURPOSE: Checks whether an integer equals its expected value.
  487. ARGS: expect - expected value.
  488. actual - value being checked.
  489. format, args - Printf-style format/parameters describing test.
  490. RETURN: Status code - PASS or FAIL
  491. */
  492. lub_test_status_t
  493. lub_test_check_int(int expect, int actual, const char *testName, ...)
  494. {
  495. va_list args;
  496. char testDescr[80];
  497. lub_test_status_t testStatus;
  498. char result[5];
  499. char eqne[3];
  500. lub_test_verbosity_t verb;
  501. /* evaluate expression */
  502. testStatus = (expect == actual) ? LUB_TEST_PASS : LUB_TEST_FAIL;
  503. /* extract description as a string */
  504. va_start(args, testName);
  505. vsprintf(testDescr, testName, args);
  506. va_end(args);
  507. /* log results */
  508. if (testStatus == LUB_TEST_PASS) {
  509. sprintf(result, "pass");
  510. sprintf(eqne, "==");
  511. verb = LUB_TEST_NORMAL;
  512. } else {
  513. sprintf(result, "FAIL");
  514. sprintf(eqne, "!=");
  515. verb = LUB_TEST_TERSE;
  516. }
  517. testLogNoIndent(verb, "[%s] (%d%s%d) %s",
  518. result, actual, eqne, expect, testDescr);
  519. return checkStatus(testStatus);
  520. }
  521. /* NAME: lub_test_check_float
  522. PURPOSE: Checks whether a float is within min/max limits.
  523. ARGS: min - minimum acceptable value.
  524. max - maximum acceptable value.
  525. actual - value being checked.
  526. format, args - Printf-style format/parameters describing test.
  527. RETURN: Status code - PASS or FAIL
  528. */
  529. lub_test_status_t
  530. lub_test_check_float(double min, double max, double actual,
  531. const char *testName, ...)
  532. {
  533. va_list args;
  534. char testDescr[80];
  535. lub_test_status_t testStatus;
  536. char result[5];
  537. char gteq[4], lteq[4];
  538. /* evaluate expression */
  539. testStatus = ((actual >= min)
  540. && (actual <= max)) ? LUB_TEST_PASS : LUB_TEST_FAIL;
  541. /* extract description as a string */
  542. va_start(args, testName);
  543. vsprintf(testDescr, testName, args);
  544. va_end(args);
  545. /* log results */
  546. if (testStatus == LUB_TEST_PASS) {
  547. sprintf(result, "pass");
  548. sprintf(gteq, " <=");
  549. sprintf(lteq, " <=");
  550. } else {
  551. sprintf(result, "FAIL");
  552. if (actual < min) {
  553. sprintf(gteq, "!<=");
  554. sprintf(lteq, " <=");
  555. } else {
  556. sprintf(gteq, " <=");
  557. sprintf(lteq, "!<=");
  558. }
  559. }
  560. testLogNoIndent(LUB_TEST_NORMAL, "[%s] (%8f%s%8f%s%8f) %s",
  561. result, min, gteq, actual, lteq, max, testDescr);
  562. return checkStatus(testStatus);
  563. }
  564. /* NAME: lub_test_log
  565. PURPOSE: Log output to file and/or stdout, verbosity-filtered and
  566. formatted as a "test-level" message
  567. ARGS: level - priority of this message.
  568. Will be logged only if priority equals or exceeds
  569. the current lub_test_verbosity_t level.
  570. format, args - printf-style format and parameters
  571. RETURN: none
  572. */
  573. void lub_test_log(lub_test_verbosity_t level, const char *format, ...)
  574. {
  575. va_list args;
  576. char string[160];
  577. /* Turn format,args into a string */
  578. va_start(args, format);
  579. vsprintf(string, format, args);
  580. va_end(args);
  581. unitTestLog(level, "%03d-%04d: %s", seqNum, testNum, string);
  582. }
  583. /* NAME: testLogNoIndent
  584. PURPOSE: Log output to file and/or stdout, verbosity-filtered and
  585. formatted as a "test-level" message.
  586. This "internal" version does not indent, so that the
  587. pass/fail column can be printed in the proper place.
  588. ARGS: level - priority of this message.
  589. Will be logged only if priority equals or exceeds
  590. the current lub_test_verbosity_t level.
  591. format, args - printf-style format and parameters
  592. RETURN: none
  593. */
  594. static void testLogNoIndent(lub_test_verbosity_t level, const char *format, ...)
  595. {
  596. va_list args;
  597. char string[160];
  598. /* Turn format,args into a string */
  599. va_start(args, format);
  600. vsprintf(string, format, args);
  601. va_end(args);
  602. unitTestLog(level, "%03d-%04d: %s", seqNum, testNum, string);
  603. }