1#!/bin/sh -efu 2# 3# Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org> 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 3. The name of the author may not be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28usage() 29{ 30 cat >&2 <<EOF 31Usage: $0 [<input> [<output>]] 32 33Generate test script(s) from <input> table. 34If a <output> is specified, generate the script for this test only, 35otherwise generate scripts for all tests specified in <input> table. 36EOF 37 exit 1 38} 39 40input="${0%/*}/gen_tests.in" 41[ $# -eq 0 ] || { input="$1"; shift; } 42output= 43[ $# -eq 0 ] || { output="$1"; shift; } 44[ $# -eq 0 ] || usage 45 46if [ -n "$output" ]; then 47 match="${output##*/}" 48 match="${match%.gen.test}" 49 [ -n "$match" ] || usage 50else 51 match= 52 dir="$(dirname "$input")" 53fi 54 55names= 56 57while read -r name args; do { 58 [ -n "${name###*}" ] || continue 59 if [ -z "$match" ]; then 60 names="$names $name" 61 output="$dir/$name.gen.test" 62 else 63 [ "$match" = "$name" ] || continue 64 fi 65 66 hdr="\ 67#!/bin/sh -efu 68# Generated by $0 from $input ($name $args); do not edit." 69 70 case "$args" in 71 +*) 72 cat <<-EOF 73 $hdr 74 . "\${srcdir=.}/${args#+}" 75 EOF 76 ;; 77 78 ''|-*) 79 cat <<-EOF 80 $hdr 81 . "\${srcdir=.}/init.sh" 82 run_strace_match_diff $args 83 EOF 84 ;; 85 86 *) 87 cat <<-EOF 88 $hdr 89 . "\${srcdir=.}/init.sh" 90 $args 91 EOF 92 ;; 93 esac > "$output" 94 95 chmod a+x "$output" 96} < /dev/null; done < "$input" 97 98if [ -n "$names" ]; then 99 { 100 printf '# Generated by %s from %s; do not edit.\n' "$0" "$input" 101 printf 'GEN_TESTS =' 102 printf ' %s.gen.test' $names 103 echo 104 target='$(srcdir)/%s.gen.test' 105 dep1='$(abs_srcdir)/gen_tests.sh' 106 dep2='$(srcdir)/gen_tests.in' 107 recipe='$(AM_V_GEN) $^ $@' 108 printf "\\n$target: $dep1 $dep2\\n\\t$recipe\\n" $names 109 } > "$dir/gen_tests.am" 110fi 111