Skip to content

Commit

Permalink
ci, sample: add tests for child processes
Browse files Browse the repository at this point in the history
Testing child processes is a little out-of-scope for `cargo test`,
but they need testing all the same.

Include a child process test in our existing CI integration tests.
The sample recordings are played back through samedec. A bash
script for each verifies that the $ENVironment is as expected.
  • Loading branch information
cbs228 committed Feb 3, 2024
1 parent 1151481 commit 7c419a7
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 11 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/rust_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,14 @@ jobs:
enableCrossOsArchive: true
fail-on-cache-miss: true

- name: Build and test samedec
- name: Build and unit-test samedec
shell: bash
run: |
cargo test --frozen -p samedec --verbose
- name: Run integration tests
shell: bash
run: |
set -e;
for file in $(basename -s .bin sample/*.s16le.bin); do
printf '[%s]\n' "$file";
cargo run -p samedec -- -r 22050 <"sample/$file.bin" | tee result;
cmp result "sample/$file.txt" || {
echo "FAIL!";
exit 1;
};
echo "PASS";
done
pushd sample
./test.sh
popd
6 changes: 6 additions & 0 deletions sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ You can play one of these files with sox:
```bash
play -t raw -r 22.05k -e signed -b 16 -c 1 'long_message.22050.s16le.bin'
```

You can run all of the samples as an integration test with

```bash
./test.sh
```
13 changes: 13 additions & 0 deletions sample/long_message.22050.s16le.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

# close standard input to ignore it
exec 0>/dev/null

[[ $SAMEDEC_RATE = "22050" ]]
[[ $SAMEDEC_EVENT = "Practice/Demo Warning" ]]
[[ $SAMEDEC_ORG = "EAS" ]]
[[ $SAMEDEC_SIGNIFICANCE = "W" ]]
[[ $SAMEDEC_LOCATIONS = "372088 091724 919623 645687 745748 175234 039940 955869 091611 304171 931612 334828 179485 569615 809223 830187 611340 014693 472885 084645 977764 466883 406863 390018 701741 058097 752790 311648 820127 255900 581947" ]]
[[ $SAMEDEC_ISSUETIME = "$SAMEDEC_PURGETIME" ]]

echo "+OK"
1 change: 1 addition & 0 deletions sample/long_message.22050.s16le.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ZCZC-EAS-DMO-372088-091724-919623-645687-745748-175234-039940-955869-091611-304171-931612-334828-179485-569615-809223-830187-611340-014693-472885-084645-977764-466883-406863-390018-701741-058097-752790-311648-820127-255900-581947+0000-0001122-NOCALL00-
+OK
14 changes: 14 additions & 0 deletions sample/npt.22050.s16le.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set -e

# close standard input to ignore it
exec 0>/dev/null

[[ $SAMEDEC_EVENT = "National Periodic Test" ]]
[[ $SAMEDEC_ORG = "PEP" ]]
[[ $SAMEDEC_SIGNIFICANCE = "T" ]]
[[ $SAMEDEC_LOCATIONS = "000000" ]]

lifetime=$(( $SAMEDEC_PURGETIME - $SAMEDEC_ISSUETIME))
[[ $lifetime -eq $(( 30*60 )) ]]

echo "+OK"
1 change: 1 addition & 0 deletions sample/npt.22050.s16le.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ZCZC-PEP-NPT-000000+0030-2771820-TEST -
+OK
48 changes: 48 additions & 0 deletions sample/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
#
# Runs integration tests for samedec.
#
# cd sample/
# ./test.sh
#
# By default, this will build and run a debug-mode samedec
# with cargo. You may also set SAMEDEC to the path to an
# existing executable.
#
# The integration tests ensure that samedec's child process
# spawning and environment variable assignment works.

set -euo pipefail

if [ -n "${SAMEDEC:-}" ]; then
RUNARGS=("${SAMEDEC}")
else
RUNARGS=('cargo' 'run' '-q' '-p' 'samedec' '--')
fi

run_samedec() {
# Usage: run_samedec FILE
# Runs `samedec` on given input file stem

infile="$1"

"${RUNARGS[@]}" \
--rate 22050 \
--file "${infile}.bin" \
-- \
bash \
"${infile}.bash" | tee /dev/stderr
}

for file in $(basename -s .bin *.s16le.bin); do
[ -e "${file}.bin" ] || exit 1

printf '[%s]\n' "$file"

cmp <(run_samedec "$file") "$file.txt" || {
printf '[%s]: FAIL\n' "$file"
exit 1
};

printf '[%s]: PASS\n' "$file"
done
13 changes: 13 additions & 0 deletions sample/two_and_two.22050.s16le.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

# close standard input to ignore it
exec 0>/dev/null

[[ $SAMEDEC_EVENT = "Severe Thunderstorm Warning" ]]
[[ $SAMEDEC_ORIGINATOR = "Weather Service" ]]
[[ $SAMEDEC_SIGNIFICANCE = "W" ]]

lifetime=$(( $SAMEDEC_PURGETIME - $SAMEDEC_ISSUETIME))
[[ $lifetime -eq $(( 1*60*60 + 30*60 )) ]]

echo "+OK"
1 change: 1 addition & 0 deletions sample/two_and_two.22050.s16le.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NNNN
ZCZC-WXR-SVR-012079-013019-013027-013075-013185-013173+0130-0462024-N0C4LL -
+OK

0 comments on commit 7c419a7

Please sign in to comment.