#! /bin/sh # Simple testsuite generator. # Copyright (C) 2015 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## Some important facts about this code. ## ## - it's enough to do 'false' within test and it is failure. ## - each subdirectory file is self-standing ## - each test might have several tags -- future dependencies DTF_OUTPUT=DTF_OUTPUT : ${DG=dg} export opt_distro=fedora-rawhide-x86_64 # config : ${outputdir=$PWD/$DTF_OUTPUT} : ${toporigdir=$PWD} : ${libdir=/usr/lib} : ${datadir=/usr/share} : ${dtfdatadir=$datadir/dtf} : ${dtflibdir=$dtfdatadir/lib} : ${dtftpldir=$dtfdatadir/tpl} . "$dtflibdir/default" || exit 1 info () { echo " * $*" } die () { echo >&2 "FATAL: $*" exit 1 } dg_call () { "$DG" --distro="$opt_distro".yaml "$@" \ || die "dg failure" } generate_wrapper () { _run_cmd=$outputdir/$1/run # TODO: This is not portable. fix_testname=$1 test "$fix_testname" = '.' && fix_testname=ROOT fix_testname=${fix_testname##./} echo '#! /bin/sh # DTF'\''s '\''run'\'' wrapper. # Copyright (C) 2015 Red Hat, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. : ${__DTF_TOP_TEST=:} abs_dirname () { abs_dirname_result=`cd "$1" && pwd` } abs_dirname "`dirname $0`" srcdir=$abs_dirname_result ' > "$_run_cmd" cat >> "$_run_cmd" <> "$_run_cmd" chmod +x "$_run_cmd" } # count_recursive_walk SUBDIR SRCDIR TOP_SRCDIR # --------------------------------------------- count_recursive_walk () { cd "$1" info "directory: $2" mkdir -p "$outputdir/$2" generate_wrapper "$2" "$3" if test -f testcase; then dg_call --template testcase --output "$outputdir/$2/testcase" fi test -f library && dg_call --template library >> "$outputdir/library" for _rw_i in * do __dtf_is_testdir "$_rw_i" || continue _rw_fulldir="$2/$_rw_i" mkdir -p "$outputdir/$_rw_fulldir" \ || die "can't create $outputdir/$_rw_fulldir" count_recursive_walk "$_rw_i" "$2/$_rw_i" "$3/.." done cd .. } # TODO: option parsing if test x"$1" == x--distro then test -n "$2" && opt_distro="$2" fi case $outputdir in /*) : ;; *) die "not absolute \$outputdir=$outputdir" ;; esac test -d "$outputdir" && { chmod u+w "$outputdir" -R /bin/rm -rf "$outputdir" } mkdir -p "$outputdir" cat "$dtflibdir/default" > "$outputdir/library" dg_call --template "$dtflibdir/tests" >> "$outputdir/library" count_recursive_walk "$toporigdir" . . # Protect sources! chmod a-w "$outputdir" -R