False when the run asked for coverage and cannot have it. Children run in * other working directories, so they are handed an absolute name. */
| 1453 | /* False when the run asked for coverage and cannot have it. Children run in |
| 1454 | * other working directories, so they are handed an absolute name. */ |
| 1455 | static bool tf_coverage_init(void) { |
| 1456 | const char *dir = getenv("CBM_TEST_COVERAGE_DIR"); |
| 1457 | if (!dir || !dir[0]) { |
| 1458 | return true; |
| 1459 | } |
| 1460 | #ifndef _WIN32 |
| 1461 | /* A binary built for continuous profiles starts in that mode unless |
| 1462 | * LLVM_PROFILE_FILE names a plain file, and then ignores every name this |
| 1463 | * runner gives it: all tests would land in one default.profraw. */ |
| 1464 | const char *initial = getenv("LLVM_PROFILE_FILE"); |
| 1465 | if (!initial || !initial[0] || tf_coverage_continuous) { |
| 1466 | fprintf(stderr, |
| 1467 | "a coverage run starts with LLVM_PROFILE_FILE=/dev/null " |
| 1468 | "(got: %s)\n", |
| 1469 | initial && initial[0] ? initial : "unset"); |
| 1470 | return false; |
| 1471 | } |
| 1472 | if (!tf_coverage_atfork_attempted || tf_coverage_atfork_status != 0) { |
| 1473 | fprintf(stderr, "coverage child accounting unavailable: reason=atfork code=%d\n", |
| 1474 | tf_coverage_atfork_status); |
| 1475 | return false; |
| 1476 | } |
| 1477 | #endif |
| 1478 | if (!cbm_mkdir_p(dir, 0755) || |
| 1479 | !cbm_canonical_path(dir, tf_coverage_dir, sizeof(tf_coverage_dir))) { |
| 1480 | tf_coverage_dir[0] = '\0'; |
| 1481 | fprintf(stderr, "cannot use coverage directory: %s\n", dir); |
| 1482 | return false; |
| 1483 | } |
| 1484 | #ifndef _WIN32 |
| 1485 | if (!tf_coverage_channel_activate()) { |
| 1486 | tf_coverage_dir[0] = '\0'; |
| 1487 | return false; |
| 1488 | } |
| 1489 | #endif |
| 1490 | /* Routing sets the environment, which may move what `dir` points at. */ |
| 1491 | if (!tf_coverage_route(tf_coverage_dir, "_runner.%p", "_runner.child")) { |
| 1492 | fprintf(stderr, "cannot route coverage profiles under: %s\n", tf_coverage_dir); |
| 1493 | tf_coverage_dir[0] = '\0'; |
| 1494 | #ifndef _WIN32 |
| 1495 | tf_coverage_channel_finish(); |
| 1496 | #endif |
| 1497 | return false; |
| 1498 | } |
| 1499 | return true; |
| 1500 | } |
| 1501 | |
| 1502 | #ifndef _WIN32 |
| 1503 | /* ── Children ──────────────────────────────────────────────────────── |
no test coverage detected