| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
import time |
| 11 |
import sys |
| 12 |
import re |
| 13 |
import subprocess |
| 14 |
import inc_const as const |
| 15 |
import inc_util as util |
| 16 |
from inc_cfg import * |
| 17 |
|
| 18 |
|
| 19 |
cfg_file = util.load_module_from_file("cfg_file", ARGS[1]) |
| 20 |
|
| 21 |
|
| 22 |
COMPARE_WAV_EXE = "" |
| 23 |
if sys.platform.find("win32")!=-1: |
| 24 |
COMPARE_WAV_EXE = "tools/cmp_wav.exe" |
| 25 |
G_INUNIX = False |
| 26 |
else: |
| 27 |
COMPARE_WAV_EXE = "tools/cmp_wav" |
| 28 |
G_INUNIX = True |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
COMPARE_THRESHOLD = 2 |
| 33 |
|
| 34 |
|
| 35 |
input_filename = "" |
| 36 |
output_filename = "" |
| 37 |
|
| 38 |
|
| 39 |
def test_func(t): |
| 40 |
global input_filename |
| 41 |
global output_filename |
| 42 |
|
| 43 |
endpt = t.process[0] |
| 44 |
|
| 45 |
|
| 46 |
input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1) |
| 47 |
endpt.trace("Input file = " + input_filename) |
| 48 |
|
| 49 |
|
| 50 |
output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1) |
| 51 |
endpt.trace("Output file = " + output_filename) |
| 52 |
|
| 53 |
|
| 54 |
clock_rate = re.compile(".+(\.\d+\.wav)$").match(output_filename).group(1) |
| 55 |
if (clock_rate==None): |
| 56 |
endpt.trace("Cannot compare input & output, incorrect output filename format") |
| 57 |
return |
| 58 |
input_filename = re.sub("\.\d+\.wav$", clock_rate, input_filename) |
| 59 |
endpt.trace("WAV file to be compared with output = " + input_filename) |
| 60 |
|
| 61 |
|
| 62 |
endpt.sync_stdout() |
| 63 |
|
| 64 |
endpt.send("cc 1 2") |
| 65 |
endpt.expect(const.MEDIA_CONN_PORT_SUCCESS) |
| 66 |
|
| 67 |
|
| 68 |
time.sleep(3) |
| 69 |
|
| 70 |
endpt.sync_stdout() |
| 71 |
|
| 72 |
|
| 73 |
endpt.send("cd 1 2") |
| 74 |
endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS) |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
def post_func(t): |
| 79 |
global input_filename |
| 80 |
global output_filename |
| 81 |
|
| 82 |
endpt = t.process[0] |
| 83 |
|
| 84 |
|
| 85 |
fullcmd = COMPARE_WAV_EXE + " " + input_filename + " " + output_filename + " " + "3000" |
| 86 |
endpt.trace("Popen " + fullcmd) |
| 87 |
cmp_proc = subprocess.Popen(fullcmd, shell=G_INUNIX, stdout=subprocess.PIPE, universal_newlines=True) |
| 88 |
|
| 89 |
|
| 90 |
line = cmp_proc.stdout.readline() |
| 91 |
mo_sim_val = re.match(".+=\s+(\d+)", line) |
| 92 |
if (mo_sim_val == None): |
| 93 |
raise TestError("Error comparing WAV files") |
| 94 |
return |
| 95 |
|
| 96 |
|
| 97 |
sim_val = mo_sim_val.group(1) |
| 98 |
if (int(sim_val) >= COMPARE_THRESHOLD): |
| 99 |
endpt.trace("WAV similarity = " + sim_val) |
| 100 |
else: |
| 101 |
raise TestError("WAV degraded heavily, similarity = " + sim_val) |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
test = cfg_file.test_param |
| 106 |
test.test_func = test_func |
| 107 |
test.post_func = post_func |