From nobody Thu Sep 19 01:15:58 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=syntacore.com ARC-Seal: i=1; a=rsa-sha256; t=1719329858; cv=none; d=zohomail.com; s=zohoarc; b=TLnKhaFQ0jlyRsozibaKxegDjGaE+RKqFzWzsySFlQJG7uMgT3NQffU8f39iNOFbqXmz+Jfp5K0Yil5C75IDpHCLjKAauP+eOna+nlarLtgx1FFvCv0tsqwbd4JHA5G9+FLNnCRvrAi4x9lwPzPprIT1+opkn5zbDaxe6jy+uY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719329858; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wLlcKrBkJxyiieu6ax+od3Jo2DL/gvxf1C5KMKJGUNA=; b=ge3C27kQWzms9R9VesI2hDUdHim8ByFgC5RfE5a72CVRp3ze42/NDJwRIlBO5OEFHyUIEFuz/bTezFPcNOTPcQvseqHnB+o5IVXQ8i7sJ5Bptob5gBoaY5lvBJjuEh6rTt3At436MyyfFpQhWBFNTRZ9YpXs1AZMEdufm0CM+YI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719329858510897.6566589252827; Tue, 25 Jun 2024 08:37:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM8De-0006WH-4n; Tue, 25 Jun 2024 11:36:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM8DZ-0006Rq-7I; Tue, 25 Jun 2024 11:36:25 -0400 Received: from mta-04.yadro.com ([89.207.88.248]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM8DV-00048Y-1U; Tue, 25 Jun 2024 11:36:24 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 mta-04.yadro.com 25923C0009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-04; t=1719329777; bh=wLlcKrBkJxyiieu6ax+od3Jo2DL/gvxf1C5KMKJGUNA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ZbTGnaLbYRGcwKVez5gHUbqQMoFPpVDNIyOTMm0yEY0i4qBanhzQxzjUVS1vsGfMH ZAAiCy9/lzbH3qEdqmhgI7nNWoGEsQ9KCme5pUjtot6lchWWLIzmZdik0sGZFJyhV4 F0oqYccObHOQb2Y/dUoIcjbJgiuuzcE3ry1KhE7fhvlwwnYNEnGe9ATkkiCRHkcfec wRm1tfghjCyjfPaB+wqx6T0Y/zwCOhLegjsnU3sgD0d5LtZKO+xWt/fD+BJxPX/tVI +qgW3sp6enpt2lsaveH1WEoa+5SI1DBQnSslwn1+6wGNQy6mRcJVaB3yddz+W4085u hbA1KxNJvqJxA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-03; t=1719329777; bh=wLlcKrBkJxyiieu6ax+od3Jo2DL/gvxf1C5KMKJGUNA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=sSQVWWbwgQUkN2D8zySc35RUM9IVM63ppACHQ6lDZCeQ+Yy5Z7wmu247r0dOs8hgn K+Fk8FdznT0wM474kNLhKWofv3WRmUQ5u9b8rPy8cjY5XePx/gkDFak7D9mpjy3tmx 9bk+QIenfdq5OJ0UxCwaRdr8q7SbVtedjzlKQIKJVAglrjRKTzyuxVVmhAbElgbnls hp7eLamw4sRv2WOXZY1EFRnngzuWyoKUcpRwgbKT2fu7K4b9+l4cgmX83IQbNFABjO b93CzO9f4aK+S/0ZDJQ2SfqVk9IQSucXjBJ+NrlNxsrKkjNiwOFmVm4JFY7HVG6EPQ 1y5j1pQv9OPvg== From: Ivan Klokov To: CC: , , , , , , , , , Ivan Klokov Subject: [RFC PATCH v3 2/2] tests/qtest: QTest example for RISC-V CSR register Date: Tue, 25 Jun 2024 18:35:55 +0300 Message-ID: <20240625153555.104088-3-ivan.klokov@syntacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240625153555.104088-1-ivan.klokov@syntacore.com> References: <20240625153555.104088-1-ivan.klokov@syntacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: T-EXCH-07.corp.yadro.com (172.17.11.57) To S-Exch-01.corp.yadro.com (10.78.5.241) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: permerror client-ip=89.207.88.248; envelope-from=ivan.klokov@syntacore.com; helo=mta-04.yadro.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SPF_PERMERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @syntacore.com) (identity @syntacore.com) X-ZM-MESSAGEID: 1719329860027100001 Content-Type: text/plain; charset="utf-8" Added demo for reading CSR register from qtest environment. Signed-off-by: Ivan Klokov --- tests/qtest/meson.build | 2 + tests/qtest/riscv-csr-test.c | 85 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 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 =3D \ qtests_riscv32 =3D \ (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watc= hdog-test'] : []) =20 +qtests_riscv32 +=3D ['riscv-csr-test'] + qos_test_ss =3D 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..21a3646ae9 --- /dev/null +++ b/tests/qtest/riscv-csr-test.c @@ -0,0 +1,85 @@ +/* + * 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 WIT= HOUT + * 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 =3D 0; + + res =3D qtest_csr_call(qts, name, cpu, csrno, val); + + return res; +} + +static int qcsr_get_csr(QTestState *qts, uint64_t cpu, + int csrno, uint64_t *val) +{ + int res; + + res =3D 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) +{ + int res; + + res =3D qcsr_call(qts, "set_csr", cpu, csrno, val); + + return res; +} + +static void run_test_csr(void) +{ + + uint64_t res; + uint64_t val =3D 0; + + res =3D qcsr_get_csr(global_qtest, 0, 0xf11, &val); + + g_assert_cmpint(res, =3D=3D, 0); + g_assert_cmpint(val, =3D=3D, 0x100); + + val =3D 0xff; + res =3D qcsr_set_csr(global_qtest, 0, 0x342, &val); + g_assert_cmpint(res, =3D=3D, 0); + + val =3D 0; + res =3D qcsr_get_csr(global_qtest, 0, 0x342, &val); + + g_assert_cmpint(res, =3D=3D, 0); + g_assert_cmpint(val, =3D=3D, 0xff); + + qtest_quit(global_qtest); +} + +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=3D0x100"); + + return g_test_run(); + +} --=20 2.34.1