Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5442210pxb; Sun, 7 Nov 2021 12:23:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFbGrW5tf9A3KLSYX5SX9AMx225aMMT5cPBLe1CrJAs6VNOV12j2QvW/V0YDofeIUpSnnh X-Received: by 2002:a17:906:2757:: with SMTP id a23mr91956568ejd.230.1636316602233; Sun, 07 Nov 2021 12:23:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636316602; cv=none; d=google.com; s=arc-20160816; b=s35Hi724exwcOW+cjLWtvm9XNcwyw0+LicfbSg3ItuEN9YZhHDaCKbzur55e5MhKyp tgjcd7OsZYKaBjwz66kcMIZ8v+VwrnbsE8IWcCESb3R54vInetRBhQRJsT5yPyef2GaZ PnGyAKOJMkKWHvktG/ej8gwQ9jfERqHMHejRZKCcX59Pb1unPBq4SbMLhQTGTmIPsDT/ 6yJG/+qA7FEBygcmXhNQ/UAgczjxBXji0cJ68CUC8aC6SekyHSR7sIeZ/SEU8f+DtXcK eGVRNs9FpEOslctXJNRGDmakvl+gV4/2NBdOW1BYrMTSVBNRT/8ky3ePDY/SlZsnFXwB J0CA== 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; bh=4cUueTQi/4+790HK4KwHg11WTlNjmiPX8ivUvZ1Ez2M=; b=yUggrJZDL5Xh1jocKEUUMhj05LSQm+YdzrZjO+P/q90rl9Qsupkwv1xAdLaEZKz8jn waQi5hBnyyExklhoQJMUdp+LQbn7Ml1J7M17zCbN1s43aH2g0+AxKl60n5XfEY61G3fR SKlJuJPc9GSoYq07/5W3R0sA13c3BBEtmy8hjtSK+e7HGeaKLkE1lXX+4xLTpfqmY6PG kkPLuKMX83wA4vq7/6+Xyvl+MK0Gown2R2kMbWykR63YQmb4u5jonXIej54jAkP7tKha PHzuXQ8ITAE+m/GevBf7//wNXRWVCrFfERDs0myQSNkt88SZvDOfbR8v3bEfdZQJtsq+ vzEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si22634770edi.523.2021.11.07.12.22.45; Sun, 07 Nov 2021 12:23:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235479AbhKGOMS (ORCPT + 99 others); Sun, 7 Nov 2021 09:12:18 -0500 Received: from szxga08-in.huawei.com ([45.249.212.255]:27117 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235466AbhKGOMQ (ORCPT ); Sun, 7 Nov 2021 09:12:16 -0500 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HnGJy26y2z1DJ9M; Sun, 7 Nov 2021 22:07:14 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Sun, 7 Nov 2021 22:09:24 +0800 Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Sun, 7 Nov 2021 22:09:23 +0800 From: "Longpeng(Mike)" To: , , CC: , , , , , , , , , Longpeng Subject: [PATCH v5 3/4] nitro_enclaves: Add KUnit tests setup for the misc device functionality Date: Sun, 7 Nov 2021 22:09:16 +0800 Message-ID: <20211107140918.2106-4-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20211107140918.2106-1-longpeng2@huawei.com> References: <20211107140918.2106-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Longpeng Add the initial setup for the KUnit tests that will target the Nitro Enclaves misc device functionality. Signed-off-by: Longpeng Reviewed-by: Andra Paraschiv --- drivers/virt/nitro_enclaves/Kconfig | 9 ++++++++ drivers/virt/nitro_enclaves/ne_misc_dev.c | 31 ++++++++++++++++++++++++++ drivers/virt/nitro_enclaves/ne_misc_dev_test.c | 17 ++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 drivers/virt/nitro_enclaves/ne_misc_dev_test.c diff --git a/drivers/virt/nitro_enclaves/Kconfig b/drivers/virt/nitro_enclaves/Kconfig index f53740b..2d3d981 100644 --- a/drivers/virt/nitro_enclaves/Kconfig +++ b/drivers/virt/nitro_enclaves/Kconfig @@ -14,3 +14,12 @@ config NITRO_ENCLAVES To compile this driver as a module, choose M here. The module will be called nitro_enclaves. + +config NITRO_ENCLAVES_MISC_DEV_TEST + bool "Tests for the misc device functionality of the Nitro Enclaves" + depends on NITRO_ENCLAVES && KUNIT=y + help + Enable KUnit tests for the misc device functionality of the Nitro + Enclaves. Select this option only if you will boot the kernel for + the purpose of running unit tests (e.g. under UML or qemu). If + unsure, say N. diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c index 83ed9b5..51ba4ca 100644 --- a/drivers/virt/nitro_enclaves/ne_misc_dev.c +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c @@ -1756,8 +1756,37 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return 0; } +#if defined(CONFIG_NITRO_ENCLAVES_MISC_DEV_TEST) +#include "ne_misc_dev_test.c" + +static inline int ne_misc_dev_test_init(void) +{ + return __kunit_test_suites_init(ne_misc_dev_test_suites); +} + +static inline void ne_misc_dev_test_exit(void) +{ + __kunit_test_suites_exit(ne_misc_dev_test_suites); +} +#else +static inline int ne_misc_dev_test_init(void) +{ + return 0; +} + +static inline void ne_misc_dev_test_exit(void) +{ +} +#endif + static int __init ne_init(void) { + int rc = 0; + + rc = ne_misc_dev_test_init(); + if (rc < 0) + return rc; + mutex_init(&ne_cpu_pool.mutex); return pci_register_driver(&ne_pci_driver); @@ -1768,6 +1797,8 @@ static void __exit ne_exit(void) pci_unregister_driver(&ne_pci_driver); ne_teardown_cpu_pool(); + + ne_misc_dev_test_exit(); } module_init(ne_init); diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev_test.c b/drivers/virt/nitro_enclaves/ne_misc_dev_test.c new file mode 100644 index 0000000..6862e99 --- /dev/null +++ b/drivers/virt/nitro_enclaves/ne_misc_dev_test.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +static struct kunit_case ne_misc_dev_test_cases[] = { + {} +}; + +static struct kunit_suite ne_misc_dev_test_suite = { + .name = "ne_misc_dev_test", + .test_cases = ne_misc_dev_test_cases, +}; + +static struct kunit_suite *ne_misc_dev_test_suites[] = { + &ne_misc_dev_test_suite, + NULL +}; -- 1.8.3.1