audio_loop¶
Source code: audio_loop.py
A factory test for the audio function.
Description¶
This test perform tests on audio playback and recording devices. It supports 2 loopback modes:
Loop from headphone out to headphone in.
Loop from speaker to digital microphone.
And 3 test scenarios:
Audiofun test, which plays different tones and checks recorded frequency. This test can be conducted simultaneously on different devices. This test can not be conducted with dongle inserted.
Sinewav test, which plays simple sine wav and checks if the recorded frequency is in the range specified. Optionally checks the RMS and amplitude thresholds.
Noise test, which plays nothing and record, then checks the RMS and amplitude thresholds.
Since this test is sensitive to different loopback dongles, user can set a list of output volume candidates. The test can pass if it can pass at any one of output volume candidates.
Test Procedure¶
Operator inserts the dongle (if required).
The playback starts automatically, and analyze recordings afterward.
Dependency¶
Device API
cros.factory.device.audio
.
Examples¶
Here are some test list examples for different test cases. First, you need to figure out the particular input/output device you want to perform test on.
To find the audio card name, use the command arecord -l
or aplay -l
.
For instance, if arecord -l
shows as card 0: kblrt5514rt5663
[kblrt5514rt5663max], device 1: Audio Record (*)
, then your audio card name
is kblrt5514rt5663max
or 0
and your device index is 1
. In test list
argument, input_dev is [“kblrt5514rt5663max”, “1”] or [“0”, “1”].
We also have some alias for common input and output devices:
The input_dev can be [“kblrt5514rt5663max”, “Dmic”], [“kblrt5514rt5663max”, “Dmic2”], or [“kblrt5514rt5663max”, “Extmic”].
The output_dev can be [“kblrt5514rt5663max”, “Headphone”], or [“kblrt5514rt5663max”, “Speaker”].
We use the minimal volume_gain and lower frequency to protect ears in the examples. Use default volume_gain and frequency in production to achieve higher accuracy.
To run Audiofuntest on external mic (default) and speakers:
{
"pytest_name": "audio_loop",
"label": "Speaker/External Microphone",
"related_components": [
"test_tags.TestCategory.AUDIOCODEC",
"test_tags.TestCategory.SMART_SPEAKER_AMPLIFIER",
"test_tags.TestCategory.SPEAKERAMPLIFIER"
],
"args": {
"input_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Extmic"
],
"output_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Speaker"
],
"mic_source": "Extmic",
"require_dongle": false,
"check_dongle": false,
"tests_to_conduct": [
{
"threshold": 80,
"type": "audiofun",
"volume_gain": 1,
"min_frequency": 500,
"max_frequency": 1000
}
]
}
}
To run Audiofuntest on internal mics and speaker channel 0:
{
"pytest_name": "audio_loop",
"label": "Speaker (Only Channel 0)/Microphone",
"related_components": [
"test_tags.TestCategory.AUDIOCODEC",
"test_tags.TestCategory.SMART_SPEAKER_AMPLIFIER",
"test_tags.TestCategory.SPEAKERAMPLIFIER"
],
"args": {
"input_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Dmic"
],
"output_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Speaker"
],
"mic_source": "Dmic",
"require_dongle": false,
"check_dongle": true,
"tests_to_conduct": [
{
"threshold": 80,
"type": "audiofun",
"output_channels": [
0
],
"volume_gain": 1,
"min_frequency": 500,
"max_frequency": 1000
}
]
}
}
To run noise test on internal mics and speaker:
{
"pytest_name": "audio_loop",
"label": "Speaker/Microphone Noise Test",
"related_components": [
"test_tags.TestCategory.AUDIOCODEC",
"test_tags.TestCategory.SMART_SPEAKER_AMPLIFIER",
"test_tags.TestCategory.SPEAKERAMPLIFIER"
],
"args": {
"input_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Dmic"
],
"output_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Speaker"
],
"mic_source": "Dmic",
"require_dongle": false,
"check_dongle": true,
"tests_to_conduct": [
{
"duration": 2,
"amplitude_threshold": [
-0.9,
0.9
],
"type": "noise",
"rms_threshold": [
null,
0.5
]
}
]
}
}
To run sine wave test on internal mics and speaker:
{
"pytest_name": "audio_loop",
"label": "Speaker/Microphone Sine Wave Test",
"related_components": [
"test_tags.TestCategory.AUDIOCODEC",
"test_tags.TestCategory.SMART_SPEAKER_AMPLIFIER",
"test_tags.TestCategory.SPEAKERAMPLIFIER"
],
"args": {
"input_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Dmic"
],
"output_dev": [
"eval! device.component.audio_card_name or constants.audio.card_name",
"Speaker"
],
"mic_source": "Dmic",
"require_dongle": false,
"check_dongle": true,
"tests_to_conduct": [
{
"freq_threshold": 300,
"type": "sinewav",
"rms_threshold": [
0.08,
null
]
}
]
}
}
Test Arguments¶
Name |
Type |
Description |
---|---|---|
audio_conf |
str, None |
(optional; default: |
initial_actions |
list, None |
(optional; default: |
input_dev |
list |
(optional; default: |
num_input_channels |
int |
(optional; default: |
output_dev |
list |
(optional; default: |
num_output_channels |
int |
(optional; default: |
output_volume |
int, list, None |
(optional; default: |
autostart |
bool |
(optional; default: |
require_dongle |
bool |
(optional; default: |
check_dongle |
bool |
(optional; default: |
check_cras |
bool |
(optional; default: |
cras_enabled |
bool |
(optional; default: |
mic_source |
[‘Dmic’, ‘Dmic2’, ‘Extmic’, ‘MLBDmic’] |
(optional; default: |
test_title |
str |
(optional; default: |
mic_jack_type |
str |
(optional; default: |
audiofuntest_run_delay |
int, float, None |
(optional; default: |
input_rate |
int |
(optional; default: |
output_rate |
int |
(optional; default: |
check_conformance |
bool |
(optional; default: |
conformance_rate_criteria |
float |
(optional; default: |
conformance_rate_err_criteria |
int |
(optional; default: |
tests_to_conduct |
list |
A list of dicts. A dict should contain at least one key named type indicating the test type, which can be audiofun, sinewav, or noise.
|
keep_raw_logs |
bool |
(optional; default: |