Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.15 52 lines 1.3 kB view raw
1// SPDX-License-Identifier: GPL-2.0-only 2 3#include <kunit/test.h> 4#include <linux/math.h> 5 6struct test_case_params { 7 u64 base; 8 unsigned int exponent; 9 u64 expected_result; 10 const char *name; 11}; 12 13static const struct test_case_params params[] = { 14 { 64, 0, 1, "Power of zero" }, 15 { 64, 1, 64, "Power of one"}, 16 { 0, 5, 0, "Base zero" }, 17 { 1, 64, 1, "Base one" }, 18 { 2, 2, 4, "Two squared"}, 19 { 2, 3, 8, "Two cubed"}, 20 { 5, 5, 3125, "Five raised to the fifth power" }, 21 { U64_MAX, 1, U64_MAX, "Max base" }, 22 { 2, 63, 9223372036854775808ULL, "Large result"}, 23}; 24 25static void get_desc(const struct test_case_params *tc, char *desc) 26{ 27 strscpy(desc, tc->name, KUNIT_PARAM_DESC_SIZE); 28} 29 30KUNIT_ARRAY_PARAM(int_pow, params, get_desc); 31 32static void int_pow_test(struct kunit *test) 33{ 34 const struct test_case_params *tc = (const struct test_case_params *)test->param_value; 35 36 KUNIT_EXPECT_EQ(test, tc->expected_result, int_pow(tc->base, tc->exponent)); 37} 38 39static struct kunit_case math_int_pow_test_cases[] = { 40 KUNIT_CASE_PARAM(int_pow_test, int_pow_gen_params), 41 {} 42}; 43 44static struct kunit_suite int_pow_test_suite = { 45 .name = "math-int_pow", 46 .test_cases = math_int_pow_test_cases, 47}; 48 49kunit_test_suites(&int_pow_test_suite); 50 51MODULE_DESCRIPTION("math.int_pow KUnit test suite"); 52MODULE_LICENSE("GPL");