Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][RFC] Test-case: Set PGAs to unity gain in script check-alsabat.sh #437

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions test-case/check-alsabat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ OPT_HAS_ARG['n']=1 OPT_VAL['n']=240000
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1

OPT_NAME['t']='tplg' OPT_DESC['f']='tplg file, default value is env TPLG: $''TPLG'
OPT_HAS_ARG['t']=1 OPT_VAL['f']="$TPLG"

TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
TPLGREADER="$TESTDIR"/tools/sof-tplgreader.py

func_opt_parse_option "$@"

pcm_p=${OPT_VAL['p']}
Expand All @@ -50,6 +56,7 @@ rate=${OPT_VAL['r']}
channel_c=${OPT_VAL['C']}
frequency=${OPT_VAL['f']}
frames=${OPT_VAL['n']}
tplg=${OPT_VAL['t']}

if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
then
Expand All @@ -72,11 +79,83 @@ function __upload_wav_file
done
}

set_pga_to_unity_gain()
{
tmp=$(amixer controls | grep "$1" | grep Volume)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you use very generic variable names, this first line will avoid any collision:

local tmp search cname scale ...

search="name="
cname=${tmp#*$search}

# Get volume min and step to compute value for cset
# for 0 dB gain. The amixer line looks like
# "| dBscale-min=-50.00dB,step=1.00dB,mute=1"
scale=$(amixer cget name="$cname" | grep "dBscale" || true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| true means an empty $scale is OK. Is it really?

search="dBscale-min="
tmp=${scale#*$search}
min_db="${tmp%%dB*}"
search="step="
tmp=${scale#*$search}
step_db="${tmp%%dB*}"

# Get multiplied by 100 values by removing decimal dot
min_x100="${min_db//.}"
step_x100="${step_db//.}"
val=$(printf %d "$(((-min_x100) / step_x100))")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, this would be slightly easier to read with some spaces:

val=$(printf %d "$(( (-min_x100) / step_x100))" )

Why do you need the printf at all?


# Apply the computed value for requested gain
amixer cset name="$cname" "$val"
}

set_pgas_list_to_unity_gain()
{
for pga in "$@"; do
dlogi "Set $pga"
set_pga_to_unity_gain "$pga"
done
}

get_snd_base()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_snd_dev()?

{
# Converts e.g. string hw:1,0 to /dev/snd/pcmC1D0
# the p or c for playback or capture is appended
# in the calling function.
tmp=${1#*"hw:"}
ncard="${tmp%%,*}"
ndevice="${tmp#*,}"
singalsu marked this conversation as resolved.
Show resolved Hide resolved
echo "/dev/snd/pcmC${ncard}D${ndevice}"
}

get_play_snd()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_play_snd_dev()?

{
tmp=$(get_snd_base "$1")
echo "${tmp}"p
}

get_capture_snd()
{
tmp=$(get_snd_base "$1")
echo "${tmp}"c
}

# check the PCMs before alsabat test
dlogi "check the PCMs before alsabat test"
aplay -Dplug$pcm_p -d 1 /dev/zero -q || die "Failed to play on PCM: $pcm_p"
arecord -Dplug$pcm_c -d 1 /dev/null -q || die "Failed to capture on PCM: $pcm_c"

# Set PGAs for PCMs to 0 dB value
test -n "$(command -v "$TPLGREADER")" ||
die "Command $TPLGREADER is not available."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note #471 Remove sof-test dependency on topology file, use /proc instead (but I have no idea how it would work here, this is just FYI)


test -n "$tplg" || die "Use -t or set environment variable TPLG to current topology"
singalsu marked this conversation as resolved.
Show resolved Hide resolved
tplg_full_path=$(func_lib_get_tplg_path "$tplg")
dlogi "Getting playback PGA information"
play_snd=$(get_play_snd "$pcm_p")
PLAY_PGAS=$($TPLGREADER "$tplg_full_path" -f "snd:$play_snd" -d pga -v)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-d pga seems to be compatible with topology v1 only, same problem as in #1068. @ranj063 confirm?

Copy link
Contributor

@ranj063 ranj063 Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we talking about the string "pga" in the kcontrol name here? Then yes it is compatible with the tplg2 as well. Take a look at the gain kcontrols in the nocodec tplg https://sof-ci.01.org/linuxpr/PR4937/build2360/devicetest/index.html?model=TGLU_RVP_NOCODEC-ipc4&testcase=verify-tplg-binary

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When run on topology v1 files, tools/sof-tplgreader.py shows a field named pga. Example:

 ./tools/sof-tplgreader.py /lib/firmware/intel/sof-tplg/sof-apl-nocodec.tplg -d pga


pga=PGA9.0 PGA5.0;
pga=PGA6.0;
pga=PGA11.0 PGA5.0;

Note the blank lines stand for DMIC and other PCMs without a pga= field.

What would be the equivalent for topology v2? Is there a v2 compatibility issue with sof-tplgreader.py?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the gain kcontrols in the nocodec tplg https://sof-ci.01.org/linuxpr/PR4937/build2360/devicetest/index.html?model=TGLU_RVP_NOCODEC-ipc4&testcase=verify-tplg-binary

This device has at least 15 amixer controls with "Volu.." in the name (name= which may or may not be truncated). That's the list of kcontrols volume tests want, correct?

That log shows a list of pipelines, 3 of them which have cap_name=Gain Capture.

I don't see the connection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marc-hb i see your problem. Sorry I misundertood the PGA in the picture. Looks like that's the tplgtool printing that the PGA prefix for the kcontrols.

So, yes there's no "pga" string in tplg2 kcontrol names. Infact we consciously removed the widget name from the kcontrol name as well so you have "gain" either. So the question is how to figure out which kcontrols to test?

Can we do this during tplg parsing ie when as we parse the gain widgets, save the kcontrol names for the kcontrols associated with the widget and test only those?

Copy link
Collaborator

@marc-hb marc-hb Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we parse the gain widgets, save the kcontrol names for the kcontrols associated with the widget and test only those?

Sounds like a plan. Let me take a look.

EDIT: done in

set_pgas_list_to_unity_gain $PLAY_PGAS
dlogi "Getting capture PGA information"
cap_snd=$(get_capture_snd "$pcm_c")
CAP_PGAS=$($TPLGREADER "$tplg_full_path" -f "snd:$cap_snd" -d pga -v)
set_pgas_list_to_unity_gain $CAP_PGAS

# alsabat test
# hardcode the channel number of playback to 2, as sof doesnot support mono wav.
dlogc "alsabat -P$pcm_p --standalone -n $frames -r $rate -c 2 -F $frequency"
Expand Down