tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

neteq_rtpplay_test.sh (4570B)


      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.
     13 BIN=$1
     14 TEST_RTC_EVENT_LOG=$2
     15 INPUT_PCM_FILE=$3
     16 
     17 # Check setup.
     18 if [ ! -f $BIN ]; then
     19  echo "Cannot find neteq_rtpplay binary."
     20  exit 99
     21 fi
     22 if [ ! -f $TEST_RTC_EVENT_LOG ]; then
     23  echo "Cannot find RTC event log file."
     24  exit 99
     25 fi
     26 if [ ! -f $INPUT_PCM_FILE ]; then
     27  echo "Cannot find PCM file."
     28  exit 99
     29 fi
     30 
     31 # Defines.
     32 
     33 TMP_DIR=$(mktemp -d /tmp/tmp_XXXXXXXXXX)
     34 PASS=0
     35 FAIL=1
     36 TEST_SUITE_RESULT=$PASS
     37 
     38 file_hash () {
     39  md5sum $1 | awk '{ print $1 }'
     40 }
     41 
     42 test_passed () {
     43  echo PASS
     44 }
     45 
     46 test_failed () {
     47  echo "FAIL: $1"
     48  TEST_SUITE_RESULT=$FAIL
     49 }
     50 
     51 test_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 
     65 test_file_exists () {
     66  if [ -f $1 ]; then
     67    test_passed
     68  else
     69    test_failed "$1 does not exist"
     70  fi
     71 }
     72 
     73 test_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 
     81 test_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.
     92 CASE1_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
     97 CASE1_RETURN_CODE=$?
     98 CASE1_TEXTLOG=$TMP_DIR/case1.wav.text_log.txt
     99 CASE1_PYPLOT=$TMP_DIR/case1_wav.py
    100 CASE1_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
    105 CASE2_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
    114 CASE3_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
    122 CASE3_2_RETURN_CODE=$?
    123 CASE3_2_TEXTLOG=$TMP_DIR/case3_2.text_log.txt
    124 CASE3_2_PYPLOT=$TMP_DIR/case3_2.py
    125 CASE3_2_MATPLOT=$TMP_DIR/case3_2.m
    126 
    127 # Case 4. With output audio file and --output_files_base_name.
    128 CASE4_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
    134 CASE4_RETURN_CODE=$?
    135 CASE4_TEXTLOG=$TMP_DIR/case4.text_log.txt
    136 CASE4_PYPLOT=$TMP_DIR/case4.py
    137 CASE4_MATPLOT=$TMP_DIR/case4.m
    138 
    139 # Tests.
    140 
    141 echo Check exit codes
    142 test_exit_code_0 $CASE1_RETURN_CODE
    143 test_exit_code_0 $CASE2_RETURN_CODE
    144 test_exit_code_not_0 $CASE3_1_RETURN_CODE
    145 test_exit_code_0 $CASE3_2_RETURN_CODE
    146 test_exit_code_0 $CASE4_RETURN_CODE
    147 
    148 echo Check that the expected output files exist
    149 test_file_exists $CASE1_TEXTLOG
    150 test_file_exists $CASE3_2_TEXTLOG
    151 test_file_exists $CASE4_TEXTLOG
    152 test_file_exists $CASE1_PYPLOT
    153 test_file_exists $CASE3_2_PYPLOT
    154 test_file_exists $CASE4_PYPLOT
    155 test_file_exists $CASE1_MATPLOT
    156 test_file_exists $CASE3_2_MATPLOT
    157 test_file_exists $CASE4_MATPLOT
    158 
    159 echo Check that the same WAV file is produced
    160 test_file_checksums_match $CASE1_WAV $CASE4_WAV
    161 
    162 echo Check that the same text log is produced
    163 test_file_checksums_match $CASE1_TEXTLOG $CASE3_2_TEXTLOG
    164 test_file_checksums_match $CASE1_TEXTLOG $CASE4_TEXTLOG
    165 
    166 echo Check that the same python plot scripts is produced
    167 test_file_checksums_match $CASE1_PYPLOT $CASE3_2_PYPLOT
    168 test_file_checksums_match $CASE1_PYPLOT $CASE4_PYPLOT
    169 
    170 echo Check that the same matlab plot scripts is produced
    171 test_file_checksums_match $CASE1_MATPLOT $CASE3_2_MATPLOT
    172 test_file_checksums_match $CASE1_MATPLOT $CASE4_MATPLOT
    173 
    174 # Clean up
    175 rm -fr $TMP_DIR
    176 
    177 if [ $TEST_SUITE_RESULT -eq $PASS ]; then
    178  echo All tests passed.
    179  exit 0
    180 else
    181  echo One or more tests failed.
    182  exit 1
    183 fi