Skip to content

Commit 5e7efd8

Browse files
authored
Merge pull request #240 from MPLLang/simple-tests
add simple examples to CI
2 parents 5d21545 + f29c44b commit 5e7efd8

19 files changed

Lines changed: 192 additions & 0 deletions

File tree

.github/workflows/examples.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Examples
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- ".github/workflows/examples.yml"
8+
- "examples/**"
9+
- "basis-library/**"
10+
- "mlton/**"
11+
- "runtime/**"
12+
- "include/**"
13+
- "Makefile"
14+
- "Makefile.config"
15+
- "default.nix"
16+
- "Dockerfile.amd64"
17+
- "Dockerfile.arm64"
18+
- "docker-bake.hcl"
19+
pull_request:
20+
branches: [ "main" ]
21+
paths:
22+
- ".github/workflows/examples.yml"
23+
- "examples/**"
24+
- "basis-library/**"
25+
- "mlton/**"
26+
- "runtime/**"
27+
- "include/**"
28+
- "Makefile"
29+
- "Makefile.config"
30+
- "default.nix"
31+
- "Dockerfile.amd64"
32+
- "Dockerfile.arm64"
33+
- "docker-bake.hcl"
34+
35+
jobs:
36+
build-and-run-examples:
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 45
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
44+
- name: Install dependencies
45+
run: |
46+
sudo apt-get update
47+
sudo apt-get install -y mlton libgmp-dev gcc make
48+
49+
- name: Cache MPL compiler
50+
id: cache-mpl
51+
uses: actions/cache@v4
52+
with:
53+
path: build
54+
key: mpl-${{ runner.os }}-${{ hashFiles('mlton/**', 'runtime/**', 'include/**', 'basis-library/**', 'Makefile', 'Makefile.config') }}
55+
56+
- name: Build MPL compiler
57+
if: steps.cache-mpl.outputs.cache-hit != 'true'
58+
run: make --silent
59+
60+
- name: Build examples
61+
run: make -C examples --silent
62+
63+
- name: Run examples smoke tests
64+
run: |
65+
set -euo pipefail
66+
cd examples
67+
68+
# Strip timing information from program output.
69+
# Removes "... in X.XXXXs" and "Finished in: X.XXXXs" substrings,
70+
# then removes any resulting blank lines.
71+
strip_timing() {
72+
sed -E \
73+
-e 's/[Ff]inished in:? [0-9]+\.[0-9]+s\.?//g' \
74+
-e 's/ in [0-9]+\.[0-9]+s\.?//g' \
75+
-e 's/[[:space:]]+$//' \
76+
| sed '/^$/d'
77+
}
78+
79+
fail=0
80+
check_output() {
81+
local name="$1"
82+
shift
83+
local actual
84+
actual=$("$@" 2>&1 | strip_timing)
85+
local expected
86+
expected=$(cat "expected/${name}.ok")
87+
if [ "$actual" != "$expected" ]; then
88+
echo "FAIL: $name"
89+
diff <(echo "$actual") <(echo "$expected") || true
90+
fail=1
91+
else
92+
echo "PASS: $name"
93+
fi
94+
}
95+
96+
check_output fib ./bin/fib -N 20
97+
check_output random ./bin/random -N 1000 -seed 1
98+
check_output primes ./bin/primes -N 10000
99+
check_output msort ./bin/msort -N 20000
100+
check_output dmm ./bin/dmm -N 16
101+
check_output ray bash -c './bin/ray -m 32 -n 32 -s rgbbox -f ray_result.ppm && echo "ray_result.ppm checksum: $(md5sum ray_result.ppm | cut -d" " -f1)"'
102+
check_output nn ./bin/nn -N 500
103+
check_output nqueens ./bin/nqueens -N 10
104+
check_output coins ./bin/coins -N 100 -repeat 1
105+
check_output tokens ./bin/tokens expected/input.txt
106+
check_output dedup ./bin/dedup expected/input.txt
107+
check_output seam-carve bash -c './bin/seam-carve ray_result.ppm -num-seams 5 -output seam_result.gif && echo "seam_result.gif checksum: $(md5sum seam_result.gif | cut -d" " -f1)"'
108+
check_output reverb bash -c './bin/reverb expected/test.wav -output reverb_result.wav && echo "reverb_result.wav checksum: $(md5sum reverb_result.wav | cut -d" " -f1)"'
109+
110+
if [ "$fail" -ne 0 ]; then
111+
echo "Some output checks failed!"
112+
exit 1
113+
fi

examples/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
bin/
2+
ray_result.ppm
3+
seam_result.gif
4+
reverb_result.wav

examples/expected/coins.ok

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
N 100
2+
sequential? false
3+
repeat 1
4+
Parallel: 243.

examples/expected/dedup.ok

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
brown
2+
quick
3+
jumps
4+
lazy
5+
the
6+
fox
7+
dog
8+
over

examples/expected/dmm.ok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
generating matrices of sidelength 16
2+
multiplying
3+
result [16.0, 16.0, 16.0, ..., 16.0]

examples/expected/fib.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fib 20
2+
result 6765

examples/expected/input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
the quick brown fox jumps over the lazy dog
2+
the fox the fox the dog

examples/expected/msort.ok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
generating 20000 random integers
2+
sorting
3+
result [1, 2, 3, 6, 6, 7, 8, ..., 19999]

examples/expected/nn.ok

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
N 500
2+
generated input
3+
built quadtree
4+
found all neighbors
5+
result [359, 396, 463, ..., 340]
6+
to see output, use -output and -resolution arguments
7+
for example: nn -N 10000 -output result.ppm -resolution 1000

examples/expected/nqueens.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
counting number of 10x10 solutions
2+
result 724

0 commit comments

Comments
 (0)