From nobody Wed Feb 28 15:44:34 2024 X-Original-To: dev-commits-src-all@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 4TlJZB6y19z5BpTL; Wed, 28 Feb 2024 15:44:34 +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 4TlJZB6L5Dz4t9d; Wed, 28 Feb 2024 15:44:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709135074; 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=xxRFP7bZNs6VAfgV6yNYugjvs15BKxX/Tjw6H6cZu9s=; b=GBM+CNN9NFPEex/U0pNZuHKMeU9+bVJhpWkAi/hljb8ohMcVIiAg9mTieZNl/epbHb56/S 6FRnK3TATSk3F9Chh2FV5lBvIZw1DX2of5I6IQNfl5ju68W4zRolt2SXzxy6f7lXA1tm9N V5kwMd/HDLLslBzrW55VzHS40tP4sRqE9ShpnqnfDc3H/XVrz7HzjBj8AY4Y2o1PI8dl8W e9CeWZ3OBcgAs0u4IsRXSv3s3tEoxwqKZAbRWPhSUoxPmQJmWDTKC+dC2XMmOGRU2o+XFI elQbWmVsSOn/bltyIkioinEgAr4IWn4STaVRBtUE6JFU7vTnQ1LkqftL/0HTHw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709135074; a=rsa-sha256; cv=none; b=CKR56LNd4albAPawokmqsNOm+T31Zzw6HVqhc+7Gs73T8LJwFvzBwDpS9nIDHM1WVfLuNR ngc0iSiwm1/Zu5F14T7YvSSjfg9Gz2tmQA6dlljA8d4SFRl3llzfGKiDxUa5F2RohA3BMI PH7TfOOJJKV/DB2G6KyXXpd2LvbFwW1//Besu51iKRj3cnD+Hl8spGeX4QhzJkCTID+bS4 qvNAq8fopvE9np1thYqV1INdVrGOInu1hdw9uMog3wa3oyetuLQJegWgsZlYO09dnBCqcu sqQFtv9xp6WpKlQcMbLrL1vUnqQO5iucLJ1v8rHGl5B96kJ3gTgojBmTIjCEQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709135074; 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=xxRFP7bZNs6VAfgV6yNYugjvs15BKxX/Tjw6H6cZu9s=; b=PEia+jxtpT/4QmZKxZt3vDKTFG48GOs9k9fCF9XSGDf7dJ5AAxxj27ZSJM62LaGq1Tdr42 4+eIywsyajFOzhB0RBwveZ0Oce6srmE+wiNs6brc3/d1vCV2PxgtwVi9rObUJWCvEoEKfP l1oevcje7j9BvOLbLeSX9u0zpOVvUMI07Z7Mblk769FcigDJq92wNPuhXsqQ5kN8GZNSMR 1IAxZ8p1U/Yiwd0Q6+/6z/dlo2pbSvAXTGDSIL6RE9ZVthPbu1wmgtMH4uIQb+fIRk9ZYx w/0kg4qDbeAdrYS3nlf7tQwqouCi+OlV6jloNeLFb52NcOugr2V5/+n7EWa3sA== 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 4TlJZB57Njz13NF; Wed, 28 Feb 2024 15:44:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41SFiYEA017232; Wed, 28 Feb 2024 15:44:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41SFiYuM017229; Wed, 28 Feb 2024 15:44:34 GMT (envelope-from git) Date: Wed, 28 Feb 2024 15:44:34 GMT Message-Id: <202402281544.41SFiYuM017229@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 96da41b6dbf3 - main - lorder: Add unit tests. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 96da41b6dbf383436018f11ad8a672faab2d3789 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=96da41b6dbf383436018f11ad8a672faab2d3789 commit 96da41b6dbf383436018f11ad8a672faab2d3789 Author: Dag-Erling Smørgrav AuthorDate: 2024-02-28 15:37:41 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-02-28 15:37:41 +0000 lorder: Add unit tests. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D44134 --- etc/mtree/BSD.tests.dist | 2 + usr.bin/lorder/Makefile | 4 ++ usr.bin/lorder/tests/Makefile | 4 ++ usr.bin/lorder/tests/lorder_test.sh | 111 ++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 2f7d74cb58f8..64b5f88ff2cc 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1137,6 +1137,8 @@ .. lockf .. + lorder + .. m4 .. mkimg diff --git a/usr.bin/lorder/Makefile b/usr.bin/lorder/Makefile index a7bf77dc263a..5dc868f96c7e 100644 --- a/usr.bin/lorder/Makefile +++ b/usr.bin/lorder/Makefile @@ -1,5 +1,9 @@ +.include SCRIPTS=lorder.sh MAN= lorder.1 +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests + .include diff --git a/usr.bin/lorder/tests/Makefile b/usr.bin/lorder/tests/Makefile new file mode 100644 index 000000000000..21207f413a8d --- /dev/null +++ b/usr.bin/lorder/tests/Makefile @@ -0,0 +1,4 @@ +PACKAGE= tests +ATF_TESTS_SH= lorder_test + +.include diff --git a/usr.bin/lorder/tests/lorder_test.sh b/usr.bin/lorder/tests/lorder_test.sh new file mode 100644 index 000000000000..449cda29f825 --- /dev/null +++ b/usr.bin/lorder/tests/lorder_test.sh @@ -0,0 +1,111 @@ +# +# Copyright (c) 2024 Klara, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause +# + +atf_test_case noargs +noargs_head() { + atf_set descr "No arguments" +} +noargs_body() { + atf_check -s exit:1 -e match:"^usage:" \ + lorder +} + +atf_test_case onearg +onearg_head() { + atf_set descr "One argument" +} +onearg_body() { + echo "void a(void) { }" >a.c + cc -o a.o -c a.c + echo "a.o a.o" >output + atf_check -o file:output \ + lorder *.o +} + +atf_test_case dashdash +dashdash_head() { + atf_set descr "One argument" +} +dashdash_body() { + echo "void a(void) { }" >a.c + cc -o a.o -c a.c + echo "a.o a.o" >output + atf_check -o file:output \ + lorder -- *.o +} + +atf_test_case nonexistent +nonexistent_head() { + atf_set descr "Nonexistent file" +} +nonexistent_body() { + atf_check -s not-exit:0 -e match:"No such file" -o empty \ + lorder nonexistent.o +} + +atf_test_case invalid +invalid_head() { + atf_set descr "Invalid file" +} +invalid_body() { + echo "not an object file" >invalid.o + atf_check -s not-exit:0 -e match:"File format not" -o empty \ + lorder invalid.o +} + +atf_test_case objects +objects_head() { + atf_set descr "Order objects" +} +objects_body() { + echo "void a(void) { }" >a.c + echo "void a(void); void b(void) { a(); }" >b.c + echo "void b(void); void c(void) { b(); }" >c.c + for n in a b c ; do + cc -o $n.o -c $n.c + echo "$n.o $n.o" + done >output + echo "b.o a.o" >>output + echo "c.o b.o" >>output + atf_check -o file:output \ + lorder *.o +} + +atf_test_case archives +archives_head() { + atf_set descr "Order archives" +} +archives_body() { + echo "void a(void) { }" >a.c + echo "void a(void); void b(void) { a(); }" >b.c + echo "void b(void); void c(void) { b(); }" >c.c + echo "void e(void); void d(void) { e(); }" >d.c + echo "void d(void); void e(void) { d(); }" >e.c + for n in a b c d e ; do + cc -o $n.o -c $n.c + done + for n in a b c ; do + ar -crs $n.a $n.o + echo "$n.a $n.a" + done >output + ar -crs z.a d.o e.o + echo "z.a z.a" >>output + echo "b.a a.a" >>output + echo "c.a b.a" >>output + atf_check -o file:output \ + lorder *.a +} + +atf_init_test_cases() +{ + atf_add_test_case noargs + atf_add_test_case onearg + atf_add_test_case dashdash + atf_add_test_case nonexistent + atf_add_test_case invalid + atf_add_test_case objects + atf_add_test_case archives +}