Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

config-test.sh 9.01 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
# 
# Testing the installation: the version, paths and number of extensions should be correct
# This test entirely depends on the CamitK version (version string, number of extensions...)
# (see the expectedConfigOutput)
# 
7
8
# For a CamiTK major or minor version please update the expected number and release date
# in function initTestData
9
# 
10
11
12
13
14
15
16
17
# echo $? get the last returned value of the script
# a return value of 0 indicates success (by convention)
# The value return by this script corresponds to the config test that failed
# (see log for config test id)
# 

set -e

18
19
20
# Uncomment next line to debug
# set -x

21
22
23
24
# ---------------------- initTestData ----------------------
# values to check
initTestData() {
    # fill test data
25
    extensionCount=(           [4.2]=42  [4.1]=41  [4.0]=31  )
26
    componentExtensionCount=(  [4.2]=14  [4.1]=14  [4.0]=14  )
27
    actionExtensionCount=(     [4.2]=28  [4.1]=27  [4.0]=27  )
28
    fileExtensionCount=(       [4.2]=37  [4.1]=37  [4.0]=37  )
29
    actionCount=(              [4.2]=106 [4.1]=105 [4.0]=105 )
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
    
    # fill release date
    releaseDate=(              [4.2]="not yet released, current development version" \
                               [4.1]="15 July 2018" \
                               [4.0]="22 July 2016" \
                               [3.5]="29 January 2016"
                               [3.4]="31 October 2014" \
                               [3.3]="4 March 2014" \
                               [3.2]="26 June 2013" \
                               [3.1]="1 March 2013" \
                               [3.0]="7 July 2012" )
    
}

# ---------------------- declareTestData ----------------------
declareTestData() {
    # declare all associative arrays (-g is to declare the arrays
    # in the global scope)
    declare -Ag extensionCount
    declare -Ag componentExtensionCount
    declare -Ag actionExtensionCount
    declare -Ag fileExtensionCount
    declare -Ag actionCount
    declare -Ag releaseDate
}

# ---------------------- cleanup ----------------------
57
58
59
60
# cleanup on exit
cleanup() {
    # backup the current exit status
    currentExitValue=$?
61
62
63
64
    if [[ "$osName" != "Windows" ]]; then
        # kill the xfvb
        kill $xvfbPid    
    fi
65
66
67
68
69
70
71
72
73
    # cleanup current dir (but not build dir!)
    if [ "$inBuild" == "0" ] ; then
        rm -rf $workingDir
    fi
    # use the backup value (otherwise the result of the "rm -rf" command above will
    # be used, and that's probably always 0 !)
    exit $currentExitValue
}

74
# ---------------------- checkcommand ----------------------
75
# usage: checkcommand name 
76
77
78
checkcommand() {
    if [ "$inBuild" == "0" ] ; then
        # check if current build is on windows debug version
79
80
        if ! hash ${1} 2>/dev/null; then
            echo "Executable not found"
81
        else
82
            echo "[OK]"
83
84
        fi
    else
85
86
        if [ ! -x ${1} ] ; then 
            echo "File not found or not executable"
87
        else
88
            echo "[OK]"
89
90
91
        fi
    fi
}
92

93
94
95
96
# ---------------------- init ----------------------
init() {
    echo "========== checking camitk configuration =========="
    exitStatus=0 # nothing bad. By convention exit 0 indicates success
97

98
99
100
101
102
103
    if [ $# -lt 1 -o "$1" != "-inbuild" ] ; then
        echo "===== Testing installed version ====="
        inBuild=0
        workingDir=$(mktemp --tmpdir -d camitk-test-tmp.XXXXXXXXXX)
        cd $workingDir
        echo "===== Temporary directory created $workingDir ====="
104
        camitkConfig="camitk-config"        
105
106
107
108
109
110
    else
        # if -inbuild option is specified, then the next argument should be the build dir (as set by ${PROJECT_BINARY_DIR} by cmake
        workingDir=$2
        echo "===== Testing in build dir $workingDir ====="
        inBuild=1
        cd $workingDir
111
        camitkConfig="bin/camitk-config"
112
    fi
113

114
115
116
117
118
119
120
121
    echo "===== Check OS ====="
    unameOS=$(uname)
    if [[ "$unameOS" =~ ^MINGW64.* || "$unameOS" =~ ^MSYS_NT.* ]]; then
        osName="Windows"
    else
        osName="Linux"
    fi
    echo "===== Uname is $unameOS ===== OS is $osName ====="
122

123
124
125
126
127
128
129
130
131
    if [[ "$osName" != "Windows" ]]; then
        echo "===== Configuring xvfb ====="
        # Starts the server first (to avoid a distracting warning output due to OpenGL context)
        Xvfb :5 -screen 0 1600x1200x24 -ac +extension GLX +render -noreset -v  -fbdir $workingDir/ &
        xvfbPid=$!
        echo "PID of Xvfb: $xvfbPid"
        export DISPLAY=:5
        export XAUTHORITY=/dev/null
    fi
132

133
134
135
136
137
    # Checking config executable
    echo "===== Checking $camitkConfig ====="
    checkCamiTKConfig=$(checkcommand $camitkConfig)
    echo $checkCamiTKConfig
    if [ "$checkCamiTKConfig" != "[OK]" ] ; then
138
139
        if [[ "$osName" == "Windows" ]]; then
            camitkConfig=$camitkConfig-debug
140
141
142
            echo "===== Checking ${camitkConfig} ====="
            checkCamiTKConfig=$(checkcommand $camitkConfig)
            echo $checkCamiTKConfig
143
        fi
144
    fi
145
}
146

147
148
149
150
# ---------------------- getconfig ----------------------
getconfig() {
    # initialize config output
    echo "===== Get CamiTK configuration ====="
151
    $camitkConfig --config 2>/dev/null > ./config-output
152
    camitkConfig=$(cat config-output | sed "s/QStandardPaths.*'.*'//")
153

154
155
    echo "===== config-output ====="
    cat ./config-output
156

157
158
159
    echo "===== camitkConfig ====="
    echo $camitkConfig
}
160
161
162
163

# ---------------------- expected value ----------------------
getExpectedValue() {
  case "$1" in
164
165
166
167
168
    "Global Installation Directory")
      # for package test: it should always be /usr
      echo "/usr"
      ;;
    "Current Working Directory")
169
170
      # this is an upstream test, it should be ran in build dir (for windows, remplace ^/c by C:
      echo $(pwd) | sed -e "s+^/c+C:+"
171
      ;;
172
    "Number of Component Extensions")
173
      echo ${componentExtensionCount[$shortVersion]}
174
175
      ;;       
    "Number of Action Extensions")
176
177
      echo ${actionExtensionCount[$shortVersion]}
      ;;       
178
    "Number of File Extensions Supported")
179
180
      echo ${fileExtensionCount[$shortVersion]}
      ;;       
181
    "Number of Actions")
182
183
      echo ${actionCount[$shortVersion]}
      ;;       
184
185
186
  esac
}

187
# ---------------------- getInstalledVersion ----------------------
188
getInstalledVersion() {
189
  echo $(echo $camitkConfig | head --lines=1 | cut -f5 -d" ")
190
191
}

192
193
# ------------------- getReleaseDate -------------------
getReleaseDate() {
194
195
196
197
198
    if [ ! ${releaseDate[$1]+validCamiTKVersion} ]; then
      echo "unknown version"
    else
        echo ${releaseDate[$1]}
    fi
199
200
201
202
}

# ---------------------- extension count ----------------------
getExtensionCount() {
203
  echo $(echo "$camitkConfig" | grep "^  - \[$1\] " | wc -l)
204
205
206
}

getExpectedExtensionCount() {
207
  echo ${extensionCount[$1]}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
}

# ---------------------- get config ----------------------
# get a specific value from config, text to parse from
# camitk-config --config is the first parameter of the function
# get the value after the string "... " and before the first space
getConfigValue() {
  echo $(echo "$camitkConfig" | grep "$1" | sed 's/^.*\.\.\. //g' | cut -f1 -d" ")
}

# ---------------------- check value ----------------------
# use camitk-config to check a value and compare to 
# expected value
checkValue() {
  checkedValue="$1"
  value=$(getConfigValue "$checkedValue")
  echo "===== $checkValueId- $checkedValue: $value ====="
  expected=$(getExpectedValue "$checkedValue")
  if [ "$value" != "$expected" ]; then
227
    echo "Error: unexpected $checkedValue (found $value vs $expected expected)"
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    exitStatus=$checkValueId
  else
    echo "OK"
  fi
  # increase id
  checkValueId=$((checkValueId+1))
}

# --------------------------------------------------------------------------
#
# All tests are here
#
# --------------------------------------------------------------------------

242
243
244
# if a problem occurs, call the clean method
trap "cleanup" 0 INT QUIT ABRT PIPE TERM EXIT

245
246
declareTestData
initTestData
247
248
249
init $*
getconfig

250
251
252
253
254
255
detectedVersion=$(getInstalledVersion)
shortVersion=$(echo $detectedVersion | cut -f1,2 -d".")
echo "===== 1- Detected installed CamiTK version is: [$detectedVersion] aka [$shortVersion] ====="
releaseDate=$(getReleaseDate $shortVersion)
if [ "$releaseDate" = "unknown version" ]; then
  echo -n "Error: unknown version "
256
257
258
259
  exitStatus=1
else
  echo -n "OK "
fi
260
echo "(release date: $releaseDate)"
261

262
if [ "$inBuild" == "0" ] ; then
263
  extensionRepository="G" # check for globally installed extension
264
265
266
267
268
else
  extensionRepository="W" # check extension in current build dir
fi

value=$(getExtensionCount $extensionRepository)
269
echo "===== 2- Number of extensions: $value ====="
270
expected=$(getExpectedExtensionCount $shortVersion)
271
if [ "$value" -ne "$expected" ]; then
272
  echo "Error: unexpected number of globally installed extensions (found $value vs $expected expected)"
273
274
275
276
277
278
279
  exitStatus=1
else
  echo "OK"
fi

# init the id (next test is the third test)
checkValueId=3
280
281
282
283
284
if [ "$inBuild" == "0" ] ; then
  checkValue "Global Installation Directory"
else
  checkValue "Current Working Directory"
fi
285
286
287
288
289
290
checkValue "Number of Component Extensions"
checkValue "Number of Action Extensions"
checkValue "Number of File Extensions Supported"
checkValue "Number of Actions"

exit $exitStatus