summaryrefslogtreecommitdiffstats
path: root/bin/dtf-gen
blob: 84f7312ae6f76327698cb05102a9a69878f3aeea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#! /bin/sh

## 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_TOP_TEST=:}

abs_dirname ()
{
    abs_dirname_result=`cd "$1" && pwd`
}
abs_dirname "`dirname $0`"
srcdir=$abs_dirname_result
' > "$_run_cmd"

    cat >> "$_run_cmd" <<EOF
export top_srcdir=\$srcdir/$(printf %q "$2")
export testname=$(printf %q "$fix_testname")
EOF

    dg_call --template "$dtftpldir/run.tpl" >> "$_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

test -d "$outputdir" && {
    chmod u+w "$outputdir" -R
    /bin/rm -rf "$outputdir"
}

mkdir -p "$outputdir"
cat "$dtflibdir/default" > "$outputdir/library"
count_recursive_walk "$toporigdir" . .

# Protect sources!
chmod a-w "$outputdir" -R