From patchwork Mon Nov 13 23:01:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 743488 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp1891335wrw; Mon, 13 Nov 2023 15:03:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGt6p5brJ9SBtwde3OxDM3hKhaLCqXM7mnhC2hwZ3GD03Gz276quRySfoCMMYWqbI+7cgXh X-Received: by 2002:a05:622a:1c4:b0:41e:2d40:5e64 with SMTP id t4-20020a05622a01c400b0041e2d405e64mr765390qtw.51.1699916617418; Mon, 13 Nov 2023 15:03:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699916617; cv=none; d=google.com; s=arc-20160816; b=lscQm/KhRE4R1tLH4Xup0hFOddAoHLvRx5VfdMlDlAZrfNoUsJFDd88FzHhE/Z++1u B2//58qLlmcS3rFAoR5KvhrKgV72Z+qzA3f05k7Df0OvHDmB6WKCi42I20LSABAN98Xp VjY1mHmSgl8iNDr2oPrwzUehFuZ8ugUV8hXCTKlxQsYDqIg0g0gSl7LhGU/vndObMqHf opKtU8VyU6Dpypk6U+hnPqP7oFYHbeRueCxtjkssaE/ZvKWM+5t0UcJYoAjyTTr8+8XQ 0LZwynYNe/VvqQA62fufZxVxcaO25CQDyDilDJzS7G7CLy/aokFjT0lz7r9ZPZ6EA0BO im+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=+tuKBpT3I4kfy1G+UfvPrkWVAQowwC4Vp1i+ccIq9h4=; fh=pyno6fsW5UtEiT6cw4ZJDqaizr+QoZrnuQtcSbhF3Vk=; b=Kq4SlwUR1p3WglPD6NoK8GvkJ1MMIFmiw1NnTavRdPwL0u7m7DJcVtmxL7w4xdfCiy +/TU57shlVFgkgCCB4vOSSHXtpK+0YBjfBj2LhHDPURZo/Ls/H3YaVUMdi5HVfU3JlBB hOX9Kvh3fxCnCNGT40m0ojolc9rsXFGsDMaAcqQY88H/50QctELy+S3jCO+MilzkgGn/ 0JSPnvRZFRW7JUQRgrtYzDPLuULJaL0OuZraiXbRle9lQQjZjuOM2cPVNviaHalnITfQ vIi1kvoCi/fAxXTBvlXneAsfcV604CWsOs/I+SezeUNQHjHhhWI6SOUQbYWTEhg1YG9P V7Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PNiBMPx7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u4-20020ac858c4000000b004134681883esi5550085qta.601.2023.11.13.15.03.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Nov 2023 15:03:37 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PNiBMPx7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2fwu-0001ST-T1; Mon, 13 Nov 2023 18:02:32 -0500 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 1r2fws-0001SF-DO for qemu-devel@nongnu.org; Mon, 13 Nov 2023 18:02:30 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r2fwq-0006zg-JS for qemu-devel@nongnu.org; Mon, 13 Nov 2023 18:02:30 -0500 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3b2e72fe47fso3300182b6e.1 for ; Mon, 13 Nov 2023 15:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699916546; x=1700521346; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+tuKBpT3I4kfy1G+UfvPrkWVAQowwC4Vp1i+ccIq9h4=; b=PNiBMPx7d3Pj3V03M2a6vP/c+79vr4SM8sBmAqgCwCrHD5Z1xoHXhW948Q67lafj2s OLrM/iF8r9TOc+WfzPVl70wlMAOj2TlBuA9Xj71O1sg3YyY5D5szVMygFhzS87euupg5 anj972AKYI7oRgk6mUjq1zM6UJnzHI2n2qN1NeEqunR0L8B+I0/CIKQ1L3vyL/75dU4p QDtvOt0wNHWF5Zf4SovVcEdmBL/naAoj7oOcc5I4RLylTkxrm1g9u0xCI6V7raMCnA5c Y0Gmq1po1qeo4VuWlD1Irn0eK17c5DNiG1Ft6TReNHSn0t0iRhaWZ2ggOd4v24lormJk xPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699916546; x=1700521346; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+tuKBpT3I4kfy1G+UfvPrkWVAQowwC4Vp1i+ccIq9h4=; b=kTEXCulOyKIQp2y03xIdJsZTWQLC8iM5XaM/IC7PJhqmzjcqnsbJSKjioODISI0y59 UcP2BVIeb9i0h3zvAYf+Rw7sdv8V5soYM22M8OAbvHNKUoRG41uC2RBbuunjGPdu4BOy ieaI2dtAGVN9AYeBYSHxVt9Z3BmhLRF/V/OrLvWy3ichZIdAh12KuTR3pGdXa8KHdhck MZ1VGgpu8nvSIP5rofCyGCDYjx4qcnLVDkxxuqCKmK8yaxseJhZkHT7v0goa3Um9jWw7 OZyuWVo8QWSaoy1CDFungNWUMOVP5UeAQXPeoWxOwvYY9Rcmp9ETX5DkWOcFp2aDo4TH 3jhQ== X-Gm-Message-State: AOJu0YzneZQXvK7sxqg6W9gPLOhCPARIAW2qwnQidajmbFejH+FtzDMX DSkel/KFNkDrKvNJ3LSUkvwRtYgtbGaQEhdY9D6wQ2Zi X-Received: by 2002:aca:f07:0:b0:3b6:cc01:aba2 with SMTP id 7-20020aca0f07000000b003b6cc01aba2mr9015073oip.55.1699916546633; Mon, 13 Nov 2023 15:02:26 -0800 (PST) Received: from amd.. ([2804:7f0:b401:308c:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id n14-20020a63e04e000000b0058d26647e45sm4566215pgj.54.2023.11.13.15.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 15:02:26 -0800 (PST) From: Gustavo Romero To: qemu-devel@nongnu.org, thuth@redhat.com, philmd@linaro.org Cc: lvivier@redhat.com, pbonzini@redhat.com, gustavo.romero@linaro.org Subject: [PATCH v2] test/qtest: Add API functions to capture IRQ toggling Date: Mon, 13 Nov 2023 23:01:49 +0000 Message-Id: <20231113230149.321304-1-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=gustavo.romero@linaro.org; helo=mail-oi1-x22f.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Currently, the QTest API does not provide a function to capture when an IRQ line is raised or lowered, although the QTest Protocol already reports such IRQ transitions. As a consequence, it is also not possible to capture when an IRQ line is toggled. Functions like qtest_get_irq() only read the current state of the intercepted IRQ lines, which is already high (or low) when the function is called if the IRQ line is toggled. Therefore, these functions miss the IRQ line state transitions. This commit introduces two new API functions: qtest_get_irq_raised_counter() and qtest_get_irq_lowered_counter(). These functions allow capturing the number of times an observed IRQ line transitioned from low to high state or from high to low state, respectively. When used together, these new API functions then allow checking if one or more pulses were generated (indicating if the IRQ line was toggled). Signed-off-by: Gustavo Romero Acked-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/libqtest.c | 24 ++++++++++++++++++++++++ tests/qtest/libqtest.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index f33a210861..6ada4cae6e 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -82,6 +82,8 @@ struct QTestState int expected_status; bool big_endian; bool irq_level[MAX_IRQ]; + uint64_t irq_raised_counter[MAX_IRQ]; + uint64_t irq_lowered_counter[MAX_IRQ]; GString *rx; QTestTransportOps ops; GList *pending_events; @@ -498,6 +500,8 @@ static QTestState *qtest_init_internal(const char *qemu_bin, s->rx = g_string_new(""); for (i = 0; i < MAX_IRQ; i++) { s->irq_level[i] = false; + s->irq_raised_counter[i] = 0; + s->irq_lowered_counter[i] = 0; } /* @@ -689,8 +693,10 @@ redo: g_assert_cmpint(irq, <, MAX_IRQ); if (strcmp(words[1], "raise") == 0) { + s->irq_raised_counter[irq]++; s->irq_level[irq] = true; } else { + s->irq_lowered_counter[irq]++; s->irq_level[irq] = false; } @@ -980,6 +986,22 @@ bool qtest_get_irq(QTestState *s, int num) return s->irq_level[num]; } +uint64_t qtest_get_irq_raised_counter(QTestState *s, int num) +{ + /* dummy operation in order to make sure irq is up to date */ + qtest_inb(s, 0); + + return s->irq_raised_counter[num]; +} + +uint64_t qtest_get_irq_lowered_counter(QTestState *s, int num) +{ + /* dummy operation in order to make sure irq is up to date */ + qtest_inb(s, 0); + + return s->irq_lowered_counter[num]; +} + void qtest_module_load(QTestState *s, const char *prefix, const char *libname) { qtest_sendf(s, "module_load %s %s\n", prefix, libname); @@ -1799,6 +1821,8 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch, qts->wstatus = 0; for (int i = 0; i < MAX_IRQ; i++) { qts->irq_level[i] = false; + qts->irq_raised_counter[i] = 0; + qts->irq_lowered_counter[i] = 0; } qtest_client_set_rx_handler(qts, qtest_client_inproc_recv_line); diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index 6e3d3525bf..a2a16914dc 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -364,6 +364,34 @@ void qtest_module_load(QTestState *s, const char *prefix, const char *libname); */ bool qtest_get_irq(QTestState *s, int num); +/** + * qtest_get_irq_raised_counter: + * @s: #QTestState instance to operate on. + * @num: Interrupt to observe. + * + * This function can be used in conjunction with the + * qtest_get_irq_lowered_counter() to check if one or more pulses where + * generated on the observed interrupt. + * + * Returns: The number of times IRQ @num was raised, i.e., transitioned from + * a low state (false) to a high state (true). + */ +uint64_t qtest_get_irq_raised_counter(QTestState *s, int num); + +/** + * qtest_get_irq_lowered_counter: + * @s: #QTestState instance to operate on. + * @num: Interrupt to observe. + * + * This function can be used in conjunction with the + * qtest_get_irq_raised_counter() to check if one or more pulses where + * generated on the observed interrupt. + * + * Returns: The number of times IRQ @num was lowered, i.e., transitioned from + * a high state (true) to a low state (false). + */ +uint64_t qtest_get_irq_lowered_counter(QTestState *s, int num); + /** * qtest_irq_intercept_in: * @s: #QTestState instance to operate on.