Skip to content

Commit 2f248e0

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
RISC-V: selftests: Convert hwprobe test to kselftest API
Returning (exiting with) negative exit codes isn't user friendly, because the user must output the exit code with the shell, convert it from its unsigned 8-bit value back to the negative value, and then look up where that comes from in the code (which may be multiple places). Use the kselftests TAP interface, instead. Signed-off-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent fc9fdf2 commit 2f248e0

File tree

1 file changed

+20
-34
lines changed
  • tools/testing/selftests/riscv/hwprobe

1 file changed

+20
-34
lines changed

tools/testing/selftests/riscv/hwprobe/hwprobe.c

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stddef.h>
33
#include <asm/hwprobe.h>
44

5+
#include "../../kselftest.h"
6+
57
/*
68
* Rather than relying on having a new enough libc to define this, just do it
79
* ourselves. This way we don't need to be coupled to a new-enough libc to
@@ -16,6 +18,9 @@ int main(int argc, char **argv)
1618
unsigned long cpus;
1719
long out;
1820

21+
ksft_print_header();
22+
ksft_set_plan(5);
23+
1924
/* Fake the CPU_SET ops. */
2025
cpus = -1;
2126

@@ -25,66 +30,47 @@ int main(int argc, char **argv)
2530
*/
2631
for (long i = 0; i < 8; i++)
2732
pairs[i].key = i;
33+
2834
out = riscv_hwprobe(pairs, 8, 1, &cpus, 0);
2935
if (out != 0)
30-
return -1;
36+
ksft_exit_fail_msg("hwprobe() failed with %ld\n", out);
37+
3138
for (long i = 0; i < 4; ++i) {
3239
/* Fail if the kernel claims not to recognize a base key. */
3340
if ((i < 4) && (pairs[i].key != i))
34-
return -2;
41+
ksft_exit_fail_msg("Failed to recognize base key: key != i, "
42+
"key=%ld, i=%ld\n", pairs[i].key, i);
3543

3644
if (pairs[i].key != RISCV_HWPROBE_KEY_BASE_BEHAVIOR)
3745
continue;
3846

3947
if (pairs[i].value & RISCV_HWPROBE_BASE_BEHAVIOR_IMA)
4048
continue;
4149

42-
return -3;
50+
ksft_exit_fail_msg("Unexpected pair: (%ld, %ld)\n", pairs[i].key, pairs[i].value);
4351
}
4452

45-
/*
46-
* This should also work with a NULL CPU set, but should not work
47-
* with an improperly supplied CPU set.
48-
*/
4953
out = riscv_hwprobe(pairs, 8, 0, 0, 0);
50-
if (out != 0)
51-
return -4;
54+
ksft_test_result(out == 0, "NULL CPU set\n");
5255

5356
out = riscv_hwprobe(pairs, 8, 0, &cpus, 0);
54-
if (out == 0)
55-
return -5;
57+
ksft_test_result(out != 0, "Bad CPU set\n");
5658

5759
out = riscv_hwprobe(pairs, 8, 1, 0, 0);
58-
if (out == 0)
59-
return -6;
60+
ksft_test_result(out != 0, "NULL CPU set with non-zero count\n");
6061

61-
/*
62-
* Check that keys work by providing one that we know exists, and
63-
* checking to make sure the resultig pair is what we asked for.
64-
*/
6562
pairs[0].key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR;
6663
out = riscv_hwprobe(pairs, 1, 1, &cpus, 0);
67-
if (out != 0)
68-
return -7;
69-
if (pairs[0].key != RISCV_HWPROBE_KEY_BASE_BEHAVIOR)
70-
return -8;
64+
ksft_test_result(out == 0 && pairs[0].key == RISCV_HWPROBE_KEY_BASE_BEHAVIOR,
65+
"Existing key is maintained\n");
7166

72-
/*
73-
* Check that an unknown key gets overwritten with -1,
74-
* but doesn't block elements after it.
75-
*/
7667
pairs[0].key = 0x5555;
7768
pairs[1].key = 1;
7869
pairs[1].value = 0xAAAA;
7970
out = riscv_hwprobe(pairs, 2, 0, 0, 0);
80-
if (out != 0)
81-
return -9;
82-
83-
if (pairs[0].key != -1)
84-
return -10;
85-
86-
if ((pairs[1].key != 1) || (pairs[1].value == 0xAAAA))
87-
return -11;
71+
ksft_test_result(out == 0 && pairs[0].key == -1 &&
72+
pairs[1].key == 1 && pairs[1].value != 0xAAAA,
73+
"Unknown key overwritten with -1 and doesn't block other elements\n");
8874

89-
return 0;
75+
ksft_finished();
9076
}

0 commit comments

Comments
 (0)