summaryrefslogtreecommitdiff
path: root/test/cmd
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2024-08-27 19:44:29 -0600
committerSimon Glass <[email protected]>2024-10-18 14:10:21 -0600
commitc4e582654a94fc085196464ebe409ce7f89739f6 (patch)
treec5b4f57fe4c820d1abad1eb2dce1aa840ee835f0 /test/cmd
parent557767f80294054932c7453be0e268ad39643fdc (diff)
x86: Add msr command
It is useful to obtain the results of MSR queries as well as to update MSR registers, so add a command these tasks. Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'test/cmd')
-rw-r--r--test/cmd/Makefile2
-rw-r--r--test/cmd/msr.c38
2 files changed, 39 insertions, 1 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 302c748389b..40808350962 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -12,7 +12,7 @@ ifdef CONFIG_CONSOLE_RECORD
obj-$(CONFIG_CMD_PAUSE) += test_pause.o
endif
obj-y += exit.o mem.o
-obj-$(CONFIG_X86) += cpuid.o
+obj-$(CONFIG_X86) += cpuid.o msr.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_BDI) += bdinfo.o
obj-$(CONFIG_CMD_FDT) += fdt.o
diff --git a/test/cmd/msr.c b/test/cmd/msr.c
new file mode 100644
index 00000000000..e9a152ee5bf
--- /dev/null
+++ b/test/cmd/msr.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for msr command
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <test/cmd.h>
+#include <test/ut.h>
+
+static int cmd_test_msr(struct unit_test_state *uts)
+{
+ ut_assertok(run_commandf("msr read 200"));
+ ut_assert_nextline("00000000 ffe00006");
+ ut_assert_console_end();
+
+ /* change the first variable msr and see it reflected in the mtrr cmd */
+ ut_assertok(run_commandf("mtrr"));
+ ut_assert_nextline("CPU 65537:");
+ ut_assert_nextlinen("Reg");
+ ut_assert_nextlinen("0 Y Back 00000000ffe00000");
+ ut_assertok(console_record_reset_enable());
+
+ /* change the type from 6 to 5 */
+ ut_assertok(run_commandf("msr write 200 0 ffe00005"));
+ ut_assert_console_end();
+
+ /* Now it shows 'Protect' */
+ ut_assertok(run_commandf("mtrr"));
+ ut_assert_nextline("CPU 65537:");
+ ut_assert_nextlinen("Reg");
+ ut_assert_nextlinen("0 Y Protect 00000000ffe00000");
+ ut_assertok(console_record_reset_enable());
+
+ return 0;
+}
+CMD_TEST(cmd_test_msr, UTF_CONSOLE);