1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2023 Rivos Inc. 4 */ 5 6 #include <linux/module.h> 7 #include <linux/kernel.h> 8 #include <linux/init.h> 9 #include <kunit/test.h> 10 11 MODULE_LICENSE("GPL"); 12 MODULE_DESCRIPTION("Test module linking"); 13 14 extern int test_set32(void); 15 extern int test_set16(void); 16 extern int test_set8(void); 17 extern int test_set6(void); 18 extern long test_sub64(void); 19 extern int test_sub32(void); 20 extern int test_sub16(void); 21 extern int test_sub8(void); 22 extern int test_sub6(void); 23 24 #ifdef CONFIG_AS_HAS_ULEB128 25 extern int test_uleb_basic(void); 26 extern int test_uleb_large(void); 27 #endif 28 29 #define CHECK_EQ(lhs, rhs) KUNIT_ASSERT_EQ(test, lhs, rhs) 30 31 void run_test_set(struct kunit *test); 32 void run_test_sub(struct kunit *test); 33 void run_test_uleb(struct kunit *test); 34 35 void run_test_set(struct kunit *test) 36 { 37 int val32 = test_set32(); 38 int val16 = test_set16(); 39 int val8 = test_set8(); 40 int val6 = test_set6(); 41 42 CHECK_EQ(val32, 0); 43 CHECK_EQ(val16, 0); 44 CHECK_EQ(val8, 0); 45 CHECK_EQ(val6, 0); 46 } 47 48 void run_test_sub(struct kunit *test) 49 { 50 int val64 = test_sub64(); 51 int val32 = test_sub32(); 52 int val16 = test_sub16(); 53 int val8 = test_sub8(); 54 int val6 = test_sub6(); 55 56 CHECK_EQ(val64, 0); 57 CHECK_EQ(val32, 0); 58 CHECK_EQ(val16, 0); 59 CHECK_EQ(val8, 0); 60 CHECK_EQ(val6, 0); 61 } 62 63 #ifdef CONFIG_AS_HAS_ULEB128 64 void run_test_uleb(struct kunit *test) 65 { 66 int val_uleb = test_uleb_basic(); 67 int val_uleb2 = test_uleb_large(); 68 69 CHECK_EQ(val_uleb, 0); 70 CHECK_EQ(val_uleb2, 0); 71 } 72 #endif 73 74 static struct kunit_case __refdata riscv_module_linking_test_cases[] = { 75 KUNIT_CASE(run_test_set), 76 KUNIT_CASE(run_test_sub), 77 #ifdef CONFIG_AS_HAS_ULEB128 78 KUNIT_CASE(run_test_uleb), 79 #endif 80 {} 81 }; 82 83 static struct kunit_suite riscv_module_linking_test_suite = { 84 .name = "riscv_checksum", 85 .test_cases = riscv_module_linking_test_cases, 86 }; 87 88 kunit_test_suites(&riscv_module_linking_test_suite); 89
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.