Skip to content

Commit 2dc8b9e

Browse files
committed
test-case: latency-metrics.sh: Add latency threshold parameter
The parameter sets a threshold for the average latency value. If `avg_ms` exceeds this value, the test will fail. Signed-off-by: Pawel Langowski <pawelx.langowski@intel.com>
1 parent deffa76 commit 2dc8b9e

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

test-case/latency-metrics.sh

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,53 +40,56 @@ TESTLIB="${TESTDIR}/case-lib"
4040
# shellcheck source=case-lib/lib.sh
4141
source "${TESTLIB}/lib.sh"
4242

43-
OPT_NAME['R']='running-time' OPT_DESC['R']='Test running time (in seconds) to collect latency probes.'
44-
OPT_HAS_ARG['R']=1 OPT_VAL['R']="30"
43+
OPT_NAME['R']='running-time' OPT_DESC['R']='Test running time (in seconds) to collect latency probes.'
44+
OPT_HAS_ARG['R']=1 OPT_VAL['R']="30"
4545

46-
OPT_NAME['d']='device' OPT_DESC['d']='ALSA pcm device for playback and capture. Example: hw:0'
47-
OPT_HAS_ARG['d']=1 OPT_VAL['d']=''
46+
OPT_NAME['d']='device' OPT_DESC['d']='ALSA pcm device for playback and capture. Example: hw:0'
47+
OPT_HAS_ARG['d']=1 OPT_VAL['d']=''
4848

49-
OPT_NAME['p']='pcm_p' OPT_DESC['p']='ALSA pcm device for playback only. Example: hw:soundwire,0'
50-
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
49+
OPT_NAME['p']='pcm_p' OPT_DESC['p']='ALSA pcm device for playback only. Example: hw:soundwire,0'
50+
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
5151

52-
OPT_NAME['c']='pcm_c' OPT_DESC['c']='ALSA pcm device for capture only. Example: hw:soundwire,1'
53-
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
52+
OPT_NAME['c']='pcm_c' OPT_DESC['c']='ALSA pcm device for capture only. Example: hw:soundwire,1'
53+
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
5454

55-
OPT_NAME['r']='rate' OPT_DESC['r']='Sample rate to try latency with'
56-
OPT_HAS_ARG['r']=1 OPT_VAL['r']=48000
55+
OPT_NAME['r']='rate' OPT_DESC['r']='Sample rate to try latency with'
56+
OPT_HAS_ARG['r']=1 OPT_VAL['r']=48000
5757

58-
OPT_NAME['f']='frames' OPT_DESC['f']='jackd alsa --period, number of frames.'
59-
OPT_HAS_ARG['f']=1 OPT_VAL['f']=1024 # JACK's default
58+
OPT_NAME['f']='frames' OPT_DESC['f']='jackd alsa --period, number of frames.'
59+
OPT_HAS_ARG['f']=1 OPT_VAL['f']=1024 # JACK's default
6060

61-
OPT_NAME['n']='nperiods' OPT_DESC['n']='jackd alsa --nperiods, periods in the buffer.'
62-
OPT_HAS_ARG['n']=1 OPT_VAL['n']=2 # JACK's default and min value.
61+
OPT_NAME['n']='nperiods' OPT_DESC['n']='jackd alsa --nperiods, periods in the buffer.'
62+
OPT_HAS_ARG['n']=1 OPT_VAL['n']=2 # JACK's default and min value.
6363

64-
OPT_NAME['S']='shorts' OPT_DESC['S']='Try to use 16-bit samples instead of 32-bit, if possible.'
65-
OPT_HAS_ARG['S']=0 OPT_VAL['S']=0
64+
OPT_NAME['S']='shorts' OPT_DESC['S']='Try to use 16-bit samples instead of 32-bit, if possible.'
65+
OPT_HAS_ARG['S']=0 OPT_VAL['S']=0
6666

67-
OPT_NAME['P']='port_p' OPT_DESC['P']='JACK playback port with loopback.'
68-
OPT_HAS_ARG['P']=1 OPT_VAL['P']='system:playback_1'
67+
OPT_NAME['P']='port_p' OPT_DESC['P']='JACK playback port with loopback.'
68+
OPT_HAS_ARG['P']=1 OPT_VAL['P']='system:playback_1'
6969

70-
OPT_NAME['C']='port_c' OPT_DESC['C']='JACK capture port with loopback.'
71-
OPT_HAS_ARG['C']=1 OPT_VAL['C']='system:capture_1'
70+
OPT_NAME['C']='port_c' OPT_DESC['C']='JACK capture port with loopback.'
71+
OPT_HAS_ARG['C']=1 OPT_VAL['C']='system:capture_1'
7272

73-
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
74-
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
73+
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
74+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
7575

76-
OPT_NAME['v']='verbose' OPT_DESC['v']='Verbose logging.'
77-
OPT_HAS_ARG['v']=0 OPT_VAL['v']=0
76+
OPT_NAME['v']='verbose' OPT_DESC['v']='Verbose logging.'
77+
OPT_HAS_ARG['v']=0 OPT_VAL['v']=0
7878

79-
OPT_NAME['X']='xruns-ignore' OPT_DESC['X']="How many 'xrun' errors to ignore."
80-
OPT_HAS_ARG['X']=1 OPT_VAL['X']=0
79+
OPT_NAME['X']='xruns-ignore' OPT_DESC['X']="How many 'xrun' errors to ignore."
80+
OPT_HAS_ARG['X']=1 OPT_VAL['X']=0
8181

82-
OPT_NAME['L']='loopback' OPT_DESC['L']="Set internal loopback at JACK instead of ports."
83-
OPT_HAS_ARG['L']=0 OPT_VAL['L']=0
82+
OPT_NAME['L']='loopback' OPT_DESC['L']="Set internal loopback at JACK instead of ports."
83+
OPT_HAS_ARG['L']=0 OPT_VAL['L']=0
8484

85-
OPT_NAME['t']='trial' OPT_DESC['t']="Trial mode: repeat measurements decreasing buffer."
86-
OPT_HAS_ARG['t']=0 OPT_VAL['t']=0
85+
OPT_NAME['t']='trial' OPT_DESC['t']="Trial mode: repeat measurements decreasing buffer."
86+
OPT_HAS_ARG['t']=0 OPT_VAL['t']=0
8787

88-
OPT_NAME['T']='trial-until' OPT_DESC['T']="Trial mode: repeat until this value."
89-
OPT_HAS_ARG['T']=1 OPT_VAL['T']=2
88+
OPT_NAME['T']='trial-until' OPT_DESC['T']="Trial mode: repeat until this value."
89+
OPT_HAS_ARG['T']=1 OPT_VAL['T']=2
90+
91+
OPT_NAME['l']='latency_threshold' OPT_DESC['l']='latency threshold in ms'
92+
OPT_HAS_ARG['l']=1 OPT_VAL['l']=85
9093

9194
func_opt_parse_option "$@"
9295

@@ -106,6 +109,7 @@ jackd_period=${jackd_frames}
106109
jackd_nperiods=${OPT_VAL['n']}
107110
trial_mode=${OPT_VAL['t']}
108111
trial_until=${OPT_VAL['T']}
112+
latency_threshold=${OPT_VAL['l']}
109113

110114
METRICS_JSON="${LOG_ROOT}/metrics_iodelay.json"
111115
EVENTS_JSON="${LOG_ROOT}/events_jackd.json"
@@ -242,6 +246,12 @@ report_metric()
242246

243247
printf '%s}' "${metrics_}" >> "${RESULT_JSON}" && rm "${METRICS_JSON}"
244248

249+
avg_latency=$(echo "{${metrics_}}" | jq '.avg_ms')
250+
dlogi "Avg latency: ${avg_latency}ms"
251+
dlogi "Threshold: ${latency_threshold}ms"
252+
if (( $(echo "$avg_latency > $latency_threshold" | bc -l) )); then
253+
die "Avg latency ${avg_latency}ms is higher than threshold ${latency_threshold}ms"
254+
fi
245255
xruns=$(echo "{${metrics_}}" | jq 'select(.xruns > 0).xruns')
246256
if [ -n "${xruns}" ] && [ "${xruns}" -gt "${max_xruns}" ]; then
247257
printf ']}' >> "${RESULT_JSON}"

0 commit comments

Comments
 (0)