1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2023 Google LLC
5 #include <kunit/test.h>
6 #include <linux/unaligned.h>
7 #include <scsi/scsi_proto.h>
9 static void test_scsi_proto(struct kunit
*test
)
12 struct scsi_io_group_descriptor desc
;
13 u8 arr
[sizeof(struct scsi_io_group_descriptor
)];
14 } d
= { .arr
= { 0x45, 0, 0, 0, 0xb0, 0xe4, 0xe3 } };
15 KUNIT_EXPECT_EQ(test
, d
.desc
.io_advice_hints_mode
+ 0, 1);
16 KUNIT_EXPECT_EQ(test
, d
.desc
.st_enble
+ 0, 1);
17 KUNIT_EXPECT_EQ(test
, d
.desc
.cs_enble
+ 0, 0);
18 KUNIT_EXPECT_EQ(test
, d
.desc
.ic_enable
+ 0, 1);
19 KUNIT_EXPECT_EQ(test
, d
.desc
.acdlu
+ 0, 1);
20 KUNIT_EXPECT_EQ(test
, d
.desc
.rlbsr
+ 0, 3);
21 KUNIT_EXPECT_EQ(test
, d
.desc
.lbm_descriptor_type
+ 0, 0);
22 KUNIT_EXPECT_EQ(test
, d
.desc
.params
[0] + 0, 0xe4);
23 KUNIT_EXPECT_EQ(test
, d
.desc
.params
[1] + 0, 0xe3);
26 struct scsi_stream_status s
;
27 u8 arr
[sizeof(struct scsi_stream_status
)];
28 } ss
= { .arr
= { 0x80, 0, 0x12, 0x34, 0x3f } };
29 KUNIT_EXPECT_EQ(test
, ss
.s
.perm
+ 0, 1);
30 KUNIT_EXPECT_EQ(test
, get_unaligned_be16(&ss
.s
.stream_identifier
),
32 KUNIT_EXPECT_EQ(test
, ss
.s
.rel_lifetime
+ 0, 0x3f);
35 struct scsi_stream_status_header h
;
36 u8 arr
[sizeof(struct scsi_stream_status_header
)];
37 } sh
= { .arr
= { 1, 2, 3, 4, 0, 0, 5, 6 } };
38 KUNIT_EXPECT_EQ(test
, get_unaligned_be32(&sh
.h
.len
), 0x1020304);
39 KUNIT_EXPECT_EQ(test
, get_unaligned_be16(&sh
.h
.number_of_open_streams
),
43 static struct kunit_case scsi_proto_test_cases
[] = {
44 KUNIT_CASE(test_scsi_proto
),
48 static struct kunit_suite scsi_proto_test_suite
= {
50 .test_cases
= scsi_proto_test_cases
,
52 kunit_test_suite(scsi_proto_test_suite
);
54 MODULE_DESCRIPTION("<scsi/scsi_proto.h> unit tests");
55 MODULE_AUTHOR("Bart Van Assche");
56 MODULE_LICENSE("GPL");