From nobody Fri May 20 14:36:35 2022 X-Original-To: dev-commits-src-main@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 74D471B37681; Fri, 20 May 2022 14:36:36 +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 4L4TnJ0nG6z3hxF; Fri, 20 May 2022 14:36:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653057396; 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=wRp1khXRlSF0HXYtj/6t/dzK4N+h9FDTpGyEe40GASQ=; b=riiNqJKc8Ax/YOvauasflUi2gTN/DR84BFEJ4zPb4jZXyuCUjroP5WKMiZxi4KmwLKDHY8 /WOKoBvfWcbWZmRczmh88zmVz2GEur3mHkoy/dWIKDtasadZvQ0hpRhDFKd9qxD414cUiN xWvgWjoVIM9ZvuVvbBODcZQ8MPRJJsXWAawiohTHZWpBTM2dNqGInaFpwgqFURY1HCLs3F 3El1TqcVFejw1s7KxqqRcxkcy9crUWoHXbBYFknNSpKcATaD2zyjSwonM25lwE+EIctMry ytf8UuuE4J8IXW+xZdb4pcwiL+UxuWihRAAvqwFwPnhOIL6ZzZOZRXjREUO4TA== 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 BE715140D1; Fri, 20 May 2022 14:36:35 +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 24KEaZwd028058; Fri, 20 May 2022 14:36:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24KEaZH5028057; Fri, 20 May 2022 14:36:35 GMT (envelope-from git) Date: Fri, 20 May 2022 14:36:35 GMT Message-Id: <202205201436.24KEaZH5028057@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 670be460e408 - main - bitstring_test: Add regression tests for bit_ff(c|s)_area_at() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 670be460e4089038aadb47917bd71fe07d2cac21 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653057396; 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=wRp1khXRlSF0HXYtj/6t/dzK4N+h9FDTpGyEe40GASQ=; b=sFTuojrdmswL+vMF/u7Qp6rTg98XcfzB29by8/85tDEYid85zvnOXbEMIykxYmrxVlrVPg zA6R7Ek1Ok/1WhfFE+awWfWyV9aFe67o7nvayw0S7F2rL6+Tg2podX50y/uXS6+MkJ7GOs cR5v+1FH24jr8IHnf3uVuzAiOZYkL300T8XXTVHz5eYYw0+7dD7hMn4Y6Y8dotDfbd2TH8 5VWDYjj9p0CZJm3QdjqaeV0G2LDIljiEW6CZ14uOakntTlOlLmgVwrYWbK4u31w7XFy1bT rWcJnK6uXsJQlhLeGGGvZqmTITAegCVmDMmqpLb3OsyGAafWKMknbueOt4oWXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653057396; a=rsa-sha256; cv=none; b=X881ssNb6nOFg+axTOW/hfiyKPiG/WVvzjhRV4JMqXxNN0kARhnHPZHC4MNgZlT/pmS34W XiN5IDJhEZsfWmihhFzxjOmTaszinI/nQ1dgdsTYCj9oBaD64a2qCv/vLw910PZwxRy+3/ N33hLtY1ANMWiXuXMZgTuVVjESdkqeu8wCEbNY33cyUq1IHrsriBJJ352S/5rVb1kUKQBm fBfVkb/rt+XM3TGIn/BnKmvgKb+wE2fJcmzQMSPFIw7QnSx0enA4gq7nfwdp4y9XjbwC9Z CFaqQjOwQuhMIomlNKftwenmGeqUcQUMCalYsP49bxYlpYVMDER3eU54xmk56g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=670be460e4089038aadb47917bd71fe07d2cac21 commit 670be460e4089038aadb47917bd71fe07d2cac21 Author: Mark Johnston AuthorDate: 2022-05-20 14:18:10 +0000 Commit: Mark Johnston CommitDate: 2022-05-20 14:36:05 +0000 bitstring_test: Add regression tests for bit_ff(c|s)_area_at() Validate the cases where a match can be found immediately and where no match can be found. This extends the existing test cases and is enough to catch the bug fixed in commit 6e7a585348d5 ("bitstring: fix ff_area() when start!=0"). Reviewed by: dougm MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35259 --- tests/sys/sys/bitstring_test.c | 73 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/tests/sys/sys/bitstring_test.c b/tests/sys/sys/bitstring_test.c index 97aa97a680f0..68f394c88d7c 100644 --- a/tests/sys/sys/bitstring_test.c +++ b/tests/sys/sys/bitstring_test.c @@ -29,6 +29,7 @@ * * $FreeBSD$ */ + #include #include @@ -321,26 +322,72 @@ BITSTRING_TC_DEFINE(bit_ffc_at) nbits, memloc, nbits + 3, found_clear_bit); } -BITSTRING_TC_DEFINE(bit_ffc_area_no_match) +BITSTRING_TC_DEFINE(bit_ffc_area_at_all_or_nothing) /* bitstr_t *bitstr, int nbits, const char *memloc */ { - int found_clear_bits; + int found; - memset(bitstr, 0xFF, bitstr_size(nbits)); - bit_ffc_area(bitstr, nbits, 2, &found_clear_bits); - ATF_REQUIRE_EQ_MSG(-1, found_clear_bits, - "bit_ffc_area_%d_%s: Failed all set bits.", nbits, memloc); + memset(bitstr, 0, bitstr_size(nbits)); + if (nbits % _BITSTR_BITS != 0) + bit_nset(bitstr, nbits, roundup2(nbits, _BITSTR_BITS) - 1); + + for (int start = 0; start < nbits; start++) { + for (int size = 1; size < nbits - start; size++) { + bit_ffc_area_at(bitstr, start, nbits, size, &found); + ATF_REQUIRE_EQ_MSG(start, found, + "bit_ffc_area_at_%d_%s: " + "Did not find %d clear bits at %d", + nbits, memloc, size, start); + } + } + + memset(bitstr, 0xff, bitstr_size(nbits)); + if (nbits % _BITSTR_BITS != 0) + bit_nclear(bitstr, nbits, roundup2(nbits, _BITSTR_BITS) - 1); + + for (int start = 0; start < nbits; start++) { + for (int size = 1; size < nbits - start; size++) { + bit_ffc_area_at(bitstr, start, nbits, size, &found); + ATF_REQUIRE_EQ_MSG(-1, found, + "bit_ffc_area_at_%d_%s: " + "Found %d clear bits at %d", + nbits, memloc, size, start); + } + } } -BITSTRING_TC_DEFINE(bit_ffs_area_no_match) +BITSTRING_TC_DEFINE(bit_ffs_area_at_all_or_nothing) /* bitstr_t *bitstr, int nbits, const char *memloc */ { - int found_clear_bits; + int found; memset(bitstr, 0, bitstr_size(nbits)); - bit_ffs_area(bitstr, nbits, 2, &found_clear_bits); - ATF_REQUIRE_EQ_MSG(-1, found_clear_bits, - "bit_ffs_area_%d_%s: Failed all clear bits.", nbits, memloc); + if (nbits % _BITSTR_BITS != 0) + bit_nset(bitstr, nbits, roundup2(nbits, _BITSTR_BITS) - 1); + + for (int start = 0; start < nbits; start++) { + for (int size = 1; size < nbits - start; size++) { + bit_ffs_area_at(bitstr, start, nbits, size, &found); + ATF_REQUIRE_EQ_MSG(-1, found, + "bit_ffs_area_at_%d_%s: " + "Found %d set bits at %d", + nbits, memloc, size, start); + } + } + + memset(bitstr, 0xff, bitstr_size(nbits)); + if (nbits % _BITSTR_BITS != 0) + bit_nclear(bitstr, nbits, roundup2(nbits, _BITSTR_BITS) - 1); + + for (int start = 0; start < nbits; start++) { + for (int size = 1; size < nbits - start; size++) { + bit_ffs_area_at(bitstr, start, nbits, size, &found); + ATF_REQUIRE_EQ_MSG(start, found, + "bit_ffs_area_at_%d_%s: " + "Did not find %d set bits at %d", + nbits, memloc, size, start); + } + } } ATF_TC_WITHOUT_HEAD(bit_ffs_area); @@ -833,8 +880,8 @@ ATF_TP_ADD_TCS(tp) BITSTRING_TC_ADD(tp, bit_nclear); BITSTRING_TC_ADD(tp, bit_nset); BITSTRING_TC_ADD(tp, bit_count); - BITSTRING_TC_ADD(tp, bit_ffs_area_no_match); - BITSTRING_TC_ADD(tp, bit_ffc_area_no_match); + BITSTRING_TC_ADD(tp, bit_ffs_area_at_all_or_nothing); + BITSTRING_TC_ADD(tp, bit_ffc_area_at_all_or_nothing); BITSTRING_TC_ADD(tp, bit_foreach); BITSTRING_TC_ADD(tp, bit_foreach_at); BITSTRING_TC_ADD(tp, bit_foreach_unset);