From: Thomas Huth <thuth@redhat.com>
To: Ivan Klokov <ivan.klokov@syntacore.com>, qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com, bmeng.cn@gmail.com,
liwei1518@gmail.com, dbarboza@ventanamicro.com,
zhiwei_liu@linux.alibaba.com, lvivier@redhat.com,
pbonzini@redhat.com
Subject: Re: [RFC PATCH v4 2/2] tests/qtest: QTest example for RISC-V CSR register
Date: Mon, 22 Jul 2024 11:47:31 +0200 [thread overview]
Message-ID: <b09331f3-0cc6-41ee-9d4e-22310943e2f7@redhat.com> (raw)
In-Reply-To: <20240703081939.498641-3-ivan.klokov@syntacore.com>
On 03/07/2024 10.19, 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 | 86 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 88 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']
Could you please add it directly to the qtests_riscv32 list above intead of
using a separate += line here?
> 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..e9af9ca724
> --- /dev/null
> +++ b/tests/qtest/riscv-csr-test.c
> @@ -0,0 +1,86 @@
> +/*
> + * 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 "libqtest.h"
> +
> +static uint64_t qcsr_call(QTestState *qts, const char *name, uint64_t cpu,
> + int csrno, uint64_t *val)
> +{
> + uint64_t res = 0;
> +
> + res = qtest_csr_call(qts, name, cpu, csrno, val);
> +
> + return res;
> +}
Could you please get rid of this useless qcsr_call() wrapper and call
qtest_csr_call() everywhere instead?
> +static int qcsr_get_csr(QTestState *qts, uint64_t cpu,
> + int csrno, uint64_t *val)
Bad indentation, please align "int csrno" with QTestState.
> +{
> + int res;
> +
> + res = qcsr_call(qts, "get_csr", cpu, csrno, val);
> +
> + return res;
> +}
> +
> +static int qcsr_set_csr(QTestState *qts, uint64_t cpu,
> + int csrno, uint64_t *val)
dito.
> +{
> + int res;
> +
> + res = qcsr_call(qts, "set_csr", cpu, csrno, val);
> +
> + return res;
> +}
> +
> +static void run_test_csr(void)
> +{
> +
Please remove the empty line above.
> + uint64_t res;
> + uint64_t val = 0;
> +
> + res = qcsr_call(global_qtest, "get_csr", 0, 0xf11, &val);
> +
> + g_assert_cmpint(res, ==, 0);
> + g_assert_cmpint(val, ==, 0x100);
> +
> + val = 0xff;
> + res = qcsr_call(global_qtest, "set_csr", 0, 0x342, &val);
> +
> + g_assert_cmpint(res, ==, 0);
> +
> + val = 0;
> + res = qcsr_call(global_qtest, "get_csr", 0, 0x342, &val);
> +
> + g_assert_cmpint(res, ==, 0);
> + g_assert_cmpint(val, ==, 0xff);
> +
> + qtest_quit(global_qtest);
Having qtest_quit here, while qtest_start is in the main function, looks
really ugly and will likely cause trouble when extending the test later.
Please clean it up: Use qts = qtest_init() at the beginning of this function
instead of calling qtest_start() in main(). Then you can get rid of
global_qtest completely and also drop the #include "libtest-single.h"
statement at the beginning of the function.
Thanks,
Thomas
> +}
> +
> +int main(int argc, char **argv)
> +{
> + g_test_init(&argc, &argv, NULL);
> +
> + qtest_add_func("/cpu/csr", run_test_csr);
> +
> + qtest_start("-machine virt -cpu any,mvendorid=0x100");
> +
> + return g_test_run();
> +
> +}
prev parent reply other threads:[~2024-07-22 9:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 8:19 [RFC PATCH v4 0/2] Support RISC-V CSR read/write in Qtest environment Ivan Klokov
2024-07-03 8:19 ` [RFC PATCH v4 1/2] target/riscv: Add RISC-V CSR qtest support Ivan Klokov
2024-07-22 9:50 ` Thomas Huth
2024-07-03 8:19 ` [RFC PATCH v4 2/2] tests/qtest: QTest example for RISC-V CSR register Ivan Klokov
2024-07-22 9:47 ` Thomas Huth [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b09331f3-0cc6-41ee-9d4e-22310943e2f7@redhat.com \
--to=thuth@redhat.com \
--cc=bmeng.cn@gmail.com \
--cc=dbarboza@ventanamicro.com \
--cc=ivan.klokov@syntacore.com \
--cc=liwei1518@gmail.com \
--cc=lvivier@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).