sys_hwprobe_test.cpp: compare vdso to syscall.
Also fix a __has_include() that was copy & pasted without modification
from a different test.
Test: treehugger
Change-Id: Iafceb331a95ec788596ffdad60aa2202b692e589
diff --git a/tests/sys_hwprobe_test.cpp b/tests/sys_hwprobe_test.cpp
index 15028ff..a4b47c7 100644
--- a/tests/sys_hwprobe_test.cpp
+++ b/tests/sys_hwprobe_test.cpp
@@ -30,10 +30,11 @@
#if __has_include(<sys/hwprobe.h>)
#include <sys/hwprobe.h>
+#include <sys/syscall.h>
#endif
TEST(sys_hwprobe, __riscv_hwprobe) {
-#if defined(__riscv) && __has_include(<sys/cachectl.h>)
+#if defined(__riscv) && __has_include(<sys/hwprobe.h>)
riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
{.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
ASSERT_EQ(0, __riscv_hwprobe(probes, 2, 0, nullptr, 0));
@@ -60,3 +61,25 @@
GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
#endif
}
+
+TEST(sys_hwprobe, __riscv_hwprobe_syscall_vdso) {
+#if defined(__riscv) && __has_include(<sys/hwprobe.h>)
+ riscv_hwprobe probes_vdso[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
+ {.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
+ ASSERT_EQ(0, __riscv_hwprobe(probes_vdso, 2, 0, nullptr, 0));
+
+ riscv_hwprobe probes_syscall[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
+ {.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
+ ASSERT_EQ(0, syscall(SYS_riscv_hwprobe, probes_syscall, 2, 0, nullptr, 0));
+
+ // Check we got the same answers from the vdso and the syscall.
+ EXPECT_EQ(RISCV_HWPROBE_KEY_IMA_EXT_0, probes_syscall[0].key);
+ EXPECT_EQ(probes_vdso[0].key, probes_syscall[0].key);
+ EXPECT_EQ(probes_vdso[0].value, probes_syscall[0].value);
+ EXPECT_EQ(RISCV_HWPROBE_KEY_CPUPERF_0, probes_syscall[1].key);
+ EXPECT_EQ(probes_vdso[1].key, probes_syscall[1].key);
+ EXPECT_EQ(probes_vdso[1].value, probes_syscall[1].value);
+#else
+ GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
+#endif
+}