xref: /linux/drivers/firewire/ohci-serdes-test.c (revision 170aafe35cb98e0f3fbacb446ea86389fbce22ea)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 //
3 // ohci-serdes-test.c - An application of Kunit to check serialization/deserialization of data in
4 //			buffers and registers defined in 1394 OHCI specification.
5 //
6 // Copyright (c) 2024 Takashi Sakamoto
7 
8 #include <kunit/test.h>
9 
10 #include "ohci.h"
11 
12 
13 static void test_self_id_count_register_deserialization(struct kunit *test)
14 {
15 	const u32 expected = 0x803d0594;
16 
17 	bool is_error = ohci1394_self_id_count_is_error(expected);
18 	u8 generation = ohci1394_self_id_count_get_generation(expected);
19 	u32 size = ohci1394_self_id_count_get_size(expected);
20 
21 	KUNIT_EXPECT_TRUE(test, is_error);
22 	KUNIT_EXPECT_EQ(test, 0x3d, generation);
23 	KUNIT_EXPECT_EQ(test, 0x165, size);
24 }
25 
26 static void test_self_id_receive_buffer_deserialization(struct kunit *test)
27 {
28 	const u32 buffer[] = {
29 		0x0006f38b,
30 		0x807fcc56,
31 		0x7f8033a9,
32 		0x8145cc5e,
33 		0x7eba33a1,
34 	};
35 
36 	u8 generation = ohci1394_self_id_receive_q0_get_generation(buffer[0]);
37 	u16 timestamp = ohci1394_self_id_receive_q0_get_timestamp(buffer[0]);
38 
39 	KUNIT_EXPECT_EQ(test, 0x6, generation);
40 	KUNIT_EXPECT_EQ(test, 0xf38b, timestamp);
41 }
42 
43 static struct kunit_case ohci_serdes_test_cases[] = {
44 	KUNIT_CASE(test_self_id_count_register_deserialization),
45 	KUNIT_CASE(test_self_id_receive_buffer_deserialization),
46 	{}
47 };
48 
49 static struct kunit_suite ohci_serdes_test_suite = {
50 	.name = "firewire-ohci-serdes",
51 	.test_cases = ohci_serdes_test_cases,
52 };
53 kunit_test_suite(ohci_serdes_test_suite);
54 
55 MODULE_DESCRIPTION("FireWire buffers and registers serialization/deserialization unit test suite");
56 MODULE_LICENSE("GPL");
57