Message ID | 20240613095601.16299-3-ivan.klokov@syntacore.com |
---|---|
State | New |
Headers | show |
Series | Support RISC-V CSR read/write in Qtest environment | expand |
On 13/06/2024 11.56, Ivan Klokov wrote: > Added demo for reading CSR register from qtest environment. > > Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com> > --- > tests/qtest/meson.build | 2 ++ > tests/qtest/riscv-csr-test.c | 68 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 70 insertions(+) > create mode 100644 tests/qtest/riscv-csr-test.c > > diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build > index 12792948ff..45d651da99 100644 > --- a/tests/qtest/meson.build > +++ b/tests/qtest/meson.build > @@ -259,6 +259,8 @@ qtests_s390x = \ > qtests_riscv32 = \ > (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : []) > > +qtests_riscv32 += ['riscv-csr-test'] > + > qos_test_ss = ss.source_set() > qos_test_ss.add( > 'ac97-test.c', > diff --git a/tests/qtest/riscv-csr-test.c b/tests/qtest/riscv-csr-test.c > new file mode 100644 > index 0000000000..715d5fe4b7 > --- /dev/null > +++ b/tests/qtest/riscv-csr-test.c > @@ -0,0 +1,68 @@ > +/* > + * QTest testcase for RISC-V CSRs > + * > + * Copyright (c) 2024 Syntacore. > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License as published by the > + * Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License > + * for more details. > + */ > + > +#include "qemu/osdep.h" > +#include "libqtest-single.h" > +#include "qemu/error-report.h" > + > +#include "qapi/qmp/qdict.h" > +#include "qapi/qmp/qjson.h" > +#include "qapi/qmp/qlist.h" > +#include "qapi/qmp/qstring.h" > +#include "qapi/qmp/qobject.h" > +#include "qapi/qobject-input-visitor.h" > +#include "qapi/qobject-output-visitor.h" > +#include "qom/object_interfaces.h" Do you really need all these headers for the short code below? Please double check and trim the list. > +#include "qemu/osdep.h" > +#include "qapi/error.h" > +#include "qemu/error-report.h" > +#include "hw/qdev-properties.h" > + > +#include "qemu/osdep.h" Duplicate include statement, please remove. > +#include "qemu/cutils.h" > +#include "libqtest.h" > + > +#include "libqos/csr.h" > +#include "libqos/libqos.h" > + > +static void run_test_csr(void) > +{ > + > + uint64_t res; > + uint64_t val = 0; > + > + res = qcsr_get_csr(global_qtest, 0, 0xf11, &val); > + > + g_assert_cmpint(res, ==, 0); > + g_assert_cmpint(val, ==, 0x100); > +} > + > +int main(int argc, char **argv) > +{ > + g_test_init(&argc, &argv, NULL); > + > + qtest_add_func("/cpu/csr", run_test_csr); > + > + qtest_start("--nographic -machine virt -cpu any,mvendorid=0x100"); You don't need --nographic, it's been taken care off by the libqtest framework already. > + g_test_run(); > + > + qtest_quit(global_qtest); > + > + return 0; You should return the result of g_test_run() here, otherwise your test will look like it always succeeds. > +} Thomas
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 12792948ff..45d651da99 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -259,6 +259,8 @@ qtests_s390x = \ qtests_riscv32 = \ (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : []) +qtests_riscv32 += ['riscv-csr-test'] + qos_test_ss = ss.source_set() qos_test_ss.add( 'ac97-test.c', diff --git a/tests/qtest/riscv-csr-test.c b/tests/qtest/riscv-csr-test.c new file mode 100644 index 0000000000..715d5fe4b7 --- /dev/null +++ b/tests/qtest/riscv-csr-test.c @@ -0,0 +1,68 @@ +/* + * QTest testcase for RISC-V CSRs + * + * Copyright (c) 2024 Syntacore. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "qemu/error-report.h" + +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qlist.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qobject.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" +#include "qom/object_interfaces.h" + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/qdev-properties.h" + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "libqtest.h" + +#include "libqos/csr.h" +#include "libqos/libqos.h" + +static void run_test_csr(void) +{ + + uint64_t res; + uint64_t val = 0; + + res = qcsr_get_csr(global_qtest, 0, 0xf11, &val); + + g_assert_cmpint(res, ==, 0); + g_assert_cmpint(val, ==, 0x100); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/cpu/csr", run_test_csr); + + qtest_start("--nographic -machine virt -cpu any,mvendorid=0x100"); + + g_test_run(); + + qtest_quit(global_qtest); + + return 0; + +}
Added demo for reading CSR register from qtest environment. Signed-off-by: Ivan Klokov <ivan.klokov@syntacore.com> --- tests/qtest/meson.build | 2 ++ tests/qtest/riscv-csr-test.c | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/qtest/riscv-csr-test.c