-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (88 loc) · 3.16 KB
/
Copy pathtest-consistency.yaml
File metadata and controls
105 lines (88 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Test cross-implementation consistency
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_call:
env:
CARGO_TERM_COLOR: always
jobs:
consistency:
name: Verify all 3 implementations produce identical basic-example output
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config
- name: Build C library
run: |
cd crates/libspot/libspot
make clean
make
- name: Build & run raw C basic example
id: run_c
run: |
cd crates/libspot
# Find the produced static archive (e.g. libspot.a.2.0b5 or libspot.a.3.0.0)
ARCHIVE=$(ls libspot/dist/libspot.a.* | head -n1)
echo "Using archive: $ARCHIVE"
# Use the wrapper crate's own examples/basic.c (kept in sync with the
# Rust examples for output format and K). The submodule may ship a
# different basic.c with a smaller K and different output format.
cc -O2 -std=c99 -o /tmp/basic_c examples/basic.c -Ilibspot/include/ "$ARCHIVE" -lm
/tmp/basic_c | tee /tmp/out_c.txt
- name: Build & run Rust FFI basic example
run: |
cd crates/libspot
cargo run --release --example basic | tee /tmp/out_ffi.txt
- name: Build & run pure-Rust basic example
run: |
cd crates/libspot-rs
cargo run --release --example basic | tee /tmp/out_pure.txt
- name: Compare ANOMALY/EXCESS/NORMAL/Z/T across the 3 implementations
run: |
set -euo pipefail
extract() {
# Extracts the two canonical lines into a normalized "key=value" form.
local file="$1"
local counts z_t
counts=$(grep -E '^ANOMALY=[0-9]+ EXCESS=[0-9]+ NORMAL=[0-9]+$' "$file" | tail -n1)
z_t=$(grep -E '^Z=[-0-9.]+ T=[-0-9.]+$' "$file" | tail -n1)
if [[ -z "$counts" || -z "$z_t" ]]; then
echo "ERROR: could not find canonical output lines in $file" >&2
cat "$file" >&2
exit 1
fi
printf '%s\n%s\n' "$counts" "$z_t"
}
C_OUT=$(extract /tmp/out_c.txt)
FFI_OUT=$(extract /tmp/out_ffi.txt)
PURE_OUT=$(extract /tmp/out_pure.txt)
echo "::group::Raw C"
echo "$C_OUT"
echo "::endgroup::"
echo "::group::Rust FFI (libspot)"
echo "$FFI_OUT"
echo "::endgroup::"
echo "::group::Pure Rust (libspot-rs)"
echo "$PURE_OUT"
echo "::endgroup::"
if [[ "$C_OUT" != "$FFI_OUT" ]]; then
echo "::error::Raw C and Rust FFI outputs differ"
diff <(echo "$C_OUT") <(echo "$FFI_OUT") || true
exit 1
fi
if [[ "$C_OUT" != "$PURE_OUT" ]]; then
echo "::error::Raw C and pure-Rust outputs differ"
diff <(echo "$C_OUT") <(echo "$PURE_OUT") || true
exit 1
fi
echo "All three implementations produced identical output."