From patchwork Thu Oct 5 14:38:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 148792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp354973vqb; Thu, 5 Oct 2023 07:58:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEp3DPBFNuZa2bVcOJUt0DgoHAoqUTSZlmq5IEL5v0mlJ5KwEQXC/3jUzP/NrRgAt3qzYxk X-Received: by 2002:a9d:6d0d:0:b0:6c4:6aef:cd58 with SMTP id o13-20020a9d6d0d000000b006c46aefcd58mr5279967otp.8.1696517902328; Thu, 05 Oct 2023 07:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517902; cv=none; d=google.com; s=arc-20160816; b=b3rZMb90qe2zQDdEqMLYeeB3aGkyidG6TCQBuhyQwGDY8EOxxzBKe1NdSSKd4cakLb EvyNXLoTFJ89JYIQYpxb0DHZjm3uf38jqwAFVLLVd2A87IMrw0evJhEzVnqFvopAREF2 PTs3+JiFmQ496941uD0BeFeAlicu7S/9YS/J6Q1V6BiWL/sICyz2/LZkvqOohnlFIAxF 68mc9m0kruJVmJKIH1G36WBFnTsZ0D3CqREz0AlPUaFBOZd28a79DFJJjOSs4ImyE8+P R2WhbjPFBm2GQmAX7vwYwSeRXok0JJWPOivrpZd54Rnd/iEbVvZU5nNaSDa08bx+guhC UXCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vazohg9FZ6E9GP8kzgkpGCob+IwdhO7BJaWstWzvEzQ=; fh=WOoc99rHeo9qxHvnIaWffALNRebT/42m1dldSuRpBY0=; b=BIjy3QtsYg6en+6dNM1yIYpFmW42jSxfMyJ4bfwrlu9wvVBhkqqzqSWHQIiEqAQIVL QWRuzLYqVOFWxcr1SN9je9xHKXTCQN6bEJsB6/WH4p3P4aHh6Al2c3y3pJLwFaYppSSF +pr7P4JSyZr75Wz9Ah2hhxoumxhM7OT37lZ7LJQzDpV9icmsiALHhshoxpF/sGv3dFzX xSCTvB1FepkxJ8ye56gxWwhv+z2YzgQdG2beP8Sw+8ZyarVhFJBEoq2o2EMPInt2XGUn hkQPCxVO1N5UytzalCDK/1bpkEZNwyuBDaC8vesgATfvw+Wym/CHIsnxo+QsbE806LRq hSFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/twEhDr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id i63-20020a638742000000b00574035fd472si1587193pge.31.2023.10.05.07.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/twEhDr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 98F3F869EAE6; Thu, 5 Oct 2023 07:58:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234296AbjJEO46 (ORCPT + 19 others); Thu, 5 Oct 2023 10:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237459AbjJEOz2 (ORCPT ); Thu, 5 Oct 2023 10:55:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8805D26A4D for ; Thu, 5 Oct 2023 07:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696516729; 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=vazohg9FZ6E9GP8kzgkpGCob+IwdhO7BJaWstWzvEzQ=; b=S/twEhDraY8Vsn5CJJfUD7aYTGADaVG2MyFDXe7gNRSOYyXSQSQkjGuUQjUWoT5pB4j6ts +BhjBOonoSxb5icaZUr5pY+mn2z+IxcP+WvsIsyD6AlrhLpAT0JqJoFRLP8eKjsYoKXtZz eiBxYMDBlkvXWeRS3+BnDCnN7AWOO2Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-RutCxQ4vM7W0K_V5cIuMSw-1; Thu, 05 Oct 2023 10:38:47 -0400 X-MC-Unique: RutCxQ4vM7W0K_V5cIuMSw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFF9C3C1E9D7; Thu, 5 Oct 2023 14:38:46 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BA0A40C6EA8; Thu, 5 Oct 2023 14:38:45 +0000 (UTC) From: Thomas Huth To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 3/7] KVM: selftests: Add a macro to define a test with one vcpu Date: Thu, 5 Oct 2023 16:38:35 +0200 Message-ID: <20231005143839.365297-4-thuth@redhat.com> In-Reply-To: <20231005143839.365297-1-thuth@redhat.com> References: <20231005143839.365297-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:58:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778927955832455200 X-GMAIL-MSGID: 1778927955832455200 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 | 35 +++++++++++++++++++ 1 file changed, 35 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..04cfc44e3b506 --- /dev/null +++ b/tools/testing/selftests/kvm/include/kvm_test_harness.h @@ -0,0 +1,35 @@ +/* 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, guest_code) \ + FIXTURE(name) { \ + struct kvm_vcpu *vcpu; \ + }; \ + \ + FIXTURE_SETUP(name) { \ + (void)vm_create_with_one_vcpu(&self->vcpu, guest_code); \ + } \ + \ + FIXTURE_TEARDOWN(name) { \ + kvm_vm_free(self->vcpu->vm); \ + } + +#define KVM_ONE_VCPU_TEST(suite, test) \ +static void __suite##_##test(struct kvm_vcpu *vcpu); \ + \ +TEST_F(suite, test) \ +{ \ + __suite##_##test(self->vcpu); \ +} \ +static void __suite##_##test(struct kvm_vcpu *vcpu) + +#endif /* SELFTEST_KVM_TEST_HARNESS_H */