blob: 39efd05180c5fed743ed6d6fc70bedf34442a5f9 [file] [log] [blame]
Alexandre Lision67916dd2014-01-24 13:33:04 -05001# $Id$
2
3# PLAYFILE -> RECFILE:
4# Input file is played and is recorded to output, then compare them.
5# Useful to tes clock rates compatibility and resample quality
6# null-audio
7# port 1: wav file input xxxxxx.clock_rate.wav, e.g: test1.8.wav
8# port 2: wav file ouput xxxxxx.clock_rate.wav, e.g: res1.8.wav
9# wav input must be more than 3 seconds long
10
11import time
12import imp
13import sys
14import re
15import subprocess
16import inc_const as const
17from inc_cfg import *
18
19# Load configuration
20cfg_file = imp.load_source("cfg_file", ARGS[1])
21
22# WAV similarity calculator
23COMPARE_WAV_EXE = ""
24if sys.platform.find("win32")!=-1:
25 COMPARE_WAV_EXE = "tools/cmp_wav.exe"
26 G_INUNIX = False
27else:
28 COMPARE_WAV_EXE = "tools/cmp_wav"
29 G_INUNIX = True
30
31
32# Threshold to declare degradation is too high when result is lower than this value
33COMPARE_THRESHOLD = 2
34
35# COMPARE params
36input_filename = "" # Input filename
37output_filename = "" # Output filename
38
39# Test body function
40def test_func(t):
41 global input_filename
42 global output_filename
43
44 endpt = t.process[0]
45
46 # Get input file name
47 input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1)
48 endpt.trace("Input file = " + input_filename)
49
50 # Get output file name
51 output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1)
52 endpt.trace("Output file = " + output_filename)
53
54 # Find appropriate clock rate for the input file
55 clock_rate = re.compile(".+(\.\d+\.wav)$").match(output_filename).group(1)
56 if (clock_rate==None):
57 endpt.trace("Cannot compare input & output, incorrect output filename format")
58 return
59 input_filename = re.sub("\.\d+\.wav$", clock_rate, input_filename)
60 endpt.trace("WAV file to be compared with output = " + input_filename)
61
62 # Connect input-output file
63 endpt.sync_stdout()
64
65 endpt.send("cc 1 2")
66 endpt.expect(const.MEDIA_CONN_PORT_SUCCESS)
67
68 # Wait
69 time.sleep(3)
70
71 endpt.sync_stdout()
72
73 # Disconnect input-output file
74 endpt.send("cd 1 2")
75 endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS)
76
77
78# Post body function
79def post_func(t):
80 global input_filename
81 global output_filename
82
83 endpt = t.process[0]
84
85 # Check WAV similarity
86 fullcmd = COMPARE_WAV_EXE + " " + input_filename + " " + output_filename + " " + "3000"
87 endpt.trace("Popen " + fullcmd)
88 cmp_proc = subprocess.Popen(fullcmd, shell=G_INUNIX, stdout=subprocess.PIPE, universal_newlines=True)
89
90 # Parse similarity ouput
91 line = cmp_proc.stdout.readline()
92 mo_sim_val = re.match(".+=\s+(\d+)", line)
93 if (mo_sim_val == None):
94 raise TestError("Error comparing WAV files")
95 return
96
97 # Evaluate the similarity value
98 sim_val = mo_sim_val.group(1)
99 if (sim_val >= COMPARE_THRESHOLD):
100 endpt.trace("WAV similarity = " + sim_val)
101 else:
102 raise TestError("WAV degraded heavily, similarity = " + sim_val)
103
104
105# Here where it all comes together
106test = cfg_file.test_param
107test.test_func = test_func
108test.post_func = post_func