summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--other/travis/env-freebsd.sh28
-rw-r--r--other/travis/env.sh1
-rwxr-xr-xother/travis/freebsd-install221
-rwxr-xr-xother/travis/toxcore-script4
5 files changed, 256 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index 70c04572..2b41b2d2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,6 +14,9 @@ matrix:
14 - env: JOB=toxcore ENV=windows ARCH=x86_64 14 - env: JOB=toxcore ENV=windows ARCH=x86_64
15 services: 15 services:
16 - docker 16 - docker
17 - env: JOB=toxcore ENV=freebsd
18 dist: trusty
19 sudo: required
17 fast_finish: true 20 fast_finish: true
18 21
19addons: 22addons:
@@ -46,6 +49,7 @@ cache:
46 - $HOME/.cabal 49 - $HOME/.cabal
47 - $HOME/.ghc 50 - $HOME/.ghc
48 - $HOME/cache 51 - $HOME/cache
52 - /opt/freebsd/cache
49 53
50install: other/travis/phase $JOB $ENV install 54install: other/travis/phase $JOB $ENV install
51script: other/travis/phase $JOB $ENV script 55script: other/travis/phase $JOB $ENV script
diff --git a/other/travis/env-freebsd.sh b/other/travis/env-freebsd.sh
new file mode 100644
index 00000000..2c391649
--- /dev/null
+++ b/other/travis/env-freebsd.sh
@@ -0,0 +1,28 @@
1#!/bin/sh
2
3CMAKE=cmake
4# Asan is disabled because it's currently broken in FreeBSD 11.
5# We should try enabling it in the next FreeBSD release and see if it works.
6CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DASAN=OFF"
7NPROC=`nproc`
8CURDIR=/root
9RUN_TESTS=true
10MAKE=gmake
11
12SCREEN_SESSION=freebsd
13SSH_PORT=10022
14
15RUN() {
16 ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p $SSH_PORT "$@"
17}
18
19TESTS() {
20 COUNT="$1"; shift
21 RUN "$@" || {
22 if [ $COUNT -gt 1 ]; then
23 TESTS `expr $COUNT - 1` "$@"
24 else
25 false
26 fi
27 }
28}
diff --git a/other/travis/env.sh b/other/travis/env.sh
index 4899ec25..aeb00c82 100644
--- a/other/travis/env.sh
+++ b/other/travis/env.sh
@@ -8,6 +8,7 @@ export PKG_CONFIG_PATH=$CACHE_DIR/lib/pkgconfig
8export ASTYLE=$CACHE_DIR/astyle/build/gcc/bin/astyle 8export ASTYLE=$CACHE_DIR/astyle/build/gcc/bin/astyle
9export CFLAGS="-O3 -DTRAVIS_ENV=1" 9export CFLAGS="-O3 -DTRAVIS_ENV=1"
10export CMAKE_EXTRA_FLAGS="-DERROR_ON_WARNING=ON -DBUILD_NTOX=ON" 10export CMAKE_EXTRA_FLAGS="-DERROR_ON_WARNING=ON -DBUILD_NTOX=ON"
11export MAKE=make
11 12
12BUILD_DIR=_build 13BUILD_DIR=_build
13MAX_TEST_RETRIES=3 14MAX_TEST_RETRIES=3
diff --git a/other/travis/freebsd-install b/other/travis/freebsd-install
new file mode 100755
index 00000000..b9562e2c
--- /dev/null
+++ b/other/travis/freebsd-install
@@ -0,0 +1,221 @@
1#!/bin/sh
2
3# Travis doesn't provide FreeBSD machines, so we just take a Linux one and run
4# FreeBSD in qemu virtual machine. qemu is being ran in curses mode inside a
5# screen session, because screen allows to easily send input and read output.
6# The input is sent using `screen -S session-name -X stuff ...` and the output
7# is read from the screen's log file. Note that for some reason you can't send
8# long input lines on Travis (it works just fine when I do it on my machine...),
9# but that limitation is not an issue, as we don't really need to send long
10# lines of input anyway. Also, note that since we run qemu in curses mode, the
11# output contains control characters intended for a terminal emulator telling
12# how to position and color the text, so it might be a little tricky to read it
13# sometimes. The only time when this script has to send input to and read the
14# output from the screen session is during the initial setup when we setup the
15# network, install and configure the ssh server, and update the system. After
16# this initial setup, ssh is used to communicate with the FreeBSD running in the
17# VM, which is a lot friendlier way of communication. Please note that Travis
18# doesn't seem to allow KVM passthrough, so qemu has to emulate all the
19# hardware, which makes it quite slow compared to the host machine. We cache
20# the qemu image since it takes a long time to run the initial system and
21# pacakge updates, and we update packages and the system on every job run.
22
23sudo apt-get install qemu -y
24
25OLD_PWD="$PWD"
26
27mkdir -p /opt/freebsd/cache
28cd /opt/freebsd/cache
29
30IMAGE_NAME=FreeBSD-11.0-RELEASE-amd64.raw
31
32# Sends keys to the VM as they are
33send_keys()
34{
35 screen -S $SCREEN_SESSION -X stuff "$1"
36}
37
38# Runs until a specific text appears on VM's screen
39wait_for()
40{
41 while ! grep "$1" screenlog.0 -q
42 do
43 sleep 1
44 done
45}
46
47# Starts VM and waits until it's fully running (until a login prompt is shown)
48start_vm()
49{
50 rm -f screenlog.0
51
52 # Start emulator. 2000mb RAM should be enough, right? The build machine has over 7gb.
53 screen -L -S $SCREEN_SESSION -d -m qemu-system-x86_64 -curses -m 2000 -smp $NPROC -net user,hostfwd=tcp::${SSH_PORT}-:22 -net nic $IMAGE_NAME
54
55 # Wait for the boot screen options
56 wait_for "Autoboot in"
57
58 # Select the 1st option
59 send_keys '
60'
61
62 # Wait for the system to boot and present the login prompt
63 wait_for "FreeBSD/amd64 ("
64}
65
66# Let's see what's in the cache directory
67ls -lh
68
69# === Get the VM running, configured to run ssh server and updated ===
70
71# Create image if it's not cached
72if [ ! -f ./$IMAGE_NAME.tgz ]; then
73
74 # https://download.freebsd.org/ftp/releases/VM-IMAGES/11.0-RELEASE/amd64/Latest/
75 DL_SHA512="1bfdef9a106e41134cf92c5ceb7f7da468293d6611d16c0bc51482a8fb3088064204bacfe6a8b1afda169d9ab63e4bbd1c9ba1de06fe3fd604864d3fb0c07326"
76 # Selecting random mirror from https://www.freebsd.org/doc/handbook/mirrors-ftp.html
77 # Note that not all mirrors listed on that page are working, so we have removed them
78 # I'm so sorry, there are no arrays in sh and we are not using bash...
79 DL_MIRROR_1=1
80 DL_MIRROR_2=4
81 DL_MIRROR_3=5
82 DL_MIRROR_4=6
83 DL_MIRROR_5=8
84 DL_MIRROR_6=10
85 DL_MIRROR_7=14
86 DL_MIRROR_8=15
87 # There are 8 mirrors
88 DL_MIRROR_RANDOM=`expr $(date +%s) % 8 + 1`
89 DL_URL=ftp://ftp$(eval echo \$DL_MIRROR_$DL_MIRROR_RANDOM).us.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/11.0-RELEASE/amd64/Latest/${IMAGE_NAME}.xz
90
91 wget $DL_URL
92
93 if ! ( echo "$DL_SHA512 $IMAGE_NAME.xz" | sha512sum -c --status - ) ; then
94 echo "Error: sha512 of $IMAGE_NAME.xz doesn't match the known one"
95 exit 1
96 fi
97
98 unxz $IMAGE_NAME.xz
99
100 # With this we don't have to guess how long a command will run for and sleeping
101 # for that amount of time, risking either under sleeping or over sleeping, instead
102 # we will sleep exactly until the command is finished by printing out a unique
103 # string after the command is executed and then checking if it was printed.
104 execute_shell_and_wait()
105 {
106 # $RANDOM is a bash built-in, so we try to avoid name collision here by using ugly RANDOM_STR name
107 RANDOM_STR=$(< /dev/urandom tr -dc _A-Za-z0-9 | head -c16)
108 send_keys "$1;echo $RANDOM_STR
109
110"
111 # \[1B is a control escape sequence for a new line in the terminal.
112 # We want to wait for <new-line>$RANDOM_STR instead of just $RANDOM_STR because
113 # $RANDOM_STR we have inputted with send_keys above would appear in the screenlog.0
114 # file and we don't want to much our input.
115 # The .\? optionally matches any character. Sometimes it happens that there is some
116 # random character inserved between the new line control escape sequence and $RANDOM_STR.
117 wait_for "\[1B.\?$RANDOM_STR"
118 }
119
120 start_vm
121
122 # Login as root user
123 send_keys 'root
124
125'
126
127 # Wait for the prompt
128 wait_for "root@:~"
129
130 # Configure network, ssh and start changing password
131 execute_shell_and_wait 'echo "ifconfig_em0=DHCP" >> /etc/rc.conf'
132 execute_shell_and_wait 'echo "Port 22" >> /etc/ssh/sshd_config'
133 execute_shell_and_wait 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'
134 execute_shell_and_wait 'echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config'
135 execute_shell_and_wait 'echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config'
136 execute_shell_and_wait 'echo "sshd_enable=YES" >> /etc/rc.conf'
137 send_keys 'sh /etc/rc.d/netif restart && sh /etc/rc.d/sshd start && passwd
138'
139
140 # Wait for the password prompt
141 wait_for "Changing local password for root"
142
143 # Reset password to empty for the passwordless ssh to work
144 send_keys '
145'
146 wait_for "New Password"
147 send_keys '
148'
149
150 # Update system
151 RUN freebsd-update --not-running-from-cron fetch
152 # It fails if there is nothing to install, so we make it always succeed with true
153 RUN freebsd-update --not-running-from-cron install || true
154
155 # Update packages
156 RUN env ASSUME_ALWAYS_YES=YES pkg upgrade
157
158 # Install and set bash as the default shell for the root user
159 RUN env ASSUME_ALWAYS_YES=YES pkg install bash
160 RUN chsh -s /usr/local/bin/bash root
161
162 # Install required toxcore dependencies
163 RUN ASSUME_ALWAYS_YES=YES pkg install git opus libvpx libsodium gmake cmake pkgconf libcheck opencv2 portaudio libsndfile texinfo autotools
164
165else
166
167 # Extract the cached image
168 tar -Sxzvf $IMAGE_NAME.tgz
169 rm $IMAGE_NAME.tgz
170
171 start_vm
172
173# TODO: Figure out if the system and packages were indeed updated, if not, then
174# there is no need to update the image stored in Travis's cache. This can
175# make the build finish ~4 minutes faster.
176
177 # Update system
178 RUN freebsd-update --not-running-from-cron fetch
179 RUN freebsd-update --not-running-from-cron install || true
180
181 # Update packages
182 RUN ASSUME_ALWAYS_YES=YES pkg upgrade
183
184fi
185
186# === Cache the updated VM image ===
187
188# Turn it off
189RUN poweroff
190
191# Wait for qemu process to terminate
192while ps aux | grep qemu | grep -vq grep
193do
194 sleep 1
195done
196
197# Create/Update cache
198tar -Sczvf $IMAGE_NAME.tgz $IMAGE_NAME
199# Get the image we wil lbe using out of the cached directory
200mv $IMAGE_NAME ..
201rm screenlog.0
202ls -lh
203
204cd ..
205
206ls -lh
207
208# === Get VM ready to build the code ===
209
210start_vm
211
212# Display FreeBSD kernel info and last login
213RUN uname -a
214RUN last
215
216cd "$OLD_PWD"
217
218# Copy over toxcore code from Travis to qemu
219scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P $SSH_PORT -r ./* root@localhost:~
220
221RUN ls -lh
diff --git a/other/travis/toxcore-script b/other/travis/toxcore-script
index 2154d558..e8d31d4e 100755
--- a/other/travis/toxcore-script
+++ b/other/travis/toxcore-script
@@ -19,7 +19,7 @@ for i in `seq 0 7`; do
19 set_opt ENABLE_SHARED 19 set_opt ENABLE_SHARED
20 set -x 20 set -x
21 RUN $CMAKE -B$BUILD_DIR -H. $opts 21 RUN $CMAKE -B$BUILD_DIR -H. $opts
22 rm -rf $BUILD_DIR 22 RUN rm -rf $BUILD_DIR
23done 23done
24 24
25# Build toxcore and run tests. 25# Build toxcore and run tests.
@@ -36,7 +36,7 @@ RUN $CMAKE \
36 36
37export CTEST_OUTPUT_ON_FAILURE=1 37export CTEST_OUTPUT_ON_FAILURE=1
38 38
39RUN make -C$BUILD_DIR -j$NPROC -k install 39RUN $MAKE -C$BUILD_DIR -j$NPROC -k install
40if $RUN_TESTS; then 40if $RUN_TESTS; then
41 TESTS $MAX_TEST_RETRIES make -C$BUILD_DIR -j$NPROC test ARGS="--rerun-failed" 41 TESTS $MAX_TEST_RETRIES make -C$BUILD_DIR -j$NPROC test ARGS="--rerun-failed"
42fi 42fi