interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / tools-om / fmt.sh

53 lines · 2288 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# fmt.om acceptance: om/tools/fmt.om (fm_f = "%.Pf", fm_g = "%.Pg"), composed with a test export, against
4# glibc snprintf through tests/tools-om/fmt_diff.c; a flipped-record negative control; recompiled mutants.
5# FMT_DIFF_N (default 40000) random doubles, nine conversions each, plus the specials.
6# Run under: bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10
7set -eu
8ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
9cd "$ROOT"
10tmp=$(mktemp -d)
11trap 'rm -rf "$tmp"' EXIT
12. tests/tools-om/lib.sh
13tom_pin
14N=${FMT_DIFF_N:-40000}
15UNIT=$tmp/fmtt.om
16{ cat om/tools/fmt.om; cat <<'OM'
17
18note fmtt: test export, conversion g (0 "%.Pf", else "%.Pg") of the f64 with bits xb at precision pr.
19fn fmtt xb ulong pr ulong g ulong o edit uchar 1600 to ulong
20x = bitcast f64 xb
21if ne g 0
22ret fm_g x pr o
23end
24ret fm_f x pr o
25end
26OM
27} > "$UNIT"
28OMEGA_SEEDED_OMC="$OMC" sh "$BRIDGE/tools/bridge-seeded" c "$UNIT" > "$tmp/fmtt.c"
29$CC $TOM_CFLAGS -o "$tmp/fmt_diff" tests/tools-om/fmt_diff.c "$tmp/fmtt.c" -lm
30"$tmp/fmt_diff" "$N" c > "$tmp/c.out"
31"$tmp/fmt_diff" "$N" om > "$tmp/om.out"
32cmp "$tmp/c.out" "$tmp/om.out" || { echo "FAIL fmt differential"; diff "$tmp/c.out" "$tmp/om.out" | head; exit 1; }
33lines=$(wc -l < "$tmp/c.out")
34echo "differential: $lines conversions identical to glibc snprintf"
35tom_flip "$tmp/c.out" "$tmp/om.out"
36
37killed=0
38"$tmp/fmt_diff" 2000 c > "$tmp/c.small"
39mut() { # NAME SITE REPLACEMENT
40 tom_mutant "$1" "$UNIT" "$2" "$3"
41 $CC $TOM_CFLAGS -o "$tmp/$1.bin" tests/tools-om/fmt_diff.c "$tmp/$1.c" -lm
42 "$tmp/$1.bin" 2000 om > "$tmp/$1.out" || true
43 if cmp -s "$tmp/c.small" "$tmp/$1.out"; then echo "FAIL mutant $1 survived"; exit 1; fi
44 echo "mutant $1: killed ($(cmp "$tmp/c.small" "$tmp/$1.out" | sed 's/.*, //'))"; killed=$((killed + 1))
45}
46mut ties_even 'ret and sub ulong get d sub q 1 48 1' 'ret ulong 1'
47mut round_down 'if lt c 53' 'if lt c 52'
48mut pow5 'n = fm_mul l n 1220703125' 'n = fm_mul l n 1220703124'
49mut exp_digits 'if lt xa 10' 'if lt xa 9'
50mut g_small 'if gt xa 4' 'if gt xa 5'
51mut g_large 'if ge xa pr' 'if gt xa pr'
52echo "fmt mutants: $killed killed"
53echo "tools-om fmt: PASS (differential $lines conversions, negative control, $killed mutants killed)"