Skip to content

random_runtime coverage is 91.43% on Linux vs 100% on macOS: the /dev/urandom fallback path is glibc-only #226

Description

@MelbourneDeveloper

Symptom

_coverage_check_c_runtime measures random_runtime.c at 91.43% of 35 lines on Linux and 100% on macOS/arm64 under xcrun llvm-cov gcov. The gate threshold is pinned at 90 (raised from main's 45) rather than the 95 the macOS numbers suggested.

Cause

compiler/runtime/random_runtime.c selects its entropy source at compile time. The /dev/urandom fallback branch only exists in the glibc build, and nothing in builtins_runtime_tests.c forces that branch — so on Linux those lines compile, instrument and then never execute.

Fix

Drive the fallback deliberately rather than incidentally: make the entropy-source selection injectable for the test build (or exercise the fallback through a seam that does not depend on which libc compiled the file), assert the fallback returns values in range and reports failure truthfully when the source cannot be opened, then ratchet random_runtime toward 95 once Linux measures it.

Do not close this by exempting the file — the uncovered lines are the failure path, which is the half that matters.

Verification

docker run --rm -v "$PWD":/w -w /w debian:bookworm bash -c '...gcc --coverage ... && gcov ...'
grep -n '#####' random_runtime.c.gcov

Related: #197.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions