From 3b9af75eeceb2fc3870a73c180832821b8fce8eb Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Wed, 27 Apr 2022 12:36:47 -0400 Subject: [PATCH] Use byte differences for sample matching --- Dockerfile | 4 ++-- Dockerfile.debian | 4 ++-- Dockerfile.debian.dockerignore | 1 + Dockerfile.dist | 4 ++-- Dockerfile.dist.dockerignore | 1 + Dockerfile.dockerignore | 1 + tests/samples_match.sh | 40 ++++++++++++++++++++++++++++++++++ 7 files changed, 49 insertions(+), 6 deletions(-) create mode 100755 tests/samples_match.sh diff --git a/Dockerfile b/Dockerfile index 46dc5bb..5856586 100644 --- a/Dockerfile +++ b/Dockerfile @@ -92,7 +92,7 @@ COPY --from=build /home/mimic3/app/ ./ COPY --from=build /root/.local/share/mimic3/voices/ /usr/share/mimic3/voices/ # Run test -COPY tests/apope_sample.txt tests/apope_sample_*.wav ./tests/ +COPY tests/* ./tests/ # Generate sample and check RUN export expected_sample="tests/apope_sample_${TARGETARCH}${TARGETVARIANT}.wav" && \ @@ -101,7 +101,7 @@ RUN export expected_sample="tests/apope_sample_${TARGETARCH}${TARGETVARIANT}.wav --voice 'en_UK/apope_low' \ < tests/apope_sample.txt \ > tests/actual_sample.wav && \ - diff tests/actual_sample.wav "${expected_sample}" + tests/samples_match.sh tests/actual_sample.wav "${expected_sample}" USER mimic3 diff --git a/Dockerfile.debian b/Dockerfile.debian index 2c575c8..e57c16f 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -166,7 +166,7 @@ RUN --mount=type=cache,id=apt-run,target=/var/cache/apt \ xargs apt install --yes # Run test -COPY tests/apope_sample.txt tests/apope_sample_*.wav tests/ +COPY tests/* tests/ # Generate sample and check RUN export expected_sample="tests/apope_sample_${TARGETARCH}${TARGETVARIANT}.wav" && \ @@ -175,7 +175,7 @@ RUN export expected_sample="tests/apope_sample_${TARGETARCH}${TARGETVARIANT}.wav --voice 'en_UK/apope_low' \ < tests/apope_sample.txt \ > tests/actual_sample.wav && \ - diff tests/actual_sample.wav "${expected_sample}" + tests/samples_match.sh tests/actual_sample.wav "${expected_sample}" # ----------------------------------------------------------------------------- diff --git a/Dockerfile.debian.dockerignore b/Dockerfile.debian.dockerignore index 25b670a..8d58c97 100644 --- a/Dockerfile.debian.dockerignore +++ b/Dockerfile.debian.dockerignore @@ -5,6 +5,7 @@ !pyinstaller/mimic3-download !tests/apope_sample.txt !tests/apope_sample_*.wav +!tests/samples_match.sh !voices/ !wheels/ diff --git a/Dockerfile.dist b/Dockerfile.dist index 824fe55..99b8b21 100644 --- a/Dockerfile.dist +++ b/Dockerfile.dist @@ -88,7 +88,7 @@ COPY voices/ /root/.local/share/mimic3/voices/ RUN .venv/bin/mimic3-download 'en_UK/apope_low' # Run test -COPY tests/apope_sample.txt tests/apope_sample_*.wav tests/ +COPY tests/* tests/ # Generate sample and check RUN export expected_sample="tests/apope_sample_${TARGETARCH}${TARGETVARIANT}.wav" && \ @@ -97,7 +97,7 @@ RUN export expected_sample="tests/apope_sample_${TARGETARCH}${TARGETVARIANT}.wav --voice 'en_UK/apope_low' \ < tests/apope_sample.txt \ > tests/actual_sample.wav && \ - diff tests/actual_sample.wav "${expected_sample}" + tests/samples_match.sh tests/actual_sample.wav "${expected_sample}" # ----------------------------------------------------------------------------- diff --git a/Dockerfile.dist.dockerignore b/Dockerfile.dist.dockerignore index 66a67fa..42305cc 100644 --- a/Dockerfile.dist.dockerignore +++ b/Dockerfile.dist.dockerignore @@ -2,6 +2,7 @@ !build-dist.sh !tests/apope_sample.txt !tests/apope_sample_*.wav +!tests/samples_match.sh !voices/ !wheels/ !debian/control.in.* diff --git a/Dockerfile.dockerignore b/Dockerfile.dockerignore index 700654b..1924534 100644 --- a/Dockerfile.dockerignore +++ b/Dockerfile.dockerignore @@ -2,6 +2,7 @@ !install.sh !tests/apope_sample.txt !tests/apope_sample_*.wav +!tests/samples_match.sh !voices/ !wheels/ !debian/control.in.* diff --git a/tests/samples_match.sh b/tests/samples_match.sh new file mode 100755 index 0000000..72d38fe --- /dev/null +++ b/tests/samples_match.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Copyright 2022 Mycroft AI Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# ----------------------------------------------------------------------------- +# +# Uses cmp to compare byte differences between two samples. +# Exits with an error if differences exceed a threshold. +# +set -o pipefail + +if [ -z "$2" ]; then + echo 'Usage: samples_match.sh WAV1 WAV2 [threshold]'; + exit 1 +fi + +wav1="$1" +wav2="$2" +threshold="${3:-5000}" + +bytes_different="$(cmp -l "${wav1}" "${wav2}" | wc -l)" + +if (( ${bytes_different} > ${threshold} )); then + echo "Samples differ too much (${bytes_different} > ${threshold})"; + exit 1; +fi + +echo 'OK'