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 47SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") 48SOF_DIR=$SCRIPTS_DIR/../ 49TESTBENCH_DIR=${SOF_DIR}/tools/test/audio 50INPUT_FILE_SIZE=10240 51 52cd "$TESTBENCH_DIR" 53rm -rf ./*.raw 54 55# create input zeros raw file 56head -c ${INPUT_FILE_SIZE} < /dev/zero > zeros_in.raw 57 58# test with volume 59echo "==========================================================" 60echo "test volume with ./volume_run.sh 16 16 48000 zeros_in.raw volume_out.raw" 61if ./volume_run.sh 16 16 48000 zeros_in.raw volume_out.raw &>vol.log; then 62 echo "volume test passed!" 63else 64 echo "volume test failed!" 65 cat vol.log 66 exit 1 67fi 68 69if comparesize ${INPUT_FILE_SIZE} "$(filesize volume_out.raw)"; then 70 echo "volume_out size check passed!" 71else 72 echo "volume_out size check failed!" 73 cat vol.log 74 exit 1 75fi 76rm volume_out.raw vol.log 77 78# test with src 79echo "==========================================================" 80echo "test src with ./src_run.sh 32 32 44100 48000 zeros_in.raw src_out.raw" 81if ./src_run.sh 32 32 44100 48000 zeros_in.raw src_out.raw &>src.log; then 82 echo "src test passed!" 83else 84 echo "src test failed!" 85 cat src.log 86 exit 1 87fi 88 89if comparesize "$(srcsize ${INPUT_FILE_SIZE} 44100 48000)" "$(filesize src_out.raw)";then 90 echo "src_out size check passed!" 91else 92 echo "src_out size check failed!" 93 cat src.log 94 exit 1 95fi 96rm src_out.raw src.log 97 98# test with eq 99echo "==========================================================" 100echo "test eqiir with ./eqiir_run.sh 16 16 48000 zeros_in.raw eqiir_out.raw" 101if ./eqiir_run.sh 16 16 48000 zeros_in.raw eqiir_out.raw &>eqiir.log; then 102 echo "eqiir test passed!" 103else 104 echo "eqiir test failed!" 105 cat eqiir.log 106 exit 1 107fi 108 109 110if comparesize $INPUT_FILE_SIZE "$(filesize eqiir_out.raw)"; then 111 echo "eqiir_out size check passed!" 112else 113 echo "eqiir_out size check failed!" 114 cat eqiir.log 115 exit 1 116fi 117rm eqiir_out.raw eqiir.log 118 119rm zeros_in.raw 120