From owner-svn-src-all@freebsd.org Wed Jun 7 05:33:57 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B9260BFBDFF; Wed, 7 Jun 2017 05:33:57 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 780DF246F; Wed, 7 Jun 2017 05:33:57 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v575Xuri010881; Wed, 7 Jun 2017 05:33:56 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v575Xu4e010878; Wed, 7 Jun 2017 05:33:56 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201706070533.v575Xu4e010878@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Wed, 7 Jun 2017 05:33:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319642 - in head: bin/chmod bin/chmod/tests etc/mtree X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jun 2017 05:33:57 -0000 Author: ngie Date: Wed Jun 7 05:33:56 2017 New Revision: 319642 URL: https://svnweb.freebsd.org/changeset/base/319642 Log: Add some basic tests for chmod(1) MFC after: 1 month Sponsored by: Dell EMC Isilon Added: head/bin/chmod/tests/ head/bin/chmod/tests/Makefile (contents, props changed) head/bin/chmod/tests/chmod_test.sh (contents, props changed) Modified: head/bin/chmod/Makefile head/etc/mtree/BSD.tests.dist Modified: head/bin/chmod/Makefile ============================================================================== --- head/bin/chmod/Makefile Wed Jun 7 01:48:11 2017 (r319641) +++ head/bin/chmod/Makefile Wed Jun 7 05:33:56 2017 (r319642) @@ -1,7 +1,11 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ +.include + PACKAGE=runtime PROG= chmod + +SUBDIR.${MK_TESTS}+= tests .include Added: head/bin/chmod/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/chmod/tests/Makefile Wed Jun 7 05:33:56 2017 (r319642) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +ATF_TESTS_SH+= chmod_test + +.include Added: head/bin/chmod/tests/chmod_test.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/chmod/tests/chmod_test.sh Wed Jun 7 05:33:56 2017 (r319642) @@ -0,0 +1,160 @@ +# +# Copyright (c) 2017 Dell EMC +# All rights reserved. +# +# 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. +# +# $FreeBSD$ + +atf_test_case RH_flag +RH_flag_head() +{ + atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -H " \ + "is specified" +} +RH_flag_body() +{ + atf_check mkdir -m 0777 -p A/B + atf_check ln -s B A/C + atf_check chmod -h 0777 A/C + atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RH 0700 A + atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C + atf_check chmod -RH 0600 A/C + atf_check -o inline:'40700\n40600\n120700\n' stat -f '%p' A A/B A/C +} + +atf_test_case RL_flag +RL_flag_head() +{ + atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -L " \ + "is specified" +} +RL_flag_body() +{ + atf_check mkdir -m 0777 -p A/B + atf_check ln -s B A/C + atf_check chmod -h 0777 A/C + atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RL 0700 A + atf_check -o inline:'40700\n40700\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RL 0600 A/C + atf_check -o inline:'40700\n40600\n120777\n' stat -f '%p' A A/B A/C +} + +atf_test_case RP_flag +RP_flag_head() +{ + atf_set "descr" "Verify that setting modes recursively via -R doesn't " \ + "affect symlinks specified via the arguments when -P " \ + "is specified" +} +RP_flag_body() +{ + atf_check mkdir -m 0777 -p A/B + atf_check ln -s B A/C + atf_check chmod -h 0777 A/C + atf_check -o inline:'40755\n40777\n120777\n' stat -f '%p' A A/B A/C + atf_check chmod -RP 0700 A + atf_check -o inline:'40700\n40700\n120700\n' stat -f '%p' A A/B A/C + atf_check chmod -RP 0600 A/C + atf_check -o inline:'40700\n40700\n120600\n' stat -f '%p' A A/B A/C +} + +atf_test_case f_flag cleanup +f_flag_head() +{ + atf_set "descr" "Verify that setting a mode for a file with -f " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" +} + +f_flag_body() +{ + atf_check truncate -s 0 foo bar + atf_check chmod 0750 foo bar + atf_check chflags uchg foo + atf_check -e not-empty -s not-exit:0 chmod 0700 foo bar + atf_check -o inline:'100750\n100700\n' stat -f '%p' foo bar + atf_check -s exit:0 chmod -f 0600 foo bar + atf_check -o inline:'100750\n100600\n' stat -f '%p' foo bar +} + +f_flag_cleanup() +{ + atf_check chflags 0 foo +} + +atf_test_case h_flag +h_flag_head() +{ + atf_set "descr" "Verify that setting a mode for a file with -f " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" +} + +h_flag_body() +{ + atf_check truncate -s 0 foo + atf_check chmod 0600 foo + atf_check -o inline:'100600\n' stat -f '%p' foo + umask 0077 + atf_check ln -s foo bar + atf_check -o inline:'100600\n120700\n' stat -f '%p' foo bar + atf_check chmod -h 0500 bar + atf_check -o inline:'100600\n120500\n' stat -f '%p' foo bar + atf_check chmod 0660 bar + atf_check -o inline:'100660\n120500\n' stat -f '%p' foo bar +} + +atf_test_case v_flag +v_flag_head() +{ + atf_set "descr" "Verify that setting a mode with -v emits the file when " \ + "doesn't emit an error message/exit with a non-zero " \ + "code" +} +v_flag_body() +{ + atf_check truncate -s 0 foo bar + atf_check chmod 0600 foo + atf_check chmod 0750 bar + atf_check -o 'inline:bar\n' chmod -v 0600 foo bar + atf_check chmod -v 0600 foo bar + for f in foo bar; do + echo "$f: 0100600 [-rw------- ] -> 0100700 [-rwx------ ]"; + done > output.txt + atf_check -o file:output.txt chmod -vv 0700 foo bar + atf_check chmod -vv 0700 foo bar +} + +atf_init_test_cases() +{ + atf_add_test_case RH_flag + atf_add_test_case RL_flag + atf_add_test_case RP_flag + atf_add_test_case f_flag + atf_add_test_case h_flag + atf_add_test_case v_flag +} Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Wed Jun 7 01:48:11 2017 (r319641) +++ head/etc/mtree/BSD.tests.dist Wed Jun 7 05:33:56 2017 (r319642) @@ -8,6 +8,8 @@ bin cat .. + chmod + .. date .. dd