요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
The Virtual PCM Test Driver
===========================
The Virtual PCM Test Driver emulates a generic PCM device, and can be used for
testing/fuzzing of the userspace ALSA applications, as well as for testing/fuzzing of
the PCM middle layer. Additionally, it can be used for simulating hard to reproduce
problems with PCM devices.
What can this driver do?
~~~~~~~~~~~~~~~~~~~~~~~~
At this moment the driver can do the following things:
* Simulate both capture and playback processes
* Generate random or pattern-based capturing data
* Inject delays into the playback and capturing processes
* Inject errors during the PCM callbacks
It supports up to 8 substreams and 4 channels. Also it supports both interleaved and
non-interleaved access modes.
Also, this driver can check the playback stream for containing the predefined pattern,
which is used in the corresponding selftest (alsa/pcmtest-test.sh) to check the PCM middle
layer data transferring functionality. Additionally, this driver redefines the default
RESET ioctl, and the selftest covers this PCM API functionality as well.
Configuration
-------------
The driver has several parameters besides the common ALSA module parameters:
* fill_mode (bool) - Buffer fill mode (see below)
* inject_delay (int)
* inject_hwpars_err (bool)
* inject_prepare_err (bool)
* inject_trigger_err (bool)
Capture Data Generation
-----------------------
The driver has two modes of data generation: the first (0 in the fill_mode parameter)
means random data generation, the second (1 in the fill_mode) - pattern-based
data generation. Let's look at the second mode.
First of all, you may want to specify the pattern for data generation. You can do it
by writing the pattern to the debugfs file. There are pattern buffer debugfs entries
for each channel, as well as entries which contain the pattern buffer length.
* /sys/kernel/debug/pcmtest/fill_pattern[0-3]
* /sys/kernel/debug/pcmtest/fill_pattern[0-3]_len
To set the pattern for the channel 0 you can execute the following command:
.. code-block:: bash
echo -n mycoolpattern > /sys/kernel/debug/pcmtest/fill_pattern0
Then, after every capture action performed on the 'pcmtest' device the buffer for the
channel 0 will contain 'mycoolpatternmycoolpatternmycoolpatternmy...'.
The pattern itself can be up to 4096 bytes long.
Delay injection
---------------
The driver has 'inject_delay' parameter, which has very self-descriptive name and
can be used for time delay/speedup simulations. The parameter has integer type, and
it means the delay added between module's internal timer ticks.
If the 'inject_delay' value is positive, the buffer will be filled slower, if it is
negative - faster. You can try it yourself by starting a recording in any
audiorecording application (like Audacity) and selecting the 'pcmtest' device as a
source.
This parameter can be also used for generating a huge amount of sound data in a very
short period of time (with the negative 'inject_delay' value).
Errors injection
----------------
This module can be used for injecting errors into the PCM communication process. This
action can help you to figure out how the userspace ALSA program behaves under unusual
circumstances.
For example, you can make all 'hw_params' PCM callback calls return EBUSY error by
writing '1' to the 'inject_hwpars_err' module parameter:
.. code-block:: bash
echo 1 > /sys/module/snd_pcmtest/parameters/inject_hwpars_err
Errors can be injected into the following PCM callbacks:
* hw_params (EBUSY)
* prepare (EINVAL)
* trigger (EINVAL)
Playback test
-------------
This driver can be also used for the playback functionality testing - every time you
write the playback data to the 'pcmtest' PCM device and close it, the driver checks the
buffer for containing the looped pattern (which is specified in the fill_pattern
debugfs file for each channel). If the playback buffer content represents the looped
pattern, 'pc_test' debugfs entry is set into '1'. Otherwise, the driver sets it to '0'.
ioctl redefinition test
-----------------------
The driver redefines the 'reset' ioctl, which is default for all PCM devices. To test
this functionality, we can trigger the reset ioctl and check the 'ioctl_test' debugfs
entry:
.. code-block:: bash
cat /sys/kernel/debug/pcmtest/ioctl_test
If the ioctl is triggered successfully, this file will contain '1', and '0' otherwise.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
용도, 기능과 구성 매개변수
1-39가상 PCM 테스트 드라이버는 일반 PCM 장치를 에뮬레이션한다. 사용자 공간 ALSA 응용 프로그램과 PCM 중간 계층을 시험하거나 fuzzing하는 데 쓸 수 있고, 실제 PCM 장치에서 재현하기 어려운 문제도 시뮬레이션할 수 있다.
현재 캡처와 재생을 모두 시뮬레이션하고, 무작위 또는 패턴 기반 캡처 데이터를 생성하며, 재생·캡처 과정에 지연을 주입하고, PCM callback에서 오류를 주입할 수 있다. 최대 8개 substream과 4채널을 지원하며 interleaved와 non-interleaved 접근 모드를 모두 지원한다.
드라이버는 재생 스트림에 사전 정의된 반복 패턴이 들어 있는지 검사한다. 대응 selftest `alsa/pcmtest-test.sh`는 이를 이용해 PCM 중간 계층의 데이터 전송을 검증한다. 기본 `RESET` ioctl도 재정의하며 selftest가 이 PCM API도 검사한다.
공통 ALSA 모듈 매개변수 외에 `fill_mode`(bool), `inject_delay`(int), `inject_hwpars_err`(bool), `inject_prepare_err`(bool), `inject_trigger_err`(bool)를 제공한다.
가상 장치가 제공하는 시험·fuzzing 기능과 한계다.
공통 ALSA 옵션 외의 드라이버 전용 설정이다.
.. SPDX-License-Identifier: GPL-2.0
The Virtual PCM Test Driver
===========================
The Virtual PCM Test Driver emulates a generic PCM device, and can be used for
testing/fuzzing of the userspace ALSA applications, as well as for testing/fuzzing of
the PCM middle layer. Additionally, it can be used for simulating hard to reproduce
problems with PCM devices.
What can this driver do?
~~~~~~~~~~~~~~~~~~~~~~~~
At this moment the driver can do the following things:
* Simulate both capture and playback processes
* Generate random or pattern-based capturing data
* Inject delays into the playback and capturing processes
* Inject errors during the PCM callbacks
It supports up to 8 substreams and 4 channels. Also it supports both interleaved and
non-interleaved access modes.
Also, this driver can check the playback stream for containing the predefined pattern,
which is used in the corresponding selftest (alsa/pcmtest-test.sh) to check the PCM middle
layer data transferring functionality. Additionally, this driver redefines the default
RESET ioctl, and the selftest covers this PCM API functionality as well.
Configuration
-------------
The driver has several parameters besides the common ALSA module parameters:
* fill_mode (bool) - Buffer fill mode (see below)
* inject_delay (int)
* inject_hwpars_err (bool)
* inject_prepare_err (bool)
* inject_trigger_err (bool)
캡처 패턴 생성과 지연 주입
40-79데이터 생성 모드는 두 가지다. `fill_mode=0`은 무작위 생성이고 `fill_mode=1`은 패턴 기반 생성이다. 패턴 모드에서는 채널별 debugfs 파일과 길이 항목에 원하는 패턴을 기록한다.
/sys/kernel/debug/pcmtest/fill_pattern[0-3]
/sys/kernel/debug/pcmtest/fill_pattern[0-3]_len
echo -n mycoolpattern > /sys/kernel/debug/pcmtest/fill_pattern0
채널 0에 위 명령을 실행하면 이후 `pcmtest` 캡처 때마다 채널 0 버퍼가 `mycoolpatternmycoolpatternmycoolpatternmy...`처럼 반복 패턴으로 채워진다. 패턴은 최대 4096바이트다.
`inject_delay`는 모듈 내부 timer tick 사이에 더할 정수 지연을 뜻한다. 양수면 버퍼가 느리게 채워지고 음수면 더 빠르게 채워진다. Audacity 같은 녹음 응용 프로그램에서 `pcmtest`를 소스로 선택해 시험할 수 있다. 큰 음수 값을 사용하면 매우 짧은 시간에 방대한 사운드 데이터를 만들 수도 있다.
채널별 debugfs 패턴이 캡처 버퍼에 반복된다.
Capture Data Generation
-----------------------
The driver has two modes of data generation: the first (0 in the fill_mode parameter)
means random data generation, the second (1 in the fill_mode) - pattern-based
data generation. Let's look at the second mode.
First of all, you may want to specify the pattern for data generation. You can do it
by writing the pattern to the debugfs file. There are pattern buffer debugfs entries
for each channel, as well as entries which contain the pattern buffer length.
* /sys/kernel/debug/pcmtest/fill_pattern[0-3]
* /sys/kernel/debug/pcmtest/fill_pattern[0-3]_len
To set the pattern for the channel 0 you can execute the following command:
.. code-block:: bash
echo -n mycoolpattern > /sys/kernel/debug/pcmtest/fill_pattern0
Then, after every capture action performed on the 'pcmtest' device the buffer for the
channel 0 will contain 'mycoolpatternmycoolpatternmycoolpatternmy...'.
The pattern itself can be up to 4096 bytes long.
Delay injection
---------------
The driver has 'inject_delay' parameter, which has very self-descriptive name and
can be used for time delay/speedup simulations. The parameter has integer type, and
it means the delay added between module's internal timer ticks.
If the 'inject_delay' value is positive, the buffer will be filled slower, if it is
negative - faster. You can try it yourself by starting a recording in any
audiorecording application (like Audacity) and selecting the 'pcmtest' device as a
source.
This parameter can be also used for generating a huge amount of sound data in a very
short period of time (with the negative 'inject_delay' value).
오류·재생·ioctl 테스트
80-120이 모듈은 PCM 통신 과정에 오류를 주입해 비정상 상황에서 사용자 공간 ALSA 프로그램이 어떻게 동작하는지 확인할 수 있다. 예를 들어 다음 명령은 모든 `hw_params` callback이 `EBUSY`를 반환하게 한다.
echo 1 > /sys/module/snd_pcmtest/parameters/inject_hwpars_err
주입 가능한 callback과 오류는 `hw_params`의 `EBUSY`, `prepare`의 `EINVAL`, `trigger`의 `EINVAL`이다.
재생 기능 시험에서는 `pcmtest` PCM 장치에 데이터를 쓰고 닫을 때마다 드라이버가 채널별 `fill_pattern` debugfs 패턴이 재생 버퍼에서 반복되는지 검사한다. 일치하면 `pc_test` debugfs 항목을 1, 아니면 0으로 설정한다.
모든 PCM 장치의 기본 `reset` ioctl도 재정의한다. reset ioctl을 발생시킨 뒤 다음 debugfs 파일을 읽어 시험한다. 성공적으로 호출됐으면 1, 아니면 0이다.
cat /sys/kernel/debug/pcmtest/ioctl_test
매개변수별 callback과 강제 반환값이다.
재생 패턴과 RESET ioctl 검증 결과의 의미다.
Errors injection
----------------
This module can be used for injecting errors into the PCM communication process. This
action can help you to figure out how the userspace ALSA program behaves under unusual
circumstances.
For example, you can make all 'hw_params' PCM callback calls return EBUSY error by
writing '1' to the 'inject_hwpars_err' module parameter:
.. code-block:: bash
echo 1 > /sys/module/snd_pcmtest/parameters/inject_hwpars_err
Errors can be injected into the following PCM callbacks:
* hw_params (EBUSY)
* prepare (EINVAL)
* trigger (EINVAL)
Playback test
-------------
This driver can be also used for the playback functionality testing - every time you
write the playback data to the 'pcmtest' PCM device and close it, the driver checks the
buffer for containing the looped pattern (which is specified in the fill_pattern
debugfs file for each channel). If the playback buffer content represents the looped
pattern, 'pc_test' debugfs entry is set into '1'. Otherwise, the driver sets it to '0'.
ioctl redefinition test
-----------------------
The driver redefines the 'reset' ioctl, which is default for all PCM devices. To test
this functionality, we can trigger the reset ioctl and check the 'ioctl_test' debugfs
entry:
.. code-block:: bash
cat /sys/kernel/debug/pcmtest/ioctl_test
If the ioctl is triggered successfully, this file will contain '1', and '0' otherwise.
요약·해설
pcmtest.rst:1-120가상 `snd_pcmtest` 장치의 패턴·무작위 캡처 생성, 지연과 PCM callback 오류 주입, 재생 패턴 및 RESET ioctl selftest를 설명합니다.