tools/testing/selftests/alsa/pcm-test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/alsa/pcm-test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/alsa/pcm-test.c- Extension
.c- Size
- 18831 bytes
- Lines
- 672
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstdbool.herrno.hassert.hpthread.hkselftest.halsa-local.h
Detected Declarations
struct card_datastruct pcm_dataenum test_classfunction timestamp_nowfunction timestamp_diff_msfunction device_from_idfunction missing_devicefunction missing_devicesfunction snd_config_for_eachfunction find_pcmsfunction test_pcm_timefunction run_time_testsfunction snd_config_for_eachfunction main
Annotated Snippet
struct card_data {
int card;
snd_ctl_card_info_t *info;
const char *name;
pthread_t thread;
struct card_data *next;
};
struct card_data *card_list;
struct pcm_data {
snd_pcm_t *handle;
int card;
int device;
int subdevice;
const char *card_name;
snd_pcm_stream_t stream;
snd_config_t *pcm_config;
struct pcm_data *next;
};
struct pcm_data *pcm_list;
int num_missing;
struct pcm_data *pcm_missing;
snd_config_t *default_pcm_config;
/* Lock while reporting results since kselftest doesn't */
pthread_mutex_t results_lock = PTHREAD_MUTEX_INITIALIZER;
enum test_class {
TEST_CLASS_DEFAULT,
TEST_CLASS_SYSTEM,
};
void timestamp_now(timestamp_t *tstamp)
{
if (clock_gettime(CLOCK_MONOTONIC_RAW, tstamp))
ksft_exit_fail_msg("clock_get_time\n");
}
long long timestamp_diff_ms(timestamp_t *tstamp)
{
timestamp_t now, diff;
timestamp_now(&now);
if (tstamp->tv_nsec > now.tv_nsec) {
diff.tv_sec = now.tv_sec - tstamp->tv_sec - 1;
diff.tv_nsec = (now.tv_nsec + 1000000000L) - tstamp->tv_nsec;
} else {
diff.tv_sec = now.tv_sec - tstamp->tv_sec;
diff.tv_nsec = now.tv_nsec - tstamp->tv_nsec;
}
return (diff.tv_sec * 1000) + ((diff.tv_nsec + 500000L) / 1000000L);
}
static long device_from_id(snd_config_t *node)
{
const char *id;
char *end;
long v;
if (snd_config_get_id(node, &id))
ksft_exit_fail_msg("snd_config_get_id\n");
errno = 0;
v = strtol(id, &end, 10);
if (errno || *end)
return -1;
return v;
}
static void missing_device(int card, int device, int subdevice, snd_pcm_stream_t stream)
{
struct pcm_data *pcm_data;
for (pcm_data = pcm_list; pcm_data != NULL; pcm_data = pcm_data->next) {
if (pcm_data->card != card)
continue;
if (pcm_data->device != device)
continue;
if (pcm_data->subdevice != subdevice)
continue;
if (pcm_data->stream != stream)
continue;
return;
}
pcm_data = calloc(1, sizeof(*pcm_data));
if (!pcm_data)
ksft_exit_fail_msg("Out of memory\n");
pcm_data->card = card;
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `stdbool.h`, `errno.h`, `assert.h`, `pthread.h`, `kselftest.h`, `alsa-local.h`.
- Detected declarations: `struct card_data`, `struct pcm_data`, `enum test_class`, `function timestamp_now`, `function timestamp_diff_ms`, `function device_from_id`, `function missing_device`, `function missing_devices`, `function snd_config_for_each`, `function find_pcms`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.