sound/core/sound_kunit.c

Source file repositories/reference/linux-study-clean/sound/core/sound_kunit.c

File Facts

System
Linux kernel
Corpus path
sound/core/sound_kunit.c
Extension
.c
Size
11564 bytes
Lines
325
Domain
Driver Families
Bucket
sound/core
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct snd_format_test_data {
	snd_pcm_format_t format;
	int physical_bits;
	int width;
	int le;
	int sd;
	unsigned char silence[8];
	unsigned char *name;
};

struct avail_test_data {
	snd_pcm_uframes_t buffer_size;
	snd_pcm_uframes_t hw_ptr;
	snd_pcm_uframes_t appl_ptr;
	snd_pcm_uframes_t expected_avail;
};

static const struct snd_format_test_data valid_fmt[] = {
	DEFINE_FORMAT(S8, 8, 8, -1, 1, SILENCE()),
	DEFINE_FORMAT(U8, 8, 8, -1, 0, SILENCE(0x80)),
	DEFINE_FORMAT(S16_LE, 16, 16, 1, 1, SILENCE()),
	DEFINE_FORMAT(S16_BE, 16, 16, 0, 1, SILENCE()),
	DEFINE_FORMAT(U16_LE, 16, 16, 1, 0, SILENCE(0x00, 0x80)),
	DEFINE_FORMAT(U16_BE, 16, 16, 0, 0, SILENCE(0x80, 0x00)),
	DEFINE_FORMAT(S24_LE, 32, 24, 1, 1, SILENCE()),
	DEFINE_FORMAT(S24_BE, 32, 24, 0, 1, SILENCE()),
	DEFINE_FORMAT(U24_LE, 32, 24, 1, 0, SILENCE(0x00, 0x00, 0x80)),
	DEFINE_FORMAT(U24_BE, 32, 24, 0, 0, SILENCE(0x00, 0x80, 0x00, 0x00)),
	DEFINE_FORMAT(S32_LE, 32, 32, 1, 1, SILENCE()),
	DEFINE_FORMAT(S32_BE, 32, 32, 0, 1, SILENCE()),
	DEFINE_FORMAT(U32_LE, 32, 32, 1, 0, SILENCE(0x00, 0x00, 0x00, 0x80)),
	DEFINE_FORMAT(U32_BE, 32, 32, 0, 0, SILENCE(0x80, 0x00, 0x00, 0x00)),
	DEFINE_FORMAT(FLOAT_LE, 32, 32, 1, -1, SILENCE()),
	DEFINE_FORMAT(FLOAT_BE, 32, 32, 0, -1, SILENCE()),
	DEFINE_FORMAT(FLOAT64_LE, 64, 64, 1, -1, SILENCE()),
	DEFINE_FORMAT(FLOAT64_BE, 64, 64, 0, -1, SILENCE()),
	DEFINE_FORMAT(IEC958_SUBFRAME_LE, 32, 32, 1, -1, SILENCE()),
	DEFINE_FORMAT(IEC958_SUBFRAME_BE, 32, 32, 0, -1, SILENCE()),
	DEFINE_FORMAT(MU_LAW, 8, 8, -1, -1, SILENCE(0x7f)),
	DEFINE_FORMAT(A_LAW, 8, 8, -1, -1, SILENCE(0x55)),
	DEFINE_FORMAT(IMA_ADPCM, 4, 4, -1, -1, SILENCE()),
	DEFINE_FORMAT(G723_24, 3, 3, -1, -1, SILENCE()),
	DEFINE_FORMAT(G723_40, 5, 5, -1, -1, SILENCE()),
	DEFINE_FORMAT(DSD_U8, 8, 8, 1, 0, SILENCE(0x69)),
	DEFINE_FORMAT(DSD_U16_LE, 16, 16, 1, 0, SILENCE(0x69, 0x69)),
	DEFINE_FORMAT(DSD_U32_LE, 32, 32, 1, 0, SILENCE(0x69, 0x69, 0x69, 0x69)),
	DEFINE_FORMAT(DSD_U16_BE, 16, 16, 0, 0, SILENCE(0x69, 0x69)),
	DEFINE_FORMAT(DSD_U32_BE, 32, 32, 0, 0, SILENCE(0x69, 0x69, 0x69, 0x69)),
	DEFINE_FORMAT(S20_LE, 32, 20, 1, 1, SILENCE()),
	DEFINE_FORMAT(S20_BE, 32, 20, 0, 1, SILENCE()),
	DEFINE_FORMAT(U20_LE, 32, 20, 1, 0, SILENCE(0x00, 0x00, 0x08, 0x00)),
	DEFINE_FORMAT(U20_BE, 32, 20, 0, 0, SILENCE(0x00, 0x08, 0x00, 0x00)),
	DEFINE_FORMAT(S24_3LE, 24, 24, 1, 1, SILENCE()),
	DEFINE_FORMAT(S24_3BE, 24, 24, 0, 1, SILENCE()),
	DEFINE_FORMAT(U24_3LE, 24, 24, 1, 0, SILENCE(0x00, 0x00, 0x80)),
	DEFINE_FORMAT(U24_3BE, 24, 24, 0, 0, SILENCE(0x80, 0x00, 0x00)),
	DEFINE_FORMAT(S20_3LE, 24, 20, 1, 1, SILENCE()),
	DEFINE_FORMAT(S20_3BE, 24, 20, 0, 1, SILENCE()),
	DEFINE_FORMAT(U20_3LE, 24, 20, 1, 0, SILENCE(0x00, 0x00, 0x08)),
	DEFINE_FORMAT(U20_3BE, 24, 20, 0, 0, SILENCE(0x08, 0x00, 0x00)),
	DEFINE_FORMAT(S18_3LE, 24, 18, 1, 1, SILENCE()),
	DEFINE_FORMAT(S18_3BE, 24, 18, 0, 1, SILENCE()),
	DEFINE_FORMAT(U18_3LE, 24, 18, 1, 0, SILENCE(0x00, 0x00, 0x02)),
	DEFINE_FORMAT(U18_3BE, 24, 18, 0, 0, SILENCE(0x02, 0x00, 0x00)),
	DEFINE_FORMAT(G723_24_1B, 8, 3, -1, -1, SILENCE()),
	DEFINE_FORMAT(G723_40_1B, 8, 5, -1, -1, SILENCE()),
};

static void test_phys_format_size(struct kunit *test)
{
	u32 i;

	for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) {
		KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(valid_fmt[i].format),
				valid_fmt[i].physical_bits);
	}

	KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_1), -EINVAL);
	KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_2), -EINVAL);
}

static void test_format_width(struct kunit *test)
{
	u32 i;

	for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) {
		KUNIT_EXPECT_EQ(test, snd_pcm_format_width(valid_fmt[i].format),
				valid_fmt[i].width);
	}

Annotation

Implementation Notes