123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import time
- import sys
- import re
- import subprocess
- import inc_const as const
- import inc_util as util
- from inc_cfg import *
- cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
- COMPARE_WAV_EXE = ""
- if sys.platform.find("win32")!=-1:
- COMPARE_WAV_EXE = "tools/cmp_wav.exe"
- G_INUNIX = False
- else:
- COMPARE_WAV_EXE = "tools/cmp_wav"
- G_INUNIX = True
- COMPARE_THRESHOLD = 2
- input_filename = ""
- output_filename = ""
- def test_func(t):
- global input_filename
- global output_filename
- endpt = t.process[0]
-
-
- input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1)
- endpt.trace("Input file = " + input_filename)
-
- output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1)
- endpt.trace("Output file = " + output_filename)
-
- clock_rate = re.compile(".+(\.\d+\.wav)$").match(output_filename).group(1)
- if (clock_rate==None):
- endpt.trace("Cannot compare input & output, incorrect output filename format")
- return
- input_filename = re.sub("\.\d+\.wav$", clock_rate, input_filename)
- endpt.trace("WAV file to be compared with output = " + input_filename)
-
- endpt.sync_stdout()
- endpt.send("cc 1 2")
- endpt.expect(const.MEDIA_CONN_PORT_SUCCESS)
-
- time.sleep(3)
- endpt.sync_stdout()
-
- endpt.send("cd 1 2")
- endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS)
- def post_func(t):
- global input_filename
- global output_filename
- endpt = t.process[0]
-
- fullcmd = COMPARE_WAV_EXE + " " + input_filename + " " + output_filename + " " + "3000"
- endpt.trace("Popen " + fullcmd)
- cmp_proc = subprocess.Popen(fullcmd, shell=G_INUNIX, stdout=subprocess.PIPE, universal_newlines=True)
-
- line = cmp_proc.stdout.readline()
- mo_sim_val = re.match(".+=\s+(\d+)", line)
- if (mo_sim_val == None):
- raise TestError("Error comparing WAV files")
- return
-
- sim_val = mo_sim_val.group(1)
- if (int(sim_val) >= COMPARE_THRESHOLD):
- endpt.trace("WAV similarity = " + sim_val)
- else:
- raise TestError("WAV degraded heavily, similarity = " + sim_val)
- test = cfg_file.test_param
- test.test_func = test_func
- test.post_func = post_func
|