File: AutoTest

package info (click to toggle)
openfoam 1912.200626-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 238,940 kB
  • sloc: cpp: 1,159,638; sh: 15,902; ansic: 5,195; lex: 660; xml: 387; python: 282; awk: 212; makefile: 103; sed: 88; csh: 3
file content (199 lines) | stat: -rwxr-xr-x 4,889 bytes parent folder | download | duplicates (2)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | www.openfoam.com
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
#     Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
#     tutorials/AutoTest dir [.. dirN]
#
# Description
#     Run foamRunTutorials with specified tutorial directories
#     Creates/destroys a temporary directory for each test.
#
# Environment
#     Requires an initialized OpenFOAM environment.
#
# Note
#     Potentially useful for debian autopkgtest
#
#------------------------------------------------------------------------------
# Auto-detect from location
#Unused# projectDir="$(\cd "$(dirname "${0%/*}")" && \pwd -L)"

#------------------------------------------------------------------------------
printHelp() {
    cat<<USAGE

usage: ${0##*/} [OPTION] dir [.. dirN]

options:
  -1            Modify case controlDict to run only one time step (default)
  -full         Do not modify controlDict (run tutorial to completion)
  -debian       Any modifications when running with autopkgtest
  -help         Print the usage

Run foamRunTutorials with specified tutorial directories.
Creates/destroys a temporary directory for each.

USAGE
    exit 0 # A clean exit
}

# Report error and exit
die()
{
    exec 1>&2
    echo
    echo "Error encountered:"
    while [ "$#" -ge 1 ]; do echo "    $1"; shift; done
    echo
    echo "See '${0##*/} -help' for usage"
    echo
    exit 1
}

#------------------------------------------------------------------------------

unset optDebian optVerbose
optRunLimit=1

# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
    -h*)
        printHelp
        ;;

    -1)
        optRunLimit="${1#-}"
        ;;

    -full)
        unset optRunLimit
        ;;

    -debian)
        # Redirect stderr to stdout, if autopkgtest (tests/control)
        # does NOT use "Restrictions: allow-stderr"
        exec 2>&1
        ;;

    --)
        break
        ;;

    -*)
        die "unknown option $1"
        ;;

    *)
        break
        ;;
    esac
    shift
done


#------------------------------------------------------------------------------
# Basic sanity checks

[ -n "$FOAM_TUTORIALS" ] || export FOAM_TUTORIALS="$WM_PROJECT_DIR"/tutorials

[ -d "${WM_PROJECT_DIR:?}" ] || die "No OpenFOAM environment: $WM_PROJECT_DIR"
[ -d "$FOAM_TUTORIALS" ] || die "No OpenFOAM tutorials : $FOAM_TUTORIALS"


#------------------------------------------------------------------------------

#
# Modify case controlDicts to run only one time step
#
modifyCaseControlDict()
{
    for dict in $(find . -name "controlDict*" -type f)
    do
        cp -f "${dict}" "${dict}.orig"
        sed \
            -e 's/\(startFrom[ \t]*\)\([A-Za-z]*\);/\1 latestTime;/' \
            -e 's/\(stopAt[ \t]*\)\([A-Za-z]*\);/\1 nextWrite;/' \
            -e 's/\(writeControl[ \t]*\)\([A-Za-z]*\);/\1 timeStep;/' \
            -e 's/\(writeInterval[ \t]*\)\([-.0-9A-Za-z]*\);/\1 '"$optRunLimit"';/' \
            "${dict}.orig" > "${dict}"
    done
}


#------------------------------------------------------------------------------

nTests="$#"
nPassed=0

for testdir in "$@"
do
    testdir="${testdir#tutorials/}"
    testdir="$(echo "$testdir" | sed -e 's@^//*@@; s@//*$@@;')"
    suffix="$(echo "$testdir" | sed -e 's@//*@_@g')"

    if [ -n "$testdir" ] && [ -d "$FOAM_TUTORIALS/$testdir" ]
    then
    (
        echo "Run test: $testdir"
        set -e

        TESTDIR="$(mktemp --directory --suffix=".$suffix")"
        trap 'rm -rf $TESTDIR' 0 INT QUIT ABRT PIPE TERM

        cp -r "$FOAM_TUTORIALS/$testdir"/* "$TESTDIR"/
        cd "$TESTDIR"

        if [ -n "$optRunLimit" ]
        then
            set +e
            modifyCaseControlDict
            set -e
        fi

        nInput="$(ls | wc -l)"
        foamRunTutorials
        nOutput="$(ls | wc -l)"

        if [ "$nInput" = 0 ]
        then
            echo "No input for $testdir" 1>&2
            exit 1
        elif [ "$nOutput" = "$nInput" ]
        then
            echo "Run failure for $testdir" 1>&2
            exit 1
        else
            echo "run: OK"
        fi
    ) && nPassed=$((nPassed + 1))

    else
        echo "No tutorial: $testdir" 1>&2
    fi
done


if [ "$nTests" = 0 ]
then
    die "No tests specified"
elif [ "$nPassed" = "$nTests" ]
then
    echo "Passed all $nTests tests"
else
    echo "Passed $nPassed/$nTests tests" 1>&2
    exit 1
fi

#------------------------------------------------------------------------------