1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 2023 Google LLC 4 */ 5 #include <kunit/test.h> 6 #include <asm-generic/unaligned.h> 7 #include <scsi/scsi_proto.h> 8 9 static void test_scsi_proto(struct kunit *test) 10 { 11 static const union { 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); 24 25 static const union { 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), 31 0x1234); 32 KUNIT_EXPECT_EQ(test, ss.s.rel_lifetime + 0, 0x3f); 33 34 static const union { 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), 40 0x506); 41 } 42 43 static struct kunit_case scsi_proto_test_cases[] = { 44 KUNIT_CASE(test_scsi_proto), 45 {} 46 }; 47 48 static struct kunit_suite scsi_proto_test_suite = { 49 .name = "scsi_proto", 50 .test_cases = scsi_proto_test_cases, 51 }; 52 kunit_test_suite(scsi_proto_test_suite); 53 54 MODULE_DESCRIPTION("<scsi/scsi_proto.h> unit tests"); 55 MODULE_AUTHOR("Bart Van Assche"); 56 MODULE_LICENSE("GPL"); 57