MCPcopy Create free account
hub / github.com/corosync/corosync / run_test

Function run_test

test/testsam.c:1315–1371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1313}
1314
1315static int run_test(const char *test_name, int (test_func)(void), int skippable, int *all_passed, int *no_skipped)
1316{
1317 pid_t pid;
1318 int err;
1319 int stat;
1320 const char *res_str;
1321
1322 fprintf (stderr, "Running %s test\n", test_name);
1323 pid = fork ();
1324
1325 if (pid == -1) {
1326 fprintf (stderr, "Can't fork\n");
1327
1328 exit(1);
1329 }
1330
1331 if (pid == 0) {
1332 /*
1333 * Child runs tests and sets exit code to result of test
1334 */
1335 err = test_func ();
1336
1337 /*
1338 * After sam_register this is child of child
1339 */
1340 sam_finalize ();
1341
1342 exit (err);
1343 }
1344
1345 /*
1346 * Parent waits for child to run the test and return exit code
1347 */
1348 waitpid (pid, &stat, 0);
1349
1350 err = WEXITSTATUS (stat);
1351
1352 if (!skippable) {
1353 res_str = (err == 0 ? "passed" : "failed");
1354
1355 if (err != 0) {
1356 (*all_passed) = 0;
1357 }
1358 } else {
1359 res_str = (err == 0 ? "passed" : (err == 1 ? "skipped" : "failed"));
1360
1361 if (err == 1) {
1362 (*no_skipped)++;
1363 } else if (err > 1) {
1364 (*all_passed) = 0;
1365 }
1366 }
1367
1368 fprintf (stderr, "%s test %s\n", test_name, res_str);
1369
1370 return (err);
1371}
1372

Callers 1

mainFunction · 0.85

Calls 1

sam_finalizeFunction · 0.85

Tested by

no test coverage detected