1#!/bin/bash
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright(c) 2018 Intel Corporation. All rights reserved.
4
5#
6# Usage:
7# please run following scrits for the test tplg and host build
8# ./scripts/build-tools.sh -t
9# ./scripts/rebuild-testbench.sh
10# Run test
11# ./scripts/host-testbench.sh
12#
13
14# stop on most errors
15set -e
16
17function filesize() {
18  du -b "$1" | awk '{print $1}'
19}
20
21function comparesize() {
22  INPUT_SIZE=$1
23  OUTPUT_SIZE=$2
24  INPUT_SIZE_MIN=$(echo "$INPUT_SIZE*0.9/1"|bc)
25  # echo "MIN SIZE with 90% tolerance is $INPUT_SIZE_MIN"
26  # echo "ACTUALL SIZE is $OUTPUT_SIZE"
27  if [[ "$OUTPUT_SIZE" -gt "$INPUT_SIZE" ]]; then
28    echo "OUTPUT_SIZE $OUTPUT_SIZE too big"
29    return 1
30  fi
31  if [[ "$OUTPUT_SIZE" -lt "$INPUT_SIZE_MIN" ]]; then
32    echo "OUTPUT_SIZE $OUTPUT_SIZE too small"
33    return 1
34  fi
35
36  return 0
37}
38
39function srcsize() {
40  INPUT_SIZE=$1
41  INPUT_RATE=$2
42  OUTPUT_RATE=$3
43  OUTPUT_SIZE=$(echo "${INPUT_SIZE}*${OUTPUT_RATE}/${INPUT_RATE}"|bc)
44  echo "$OUTPUT_SIZE"
45}
46
47function die() {
48  printf "$@"
49  exit 1
50}
51
52process_test_cmd() {
53  octave -q --eval "pkg load signal io; [n_fail]=process_test('$1', $2, $3, $4, $5);exit(n_fail)"
54}
55
56# function test_component()
57# $1 : component name
58# $2 : input bits per sample
59# $3 : output bits per sample
60# $4 : sampling rate
61# $5 : quick test=0, fulltest=1
62test_component() {
63  test "$#" -eq 5 || die "Have $# parameters but 5 expected"
64
65  echo "------------------------------------------------------------"
66  echo "test $1 component with $2 $3 $4 $5"
67  if process_test_cmd "$@"; then
68    echo "$1 test passed!"
69  else
70    die "$1 test failed!"
71  fi
72}
73
74SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
75SOF_DIR=$SCRIPTS_DIR/../
76TESTBENCH_DIR=${SOF_DIR}/tools/test/audio
77INPUT_FILE_SIZE=10240
78
79cd "$TESTBENCH_DIR"
80rm -rf ./*.raw
81
82# create input zeros raw file
83head -c ${INPUT_FILE_SIZE} < /dev/zero > zeros_in.raw
84
85# by default quick test
86FullTest=${FullTest:-0}
87
88# test with volume
89test_component volume 16 16 48000 "$FullTest"
90test_component volume 24 24 48000 "$FullTest"
91test_component volume 32 32 48000 "$FullTest"
92
93# test with eq-iir
94test_component eq-iir 16 16 48000 "$FullTest"
95test_component eq-iir 24 24 48000 "$FullTest"
96test_component eq-iir 32 32 48000 "$FullTest"
97
98# test with eq-fir
99test_component eq-fir 32 32 48000 "$FullTest"
100
101# test with dcblock
102test_component dcblock 32 32 48000 "$FullTest"
103
104# test with drc
105test_component drc 32 32 48000 "$FullTest"
106
107# test with multiband-drc
108test_component multiband-drc 32 32 48000 "$FullTest"
109
110# test with src
111test_component src 24 24 48000 "$FullTest"
112
113# test with tdfb
114test_component tdfb 32 32 48000 "$FullTest"
115
116echo "All tests are done!"
117