^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * KUnit test for the linear_ranges helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2020, ROHM Semiconductors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Matti Vaittinen <matti.vaittien@fi.rohmeurope.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <kunit/test.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/linear_range.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /* First things first. I deeply dislike unit-tests. I have seen all the hell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * breaking loose when people who think the unit tests are "the silver bullet"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * to kill bugs get to decide how a company should implement testing strategy...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Believe me, it may get _really_ ridiculous. It is tempting to think that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * walking through all the possible execution branches will nail down 100% of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * bugs. This may lead to ideas about demands to get certain % of "test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * coverage" - measured as line coverage. And that is one of the worst things
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * you can do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Ask people to provide line coverage and they do. I've seen clever tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * which generate test cases to test the existing functions - and by default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * these tools expect code to be correct and just generate checks which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * passing when ran against current code-base. Run this generator and you'll get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * tests that do not test code is correct but just verify nothing changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Problem is that testing working code is pointless. And if it is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * working, your test must not assume it is working. You won't catch any bugs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * by such tests. What you can do is to generate a huge amount of tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Especially if you were are asked to proivde 100% line-coverage x_x. So what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * does these tests - which are not finding any bugs now - do?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * They add inertia to every future development. I think it was Terry Pratchet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * who wrote someone having same impact as thick syrup has to chronometre.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Excessive amount of unit-tests have this effect to development. If you do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * actually find _any_ bug from code in such environment and try fixing it...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * ...chances are you also need to fix the test cases. In sunny day you fix one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * test. But I've done refactoring which resulted 500+ broken tests (which had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * really zero value other than proving to managers that we do do "quality")...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * After this being said - there are situations where UTs can be handy. If you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * have algorithms which take some input and should produce output - then you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * can implement few, carefully selected simple UT-cases which test this. I've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * previously used this for example for netlink and device-tree data parsing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * functions. Feed some data examples to functions and verify the output is as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * expected. I am not covering all the cases but I will see the logic should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * working.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Here we also do some minor testing. I don't want to go through all branches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * or test more or less obvious things - but I want to see the main logic is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * working. And I definitely don't want to add 500+ test cases that break when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * some simple fix is done x_x. So - let's only add few, well selected tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * which ensure as much logic is good as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Test Range 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * selectors: 2 3 4 5 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * values (5): 10 20 30 40 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Test Range 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * selectors: 7 8 9 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * values (4): 100 150 200 250
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define RANGE1_MIN 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define RANGE1_MIN_SEL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define RANGE1_STEP 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* 2, 3, 4, 5, 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static const unsigned int range1_sels[] = { RANGE1_MIN_SEL, RANGE1_MIN_SEL + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) RANGE1_MIN_SEL + 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) RANGE1_MIN_SEL + 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) RANGE1_MIN_SEL + 4 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* 10, 20, 30, 40, 50 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static const unsigned int range1_vals[] = { RANGE1_MIN, RANGE1_MIN +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) RANGE1_STEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) RANGE1_MIN + RANGE1_STEP * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) RANGE1_MIN + RANGE1_STEP * 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) RANGE1_MIN + RANGE1_STEP * 4 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define RANGE2_MIN 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define RANGE2_MIN_SEL 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define RANGE2_STEP 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* 7, 8, 9, 10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static const unsigned int range2_sels[] = { RANGE2_MIN_SEL, RANGE2_MIN_SEL + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) RANGE2_MIN_SEL + 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) RANGE2_MIN_SEL + 3 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* 100, 150, 200, 250 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static const unsigned int range2_vals[] = { RANGE2_MIN, RANGE2_MIN +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) RANGE2_STEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) RANGE2_MIN + RANGE2_STEP * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) RANGE2_MIN + RANGE2_STEP * 3 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define RANGE1_NUM_VALS (ARRAY_SIZE(range1_vals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define RANGE2_NUM_VALS (ARRAY_SIZE(range2_vals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define RANGE_NUM_VALS (RANGE1_NUM_VALS + RANGE2_NUM_VALS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define RANGE1_MAX_SEL (RANGE1_MIN_SEL + RANGE1_NUM_VALS - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define RANGE1_MAX_VAL (range1_vals[RANGE1_NUM_VALS - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define RANGE2_MAX_SEL (RANGE2_MIN_SEL + RANGE2_NUM_VALS - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define RANGE2_MAX_VAL (range2_vals[RANGE2_NUM_VALS - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define SMALLEST_SEL RANGE1_MIN_SEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define SMALLEST_VAL RANGE1_MIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static struct linear_range testr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .min = RANGE1_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .min_sel = RANGE1_MIN_SEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .max_sel = RANGE1_MAX_SEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .step = RANGE1_STEP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .min = RANGE2_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .min_sel = RANGE2_MIN_SEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .max_sel = RANGE2_MAX_SEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .step = RANGE2_STEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void range_test_get_value(struct kunit *test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) unsigned int sel, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) for (i = 0; i < RANGE1_NUM_VALS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) sel = range1_sels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ret = linear_range_get_value_array(&testr[0], 2, sel, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) KUNIT_EXPECT_EQ(test, val, range1_vals[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (i = 0; i < RANGE2_NUM_VALS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) sel = range2_sels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ret = linear_range_get_value_array(&testr[0], 2, sel, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) KUNIT_EXPECT_EQ(test, val, range2_vals[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ret = linear_range_get_value_array(&testr[0], 2, sel + 1, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) KUNIT_EXPECT_NE(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void range_test_get_selector_high(struct kunit *test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) unsigned int sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) bool found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) for (i = 0; i < RANGE1_NUM_VALS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ret = linear_range_get_selector_high(&testr[0], range1_vals[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) &sel, &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) KUNIT_EXPECT_EQ(test, sel, range1_sels[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) KUNIT_EXPECT_TRUE(test, found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ret = linear_range_get_selector_high(&testr[0], RANGE1_MAX_VAL + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) &sel, &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) KUNIT_EXPECT_LE(test, ret, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret = linear_range_get_selector_high(&testr[0], RANGE1_MIN - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) &sel, &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) KUNIT_EXPECT_FALSE(test, found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) KUNIT_EXPECT_EQ(test, sel, range1_sels[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void range_test_get_value_amount(struct kunit *test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ret = linear_range_values_in_range_array(&testr[0], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) KUNIT_EXPECT_EQ(test, (int)RANGE_NUM_VALS, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static void range_test_get_selector_low(struct kunit *test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) unsigned int sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) bool found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) for (i = 0; i < RANGE1_NUM_VALS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ret = linear_range_get_selector_low_array(&testr[0], 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) range1_vals[i], &sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) KUNIT_EXPECT_EQ(test, sel, range1_sels[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) KUNIT_EXPECT_TRUE(test, found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) for (i = 0; i < RANGE2_NUM_VALS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ret = linear_range_get_selector_low_array(&testr[0], 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) range2_vals[i], &sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) KUNIT_EXPECT_EQ(test, sel, range2_sels[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) KUNIT_EXPECT_TRUE(test, found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * Seek value greater than range max => get_selector_*_low should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * return Ok - but set found to false as value is not in range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ret = linear_range_get_selector_low_array(&testr[0], 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) range2_vals[RANGE2_NUM_VALS - 1] + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) &sel, &found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) KUNIT_EXPECT_EQ(test, 0, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) KUNIT_EXPECT_EQ(test, sel, range2_sels[RANGE2_NUM_VALS - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) KUNIT_EXPECT_FALSE(test, found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static struct kunit_case range_test_cases[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) KUNIT_CASE(range_test_get_value_amount),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) KUNIT_CASE(range_test_get_selector_high),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) KUNIT_CASE(range_test_get_selector_low),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) KUNIT_CASE(range_test_get_value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static struct kunit_suite range_test_module = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .name = "linear-ranges-test",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .test_cases = range_test_cases,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) kunit_test_suites(&range_test_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) MODULE_LICENSE("GPL");