]> git.ipfire.org Git - thirdparty/util-linux.git/blob - .travis-functions.sh
build-sys: cleanup prefixed used for tests
[thirdparty/util-linux.git] / .travis-functions.sh
1 #!/bin/bash
2
3 #
4 # .travis-functions.sh:
5 # - helper functions to be sourced from .travis.yml
6 # - designed to respect travis' environment but testing locally is possible
7 #
8 # Variables:
9 #
10 # TS_OPT_<name>_<something>=yes
11 # - forces tests/functions.sh:ts_has_option() to return "yes" for
12 # variable <something> in test <name>
13 #
14 # TESTS_OPTIONS=
15 # TESTS_PARALLEL_OPTION=
16 # TESTS_COMMAND=
17 # - overwrites default from tests/Makemodule.am
18 #
19 # Do not use TS_* prefix for any travis or build-system stuff. This prefix is
20 # exclusively used by tests/ stuff.
21 #
22
23 if [ ! -f "configure.ac" ]; then
24 echo ".travis-functions.sh must be sourced from source dir" >&2
25 return 1 || exit 1
26 fi
27
28 ## some config settings
29 # travis docs say we get 1.5 CPUs
30 MAKE="make -j2"
31 DUMP_CONFIG_LOG="short"
32 export TS_OPT_parsable="yes"
33
34 # workaround ugly warning on travis OSX,
35 # see https://github.com/direnv/direnv/issues/210
36 shell_session_update() { :; }
37
38 function xconfigure
39 {
40 which "$CC"
41 "$CC" --version
42
43 ./configure "$@" $OSX_CONFOPTS
44 err=$?
45 if [ "$DUMP_CONFIG_LOG" = "short" ]; then
46 grep -B1 -A10000 "^## Output variables" config.log | grep -v "_FALSE="
47 elif [ "$DUMP_CONFIG_LOG" = "full" ]; then
48 cat config.log
49 fi
50 return $err
51 }
52
53 # TODO: integrate checkusage into our regular tests and remove this function
54 function make_checkusage
55 {
56 local tmp
57 if ! tmp=$($MAKE checkusage 2>&1) || test -n "$tmp"; then
58 echo "$tmp"
59 echo "make checkusage failed" >&2
60 return 1
61 fi
62 }
63
64 function check_nonroot
65 {
66 local make_opts="$MAKE_CHECK_OPTS --show-diff"
67 local conf_opts="\
68 --disable-use-tty-group \
69 --disable-makeinstall-chown \
70 --enable-all-programs"
71
72 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
73 conf_opts="$conf_opts --enable-asan"
74 make_opts="$make_opts --memcheck-asan"
75 fi
76
77 xconfigure $conf_opts || return
78 $MAKE || return
79
80 osx_prepare_check
81
82 # TESTS_* overwrites default from tests/Makemodule.am
83 $MAKE check TESTS_OPTIONS="$make_opts" || return
84
85 make_checkusage || return
86
87 $MAKE install DESTDIR=/tmp/dest || return
88 }
89
90 function check_root
91 {
92 local make_opts="$MAKE_CHECK_OPTS --show-diff"
93 local conf_opts="--enable-all-programs"
94
95 if [ "$TRAVIS_OS_NAME" != "osx" ]; then
96 conf_opts="$conf_opts --enable-asan"
97 make_opts="$make_opts --memcheck-asan"
98 fi
99
100 xconfigure $conf_opts || return
101 $MAKE || return
102
103 # compile tests only
104 $MAKE check-programs || return
105
106 # Modify environment for OSX
107 osx_prepare_check
108
109 # TESTS_* overwrites default from tests/Makemodule.am
110 sudo -E $MAKE check "TESTS_PARALLEL_OPTION=--parallel=none" TESTS_OPTIONS="$make_opts" || return
111
112 # root on osx has not enough permission for make install ;)
113 [ "$TRAVIS_OS_NAME" = "osx" ] && return
114
115 # keep PATH to make sure sudo would find $CC
116 sudo env "PATH=$PATH" $MAKE install || return
117 }
118
119 function check_dist
120 {
121 xconfigure \
122 || return
123 $MAKE distcheck || return
124 }
125
126 function travis_install_script
127 {
128 if [ "$TRAVIS_OS_NAME" = "osx" ]; then
129 osx_install_script
130 return
131 fi
132
133 # install required packages
134 sudo apt-get -qq update --fix-missing
135 sudo apt-get install -qq >/dev/null \
136 bc \
137 btrfs-tools \
138 dnsutils \
139 libcap-ng-dev \
140 libncursesw5-dev \
141 libpam-dev \
142 libudev-dev \
143 gtk-doc-tools \
144 mdadm \
145 ntp \
146 socat \
147 || return
148
149 # install only if available (e.g. Ubuntu Trusty)
150 sudo apt-get install -qq >/dev/null \
151 libsystemd-daemon-dev \
152 libsystemd-journal-dev \
153 || true
154 }
155
156 function osx_install_script
157 {
158 brew update >/dev/null
159
160 brew install gettext ncurses socat xz
161 brew link --force gettext
162 brew link --force ncurses
163
164 OSX_CONFOPTS="
165 --disable-ipcrm \
166 --disable-ipcs \
167 "
168
169 # workaround: glibtoolize could not find sed
170 export SED="sed"
171 }
172
173 function osx_prepare_check
174 {
175 [ "$TRAVIS_OS_NAME" = "osx" ] || return 0
176
177 # these ones only need to be gnu for our test-suite
178 brew install coreutils findutils gnu-tar gnu-sed
179
180 # symlink minimally needed gnu commands into PATH
181 mkdir ~/bin
182 for cmd in readlink seq timeout truncate find xargs tar sed; do
183 ln -s /usr/local/bin/g$cmd $HOME/bin/$cmd
184 done
185 hash -r
186
187 export TS_OPT_col_multibyte_known_fail=yes
188 export TS_OPT_colcrt_regressions_known_fail=yes
189 export TS_OPT_column_invalid_multibyte_known_fail=yes
190 }
191
192 function travis_before_script
193 {
194 set -o xtrace
195
196 ./autogen.sh
197 ret=$?
198
199 set +o xtrace
200 return $ret
201 }
202
203 function travis_script
204 {
205 local ret
206 set -o xtrace
207
208 case "$MAKE_CHECK" in
209 nonroot)
210 check_nonroot
211 ;;
212 root)
213 check_root
214 ;;
215 dist)
216 check_dist
217 ;;
218 *)
219 echo "error, check environment (travis.yml)" >&2
220 false
221 ;;
222 esac
223
224 # We exit here with case-switch return value!
225 ret=$?
226 set +o xtrace
227 return $ret
228 }
229
230 function travis_after_script
231 {
232 local diff_dir
233 local tmp
234
235 # find diff dir from check as well as from distcheck
236 diff_dir=$(find . -type d -name "diff" | grep "tests/diff" | head -n 1)
237 if [ -d "$diff_dir" ]; then
238 tmp=$(find "$diff_dir" -type f | sort)
239 echo -en "dump test diffs:\n${tmp}\n"
240 echo "$tmp" | xargs cat
241 fi
242 }