← Documents Documentation/sound/cards/pcmtest.rst GitHub 원문 ↗

Linux 6.18.37 · Sound

가상 PCM 테스트 드라이버

가상 `snd_pcmtest` 장치의 패턴·무작위 캡처 생성, 지연과 PCM callback 오류 주입, 재생 패턴 및 RESET ioctl selftest를 설명합니다.

Source pathDocumentation/sound/cards/pcmtest.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

pcmtest.rst:1-120

가상 `snd_pcmtest` 장치의 패턴·무작위 캡처 생성, 지연과 PCM callback 오류 주입, 재생 패턴 및 RESET ioctl selftest를 설명합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 The Virtual PCM Test Driver
4 ===========================
5
6 The Virtual PCM Test Driver emulates a generic PCM device, and can be used for
7 testing/fuzzing of the userspace ALSA applications, as well as for testing/fuzzing of
8 the PCM middle layer. Additionally, it can be used for simulating hard to reproduce
9 problems with PCM devices.
10
11 What can this driver do?
12 ~~~~~~~~~~~~~~~~~~~~~~~~
13
14 At this moment the driver can do the following things:
15 * Simulate both capture and playback processes
16 * Generate random or pattern-based capturing data
17 * Inject delays into the playback and capturing processes
18 * Inject errors during the PCM callbacks
19
20 It supports up to 8 substreams and 4 channels. Also it supports both interleaved and
21 non-interleaved access modes.
22
23 Also, this driver can check the playback stream for containing the predefined pattern,
24 which is used in the corresponding selftest (alsa/pcmtest-test.sh) to check the PCM middle
25 layer data transferring functionality. Additionally, this driver redefines the default
26 RESET ioctl, and the selftest covers this PCM API functionality as well.
27
28 Configuration
29 -------------
30
31 The driver has several parameters besides the common ALSA module parameters:
32
33 * fill_mode (bool) - Buffer fill mode (see below)
34 * inject_delay (int)
35 * inject_hwpars_err (bool)
36 * inject_prepare_err (bool)
37 * inject_trigger_err (bool)
38
39
40 Capture Data Generation
41 -----------------------
42
43 The driver has two modes of data generation: the first (0 in the fill_mode parameter)
44 means random data generation, the second (1 in the fill_mode) - pattern-based
45 data generation. Let's look at the second mode.
46
47 First of all, you may want to specify the pattern for data generation. You can do it
48 by writing the pattern to the debugfs file. There are pattern buffer debugfs entries
49 for each channel, as well as entries which contain the pattern buffer length.
50
51 * /sys/kernel/debug/pcmtest/fill_pattern[0-3]
52 * /sys/kernel/debug/pcmtest/fill_pattern[0-3]_len
53
54 To set the pattern for the channel 0 you can execute the following command:
55
56 .. code-block:: bash
57
58 echo -n mycoolpattern > /sys/kernel/debug/pcmtest/fill_pattern0
59
60 Then, after every capture action performed on the 'pcmtest' device the buffer for the
61 channel 0 will contain 'mycoolpatternmycoolpatternmycoolpatternmy...'.
62
63 The pattern itself can be up to 4096 bytes long.
64
65 Delay injection
66 ---------------
67
68 The driver has 'inject_delay' parameter, which has very self-descriptive name and
69 can be used for time delay/speedup simulations. The parameter has integer type, and
70 it means the delay added between module's internal timer ticks.
71
72 If the 'inject_delay' value is positive, the buffer will be filled slower, if it is
73 negative - faster. You can try it yourself by starting a recording in any
74 audiorecording application (like Audacity) and selecting the 'pcmtest' device as a
75 source.
76
77 This parameter can be also used for generating a huge amount of sound data in a very
78 short period of time (with the negative 'inject_delay' value).
79
80 Errors injection
81 ----------------
82
83 This module can be used for injecting errors into the PCM communication process. This
84 action can help you to figure out how the userspace ALSA program behaves under unusual
85 circumstances.
86
87 For example, you can make all 'hw_params' PCM callback calls return EBUSY error by
88 writing '1' to the 'inject_hwpars_err' module parameter:
89
90 .. code-block:: bash
91
92 echo 1 > /sys/module/snd_pcmtest/parameters/inject_hwpars_err
93
94 Errors can be injected into the following PCM callbacks:
95
96 * hw_params (EBUSY)
97 * prepare (EINVAL)
98 * trigger (EINVAL)
99
100 Playback test
101 -------------
102
103 This driver can be also used for the playback functionality testing - every time you
104 write the playback data to the 'pcmtest' PCM device and close it, the driver checks the
105 buffer for containing the looped pattern (which is specified in the fill_pattern
106 debugfs file for each channel). If the playback buffer content represents the looped
107 pattern, 'pc_test' debugfs entry is set into '1'. Otherwise, the driver sets it to '0'.
108
109 ioctl redefinition test
110 -----------------------
111
112 The driver redefines the 'reset' ioctl, which is default for all PCM devices. To test
113 this functionality, we can trigger the reset ioctl and check the 'ioctl_test' debugfs
114 entry:
115
116 .. code-block:: bash
117
118 cat /sys/kernel/debug/pcmtest/ioctl_test
119
120 If the ioctl is triggered successfully, this file will contain '1', and '0' otherwise.
121

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)를 제공한다.

snd_pcmtest 기능
항목지원 내용
방향capture와 playback
데이터random 또는 pattern-based capture
시간재생·캡처 delay/speedup 주입
오류PCM callback 오류 주입
규모최대 8 substreams, 4 channels
접근interleaved / non-interleaved
API반복 패턴 검사, RESET ioctl 재정의

가상 장치가 제공하는 시험·fuzzing 기능과 한계다.

pcmtest 모듈 매개변수
매개변수형식목적
fill_modebool버퍼 채우기 모드
inject_delayinttimer tick 사이 지연·가속
inject_hwpars_errboolhw_params 오류
inject_prepare_errboolprepare 오류
inject_trigger_errbooltrigger 오류

공통 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`를 소스로 선택해 시험할 수 있다. 큰 음수 값을 사용하면 매우 짧은 시간에 방대한 사운드 데이터를 만들 수도 있다.

패턴 기반 캡처
fill_mode=1fill_pattern0~3에 최대 4096바이트 기록캡처 실행채널 버퍼에 패턴 반복
inject_delay > 0느린 채우기
inject_delay < 0빠른 채우기·대량 데이터 생성

채널별 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
PCM callback 오류 주입
매개변수Callback오류
inject_hwpars_errhw_paramsEBUSY
inject_prepare_errprepareEINVAL
inject_trigger_errtriggerEINVAL

매개변수별 callback과 강제 반환값이다.

pcmtest 결과 항목
debugfs 항목10
pc_test재생 버퍼가 반복 패턴과 일치불일치
ioctl_testreset ioctl 성공실패 또는 미호출

재생 패턴과 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.