Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/cobalt
2 changes: 1 addition & 1 deletion libs/codecs
2 changes: 1 addition & 1 deletion libs/secure
50 changes: 49 additions & 1 deletion tools/test/crypto_dudect_judge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@
|t| is 10 or more, the planted program and the harness's test excepted; with --rerun it measures
each judged case over 10 again in two fresh processes and fails exactly when two of the three
values are 10 or more, naming them; it never reruns a case that is not judged; it refuses an
output with no case line; and on wasip2 it runs the program through the launcher. Run with the
output with no case line; on wasip2 it runs the program through the launcher; and it prints the
CPU it runs on, read from /proc/cpuinfo's text as dudect.hpp reads it, and repeats it in each
warning. Run with the
names of some cases to run only those."""

from __future__ import annotations

import importlib.util
import platform
import re
import shlex
import subprocess
import sys
import tempfile
from collections.abc import Callable
from importlib.machinery import SourceFileLoader
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
Expand Down Expand Up @@ -49,6 +55,15 @@ def run_judge(*args: str) -> subprocess.CompletedProcess[str]:
check=False, timeout=120)


def judge_module():
"""The judge, imported, for its functions."""
spec = importlib.util.spec_from_file_location('dudect_judge', JUDGE)
assert spec is not None and isinstance(spec.loader, SourceFileLoader)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


def write_output(directory: Path, name: str, text: str, suffix: str = '') -> Path:
"""bin/<build directory>/<name>.output holding text and the lane's exit line."""
where = directory / f'{name}.test/clang/release{suffix}'
Expand Down Expand Up @@ -149,6 +164,37 @@ def judge_wasip2_launcher(scratch: Path) -> None:
assert '69.80, 1.00, 1.00' in done.stdout, done.stdout


HOST = re.compile(r'^dudect host cpu="[^"]+" microcode=\S+$')


def judge_prints_host(scratch: Path) -> None:
write_output(scratch, 'dudect_bearssl', BEARSSL)
done = run_judge('--bin', str(scratch), '--target', 'wasip2')
expect(done, 0)
host = done.stdout.splitlines()[0]
assert HOST.match(host), done.stdout
if platform.system() in ('Linux', 'Darwin') and platform.machine() in ('x86_64', 'AMD64'):
assert 'cpu="unavailable"' not in host, host
warnings = [line for line in done.stdout.splitlines() if line.startswith('::warning')]
assert len(warnings) == 1 and warnings[0].endswith('%0A' + host), warnings


def judge_parses_cpuinfo(scratch: Path) -> None:
del scratch
parse = judge_module().parse_cpuinfo
x86 = ('processor\t: 0\nvendor_id\t: AuthenticAMD\n'
'model name\t: AMD EPYC 9V74 80-Core Processor\nmicrocode\t: 0xa10113e\n'
'processor\t: 1\nmodel name\t: other\n')
assert parse(x86) == ('AMD EPYC 9V74 80-Core Processor', '0xa10113e'), parse(x86)
quoted = 'model name\t: Intel(R) Xeon(R) "6975P-C"\nmicrocode\t: 0x1 "a"\n'
assert parse(quoted) == ("Intel(R) Xeon(R) '6975P-C'", '0x1__a_'), parse(quoted)
arm64 = ('processor\t: 0\nCPU implementer\t: 0x41\nCPU architecture: 8\n'
'CPU variant\t: 0x1\nCPU part\t: 0xd4f\nCPU revision\t: 1\n')
assert parse(arm64) == ('arm64 implementer=0x41 part=0xd4f variant=0x1 revision=1',
'unavailable'), parse(arm64)
assert parse('') == ('unavailable', 'unavailable'), parse('')


CASES: list[Callable[[Path], None]] = [
judge_prints_and_warns,
judge_two_of_three_pass,
Expand All @@ -157,6 +203,8 @@ def judge_wasip2_launcher(scratch: Path) -> None:
judge_skips_planted,
judge_output_without_case_lines,
judge_wasip2_launcher,
judge_prints_host,
judge_parses_cpuinfo,
]


Expand Down
Loading