From nobody Wed May 11 18:44:22 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 665AD1ACBEE4; Wed, 11 May 2022 18:44:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kz3jL2PMWz4cFv; Wed, 11 May 2022 18:44:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652294662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SezH9ANLn0vq/048Pg9BT5p5KY9Y8gUgRQwO3w8u4Ag=; b=t/8FRD175hhOP2oh6i7dSp1AD6qu0OY/Ci2ZIYjMEQMS1oVVYZchhCEtTw5Rz87fO+uCk9 rXgI46TGI6mqRlc+csej+WaabxlDC31qS2tZQf8I9PHXGzRw42Nxq3bh1mfYKgOqb3LzPj /6NoCXPYyKinrtrDJLOhyVh2dIFaS0E2rKDwybMkdXm2iPjRdwb546iPDtB5I6wCh5WVMq C5xBBmyEfBnR1Wi5XEnIC/axK6alaqMb/VahHau4BxO+nrj3nmALrooLSiO2rVDBKNA4gj 3SafauEYI6yZMijp/L6n3HqvlEgLEdF1zynm+U5puASV1c3TDASNM+83P7Q22A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 32D071F0DB; Wed, 11 May 2022 18:44:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 24BIiMrt034771; Wed, 11 May 2022 18:44:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24BIiMbh034770; Wed, 11 May 2022 18:44:22 GMT (envelope-from git) Date: Wed, 11 May 2022 18:44:22 GMT Message-Id: <202205111844.24BIiMbh034770@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: ec687150e52d - stable/13 - Add simple kyua tests for the mod* system calls. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ec687150e52d8803320ed8f93749c1b86db3c7be Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652294662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SezH9ANLn0vq/048Pg9BT5p5KY9Y8gUgRQwO3w8u4Ag=; b=cKBmKUc+6tDkJ3L8fW7Mj0jaiXcbvkaVP3Kdhg+dZVquAAEr0S1tVzXYX5LZ6UI/AcyHi7 C3jfHccyWKofn7E7Mzv1y2pS+nfICsUsQF2+bF37KMxsHGorrJ0sICSh5j5a1Qj1kpYWgw dbvdbpClVEU+9HW8oJe3Y2QRAjLWpF/xs0UymtouO/kQJysvhU70tArQ7fJ6JaSzEn6eGV 38NEwsNvip9lTlF08i0Uqq1Ir3r+2mgvSz/oTkXWICmr+CoV9/FYMXi/eVhkcaxdt7cPFA njGHlTvDXTS3yG5rZUGKhDFXmvHmutaJZoyZYfI8sIIwfTqp0+TcCSuxc/sHyw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652294662; a=rsa-sha256; cv=none; b=pogY3+hbphnQVcWBKSeXHp5mYcZd0SfNICDXepdPkKwdRO0TqcgaICbIcUYzYOimjY6mXQ LqdcTqizsGMgLt3zGPes+s4AY6mQ2ec+YOvuwGZifKDtCy91fFUOlZf5I26xpXx3KzTVr6 dOrMjRX8Bh/Shf3Sm2ex3DPpLrwx/06ugxOiuoyHhSHz7JTt6mxEou3QaEgOm3Tmx5Ucl5 poPSktEilftyAL+m66NxrU15ixNczfLahkivWt1mYXXSFnAyTX5Wzl6qEAbeb6WgXQHJY5 pFhjaiO+zYOMxhQItYvzPKSbdgQCQ83zOnXpFQO1emDW3eYbX2IGsLtgotGOtA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=ec687150e52d8803320ed8f93749c1b86db3c7be commit ec687150e52d8803320ed8f93749c1b86db3c7be Author: John Baldwin AuthorDate: 2022-03-04 01:51:45 +0000 Commit: John Baldwin CommitDate: 2022-05-11 17:29:45 +0000 Add simple kyua tests for the mod* system calls. Reviewed by: markj Obtained from: CheriBSD Sponsored by: University of Cambridge, Google, Inc. Differential Revision: https://reviews.freebsd.org/D34417 (cherry picked from commit 5a1de9c25defdc0e5d08150d5b1877ac117f43e4) --- tests/sys/kern/Makefile | 1 + tests/sys/kern/module_test.c | 197 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 753104c3b084..82373500cd21 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -18,6 +18,7 @@ ATF_TESTS_C+= kill_zombie .if ${MK_OPENSSL} != "no" ATF_TESTS_C+= ktls_test .endif +ATF_TESTS_C+= module_test ATF_TESTS_C+= ptrace_test TEST_METADATA.ptrace_test+= timeout="15" ATF_TESTS_C+= reaper diff --git a/tests/sys/kern/module_test.c b/tests/sys/kern/module_test.c new file mode 100644 index 000000000000..eaebf7196523 --- /dev/null +++ b/tests/sys/kern/module_test.c @@ -0,0 +1,197 @@ +/*- + * Copyright (c) 2022 University of Cambridge + * + * This software was developed by Ararat River Consulting, LLC under + * sponsorship from the University of Cambridge Computer Laboratory + * (Department of Computer Science and Technology) and Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include + +ATF_TC_WITHOUT_HEAD(modfind); +ATF_TC_BODY(modfind, tc) +{ + int modid; + + /* This module is present in sys/kern/subr_bus.c. */ + modid = modfind("rootbus"); + ATF_REQUIRE(modid > 0); + + modid = modfind("nonexistent_module"); + ATF_REQUIRE(modid == -1); + ATF_REQUIRE(errno = ENOENT); +} + +ATF_TC_WITHOUT_HEAD(modnext); +ATF_TC_BODY(modnext, tc) +{ + int modid; + + /* This assumes -1 is never used as a valid module id. */ + modid = modnext(-1); + ATF_REQUIRE(modid == -1); + ATF_REQUIRE(errno = ENOENT); + + modid = modnext(0); + ATF_REQUIRE(modid > 0); + + for (;;) { + modid = modnext(modid); + ATF_REQUIRE(modid >= 0); + if (modid == 0) + break; + } +} + +ATF_TC_WITHOUT_HEAD(modfnext); +ATF_TC_BODY(modfnext, tc) +{ + int modid; + + /* This assumes -1 is never used as a valid module id. */ + modid = modfnext(-1); + ATF_REQUIRE(modid == -1); + ATF_REQUIRE(errno = ENOENT); + + modid = modfnext(0); + ATF_REQUIRE(modid == -1); + ATF_REQUIRE(errno = ENOENT); + + modid = modnext(0); + ATF_REQUIRE(modid > 0); + + for (;;) { + modid = modfnext(modid); + ATF_REQUIRE(modid >= 0); + if (modid == 0) + break; + } +} + +ATF_TC_WITHOUT_HEAD(modstat); +ATF_TC_BODY(modstat, tc) +{ + struct module_stat ms; + int modid; + + ms.version = sizeof(ms); + ATF_REQUIRE(modstat(0, &ms) == -1); + ATF_REQUIRE(errno == ENOENT); + + modid = modnext(0); + ATF_REQUIRE(modid > 0); + + ATF_REQUIRE(modstat(modid, NULL) == -1); + ATF_REQUIRE(errno == EFAULT); + + ms.version = 0; + ATF_REQUIRE(modstat(modid, &ms) == -1); + ATF_REQUIRE(errno == EINVAL); + + ms.version = sizeof(ms); + ATF_REQUIRE(modstat(modid, &ms) == 0); + ATF_REQUIRE(ms.id == modid); + if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name)) + ATF_REQUIRE(modfind(ms.name) == modid); +} + +ATF_TC_WITHOUT_HEAD(modstat_v1); +ATF_TC_BODY(modstat_v1, tc) +{ + struct module_stat_v1 { + int version; + char name[32]; + int refs; + int id; + } ms; + int modid; + + ms.version = sizeof(ms); + ATF_REQUIRE(modstat(0, (struct module_stat *)&ms) == -1); + ATF_REQUIRE(errno == ENOENT); + + modid = modnext(0); + ATF_REQUIRE(modid > 0); + + ATF_REQUIRE(modstat(modid, NULL) == -1); + ATF_REQUIRE(errno == EFAULT); + + ms.version = 0; + ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == -1); + ATF_REQUIRE(errno == EINVAL); + + ms.version = sizeof(ms); + ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == 0); + ATF_REQUIRE(ms.id == modid); + if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name)) + ATF_REQUIRE(modfind(ms.name) == modid); +} + +ATF_TC_WITHOUT_HEAD(modstat_v2); +ATF_TC_BODY(modstat_v2, tc) +{ + struct module_stat_v2 { + int version; + char name[32]; + int refs; + int id; + modspecific_t data; + } ms; + int modid; + + ms.version = sizeof(ms); + ATF_REQUIRE(modstat(0, (struct module_stat *)&ms) == -1); + ATF_REQUIRE(errno == ENOENT); + + modid = modnext(0); + ATF_REQUIRE(modid > 0); + + ATF_REQUIRE(modstat(modid, NULL) == -1); + ATF_REQUIRE(errno == EFAULT); + + ms.version = 0; + ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == -1); + ATF_REQUIRE(errno == EINVAL); + + ms.version = sizeof(ms); + ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == 0); + ATF_REQUIRE(ms.id == modid); + if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name)) + ATF_REQUIRE(modfind(ms.name) == modid); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, modfind); + ATF_TP_ADD_TC(tp, modnext); + ATF_TP_ADD_TC(tp, modfnext); + ATF_TP_ADD_TC(tp, modstat); + ATF_TP_ADD_TC(tp, modstat_v1); + ATF_TP_ADD_TC(tp, modstat_v2); + + return (atf_no_error()); +}