1
These patches add functionality for unit testing RISC-V-specific registers.
1
These patches add functionality for unit testing RISC-V-specific registers.
2
The first patch adds a Qtest backend, and the second implements a simple test.
2
The first patch adds a Qtest backend, and the second implements a simple test.
3
3
4
---
4
---
5
v9:
6
- Fix build errors.
5
v8:
7
v8:
6
- Delete RFC label.
8
- Delete RFC label.
7
v7:
9
v7:
8
- Fix build errors, add Reviewed-by, Acked-by.
10
- Fix build errors, add Reviewed-by, Acked-by.
9
---
11
---
10
12
11
Ivan Klokov (2):
13
Ivan Klokov (2):
12
target/riscv: Add RISC-V CSR qtest support
14
target/riscv: Add RISC-V CSR qtest support
13
tests/qtest: QTest example for RISC-V CSR register
15
tests/qtest: QTest example for RISC-V CSR register
14
16
15
hw/riscv/riscv_hart.c | 56 ++++++++++++++++++++++++++++++++++++
17
hw/riscv/riscv_hart.c | 55 +++++++++++++++++++++++++++++++++++
16
tests/qtest/libqtest.c | 27 +++++++++++++++++
18
tests/qtest/libqtest.c | 27 +++++++++++++++++
17
tests/qtest/libqtest.h | 14 +++++++++
19
tests/qtest/libqtest.h | 14 +++++++++
18
tests/qtest/meson.build | 2 +-
20
tests/qtest/meson.build | 2 +-
19
tests/qtest/riscv-csr-test.c | 56 ++++++++++++++++++++++++++++++++++++
21
tests/qtest/riscv-csr-test.c | 56 ++++++++++++++++++++++++++++++++++++
20
5 files changed, 154 insertions(+), 1 deletion(-)
22
5 files changed, 153 insertions(+), 1 deletion(-)
21
create mode 100644 tests/qtest/riscv-csr-test.c
23
create mode 100644 tests/qtest/riscv-csr-test.c
22
24
23
--
25
--
24
2.34.1
26
2.34.1
diff view generated by jsdifflib
...
...
5
5
6
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
6
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
7
Acked-by: Fabiano Rosas <farosas@suse.de>
7
Acked-by: Fabiano Rosas <farosas@suse.de>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
---
9
---
10
hw/riscv/riscv_hart.c | 56 ++++++++++++++++++++++++++++++++++++++++++
10
hw/riscv/riscv_hart.c | 55 ++++++++++++++++++++++++++++++++++++++++++
11
tests/qtest/libqtest.c | 27 ++++++++++++++++++++
11
tests/qtest/libqtest.c | 27 +++++++++++++++++++++
12
tests/qtest/libqtest.h | 14 +++++++++++
12
tests/qtest/libqtest.h | 14 +++++++++++
13
3 files changed, 97 insertions(+)
13
3 files changed, 96 insertions(+)
14
14
15
diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c
15
diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/riscv/riscv_hart.c
17
--- a/hw/riscv/riscv_hart.c
18
+++ b/hw/riscv/riscv_hart.c
18
+++ b/hw/riscv/riscv_hart.c
19
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
20
#include "qapi/error.h"
20
#include "qapi/error.h"
21
#include "qemu/module.h"
21
#include "qemu/module.h"
22
#include "system/reset.h"
22
#include "system/reset.h"
23
+#include "system/qtest.h"
23
+#include "qemu/cutils.h"
24
+#include "qemu/cutils.h"
24
+#include "sysemu/qtest.h"
25
+#include "sysemu/reset.h"
26
#include "hw/sysbus.h"
25
#include "hw/sysbus.h"
27
#include "target/riscv/cpu.h"
26
#include "target/riscv/cpu.h"
28
#include "hw/qdev-properties.h"
27
#include "hw/qdev-properties.h"
29
@@ -XXX,XX +XXX,XX @@ static void riscv_harts_cpu_reset(void *opaque)
28
@@ -XXX,XX +XXX,XX @@ static void riscv_harts_cpu_reset(void *opaque)
30
cpu_reset(CPU(cpu));
29
cpu_reset(CPU(cpu));
...
...
149
+ *
148
+ *
150
+ * Call an RISC-V CSR read/write function
149
+ * Call an RISC-V CSR read/write function
151
+ */
150
+ */
152
+uint64_t qtest_csr_call(QTestState *s, const char *name,
151
+uint64_t qtest_csr_call(QTestState *s, const char *name,
153
+ uint64_t cpu, int csr,
152
+ uint64_t cpu, int csr,
154
+ unsigned long *val);
153
+ uint64_t *val);
155
+
154
+
156
/**
155
/**
157
* qtest_bufread:
156
* qtest_bufread:
158
* @s: #QTestState instance to operate on.
157
* @s: #QTestState instance to operate on.
159
--
158
--
160
2.34.1
159
2.34.1
diff view generated by jsdifflib
1
Added demo for reading CSR register from qtest environment.
1
Added demo for reading CSR register from qtest environment.
2
2
3
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
3
Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com>
4
Reviewed-by: Fabiano Rosas <farosas@suse.de>
4
Reviewed-by: Fabiano Rosas <farosas@suse.de>
5
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
5
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
6
---
6
---
7
tests/qtest/meson.build | 2 +-
7
tests/qtest/meson.build | 2 +-
8
tests/qtest/riscv-csr-test.c | 56 ++++++++++++++++++++++++++++++++++++
8
tests/qtest/riscv-csr-test.c | 56 ++++++++++++++++++++++++++++++++++++
9
2 files changed, 57 insertions(+), 1 deletion(-)
9
2 files changed, 57 insertions(+), 1 deletion(-)
10
create mode 100644 tests/qtest/riscv-csr-test.c
10
create mode 100644 tests/qtest/riscv-csr-test.c
11
11
12
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
12
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
13
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tests/qtest/meson.build
14
--- a/tests/qtest/meson.build
15
+++ b/tests/qtest/meson.build
15
+++ b/tests/qtest/meson.build
16
@@ -XXX,XX +XXX,XX @@ qtests_s390x = \
16
@@ -XXX,XX +XXX,XX @@ qtests_s390x = \
17
qtests_riscv32 = \
17
qtests_riscv32 = \
18
(config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
18
(config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
19
19
20
-qtests_riscv64 = \
20
-qtests_riscv64 = \
21
+qtests_riscv64 = ['riscv-csr-test'] + \
21
+qtests_riscv64 = ['riscv-csr-test'] + \
22
(unpack_edk2_blobs ? ['bios-tables-test'] : [])
22
(unpack_edk2_blobs ? ['bios-tables-test'] : [])
23
23
24
qos_test_ss = ss.source_set()
24
qos_test_ss = ss.source_set()
25
diff --git a/tests/qtest/riscv-csr-test.c b/tests/qtest/riscv-csr-test.c
25
diff --git a/tests/qtest/riscv-csr-test.c b/tests/qtest/riscv-csr-test.c
26
new file mode 100644
26
new file mode 100644
27
index XXXXXXX..XXXXXXX
27
index XXXXXXX..XXXXXXX
28
--- /dev/null
28
--- /dev/null
29
+++ b/tests/qtest/riscv-csr-test.c
29
+++ b/tests/qtest/riscv-csr-test.c
30
@@ -XXX,XX +XXX,XX @@
30
@@ -XXX,XX +XXX,XX @@
31
+/*
31
+/*
32
+ * QTest testcase for RISC-V CSRs
32
+ * QTest testcase for RISC-V CSRs
33
+ *
33
+ *
34
+ * Copyright (c) 2024 Syntacore.
34
+ * Copyright (c) 2024 Syntacore.
35
+ *
35
+ *
36
+ * This program is free software; you can redistribute it and/or modify it
36
+ * This program is free software; you can redistribute it and/or modify it
37
+ * under the terms of the GNU General Public License as published by the
37
+ * under the terms of the GNU General Public License as published by the
38
+ * Free Software Foundation; either version 2 of the License, or
38
+ * Free Software Foundation; either version 2 of the License, or
39
+ * (at your option) any later version.
39
+ * (at your option) any later version.
40
+ *
40
+ *
41
+ * This program is distributed in the hope that it will be useful, but WITHOUT
41
+ * This program is distributed in the hope that it will be useful, but WITHOUT
42
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
44
+ * for more details.
44
+ * for more details.
45
+ */
45
+ */
46
+
46
+
47
+#include "qemu/osdep.h"
47
+#include "qemu/osdep.h"
48
+#include "libqtest.h"
48
+#include "libqtest.h"
49
+
49
+
50
+#define CSR_MVENDORID 0xf11
50
+#define CSR_MVENDORID 0xf11
51
+#define CSR_MISELECT 0x350
51
+#define CSR_MISELECT 0x350
52
+
52
+
53
+static void run_test_csr(void)
53
+static void run_test_csr(void)
54
+{
54
+{
55
+ uint64_t res;
55
+ uint64_t res;
56
+ uint64_t val = 0;
56
+ uint64_t val = 0;
57
+
57
+
58
+ QTestState *qts = qtest_init("-machine virt -cpu veyron-v1");
58
+ QTestState *qts = qtest_init("-machine virt -cpu veyron-v1");
59
+
59
+
60
+ res = qtest_csr_call(qts, "get_csr", 0, CSR_MVENDORID, &val);
60
+ res = qtest_csr_call(qts, "get_csr", 0, CSR_MVENDORID, &val);
61
+
61
+
62
+ g_assert_cmpint(res, ==, 0);
62
+ g_assert_cmpint(res, ==, 0);
63
+ g_assert_cmpint(val, ==, 0x61f);
63
+ g_assert_cmpint(val, ==, 0x61f);
64
+
64
+
65
+ val = 0xff;
65
+ val = 0xff;
66
+ res = qtest_csr_call(qts, "set_csr", 0, CSR_MISELECT, &val);
66
+ res = qtest_csr_call(qts, "set_csr", 0, CSR_MISELECT, &val);
67
+
67
+
68
+ g_assert_cmpint(res, ==, 0);
68
+ g_assert_cmpint(res, ==, 0);
69
+
69
+
70
+ val = 0;
70
+ val = 0;
71
+ res = qtest_csr_call(qts, "get_csr", 0, CSR_MISELECT, &val);
71
+ res = qtest_csr_call(qts, "get_csr", 0, CSR_MISELECT, &val);
72
+
72
+
73
+ g_assert_cmpint(res, ==, 0);
73
+ g_assert_cmpint(res, ==, 0);
74
+ g_assert_cmpint(val, ==, 0xff);
74
+ g_assert_cmpint(val, ==, 0xff);
75
+
75
+
76
+ qtest_quit(qts);
76
+ qtest_quit(qts);
77
+}
77
+}
78
+
78
+
79
+int main(int argc, char **argv)
79
+int main(int argc, char **argv)
80
+{
80
+{
81
+ g_test_init(&argc, &argv, NULL);
81
+ g_test_init(&argc, &argv, NULL);
82
+
82
+
83
+ qtest_add_func("/cpu/csr", run_test_csr);
83
+ qtest_add_func("/cpu/csr", run_test_csr);
84
+
84
+
85
+ return g_test_run();
85
+ return g_test_run();
86
+}
86
+}
87
--
87
--
88
2.34.1
88
2.34.1
diff view generated by jsdifflib