1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * 4 * KUnit tests of SMB1 maperror 5 * 6 * Copyright (C) 2026 KylinSoft Co., Ltd. All rights reserved. 7 * Author(s): Youling Tang <tangyouling@kylinos.cn> 8 * ChenXiaoSong <chenxiaosong@kylinos.cn> 9 * 10 */ 11 12 #include <kunit/test.h> 13 #include "smb1proto.h" 14 #include "nterr.h" 15 #include "smberr.h" 16 17 #define DEFINE_CHECK_SEARCH_FUNC(__struct_name, __field, \ 18 __array, __num) \ 19 static void check_search_ ## __array(struct kunit *test) \ 20 { \ 21 unsigned int i; \ 22 const struct __struct_name *expect, *result; \ 23 \ 24 for (i = 0; i < __num; i++) { \ 25 expect = &__array ## _test[i]; \ 26 result = search_ ## __array ## _test(expect->__field); \ 27 KUNIT_ASSERT_NOT_NULL(test, result); \ 28 test_cmp_ ## __struct_name(test, expect, result); \ 29 } \ 30 } 31 32 static void 33 test_cmp_ntstatus_to_dos_err(struct kunit *test, 34 const struct ntstatus_to_dos_err *expect, 35 const struct ntstatus_to_dos_err *result) 36 { 37 KUNIT_EXPECT_EQ(test, expect->dos_class, result->dos_class); 38 KUNIT_EXPECT_EQ(test, expect->dos_code, result->dos_code); 39 KUNIT_EXPECT_EQ(test, expect->ntstatus, result->ntstatus); 40 KUNIT_EXPECT_STREQ(test, expect->nt_errstr, result->nt_errstr); 41 } 42 43 static void 44 test_cmp_smb_to_posix_error(struct kunit *test, 45 const struct smb_to_posix_error *expect, 46 const struct smb_to_posix_error *result) 47 { 48 KUNIT_EXPECT_EQ(test, expect->smb_err, result->smb_err); 49 KUNIT_EXPECT_EQ(test, expect->posix_code, result->posix_code); 50 } 51 52 /* check_search_ntstatus_to_dos_map */ 53 DEFINE_CHECK_SEARCH_FUNC(ntstatus_to_dos_err, ntstatus, ntstatus_to_dos_map, 54 ntstatus_to_dos_num); 55 /* check_search_mapping_table_ERRDOS */ 56 DEFINE_CHECK_SEARCH_FUNC(smb_to_posix_error, smb_err, mapping_table_ERRDOS, 57 mapping_table_ERRDOS_num); 58 /* check_search_mapping_table_ERRSRV */ 59 DEFINE_CHECK_SEARCH_FUNC(smb_to_posix_error, smb_err, mapping_table_ERRSRV, 60 mapping_table_ERRSRV_num); 61 62 static struct kunit_case maperror_test_cases[] = { 63 KUNIT_CASE(check_search_ntstatus_to_dos_map), 64 KUNIT_CASE(check_search_mapping_table_ERRDOS), 65 KUNIT_CASE(check_search_mapping_table_ERRSRV), 66 {} 67 }; 68 69 static struct kunit_suite maperror_suite = { 70 .name = "smb1_maperror", 71 .test_cases = maperror_test_cases, 72 }; 73 74 kunit_test_suite(maperror_suite); 75 76 MODULE_LICENSE("GPL"); 77 MODULE_DESCRIPTION("KUnit tests of SMB1 maperror"); 78