From patchwork Thu Feb 8 20:48:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 198575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp447352dyd; Thu, 8 Feb 2024 12:58:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCURLCxIa8z+iuL/IhtSaEhln3Q6aqJcS8yrIDD/bsTqyRVloZiGBupqoTNcRXISx6sEKCpMDjlzswpIapVVGNXJTiJyig== X-Google-Smtp-Source: AGHT+IEBkOxGDEtCNmiA5Sdy0iWdESnp7zNKJbv+ei6EFWZSs7iIVmdDxuMJiMCibe49+LP7FnL5 X-Received: by 2002:a05:6870:420f:b0:219:b83c:f038 with SMTP id u15-20020a056870420f00b00219b83cf038mr690314oac.26.1707425936013; Thu, 08 Feb 2024 12:58:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707425935; cv=pass; d=google.com; s=arc-20160816; b=TtfNmHCMwNpSUyGHrW+CMndyan08UGCjhYUaUa7t8HoBB7ob5Ggpj4GJEBy1HpoeAS /2WZfzGdJ79enjY3/2P1GhBssZDwlFUYlJU5wpZct7tgkcP4ftd5h398Uy4IEDuPJHGJ QeFeQh3oDkgd6NJRt8rH/Ygw7qNtMeFZuMI7aaml0Ysqgez1ggs/fnO/Wv+Vb7Sobq2b T/Rn0fYyt8drLf2WUN2qZQ1WDFOklPy2hGeZ7YvZ49dhL9IKGtk4Y/zip+bezAmEf3MJ 1RyAqwnNP95RKsXe+Twnu/nd4M81D6p+t7VyjxOOWMjOay9D7xGqr747oNu5p9x5vWoq HQ5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZBTElX16WHnJ/uasV+kMXYqDLGTcdRCMmjiGOz8erC0=; fh=Te73pc5d24q9iZVCskQT/+4g9MvWDKk0b+j5FORUs+0=; b=j6O9o3KdNTn4CqP0p429YDHNo9YFlxXYcRtBt/Wjq/j55Je+6RJn9ajvMpY5EVaz1r 8eUCwHaaKpQxlKIxPEp03ftArpcmXsjJ1/3jA3f+ndSZuV8CKgwhSUNlZ1ZIe84BGsTq fmD9uHZZQ2xqfRk5hbZ7BKxZ9SXLO+ZMWK/5DuFVToPpH8vdPq+Psa3+LNCGdWuCuBu4 5Qia8l9v97Y2TTok4FjTKq3E8QU9Vk4wQCsCV0mkzc1NP+QZS6NJo481R6KqkOJUO9XH mPsuQ9ajxe3BbVZeaxFm6A+cDUqpzqkljouIPqLYVbFHPLkStdde2Soz/dTVWkoqxEaO M8xQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Bs/wKA6e"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-58680-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58680-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCVCqAw9EdboOBTgNh5BTb7/RPc3xtEAWhbdbujebvPiTdF8RpwuctdW3xYxKDmgc5jsmMEPpgTZ7cz4w84uWFyRvQgjXQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bq7-20020a056a02044700b005dc489985a6si423427pgb.618.2024.02.08.12.58.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 12:58:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58680-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Bs/wKA6e"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-58680-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58680-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 767B3291036 for ; Thu, 8 Feb 2024 20:50:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07E0550244; Thu, 8 Feb 2024 20:49:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bs/wKA6e" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9EED4F889 for ; Thu, 8 Feb 2024 20:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707425341; cv=none; b=C8mgxS1tJ76BpzYHChxSx3FX/+XqWaGMdnjxy/862VWW+kYxvBE/k1IqYtktx+L7JwJTA9qs3nTQshMZ5WwLqm1zxSY2F8hMN28V8jnclasUMoSv7KZ9/cTPh/Vsh9wt4FdM60+as/njBXYbx1QSXxM6y+jowdCMRnmKshNRB2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707425341; c=relaxed/simple; bh=VI7qXJxS/lasyNThrbyjvkzs+3R4P9ZKyEkXMk7ilKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G1G7vmO+CaKTF5vA3Btvr/4dvKIlcF0eeMojhBJCe3/Du+96hqIMOlwyRGFeUck841GZamEu0OrAR0mwJFFoiRThVqYleFEamU+o4LS+1hYAN9BGzUJsmhqI/3YB8mZFIIeWDNbFWovXcpVURrnmN8Tez+gPMvHlnSx1QIOFLJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Bs/wKA6e; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707425338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZBTElX16WHnJ/uasV+kMXYqDLGTcdRCMmjiGOz8erC0=; b=Bs/wKA6eiGTfNTIosnLpIs/XPLgk0MVJ56tVjXaqH7CJxkRHZG39IvkWXl+w8oRyvPmweK /ftJFOLDFHbp4Gcm4XpxDObX4uQJhA2W5vLlYlAEo6lrkev7Zb1/L5TENQ22jIh1aurws9 mA8jbIFHQtpYSv5Qy6GxctHb/uHWLZs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-Fdy4qd_EMbOwjBSIVnuhwQ-1; Thu, 08 Feb 2024 15:48:56 -0500 X-MC-Unique: Fdy4qd_EMbOwjBSIVnuhwQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7D211C05141; Thu, 8 Feb 2024 20:48:55 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 856C91C10C0E; Thu, 8 Feb 2024 20:48:54 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Sean Christopherson Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Andrew Jones Subject: [PATCH v3 4/8] KVM: selftests: Add a macro to define a test with one vcpu Date: Thu, 8 Feb 2024 21:48:40 +0100 Message-ID: <20240208204844.119326-5-thuth@redhat.com> In-Reply-To: <20240208204844.119326-1-thuth@redhat.com> References: <20240208204844.119326-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790365858227286358 X-GMAIL-MSGID: 1790365858227286358 Most tests are currently not giving any proper output for the user to see how much sub-tests have already been run, or whether new sub-tests are part of a binary or not. So it would be good to support TAP output in the KVM selftests. There is already a nice framework for this in the kselftest_harness.h header which we can use. But since we also need a vcpu in most KVM selftests, it also makes sense to introduce our own wrapper around this which takes care of creating a VM with one vcpu, so we don't have to repeat this boilerplate in each and every test. Thus let's introduce a KVM_ONE_VCPU_TEST() macro here which takes care of this. Suggested-by: Sean Christopherson Link: https://lore.kernel.org/all/Y2v+B3xxYKJSM%2FfH@google.com/ Signed-off-by: Thomas Huth --- .../selftests/kvm/include/kvm_test_harness.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/kvm_test_harness.h diff --git a/tools/testing/selftests/kvm/include/kvm_test_harness.h b/tools/testing/selftests/kvm/include/kvm_test_harness.h new file mode 100644 index 0000000000000..8f7c6858e8e2d --- /dev/null +++ b/tools/testing/selftests/kvm/include/kvm_test_harness.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Macros for defining a KVM test + * + * Copyright (C) 2022, Google LLC. + */ + +#ifndef SELFTEST_KVM_TEST_HARNESS_H +#define SELFTEST_KVM_TEST_HARNESS_H + +#include "kselftest_harness.h" + +#define KVM_ONE_VCPU_TEST_SUITE(name) \ + FIXTURE(name) { \ + struct kvm_vcpu *vcpu; \ + }; \ + \ + FIXTURE_SETUP(name) { \ + (void)vm_create_with_one_vcpu(&self->vcpu, NULL); \ + } \ + \ + FIXTURE_TEARDOWN(name) { \ + kvm_vm_free(self->vcpu->vm); \ + } + +#define KVM_ONE_VCPU_TEST(suite, test, guestcode) \ +static void __suite##_##test(struct kvm_vcpu *vcpu); \ + \ +TEST_F(suite, test) \ +{ \ + vcpu_arch_set_entry_point(self->vcpu, guestcode); \ + __suite##_##test(self->vcpu); \ +} \ +static void __suite##_##test(struct kvm_vcpu *vcpu) + +#endif /* SELFTEST_KVM_TEST_HARNESS_H */