1 // SPDX-License-Identifier: GPL-2.0-or-later
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.
6 // Copyright (c) 2024 Takashi Sakamoto
8 #include <kunit/test.h>
13 static void test_self_id_count_register_deserialization(struct kunit
*test
)
15 const u32 expected
= 0x803d0594;
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
);
21 KUNIT_EXPECT_TRUE(test
, is_error
);
22 KUNIT_EXPECT_EQ(test
, 0x3d, generation
);
23 KUNIT_EXPECT_EQ(test
, 0x165, size
);
26 static void test_self_id_receive_buffer_deserialization(struct kunit
*test
)
28 const u32 buffer
[] = {
36 u8 generation
= ohci1394_self_id_receive_q0_get_generation(buffer
[0]);
37 u16 timestamp
= ohci1394_self_id_receive_q0_get_timestamp(buffer
[0]);
39 KUNIT_EXPECT_EQ(test
, 0x6, generation
);
40 KUNIT_EXPECT_EQ(test
, 0xf38b, timestamp
);
43 static void test_at_data_serdes(struct kunit
*test
)
45 static const __le32 expected
[] = {
46 cpu_to_le32(0x00020e80),
47 cpu_to_le32(0xffc2ffff),
48 cpu_to_le32(0xe0000000),
50 __le32 quadlets
[] = {0, 0, 0};
51 bool has_src_bus_id
= ohci1394_at_data_get_src_bus_id(expected
);
52 unsigned int speed
= ohci1394_at_data_get_speed(expected
);
53 unsigned int tlabel
= ohci1394_at_data_get_tlabel(expected
);
54 unsigned int retry
= ohci1394_at_data_get_retry(expected
);
55 unsigned int tcode
= ohci1394_at_data_get_tcode(expected
);
56 unsigned int destination_id
= ohci1394_at_data_get_destination_id(expected
);
57 u64 destination_offset
= ohci1394_at_data_get_destination_offset(expected
);
59 KUNIT_EXPECT_FALSE(test
, has_src_bus_id
);
60 KUNIT_EXPECT_EQ(test
, 0x02, speed
);
61 KUNIT_EXPECT_EQ(test
, 0x03, tlabel
);
62 KUNIT_EXPECT_EQ(test
, 0x02, retry
);
63 KUNIT_EXPECT_EQ(test
, 0x08, tcode
);
65 ohci1394_at_data_set_src_bus_id(quadlets
, has_src_bus_id
);
66 ohci1394_at_data_set_speed(quadlets
, speed
);
67 ohci1394_at_data_set_tlabel(quadlets
, tlabel
);
68 ohci1394_at_data_set_retry(quadlets
, retry
);
69 ohci1394_at_data_set_tcode(quadlets
, tcode
);
70 ohci1394_at_data_set_destination_id(quadlets
, destination_id
);
71 ohci1394_at_data_set_destination_offset(quadlets
, destination_offset
);
73 KUNIT_EXPECT_MEMEQ(test
, quadlets
, expected
, sizeof(expected
));
76 static void test_it_data_serdes(struct kunit
*test
)
78 static const __le32 expected
[] = {
79 cpu_to_le32(0x000349a7),
80 cpu_to_le32(0x02300000),
82 __le32 quadlets
[] = {0, 0};
83 unsigned int scode
= ohci1394_it_data_get_speed(expected
);
84 unsigned int tag
= ohci1394_it_data_get_tag(expected
);
85 unsigned int channel
= ohci1394_it_data_get_channel(expected
);
86 unsigned int tcode
= ohci1394_it_data_get_tcode(expected
);
87 unsigned int sync
= ohci1394_it_data_get_sync(expected
);
88 unsigned int data_length
= ohci1394_it_data_get_data_length(expected
);
90 KUNIT_EXPECT_EQ(test
, 0x03, scode
);
91 KUNIT_EXPECT_EQ(test
, 0x01, tag
);
92 KUNIT_EXPECT_EQ(test
, 0x09, channel
);
93 KUNIT_EXPECT_EQ(test
, 0x0a, tcode
);
94 KUNIT_EXPECT_EQ(test
, 0x7, sync
);
95 KUNIT_EXPECT_EQ(test
, 0x0230, data_length
);
97 ohci1394_it_data_set_speed(quadlets
, scode
);
98 ohci1394_it_data_set_tag(quadlets
, tag
);
99 ohci1394_it_data_set_channel(quadlets
, channel
);
100 ohci1394_it_data_set_tcode(quadlets
, tcode
);
101 ohci1394_it_data_set_sync(quadlets
, sync
);
102 ohci1394_it_data_set_data_length(quadlets
, data_length
);
104 KUNIT_EXPECT_MEMEQ(test
, quadlets
, expected
, sizeof(expected
));
107 static struct kunit_case ohci_serdes_test_cases
[] = {
108 KUNIT_CASE(test_self_id_count_register_deserialization
),
109 KUNIT_CASE(test_self_id_receive_buffer_deserialization
),
110 KUNIT_CASE(test_at_data_serdes
),
111 KUNIT_CASE(test_it_data_serdes
),
115 static struct kunit_suite ohci_serdes_test_suite
= {
116 .name
= "firewire-ohci-serdes",
117 .test_cases
= ohci_serdes_test_cases
,
119 kunit_test_suite(ohci_serdes_test_suite
);
121 MODULE_DESCRIPTION("FireWire buffers and registers serialization/deserialization unit test suite");
122 MODULE_LICENSE("GPL");