From owner-svn-src-all@FreeBSD.ORG Fri Dec 5 12:51:29 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E3AAE78F; Fri, 5 Dec 2014 12:51:28 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 C4BAD79A; Fri, 5 Dec 2014 12:51:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sB5CpSgL003109; Fri, 5 Dec 2014 12:51:28 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sB5CpSrV003106; Fri, 5 Dec 2014 12:51:28 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201412051251.sB5CpSrV003106@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Fri, 5 Dec 2014 12:51:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r275511 - in stable/10: . sbin/mdconfig/tests X-SVN-Group: stable-10 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.18-1 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: Fri, 05 Dec 2014 12:51:29 -0000 Author: ngie Date: Fri Dec 5 12:51:27 2014 New Revision: 275511 URL: https://svnweb.freebsd.org/changeset/base/275511 Log: MFC r275170: Convert sbin/mdconfig/tests from prove format tests to ATF format tests As a side effect... 1. The tests now checks for the root user before continuing with kyua, which is more visible than the test being skipped with the TAP protocol 2. The tests work with devices that aren't /dev/md0 by caching the device attached during the test to a file, and later use the cached information to detach the device in the cleanup routine 3. The tests no longer require perl to run PR: 191191 Sponsored by: EMC / Isilon Storage Division Added: stable/10/sbin/mdconfig/tests/mdconfig_test.sh - copied unchanged from r275170, head/sbin/mdconfig/tests/mdconfig_test.sh Deleted: stable/10/sbin/mdconfig/tests/legacy_test.sh stable/10/sbin/mdconfig/tests/mdconfig.test stable/10/sbin/mdconfig/tests/run.pl Modified: stable/10/ObsoleteFiles.inc stable/10/sbin/mdconfig/tests/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/ObsoleteFiles.inc ============================================================================== --- stable/10/ObsoleteFiles.inc Fri Dec 5 12:38:01 2014 (r275510) +++ stable/10/ObsoleteFiles.inc Fri Dec 5 12:51:27 2014 (r275511) @@ -38,6 +38,10 @@ # xargs -n1 | sort | uniq -d; # done +# 20141205: convert sbin/mdconfig/tests to ATF format tests +OLD_FILES+=usr/tests/sbin/mdconfig/legacy_test +OLD_FILES+=usr/tests/sbin/mdconfig/mdconfig.test +OLD_FILES+=usr/tests/sbin/mdconfig/run.pl # 20141028: debug files accidentally installed as directory name OLD_FILES+=usr/lib/debug/usr/lib/i18n OLD_FILES+=usr/lib/debug/usr/lib/private Modified: stable/10/sbin/mdconfig/tests/Makefile ============================================================================== --- stable/10/sbin/mdconfig/tests/Makefile Fri Dec 5 12:38:01 2014 (r275510) +++ stable/10/sbin/mdconfig/tests/Makefile Fri Dec 5 12:51:27 2014 (r275511) @@ -2,12 +2,9 @@ TESTSDIR= ${TESTSBASE}/sbin/mdconfig -TAP_TESTS_SH= legacy_test -TAP_TESTS_SH_SED_legacy_test= 's,__PERL__,${TAP_PERL_INTERPRETER},g' -TEST_METADATA.legacy_test+= required_programs="${TAP_PERL_INTERPRETER}" +ATF_TESTS_SH= mdconfig_test -FILESDIR= ${TESTSDIR} -FILES= mdconfig.test -FILES+= run.pl + +TEST_METADATA.mdconfig_test+= required_user="root" .include Copied: stable/10/sbin/mdconfig/tests/mdconfig_test.sh (from r275170, head/sbin/mdconfig/tests/mdconfig_test.sh) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sbin/mdconfig/tests/mdconfig_test.sh Fri Dec 5 12:51:27 2014 (r275511, copy of r275170, head/sbin/mdconfig/tests/mdconfig_test.sh) @@ -0,0 +1,281 @@ +# Copyright (c) 2012 Edward Tomasz NapieraƂa +# 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$ +# + +check_diskinfo() +{ + local md=$1 + local mediasize_in_bytes=$2 + local mediasize_in_sectors=$3 + local sectorsize=${4:-512} + local stripesize=${5:-0} + local stripeoffset=${6:-0} + + atf_check -s exit:0 \ + -o match:"/dev/$md *$sectorsize *$mediasize_in_bytes *$mediasize_in_sectors *$stripesize *$stripeoffset" \ + -x "diskinfo /dev/$md | expand" +} + +cleanup_common() +{ + if [ -f mdconfig.out ]; then + mdconfig -d -u $(sed -e 's/md//' mdconfig.out) + fi +} + +atf_test_case attach_vnode_non_explicit_type cleanup +attach_vnode_non_explicit_type_head() +{ + atf_set "descr" "Tests out -a / -f without -t" +} +attach_vnode_non_explicit_type_body() +{ + local md + local size_in_mb=1024 + + atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx" + atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig -af xxx' + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "1073741824" "2097152" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_vnode_non_explicit_type_cleanup() +{ + cleanup_common +} + +atf_test_case attach_vnode_implicit_a_f cleanup +attach_vnode_implicit_a_f_head() +{ + atf_set "descr" "Tests out implied -a / -f without -t" +} +attach_vnode_implicit_a_f_body() +{ + local md + local size_in_mb=1024 + + atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx" + atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig xxx' + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "1073741824" "2097152" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_vnode_implicit_a_f_cleanup() +{ + cleanup_common +} + +atf_test_case attach_vnode_explicit_type cleanup +attach_vnode_explicit_type_head() +{ + atf_set "descr" "Tests out implied -a / -f with -t vnode" +} +attach_vnode_explicit_type_body() +{ + local md + local size_in_mb=1024 + + atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx" + atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig -af xxx -t vnode' + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "1073741824" "2097152" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_vnode_explicit_type_cleanup() +{ + [ -f mdconfig.out ] && mdconfig -d -u $(sed -e 's/md//' mdconfig.out) + rm -f mdconfig.out xxx +} + +atf_test_case attach_vnode_smaller_than_file cleanup +attach_vnode_smaller_than_file_head() +{ + atf_set "descr" "Tests mdconfig -s with size less than the file size" +} +attach_vnode_smaller_than_file_body() +{ + local md + local size_in_mb=128 + + atf_check -s exit:0 -x "truncate -s 1024m xxx" + atf_check -s exit:0 -o save:mdconfig.out \ + -x "mdconfig -af xxx -s ${size_in_mb}m" + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "134217728" "262144" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_vnode_smaller_than_file_cleanup() +{ + cleanup_common +} + +atf_test_case attach_vnode_larger_than_file cleanup +attach_vnode_larger_than_file_head() +{ + atf_set "descr" "Tests mdconfig -s with size greater than the file size" +} +attach_vnode_larger_than_file_body() +{ + local md + local size_in_gb=128 + + atf_check -s exit:0 -x "truncate -s 1024m xxx" + atf_check -s exit:0 -o save:mdconfig.out \ + -x "mdconfig -af xxx -s ${size_in_gb}g" + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "137438953472" "268435456" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md vnode ${size_in_gb}G$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_vnode_larger_than_file_cleanup() +{ + cleanup_common +} + +atf_test_case attach_vnode_sector_size cleanup +attach_vnode_sector_size_head() +{ + atf_set "descr" "Tests mdconfig -s with size greater than the file size" +} +attach_vnode_sector_size_body() +{ + local md + local size_in_mb=1024 + + atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx" + atf_check -s exit:0 -o save:mdconfig.out \ + -x "mdconfig -af xxx -S 2048" + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "1073741824" "524288" "2048" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_vnode_sector_size_cleanup() +{ + cleanup_common +} + +atf_test_case attach_malloc cleanup +attach_malloc_head() +{ + atf_set "descr" "Tests mdconfig with -t malloc" +} +attach_malloc_body() +{ + local md + local size_in_mb=1024 + + atf_check -s exit:0 -o save:mdconfig.out \ + -x 'mdconfig -a -t malloc -s 1g' + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "1073741824" "2097152" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md malloc ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_malloc_cleanup() +{ + cleanup_common +} + +atf_test_case attach_swap cleanup +attach_swap_head() +{ + atf_set "descr" "Tests mdconfig with -t swap" +} +attach_swap_body() +{ + local md + local size_in_mb=1024 + + atf_check -s exit:0 -o save:mdconfig.out \ + -x 'mdconfig -a -t swap -s 1g' + md=$(cat mdconfig.out) + atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md" + check_diskinfo "$md" "1073741824" "2097152" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md swap ${size_in_mb}M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_swap_cleanup() +{ + cleanup_common +} + +atf_test_case attach_with_specific_unit_number cleanup +attach_with_specific_unit_number_head() +{ + atf_set "descr" "Tests mdconfig with a unit specified by -u" +} +attach_with_specific_unit_number_body() +{ + local md_unit=99 + local size_in_mb=10 + + local md="md${md_unit}" + + echo "$md" > mdconfig.out + + atf_check -s exit:0 -o empty \ + -x "mdconfig -a -t malloc -s ${size_in_mb}m -u $md_unit" + check_diskinfo "$md" "10485760" "20480" + # This awk strips the file path. + atf_check -s exit:0 -o match:"^$md malloc "$size_in_mb"M$" \ + -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'" +} +attach_with_specific_unit_number_cleanup() +{ + cleanup_common +} + +atf_init_test_cases() +{ + atf_add_test_case attach_vnode_non_explicit_type + atf_add_test_case attach_vnode_explicit_type + atf_add_test_case attach_vnode_smaller_than_file + atf_add_test_case attach_vnode_larger_than_file + atf_add_test_case attach_vnode_sector_size + atf_add_test_case attach_malloc + atf_add_test_case attach_swap + atf_add_test_case attach_with_specific_unit_number +}