• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3#  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
4#
5#  Use of this source code is governed by a BSD-style license
6#  that can be found in the LICENSE file in the root of the source
7#  tree. An additional intellectual property rights grant can be found
8#  in the file PATENTS.  All contributing project authors may
9#  be found in the AUTHORS file in the root of the source tree.
10#
11
12# Aliases.
13BIN=$1
14TEST_RTC_EVENT_LOG=$2
15INPUT_PCM_FILE=$3
16
17# Check setup.
18if [ ! -f $BIN ]; then
19  echo "Cannot find neteq_rtpplay binary."
20  exit 99
21fi
22if [ ! -f $TEST_RTC_EVENT_LOG ]; then
23  echo "Cannot find RTC event log file."
24  exit 99
25fi
26if [ ! -f $INPUT_PCM_FILE ]; then
27  echo "Cannot find PCM file."
28  exit 99
29fi
30
31# Defines.
32
33TMP_DIR=$(mktemp -d /tmp/tmp_XXXXXXXXXX)
34PASS=0
35FAIL=1
36TEST_SUITE_RESULT=$PASS
37
38file_hash () {
39  md5sum $1 | awk '{ print $1 }'
40}
41
42test_passed () {
43  echo PASS
44}
45
46test_failed () {
47  echo "FAIL: $1"
48  TEST_SUITE_RESULT=$FAIL
49}
50
51test_file_checksums_match () {
52  if [ ! -f $1 ] || [ ! -f $2 ]; then
53    test_failed "Cannot compare hash values: file(s) not found."
54    return
55  fi
56  HASH1=$(file_hash $1)
57  HASH2=$(file_hash $2)
58  if [ "$HASH1" = "$HASH2" ]; then
59    test_passed
60  else
61    test_failed "$1 differs from $2"
62  fi
63}
64
65test_file_exists () {
66  if [ -f $1 ]; then
67    test_passed
68  else
69    test_failed "$1 does not exist"
70  fi
71}
72
73test_exit_code_0 () {
74  if [ $1 -eq 0 ]; then
75    test_passed
76  else
77    test_failed "$1 did not return 0"
78  fi
79}
80
81test_exit_code_not_0 () {
82  if [ $1 -eq 0 ]; then
83    test_failed "$1 returned 0"
84  else
85    test_passed
86  fi
87}
88
89# Generate test data.
90
91# Case 1. Pre-existing way.
92CASE1_WAV=$TMP_DIR/case1.wav
93$BIN $TEST_RTC_EVENT_LOG $CASE1_WAV  \
94    --replacement_audio_file $INPUT_PCM_FILE  \
95    --textlog --pythonplot --matlabplot  \
96    > $TMP_DIR/case1.stdout 2> /dev/null
97CASE1_RETURN_CODE=$?
98CASE1_TEXTLOG=$TMP_DIR/case1.wav.text_log.txt
99CASE1_PYPLOT=$TMP_DIR/case1_wav.py
100CASE1_MATPLOT=$TMP_DIR/case1_wav.m
101
102# Case 2. No output files.
103$BIN $TEST_RTC_EVENT_LOG --replacement_audio_file $INPUT_PCM_FILE  \
104    > $TMP_DIR/case2.stdout 2> /dev/null
105CASE2_RETURN_CODE=$?
106
107# Case 3. No output audio file.
108
109# Case 3.1 Without --output_files_base_name (won't run).
110$BIN $TEST_RTC_EVENT_LOG  \
111    --replacement_audio_file $INPUT_PCM_FILE  \
112    --textlog --pythonplot --matlabplot  \
113    &> /dev/null
114CASE3_1_RETURN_CODE=$?
115
116# Case 3.2 With --output_files_base_name (runs).
117$BIN $TEST_RTC_EVENT_LOG  \
118    --replacement_audio_file $INPUT_PCM_FILE  \
119    --output_files_base_name $TMP_DIR/case3_2  \
120    --textlog --pythonplot --matlabplot  \
121    > $TMP_DIR/case3_2.stdout 2> /dev/null
122CASE3_2_RETURN_CODE=$?
123CASE3_2_TEXTLOG=$TMP_DIR/case3_2.text_log.txt
124CASE3_2_PYPLOT=$TMP_DIR/case3_2.py
125CASE3_2_MATPLOT=$TMP_DIR/case3_2.m
126
127# Case 4. With output audio file and --output_files_base_name.
128CASE4_WAV=$TMP_DIR/case4.wav
129$BIN $TEST_RTC_EVENT_LOG $TMP_DIR/case4.wav \
130    --replacement_audio_file $INPUT_PCM_FILE  \
131    --output_files_base_name $TMP_DIR/case4  \
132    --textlog --pythonplot --matlabplot  \
133    > $TMP_DIR/case4.stdout 2> /dev/null
134CASE4_RETURN_CODE=$?
135CASE4_TEXTLOG=$TMP_DIR/case4.text_log.txt
136CASE4_PYPLOT=$TMP_DIR/case4.py
137CASE4_MATPLOT=$TMP_DIR/case4.m
138
139# Tests.
140
141echo Check exit codes
142test_exit_code_0 $CASE1_RETURN_CODE
143test_exit_code_0 $CASE2_RETURN_CODE
144test_exit_code_not_0 $CASE3_1_RETURN_CODE
145test_exit_code_0 $CASE3_2_RETURN_CODE
146test_exit_code_0 $CASE4_RETURN_CODE
147
148echo Check that the expected output files exist
149test_file_exists $CASE1_TEXTLOG
150test_file_exists $CASE3_2_TEXTLOG
151test_file_exists $CASE4_TEXTLOG
152test_file_exists $CASE1_PYPLOT
153test_file_exists $CASE3_2_PYPLOT
154test_file_exists $CASE4_PYPLOT
155test_file_exists $CASE1_MATPLOT
156test_file_exists $CASE3_2_MATPLOT
157test_file_exists $CASE4_MATPLOT
158
159echo Check that the same WAV file is produced
160test_file_checksums_match $CASE1_WAV $CASE4_WAV
161
162echo Check that the same text log is produced
163test_file_checksums_match $CASE1_TEXTLOG $CASE3_2_TEXTLOG
164test_file_checksums_match $CASE1_TEXTLOG $CASE4_TEXTLOG
165
166echo Check that the same python plot scripts is produced
167test_file_checksums_match $CASE1_PYPLOT $CASE3_2_PYPLOT
168test_file_checksums_match $CASE1_PYPLOT $CASE4_PYPLOT
169
170echo Check that the same matlab plot scripts is produced
171test_file_checksums_match $CASE1_MATPLOT $CASE3_2_MATPLOT
172test_file_checksums_match $CASE1_MATPLOT $CASE4_MATPLOT
173
174# Clean up
175rm -fr $TMP_DIR
176
177if [ $TEST_SUITE_RESULT -eq $PASS ]; then
178  echo All tests passed.
179  exit 0
180else
181  echo One or more tests failed.
182  exit 1
183fi
184