Skip to content

Commit 7a0fa5a

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 aa8e581 commit 7a0fa5a

File tree

5 files changed

+134
-187
lines changed

5 files changed

+134
-187
lines changed

case-lib/lib.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,11 +1604,15 @@ analyze_mixed_sound()
16041604
fi
16051605
}
16061606

1607-
# Generates 20s .mp3 file for testing
1608-
# Arguments: 1 - output filename
1607+
# Generates s 2-channels .mp3 file for testing
1608+
# Arguments:
1609+
# 1 - output filename
1610+
# 2 - duration of the soundfile in seconds
1611+
# 3 - number of channels
16091612
generate_mp3_file()
16101613
{
1611-
ffmpeg -f lavfi -i "sine=frequency=1000:duration=20" "$1"
1614+
mkdir -p "$HOME/Music"
1615+
ffmpeg -f lavfi -i "sine=frequency=1000:duration=$2" -ac "$3" "$1"
16121616
}
16131617

16141618
# Load socwatch and check if module was loaded correctly
@@ -1636,9 +1640,12 @@ run_with_socwatch()
16361640
local output_file="$1"
16371641
shift
16381642

1643+
# ( set -x
1644+
# sudo "$SOCWATCH_PATH"/socwatch -m -n 200 -f cpu-pkg-cstate-res \
1645+
# -r json -o "$output_file" -p "$@") ||
1646+
# die "socwatch returned $?"
16391647
( set -x
1640-
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f pcie \
1641-
-f hw-cpu-cstate -f pcd-slps0 -f tcss-state -f tcss -f pcie-lpm -n 200 \
1642-
-r json -o "$output_file" -p "$@") ||
1648+
sudo "$SOCWATCH_PATH"/socwatch -m -n 200 -f cpu-pkg-cstate-res \
1649+
-r json -o "$output_file" -t 60) ||
16431650
die "socwatch returned $?"
16441651
}

test-case/residency-time-test.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ check_socwatch_module_loaded()
5656
check_for_PC10_state()
5757
{
5858
pc10_count=$(awk '/Package C-State Summary: Entry Counts/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
59-
if [ -z "$pc10_count" ]; then
60-
die "PC10 State not achieved"
59+
if [ -z "$pc10_count" ] || [ "$pc10_count" -eq 0 ]; then
60+
dlogw "PC10 State not achieved"
61+
else
62+
dlogi "Entered into PC10 State $pc10_count times"
63+
pc10_achieved=true # PC10 state needs to be entered at least once to pass the test
6164
fi
62-
dlogi "Entered into PC10 State $pc10_count times"
6365

6466
pc10_per=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
6567
pc10_time=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $5; exit}' "$socwatch_output".csv)
@@ -87,8 +89,8 @@ socwatch_test_once()
8789
setup_kernel_check_point
8890

8991
( set -x
90-
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f pcie -f hw-cpu-cstate \
91-
-f pcd-slps0 -f tcss-state -f tcss -f pcie-lpm -n 200 -t "$duration" -s "$wait_time" \
92+
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f hw-cpu-cstate \
93+
-f tcss-state -f pcie-lpm -n 200 -t "$duration" -s "$wait_time" \
9294
-r json -o "$socwatch_output" ) ||
9395
die "socwatch returned $?"
9496

@@ -137,10 +139,15 @@ load_modules()
137139

138140
run_socwatch_tests()
139141
{
142+
# load socwatch module, if the module is loaded, go ahead with the testing
143+
sudo bash "$SOCWATCH_PATH"/drivers/insmod-socwatch || true
144+
check_socwatch_module_loaded || die "socwatch module not loaded"
145+
140146
# Create a dir for all socwatch reports
141147
mkdir "$LOG_ROOT/socwatch-results"
142148
pc10_results_file="$LOG_ROOT/socwatch-results/pc10_results.json"
143149
touch "$pc10_results_file"
150+
pc10_achieved=false
144151

145152
for i in $(seq 1 "$loop_count")
146153
do
@@ -155,14 +162,21 @@ run_socwatch_tests()
155162
cd "$LOG_ROOT"
156163
tar -zcvf socwatch-results.tar.gz socwatch-results/
157164
rm -rf "$LOG_ROOT/socwatch-results/"
165+
166+
# unload socwatch module
167+
sudo bash "$SOCWATCH_PATH"/drivers/rmmod-socwatch
168+
169+
if "$pc10_achieved"; then
170+
dlogi "PASS: PC10 state entered at least once"
171+
else
172+
die "FAIL: PC10 state NOT ENTERED"
173+
fi
158174
}
159175

160176
main()
161177
{
162178
unload_modules
163-
load_socwatch
164179
run_socwatch_tests
165-
unload_socwatch
166180
load_modules
167181
}
168182

test-case/test-compressed-audio.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
##
4+
## Case Name: test-compressed-audio
5+
##
6+
## Preconditions:
7+
## TODO
8+
##
9+
## Description:
10+
## TODO
11+
##
12+
## Case step:
13+
## TODO
14+
##
15+
## Expect result:
16+
## TODO
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+
: "${SOCWATCH_PATH:=$HOME/socwatch}"
35+
36+
func_opt_parse_option "$@"
37+
setup_kernel_check_point
38+
39+
pcm_p=${OPT_VAL['p']}
40+
channels_p=${OPT_VAL['N']}
41+
duration=${OPT_VAL['d']}
42+
43+
analyze_socwatch_results()
44+
{
45+
pc_states_file="$LOG_ROOT/pc_states.csv"
46+
touch "$pc_states_file"
47+
results=$(cat "$socwatch_output".csv | grep "Platform Monitoring Technology CPU Package C-States Residency Summary: Residency" -A 10)
48+
echo "$results" | tee "$pc_states_file"
49+
50+
# expected_results='{"PC0":12.00, "PC2":88, "PC6.1":0, "PC6.2":11, "PC10.1":2, "PC10.2":72, "PC10.3":0}'
51+
expected_results='{"PC10.2":80}'
52+
53+
# Analyze if the % of the time spent in given PC state was as expected
54+
if python3 "$SCRIPT_HOME"/tools/analyze-pc-states.py "$pc_states_file" "$expected_results"; then
55+
dlogi "All Package Residency (%) values were as expected"
56+
else
57+
die "Some Package Residency (%) values different from expected!"
58+
fi
59+
}
60+
61+
# Checks for soundfile needed for test, generates missing ones
62+
prepare_test_soundfile()
63+
{
64+
if [ ! -f "$audio_filename" ]; then
65+
dlogi "Generating audio file for the test..."
66+
generate_mp3_file "$audio_filename" "$duration" "$channels_p"
67+
fi
68+
}
69+
70+
run_test()
71+
{
72+
audio_filename="$HOME/Music/$channels_p-ch-$duration-s.mp3"
73+
prepare_test_soundfile
74+
75+
socwatch_output="$LOG_ROOT/socwatch-results/socwatch_report"
76+
77+
play_command=("aplay" "-Dhw:0,0" "Music/test.wav" "-f" "S16_LE" "-c" "2" "-v")
78+
# play_command=("cplay" "-c" "0" "-d" "$pcm_p" "-I" "MP3" "${audio_filename}" "-v")
79+
80+
run_with_socwatch "$socwatch_output" "${play_command[@]}"
81+
82+
analyze_socwatch_results
83+
}
84+
85+
main()
86+
{
87+
export RUN_SOCWATCH=true
88+
start_test
89+
logger_disabled || func_lib_start_log_collect
90+
run_test
91+
}
92+
93+
{
94+
main "$@"; exit "$?"
95+
}

test-case/test-cplay.sh

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

0 commit comments

Comments
 (0)