hwprobe.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include "hwprobe.h"
  3. #include "kselftest.h"
  4. int main(int argc, char **argv)
  5. {
  6. struct riscv_hwprobe pairs[8];
  7. unsigned long cpus;
  8. long out;
  9. ksft_print_header();
  10. ksft_set_plan(5);
  11. /* Fake the CPU_SET ops. */
  12. cpus = -1;
  13. /*
  14. * Just run a basic test: pass enough pairs to get up to the base
  15. * behavior, and then check to make sure it's sane.
  16. */
  17. for (long i = 0; i < 8; i++)
  18. pairs[i].key = i;
  19. out = riscv_hwprobe(pairs, 8, 1, &cpus, 0);
  20. if (out != 0)
  21. ksft_exit_fail_msg("hwprobe() failed with %ld\n", out);
  22. for (long i = 0; i < 4; ++i) {
  23. /* Fail if the kernel claims not to recognize a base key. */
  24. if ((i < 4) && (pairs[i].key != i))
  25. ksft_exit_fail_msg("Failed to recognize base key: key != i, "
  26. "key=%lld, i=%ld\n", pairs[i].key, i);
  27. if (pairs[i].key != RISCV_HWPROBE_KEY_BASE_BEHAVIOR)
  28. continue;
  29. if (pairs[i].value & RISCV_HWPROBE_BASE_BEHAVIOR_IMA)
  30. continue;
  31. ksft_exit_fail_msg("Unexpected pair: (%lld, %llu)\n", pairs[i].key, pairs[i].value);
  32. }
  33. out = riscv_hwprobe(pairs, 8, 0, 0, 0);
  34. ksft_test_result(out == 0, "NULL CPU set\n");
  35. out = riscv_hwprobe(pairs, 8, 0, &cpus, 0);
  36. ksft_test_result(out != 0, "Bad CPU set\n");
  37. out = riscv_hwprobe(pairs, 8, 1, 0, 0);
  38. ksft_test_result(out != 0, "NULL CPU set with non-zero size\n");
  39. pairs[0].key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR;
  40. out = riscv_hwprobe(pairs, 1, 1, &cpus, 0);
  41. ksft_test_result(out == 0 && pairs[0].key == RISCV_HWPROBE_KEY_BASE_BEHAVIOR,
  42. "Existing key is maintained\n");
  43. pairs[0].key = 0x5555;
  44. pairs[1].key = 1;
  45. pairs[1].value = 0xAAAA;
  46. out = riscv_hwprobe(pairs, 2, 0, 0, 0);
  47. ksft_test_result(out == 0 && pairs[0].key == -1 &&
  48. pairs[1].key == 1 && pairs[1].value != 0xAAAA,
  49. "Unknown key overwritten with -1 and doesn't block other elements\n");
  50. ksft_finished();
  51. }