Skip to content

Commit 6154da5

Browse files
committed
test-compressed-audio: add test
Add test that plays mp3 audio using cplay, and check PC states with Socwatch Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent f66b28b commit 6154da5

5 files changed

Lines changed: 123 additions & 185 deletions

File tree

case-lib/lib.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ minvalue() { printf '%d' $(( "$1" < "$2" ? "$1" : "$2" )); }
8383
#
8484
start_test()
8585
{
86-
if [ "$SOF_TEST_PIPEWIRE" == true ]; then
87-
func_lib_enable_pipewire
88-
fi
89-
9086
if [ "$RUN_SOCWATCH" == true ]; then
9187
load_socwatch
9288
fi
@@ -1686,11 +1682,15 @@ analyze_mixed_sound()
16861682
fi
16871683
}
16881684

1689-
# Generates 20s .mp3 file for testing
1690-
# Arguments: 1 - output filename
1685+
# Generates s 2-channels .mp3 file for testing
1686+
# Arguments:
1687+
# 1 - output filename
1688+
# 2 - duration of the soundfile in seconds
1689+
# 3 - number of channels
16911690
generate_mp3_file()
16921691
{
1693-
ffmpeg -f lavfi -i "sine=frequency=1000:duration=20" "$1"
1692+
mkdir -p "$HOME/Music"
1693+
ffmpeg -f lavfi -i "sine=frequency=1000:duration=$2" -ac "$3" "$1"
16941694
}
16951695

16961696
# Load socwatch and check if module was loaded correctly
@@ -1719,8 +1719,7 @@ run_with_socwatch()
17191719
shift
17201720

17211721
( set -x
1722-
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f pcie \
1723-
-f hw-cpu-cstate -f pcd-slps0 -f tcss-state -f tcss -f pcie-lpm -n 200 \
1722+
sudo "$SOCWATCH_PATH"/socwatch -m -n 200 -f cpu-pkg-cstate-res \
17241723
-r json -o "$output_file" -p "$@") ||
17251724
die "socwatch returned $?"
17261725
}

test-case/residency-time-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ main()
180180
load_modules
181181
}
182182

183-
main "$@"
183+
main "$@"

test-case/test-compressed-audio.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: test-compressed-audio
5+
## Preconditions:
6+
## - socwatch installed
7+
## - cplay installed
8+
## Description:
9+
## This test verifies if we enter PC10 state when playing MP3 with offload to DSP.
10+
## Case steps:
11+
## 1. Generate MP3 sound for testing.
12+
## 2. Start Socwatch measurement and play MP3 file.
13+
## 3. Analyze Socwatch results.
14+
## Expected results:
15+
## - generated MP3 is played
16+
## - dut stays in the PC10 state for the expected amount of time
17+
##
18+
19+
# shellcheck source=case-lib/lib.sh
20+
source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
21+
22+
OPT_NAME['p']='pcm_p' OPT_DESC['p']='compression device for playback. Example: 50'
23+
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
24+
25+
OPT_NAME['N']='channels_p' OPT_DESC['N']='channel number for playback.'
26+
OPT_HAS_ARG['N']=1 OPT_VAL['N']='2'
27+
28+
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
29+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
30+
31+
OPT_NAME['d']='duration' OPT_DESC['d']='duration time for playing the test sound'
32+
OPT_HAS_ARG['d']=1 OPT_VAL['d']=10
33+
34+
OPT_NAME['pc10_per']='pc10_per' OPT_DESC['pc10_per']='pc10 state threshold - percentage of time that should be spent in pc10'
35+
OPT_HAS_ARG['pc10_per']=1 OPT_VAL['pc10_per']=80
36+
37+
: "${SOCWATCH_PATH:=$HOME/socwatch}"
38+
39+
func_opt_parse_option "$@"
40+
setup_kernel_check_point
41+
42+
pcm_p=${OPT_VAL['p']}
43+
channels_p=${OPT_VAL['N']}
44+
duration=${OPT_VAL['d']}
45+
pc10_threshold=${OPT_VAL['pc10_per']}
46+
47+
analyze_socwatch_results()
48+
{
49+
pc_states_file="$LOG_ROOT/pc_states.csv"
50+
touch "$pc_states_file"
51+
results=$(grep "Platform Monitoring Technology CPU Package C-States Residency Summary: Residency" -A 10 < "$socwatch_output".csv)
52+
echo "$results" | tee "$pc_states_file"
53+
54+
expected_results="{\"PC10.2\":$pc10_threshold}"
55+
56+
# Analyze if the % of the time spent in given PC state was as expected
57+
if python3 "$SCRIPT_HOME"/tools/analyze-pc-states.py "$pc_states_file" "$expected_results"; then
58+
dlogi "All Package Residency (%) values were as expected"
59+
else
60+
die "Some Package Residency (%) values different from expected!"
61+
fi
62+
}
63+
64+
# Checks for soundfile needed for test, generates missing ones
65+
prepare_test_soundfile()
66+
{
67+
if [ ! -f "$audio_filename" ]; then
68+
dlogi "Generating audio file for the test..."
69+
generate_mp3_file "$audio_filename" "$duration" "$channels_p"
70+
fi
71+
}
72+
73+
check_cplay_command()
74+
{
75+
dlogi "${play_command[@]}"
76+
if ! "${play_command[@]}"; then
77+
die "cplay command returned error, socwatch analysis not performed"
78+
fi
79+
}
80+
81+
run_test()
82+
{
83+
audio_filename="$HOME/Music/$channels_p-ch-$duration-s.mp3"
84+
prepare_test_soundfile
85+
86+
socwatch_output="$LOG_ROOT/socwatch-results/socwatch_report"
87+
88+
play_command=("cplay" "-c" "0" "-d" "$pcm_p" "-I" "MP3" "${audio_filename}" "-v")
89+
check_cplay_command
90+
91+
run_with_socwatch "$socwatch_output" "${play_command[@]}"
92+
93+
analyze_socwatch_results
94+
}
95+
96+
main()
97+
{
98+
export RUN_SOCWATCH=true
99+
start_test
100+
logger_disabled || func_lib_start_log_collect
101+
run_test
102+
}
103+
104+
{
105+
main "$@"; exit "$?"
106+
}

test-case/test-cplay.sh

Lines changed: 0 additions & 168 deletions
This file was deleted.

tools/analyze-pc-states.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import csv
21
import sys
32
import json
43
import re
54

6-
ACCEPTANCE_BUFFER = 2.0
5+
ACCEPTANCE_BUFFER = 8.0
76

87

98
def compare_values(real, expected):
@@ -16,23 +15,25 @@ def analyze_pc_states(pc_states_file, expected_results):
1615
pattern = re.compile(r'^PC(\d+)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*$')
1716
failures = 0
1817

19-
with open(pc_states_file) as file:
18+
with open(pc_states_file, encoding="utf-8") as file:
2019
for line in file:
2120
m = pattern.match(line)
2221
if m:
2322
pc_state_nr = int(m.group(1))
2423
pc_state = "PC"+str(pc_state_nr)
2524
value = float(m.group(2))
26-
expected_value = float(expected_results.get(pc_state))
25+
expected_value = expected_results.get(pc_state)
2726
if not expected_value:
2827
continue
29-
if not compare_values(value, expected_value):
28+
if not compare_values(value, float(expected_value)):
3029
print(f"Incorrect value: {pc_state} time % was {value}, expected {expected_value}")
3130
failures += 1
3231

33-
return 0 if failures == 0 else 1
32+
if failures:
33+
return 1
34+
return 0
35+
3436

35-
3637
# This script analyzes if the % of the time spent in given PC state was as expected
3738
if __name__ == "__main__":
3839
if len(sys.argv) != 3:

0 commit comments

Comments
 (0)