tools/testing/selftests/alsa/test-pcmtest-driver.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/alsa/test-pcmtest-driver.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/alsa/test-pcmtest-driver.c- Extension
.c- Size
- 9521 bytes
- Lines
- 331
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
string.halsa/asoundlib.hkselftest_harness.h
Detected Declarations
struct pattern_bufstruct pcmtest_test_paramsfunction read_patternsfunction get_test_resultsfunction get_sec_buf_lenfunction setup_handle
Annotated Snippet
struct pattern_buf {
char buf[1024];
int len;
};
struct pattern_buf patterns[CH_NUM];
struct pcmtest_test_params {
unsigned long buffer_size;
unsigned long period_size;
unsigned long channels;
unsigned int rate;
snd_pcm_access_t access;
size_t sec_buf_len;
size_t sample_size;
int time;
snd_pcm_format_t format;
};
static int read_patterns(void)
{
FILE *fp, *fpl;
int i;
char pf[64];
char plf[64];
for (i = 0; i < CH_NUM; i++) {
sprintf(plf, "/sys/kernel/debug/pcmtest/fill_pattern%d_len", i);
fpl = fopen(plf, "r");
if (!fpl)
return -1;
fscanf(fpl, "%u", &patterns[i].len);
fclose(fpl);
sprintf(pf, "/sys/kernel/debug/pcmtest/fill_pattern%d", i);
fp = fopen(pf, "r");
if (!fp)
return -1;
fread(patterns[i].buf, 1, patterns[i].len, fp);
fclose(fp);
}
return 0;
}
static int get_test_results(char *debug_name)
{
int result;
FILE *f;
char fname[128];
sprintf(fname, "/sys/kernel/debug/pcmtest/%s", debug_name);
f = fopen(fname, "r");
if (!f) {
printf("Failed to open file\n");
return -1;
}
fscanf(f, "%d", &result);
fclose(f);
return result;
}
static size_t get_sec_buf_len(unsigned int rate, unsigned long channels, snd_pcm_format_t format)
{
return rate * channels * snd_pcm_format_physical_width(format) / 8;
}
static int setup_handle(snd_pcm_t **handle, snd_pcm_sw_params_t *swparams,
snd_pcm_hw_params_t *hwparams, struct pcmtest_test_params *params,
int card, snd_pcm_stream_t stream)
{
char pcm_name[32];
int err;
sprintf(pcm_name, "hw:%d,0,0", card);
err = snd_pcm_open(handle, pcm_name, stream, 0);
if (err < 0)
return err;
snd_pcm_hw_params_any(*handle, hwparams);
snd_pcm_hw_params_set_rate_resample(*handle, hwparams, 0);
snd_pcm_hw_params_set_access(*handle, hwparams, params->access);
snd_pcm_hw_params_set_format(*handle, hwparams, params->format);
snd_pcm_hw_params_set_channels(*handle, hwparams, params->channels);
snd_pcm_hw_params_set_rate_near(*handle, hwparams, ¶ms->rate, 0);
snd_pcm_hw_params_set_period_size_near(*handle, hwparams, ¶ms->period_size, 0);
snd_pcm_hw_params_set_buffer_size_near(*handle, hwparams, ¶ms->buffer_size);
snd_pcm_hw_params(*handle, hwparams);
snd_pcm_sw_params_current(*handle, swparams);
Annotation
- Immediate include surface: `string.h`, `alsa/asoundlib.h`, `kselftest_harness.h`.
- Detected declarations: `struct pattern_buf`, `struct pcmtest_test_params`, `function read_patterns`, `function get_test_results`, `function get_sec_buf_len`, `function setup_handle`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.