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