Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import logging |
| 7 | import os |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 8 | import re |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 9 | import tempfile |
| 10 | import threading |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 11 | |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 12 | from glob import glob |
| 13 | |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 14 | from autotest_lib.client.bin import utils |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 15 | from autotest_lib.client.bin.input.input_device import * |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 16 | from autotest_lib.client.common_lib import error |
| 17 | |
| 18 | LD_LIBRARY_PATH = 'LD_LIBRARY_PATH' |
| 19 | |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 20 | _DEFAULT_NUM_CHANNELS = 2 |
Dylan Reid | bf9a5d4 | 2012-11-06 16:27:20 -0800 | [diff] [blame] | 21 | _DEFAULT_REC_COMMAND = 'arecord -D hw:0,0 -d 10 -f dat' |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 22 | _DEFAULT_SOX_FORMAT = '-t raw -b 16 -e signed -r 48000 -L' |
Dylan Reid | 51f289c | 2012-11-06 17:16:24 -0800 | [diff] [blame] | 23 | _DEFAULT_SOX_RMS_THRESHOLD = 0.5 |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 24 | |
Hsin-Yu Chao | 8d093f4 | 2012-11-05 18:43:22 +0800 | [diff] [blame] | 25 | _JACK_VALUE_ON_RE = re.compile('.*values=on') |
| 26 | _HP_JACK_CONTROL_RE = re.compile('numid=(\d+).*Headphone\sJack') |
| 27 | _MIC_JACK_CONTROL_RE = re.compile('numid=(\d+).*Mic\sJack') |
| 28 | |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 29 | _SOX_RMS_AMPLITUDE_RE = re.compile('RMS\s+amplitude:\s+(.+)') |
Hsinyu Chao | 2d64e1f | 2012-05-21 11:18:53 +0800 | [diff] [blame] | 30 | _SOX_ROUGH_FREQ_RE = re.compile('Rough\s+frequency:\s+(.+)') |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 31 | _SOX_FORMAT = '-t raw -b 16 -e signed -r 48000 -L' |
| 32 | |
Hsin-Yu Chao | 95ee351 | 2012-11-05 20:43:10 +0800 | [diff] [blame^] | 33 | _AUDIO_NOT_FOUND_RE = r'Audio\snot\sdetected' |
| 34 | _MEASURED_LATENCY_RE = r'Measured\sLatency:\s(\d+)\suS' |
| 35 | _REPORTED_LATENCY_RE = r'Reported\sLatency:\s(\d+)\suS' |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 36 | |
| 37 | class RecordSampleThread(threading.Thread): |
| 38 | '''Wraps the execution of arecord in a thread.''' |
| 39 | def __init__(self, audio, recordfile): |
| 40 | threading.Thread.__init__(self) |
| 41 | self._audio = audio |
| 42 | self._recordfile = recordfile |
| 43 | |
| 44 | def run(self): |
| 45 | self._audio.record_sample(self._recordfile) |
| 46 | |
| 47 | |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 48 | class AudioHelper(object): |
| 49 | ''' |
| 50 | A helper class contains audio related utility functions. |
| 51 | ''' |
Dylan Reid | bf9a5d4 | 2012-11-06 16:27:20 -0800 | [diff] [blame] | 52 | def __init__(self, test, |
| 53 | sox_format = _DEFAULT_SOX_FORMAT, |
Dylan Reid | 51f289c | 2012-11-06 17:16:24 -0800 | [diff] [blame] | 54 | sox_threshold = _DEFAULT_SOX_RMS_THRESHOLD, |
Dylan Reid | bf9a5d4 | 2012-11-06 16:27:20 -0800 | [diff] [blame] | 55 | record_command = _DEFAULT_REC_COMMAND, |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 56 | num_channels = _DEFAULT_NUM_CHANNELS): |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 57 | self._test = test |
Dylan Reid | 51f289c | 2012-11-06 17:16:24 -0800 | [diff] [blame] | 58 | self._sox_threshold = sox_threshold |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 59 | self._sox_format = sox_format |
Dylan Reid | bf9a5d4 | 2012-11-06 16:27:20 -0800 | [diff] [blame] | 60 | self._rec_cmd = record_command |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 61 | self._num_channels = num_channels |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 62 | |
| 63 | def setup_deps(self, deps): |
| 64 | ''' |
| 65 | Sets up audio related dependencies. |
| 66 | ''' |
| 67 | for dep in deps: |
| 68 | if dep == 'test_tones': |
| 69 | dep_dir = os.path.join(self._test.autodir, 'deps', dep) |
| 70 | self._test.job.install_pkg(dep, 'dep', dep_dir) |
| 71 | self.test_tones_path = os.path.join(dep_dir, 'src', dep) |
| 72 | elif dep == 'audioloop': |
| 73 | dep_dir = os.path.join(self._test.autodir, 'deps', dep) |
| 74 | self._test.job.install_pkg(dep, 'dep', dep_dir) |
| 75 | self.audioloop_path = os.path.join(dep_dir, 'src', |
| 76 | 'looptest') |
Hsin-Yu Chao | 95ee351 | 2012-11-05 20:43:10 +0800 | [diff] [blame^] | 77 | self.loopback_latency_path = os.path.join(dep_dir, 'src', |
| 78 | 'loopback_latency') |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 79 | elif dep == 'sox': |
| 80 | dep_dir = os.path.join(self._test.autodir, 'deps', dep) |
| 81 | self._test.job.install_pkg(dep, 'dep', dep_dir) |
| 82 | self.sox_path = os.path.join(dep_dir, 'bin', dep) |
| 83 | self.sox_lib_path = os.path.join(dep_dir, 'lib') |
| 84 | if os.environ.has_key(LD_LIBRARY_PATH): |
| 85 | paths = os.environ[LD_LIBRARY_PATH].split(':') |
| 86 | if not self.sox_lib_path in paths: |
| 87 | paths.append(self.sox_lib_path) |
| 88 | os.environ[LD_LIBRARY_PATH] = ':'.join(paths) |
| 89 | else: |
| 90 | os.environ[LD_LIBRARY_PATH] = self.sox_lib_path |
| 91 | |
| 92 | def cleanup_deps(self, deps): |
| 93 | ''' |
| 94 | Cleans up environments which has been setup for dependencies. |
| 95 | ''' |
| 96 | for dep in deps: |
| 97 | if dep == 'sox': |
| 98 | if (os.environ.has_key(LD_LIBRARY_PATH) |
| 99 | and hasattr(self, 'sox_lib_path')): |
| 100 | paths = filter(lambda x: x != self.sox_lib_path, |
| 101 | os.environ[LD_LIBRARY_PATH].split(':')) |
| 102 | os.environ[LD_LIBRARY_PATH] = ':'.join(paths) |
| 103 | |
Derek Basehore | e973ce4 | 2012-07-10 23:38:32 -0700 | [diff] [blame] | 104 | def set_volume_levels(self, volume, capture): |
| 105 | ''' |
| 106 | Sets the volume and capture gain through cras_test_client |
| 107 | ''' |
| 108 | logging.info('Setting volume level to %d' % volume) |
| 109 | utils.system('/usr/bin/cras_test_client --volume %d' % volume) |
| 110 | logging.info('Setting capture gain to %d' % capture) |
| 111 | utils.system('/usr/bin/cras_test_client --capture_gain %d' % capture) |
| 112 | utils.system('/usr/bin/cras_test_client --dump_server_info') |
Dylan Reid | c264e01 | 2012-11-06 18:26:12 -0800 | [diff] [blame] | 113 | utils.system('/usr/bin/cras_test_client --mute 0') |
Derek Basehore | e973ce4 | 2012-07-10 23:38:32 -0700 | [diff] [blame] | 114 | utils.system('amixer -c 0 contents') |
| 115 | |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 116 | def get_mixer_jack_status(self, jack_reg_exp): |
Hsin-Yu Chao | 8d093f4 | 2012-11-05 18:43:22 +0800 | [diff] [blame] | 117 | ''' |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 118 | Gets the mixer jack status. |
Hsin-Yu Chao | 8d093f4 | 2012-11-05 18:43:22 +0800 | [diff] [blame] | 119 | |
| 120 | Args: |
| 121 | jack_reg_exp: The regular expression to match jack control name. |
| 122 | |
| 123 | Returns: |
| 124 | None if the control does not exist, return True if jack control |
| 125 | is detected plugged, return False otherwise. |
| 126 | ''' |
| 127 | output = utils.system_output('amixer -c0 controls', retain_output=True) |
| 128 | numid = None |
| 129 | for line in output.split('\n'): |
| 130 | m = jack_reg_exp.match(line) |
| 131 | if m: |
| 132 | numid = m.group(1) |
| 133 | break |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 134 | |
| 135 | # Proceed only when matched numid is not empty. |
| 136 | if numid: |
Hsin-Yu Chao | 8d093f4 | 2012-11-05 18:43:22 +0800 | [diff] [blame] | 137 | output = utils.system_output('amixer -c0 cget numid=%s' % numid) |
| 138 | for line in output.split('\n'): |
| 139 | if _JACK_VALUE_ON_RE.match(line): |
| 140 | return True |
| 141 | return False |
| 142 | else: |
| 143 | return None |
| 144 | |
| 145 | def get_hp_jack_status(self): |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 146 | status = self.get_mixer_jack_status(_HP_JACK_CONTROL_RE) |
| 147 | if status is not None: |
| 148 | return status |
| 149 | |
| 150 | # When headphone jack is not found in amixer, lookup input devices |
| 151 | # instead. |
| 152 | # |
| 153 | # TODO(hychao): Check hp/mic jack status dynamically from evdev. And |
| 154 | # possibly replace the existing check using amixer. |
| 155 | for evdev in glob('/dev/input/event*'): |
| 156 | device = InputDevice(evdev) |
| 157 | if device.is_hp_jack(): |
| 158 | return device.get_headphone_insert() |
| 159 | else: |
| 160 | return None |
Hsin-Yu Chao | 8d093f4 | 2012-11-05 18:43:22 +0800 | [diff] [blame] | 161 | |
| 162 | def get_mic_jack_status(self): |
Hsin-Yu Chao | 084e9da | 2012-11-07 15:56:26 +0800 | [diff] [blame] | 163 | status = self.get_mixer_jack_status(_MIC_JACK_CONTROL_RE) |
| 164 | if status is not None: |
| 165 | return status |
| 166 | |
| 167 | # When mic jack is not found in amixer, lookup input devices instead. |
| 168 | for evdev in glob('/dev/input/event*'): |
| 169 | device = InputDevice(evdev) |
| 170 | if device.is_mic_jack(): |
| 171 | return device.get_microphone_insert() |
| 172 | else: |
| 173 | return None |
Hsin-Yu Chao | 8d093f4 | 2012-11-05 18:43:22 +0800 | [diff] [blame] | 174 | |
| 175 | def check_loopback_dongle(self): |
| 176 | ''' |
| 177 | Checks if loopback dongle is equipped correctly. |
| 178 | ''' |
| 179 | # Check Mic Jack |
| 180 | mic_jack_status = self.get_mic_jack_status() |
| 181 | if mic_jack_status is None: |
| 182 | logging.warning('Found no Mic Jack control, skip check.') |
| 183 | elif not mic_jack_status: |
| 184 | logging.info('Mic jack is not plugged.') |
| 185 | return False |
| 186 | else: |
| 187 | logging.info('Mic jack is plugged.') |
| 188 | |
| 189 | # Check Headphone Jack |
| 190 | hp_jack_status = self.get_hp_jack_status() |
| 191 | if hp_jack_status is None: |
| 192 | logging.warning('Found no Headphone Jack control, skip check.') |
| 193 | elif not hp_jack_status: |
| 194 | logging.info('Headphone jack is not plugged.') |
| 195 | return False |
| 196 | else: |
| 197 | logging.info('Headphone jack is plugged.') |
| 198 | |
| 199 | return True |
| 200 | |
Hsinyu Chao | 4b8300e | 2011-11-15 13:07:32 -0800 | [diff] [blame] | 201 | def set_mixer_controls(self, mixer_settings={}, card='0'): |
| 202 | ''' |
| 203 | Sets all mixer controls listed in the mixer settings on card. |
| 204 | ''' |
| 205 | logging.info('Setting mixer control values on %s' % card) |
| 206 | for item in mixer_settings: |
| 207 | logging.info('Setting %s to %s on card %s' % |
| 208 | (item['name'], item['value'], card)) |
| 209 | cmd = 'amixer -c %s cset name=%s %s' |
| 210 | cmd = cmd % (card, item['name'], item['value']) |
| 211 | try: |
| 212 | utils.system(cmd) |
| 213 | except error.CmdError: |
| 214 | # A card is allowed not to support all the controls, so don't |
| 215 | # fail the test here if we get an error. |
| 216 | logging.info('amixer command failed: %s' % cmd) |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 217 | |
Hsinyu Chao | 2d64e1f | 2012-05-21 11:18:53 +0800 | [diff] [blame] | 218 | def sox_stat_output(self, infile, channel): |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 219 | sox_mixer_cmd = self.get_sox_mixer_cmd(infile, channel) |
| 220 | stat_cmd = '%s -c 1 %s - -n stat 2>&1' % (self.sox_path, |
| 221 | self._sox_format) |
| 222 | sox_cmd = '%s | %s' % (sox_mixer_cmd, stat_cmd) |
Hsinyu Chao | 2d64e1f | 2012-05-21 11:18:53 +0800 | [diff] [blame] | 223 | return utils.system_output(sox_cmd, retain_output=True) |
| 224 | |
| 225 | def get_audio_rms(self, sox_output): |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 226 | for rms_line in sox_output.split('\n'): |
| 227 | m = _SOX_RMS_AMPLITUDE_RE.match(rms_line) |
| 228 | if m is not None: |
| 229 | return float(m.group(1)) |
| 230 | |
Hsinyu Chao | 2d64e1f | 2012-05-21 11:18:53 +0800 | [diff] [blame] | 231 | def get_rough_freq(self, sox_output): |
| 232 | for rms_line in sox_output.split('\n'): |
| 233 | m = _SOX_ROUGH_FREQ_RE.match(rms_line) |
| 234 | if m is not None: |
| 235 | return int(m.group(1)) |
| 236 | |
| 237 | |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 238 | def get_sox_mixer_cmd(self, infile, channel): |
| 239 | # Build up a pan value string for the sox command. |
| 240 | if channel == 0: |
| 241 | pan_values = '1' |
| 242 | else: |
| 243 | pan_values = '0' |
| 244 | for pan_index in range(1, self._num_channels): |
| 245 | if channel == pan_index: |
| 246 | pan_values = '%s%s' % (pan_values, ',1') |
| 247 | else: |
| 248 | pan_values = '%s%s' % (pan_values, ',0') |
| 249 | |
| 250 | return '%s -c 2 %s %s -c 1 %s - mixer %s' % (self.sox_path, |
| 251 | self._sox_format, infile, self._sox_format, pan_values) |
| 252 | |
| 253 | def noise_reduce_file(self, in_file, noise_file, out_file): |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 254 | '''Runs the sox command to noise-reduce in_file using |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 255 | the noise profile from noise_file. |
| 256 | |
| 257 | Args: |
| 258 | in_file: The file to noise reduce. |
| 259 | noise_file: The file containing the noise profile. |
| 260 | This can be created by recording silence. |
| 261 | out_file: The file contains the noise reduced sound. |
| 262 | |
| 263 | Returns: |
| 264 | The name of the file containing the noise-reduced data. |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 265 | ''' |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 266 | prof_cmd = '%s -c 2 %s %s -n noiseprof' % (self.sox_path, |
| 267 | _SOX_FORMAT, noise_file) |
| 268 | reduce_cmd = ('%s -c 2 %s %s -c 2 %s %s noisered' % |
| 269 | (self.sox_path, _SOX_FORMAT, in_file, _SOX_FORMAT, out_file)) |
| 270 | utils.system('%s | %s' % (prof_cmd, reduce_cmd)) |
| 271 | |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 272 | def record_sample(self, tmpfile): |
| 273 | '''Records a sample from the default input device. |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 274 | |
| 275 | Args: |
| 276 | duration: How long to record in seconds. |
| 277 | tmpfile: The file to record to. |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 278 | ''' |
Dylan Reid | bf9a5d4 | 2012-11-06 16:27:20 -0800 | [diff] [blame] | 279 | cmd_rec = self._rec_cmd + ' %s' % tmpfile |
| 280 | logging.info('Command %s recording now' % cmd_rec) |
Hsinyu Chao | f80337a | 2012-04-07 18:02:29 +0800 | [diff] [blame] | 281 | utils.system(cmd_rec) |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 282 | |
Dylan Reid | 51f289c | 2012-11-06 17:16:24 -0800 | [diff] [blame] | 283 | def loopback_test_channels(self, noise_file, loopback_callback): |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 284 | '''Tests loopback on all channels. |
| 285 | |
| 286 | Args: |
| 287 | noise_file: The file contains the pre-recorded noise. |
| 288 | loopback_callback: The callback to do the loopback for one channel. |
Hsinyu Chao | 2a7e2f2 | 2012-04-18 16:46:43 +0800 | [diff] [blame] | 289 | ''' |
| 290 | for channel in xrange(self._num_channels): |
| 291 | # Temp file for the final noise-reduced file. |
| 292 | with tempfile.NamedTemporaryFile(mode='w+t') as reduced_file: |
| 293 | # Temp file that records before noise reduction. |
| 294 | with tempfile.NamedTemporaryFile(mode='w+t') as tmpfile: |
| 295 | record_thread = RecordSampleThread(self, tmpfile.name) |
| 296 | record_thread.start() |
| 297 | loopback_callback(channel) |
| 298 | record_thread.join() |
| 299 | |
| 300 | self.noise_reduce_file(tmpfile.name, noise_file.name, |
| 301 | reduced_file.name) |
| 302 | |
Hsinyu Chao | 2d64e1f | 2012-05-21 11:18:53 +0800 | [diff] [blame] | 303 | sox_output = self.sox_stat_output(reduced_file.name, channel) |
Dylan Reid | 51f289c | 2012-11-06 17:16:24 -0800 | [diff] [blame] | 304 | self.check_recorded(sox_output) |
| 305 | |
| 306 | def check_recorded(self, sox_output): |
| 307 | """Checks if the calculated RMS value is expected. |
| 308 | |
| 309 | Args: |
| 310 | sox_output: The output from sox stat command. |
| 311 | |
| 312 | Raises: |
| 313 | error.TestFail if the RMS amplitude of the recording isn't above |
| 314 | the threshold. |
| 315 | """ |
| 316 | rms_val = self.get_audio_rms(sox_output) |
| 317 | |
| 318 | # In case we don't get a valid RMS value. |
| 319 | if rms_val is None: |
| 320 | raise error.TestError( |
| 321 | 'Failed to generate an audio RMS value from playback.') |
| 322 | |
| 323 | logging.info('Got audio RMS value of %f. Minimum pass is %f.' % |
| 324 | (rms_val, self._sox_threshold)) |
| 325 | if rms_val < self._sox_threshold: |
| 326 | raise error.TestError( |
| 327 | 'Audio RMS value %f too low. Minimum pass is %f.' % |
| 328 | (rms_val, self._sox_threshold)) |
Hsin-Yu Chao | 95ee351 | 2012-11-05 20:43:10 +0800 | [diff] [blame^] | 329 | |
| 330 | def loopback_latency_check(self, **args): |
| 331 | ''' |
| 332 | Checks loopback latency. |
| 333 | |
| 334 | Args: |
| 335 | args: additional arguments for loopback_latency. |
| 336 | |
| 337 | Returns: |
| 338 | A tuple containing measured and reported latency in uS. |
| 339 | Return None if no audio detected. |
| 340 | ''' |
| 341 | noise_threshold = str(args['n']) if args.has_key('n') else '400' |
| 342 | |
| 343 | cmd = '%s -n %s' % (self.loopback_latency_path, noise_threshold) |
| 344 | |
| 345 | output = utils.system_output(cmd) |
| 346 | measured_latency = None |
| 347 | reported_latency = None |
| 348 | for line in output.split('\n'): |
| 349 | match = re.search(_MEASURED_LATENCY_RE, line, re.I) |
| 350 | if match: |
| 351 | measured_latency = int(match.group(1)) |
| 352 | continue |
| 353 | match = re.search(_REPORTED_LATENCY_RE, line, re.I) |
| 354 | if match: |
| 355 | reported_latency = int(match.group(1)) |
| 356 | continue |
| 357 | if re.search(_AUDIO_NOT_FOUND_RE, line, re.I): |
| 358 | return None |
| 359 | if measured_latency and reported_latency: |
| 360 | return (measured_latency, reported_latency) |
| 361 | else: |
| 362 | # Should not reach here, just in case. |
| 363 | return None |