1 // SPDX-License-Identifier: GPL-2.0-only
3 // uapi_test.c - An application of Kunit to check layout of structures exposed to user space for
6 // Copyright (c) 2023 Takashi Sakamoto
8 #include <kunit/test.h>
9 #include <linux/firewire-cdev.h>
11 // Known issue added at v2.6.27 kernel.
12 static void structure_layout_event_response(struct kunit
*test
)
14 #if defined(CONFIG_X86_32)
15 // 4 bytes alignment for aggregate type including 8 bytes storage types.
16 KUNIT_EXPECT_EQ(test
, 20, sizeof(struct fw_cdev_event_response
));
18 // 8 bytes alignment for aggregate type including 8 bytes storage types.
19 KUNIT_EXPECT_EQ(test
, 24, sizeof(struct fw_cdev_event_response
));
22 KUNIT_EXPECT_EQ(test
, 0, offsetof(struct fw_cdev_event_response
, closure
));
23 KUNIT_EXPECT_EQ(test
, 8, offsetof(struct fw_cdev_event_response
, type
));
24 KUNIT_EXPECT_EQ(test
, 12, offsetof(struct fw_cdev_event_response
, rcode
));
25 KUNIT_EXPECT_EQ(test
, 16, offsetof(struct fw_cdev_event_response
, length
));
26 KUNIT_EXPECT_EQ(test
, 20, offsetof(struct fw_cdev_event_response
, data
));
30 static void structure_layout_event_request3(struct kunit
*test
)
32 KUNIT_EXPECT_EQ(test
, 56, sizeof(struct fw_cdev_event_request3
));
34 KUNIT_EXPECT_EQ(test
, 0, offsetof(struct fw_cdev_event_request3
, closure
));
35 KUNIT_EXPECT_EQ(test
, 8, offsetof(struct fw_cdev_event_request3
, type
));
36 KUNIT_EXPECT_EQ(test
, 12, offsetof(struct fw_cdev_event_request3
, tcode
));
37 KUNIT_EXPECT_EQ(test
, 16, offsetof(struct fw_cdev_event_request3
, offset
));
38 KUNIT_EXPECT_EQ(test
, 24, offsetof(struct fw_cdev_event_request3
, source_node_id
));
39 KUNIT_EXPECT_EQ(test
, 28, offsetof(struct fw_cdev_event_request3
, destination_node_id
));
40 KUNIT_EXPECT_EQ(test
, 32, offsetof(struct fw_cdev_event_request3
, card
));
41 KUNIT_EXPECT_EQ(test
, 36, offsetof(struct fw_cdev_event_request3
, generation
));
42 KUNIT_EXPECT_EQ(test
, 40, offsetof(struct fw_cdev_event_request3
, handle
));
43 KUNIT_EXPECT_EQ(test
, 44, offsetof(struct fw_cdev_event_request3
, length
));
44 KUNIT_EXPECT_EQ(test
, 48, offsetof(struct fw_cdev_event_request3
, tstamp
));
45 KUNIT_EXPECT_EQ(test
, 56, offsetof(struct fw_cdev_event_request3
, data
));
49 static void structure_layout_event_response2(struct kunit
*test
)
51 KUNIT_EXPECT_EQ(test
, 32, sizeof(struct fw_cdev_event_response2
));
53 KUNIT_EXPECT_EQ(test
, 0, offsetof(struct fw_cdev_event_response2
, closure
));
54 KUNIT_EXPECT_EQ(test
, 8, offsetof(struct fw_cdev_event_response2
, type
));
55 KUNIT_EXPECT_EQ(test
, 12, offsetof(struct fw_cdev_event_response2
, rcode
));
56 KUNIT_EXPECT_EQ(test
, 16, offsetof(struct fw_cdev_event_response2
, length
));
57 KUNIT_EXPECT_EQ(test
, 20, offsetof(struct fw_cdev_event_response2
, request_tstamp
));
58 KUNIT_EXPECT_EQ(test
, 24, offsetof(struct fw_cdev_event_response2
, response_tstamp
));
59 KUNIT_EXPECT_EQ(test
, 32, offsetof(struct fw_cdev_event_response2
, data
));
63 static void structure_layout_event_phy_packet2(struct kunit
*test
)
65 KUNIT_EXPECT_EQ(test
, 24, sizeof(struct fw_cdev_event_phy_packet2
));
67 KUNIT_EXPECT_EQ(test
, 0, offsetof(struct fw_cdev_event_phy_packet2
, closure
));
68 KUNIT_EXPECT_EQ(test
, 8, offsetof(struct fw_cdev_event_phy_packet2
, type
));
69 KUNIT_EXPECT_EQ(test
, 12, offsetof(struct fw_cdev_event_phy_packet2
, rcode
));
70 KUNIT_EXPECT_EQ(test
, 16, offsetof(struct fw_cdev_event_phy_packet2
, length
));
71 KUNIT_EXPECT_EQ(test
, 20, offsetof(struct fw_cdev_event_phy_packet2
, tstamp
));
72 KUNIT_EXPECT_EQ(test
, 24, offsetof(struct fw_cdev_event_phy_packet2
, data
));
75 static struct kunit_case structure_layout_test_cases
[] = {
76 KUNIT_CASE(structure_layout_event_response
),
77 KUNIT_CASE(structure_layout_event_request3
),
78 KUNIT_CASE(structure_layout_event_response2
),
79 KUNIT_CASE(structure_layout_event_phy_packet2
),
83 static struct kunit_suite structure_layout_test_suite
= {
84 .name
= "firewire-uapi-structure-layout",
85 .test_cases
= structure_layout_test_cases
,
87 kunit_test_suite(structure_layout_test_suite
);
89 MODULE_DESCRIPTION("FireWire UAPI unit test suite");
90 MODULE_LICENSE("GPL");