Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ matrix:
- env: JOB=toxcore ENV=windows ARCH=x86_64
services:
- docker
- env: JOB=toxcore ENV=freebsd
dist: trusty
sudo: required
fast_finish: true

addons:
Expand Down Expand Up @@ -46,6 +49,7 @@ cache:
- $HOME/.cabal
- $HOME/.ghc
- $HOME/cache
- /opt/freebsd/cache

install: other/travis/phase $JOB $ENV install
script: other/travis/phase $JOB $ENV script
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_flag("-Wno-sign-compare")
add_flag("-Wno-sign-conversion")
add_flag("-Wno-tautological-constant-out-of-range-compare")
# Our use of mutexes results in a false positive, see 1bbe446
add_flag("-Wno-thread-safety-analysis")
add_flag("-Wno-type-limits")
add_flag("-Wno-undef")
add_flag("-Wno-unreachable-code")
Expand Down
34 changes: 34 additions & 0 deletions other/travis/env-freebsd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

CMAKE=cmake
# Asan is disabled because it's currently broken in FreeBSD 11.
# We should try enabling it in the next FreeBSD release and see if it works.
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DASAN=OFF"
NPROC=`nproc`
CURDIR=/root
RUN_TESTS=true
MAKE=gmake
# A lot of tests fail and run for the full 2 minutes allowed, resulting in
# Travis build timing out, so we restrict it to just 1 test run until enough
# tests are fixed so that they succeed and don't run the full 2 minutes.
MAX_TEST_RETRIES=1

SCREEN_SESSION=freebsd
SSH_PORT=10022

RUN() {
ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p $SSH_PORT "$@"
}

TESTS() {
COUNT="$1"; shift
RUN "$@" || {
if [ $COUNT -gt 1 ]; then
TESTS `expr $COUNT - 1` "$@"
else
# FIXME: We allow the tests to fail for now, but this should be changed to
# "false" once we fix tests under FreeBSD
true
fi
}
}
1 change: 1 addition & 0 deletions other/travis/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export PKG_CONFIG_PATH=$CACHE_DIR/lib/pkgconfig
export ASTYLE=$CACHE_DIR/astyle/build/gcc/bin/astyle
export CFLAGS="-O3 -DTRAVIS_ENV=1"
export CMAKE_EXTRA_FLAGS="-DERROR_ON_WARNING=ON -DBUILD_NTOX=ON"
export MAKE=make

BUILD_DIR=_build
MAX_TEST_RETRIES=3
Expand Down
263 changes: 263 additions & 0 deletions other/travis/freebsd-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
#!/bin/sh

# Travis doesn't provide FreeBSD machines, so we just take a Linux one and run
# FreeBSD in qemu virtual machine. qemu is being ran in curses mode inside a
# screen session, because screen allows to easily send input and read output.
# The input is sent using `screen -S session-name -X stuff ...` and the output
# is read from the screen's log file. Note that for some reason you can't send
# long input lines on Travis (it works just fine when I do it on my machine...),
# but that limitation is not an issue, as we don't really need to send long
# lines of input anyway. Also, note that since we run qemu in curses mode, the
# output contains control characters intended for a terminal emulator telling
# how to position and color the text, so it might be a little tricky to read it
# sometimes. The only time when this script has to send input to and read the
# output from the screen session is during the initial setup when we setup the
# network, install and configure the ssh server, and update the system. After
# this initial setup, ssh is used to communicate with the FreeBSD running in the
# VM, which is a lot friendlier way of communication. Please note that Travis
# doesn't seem to allow KVM passthrough, so qemu has to emulate all the
# hardware, which makes it quite slow compared to the host machine. We cache
# the qemu image since it takes a long time to run the initial system and
# package updates, and we do incremental system and package updates on every
# change to the list of git tags (i.e. on every toxcore release, presumably).

sudo apt-get install -y qemu

git tag -l --sort=version:refname > GIT_TAGS

OLD_PWD="$PWD"

mkdir -p /opt/freebsd/cache
cd /opt/freebsd/cache

# Make sure to update DL_SHA512 when bumping the version
FREEBSD_VERSION="11.1"
IMAGE_NAME=FreeBSD-${FREEBSD_VERSION}-RELEASE-amd64.raw

# Sends keys to the VM as they are
send_keys()
{
screen -S $SCREEN_SESSION -X stuff "$1"
}

# Blocks until a specific text appears on VM's screen
wait_for()
{
while ! grep -q "$1" screenlog.0
do
sleep 1
done
}

# Starts VM and waits until it's fully running (until a login prompt is shown)
start_vm()
{
rm -f screenlog.0

# Start emulator. 2000mb RAM should be enough, right? The build machine has over 7gb.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, and it's very good to know how much RAM we're using during the build. If this increases beyond the 2G in the VM, we may be doing something dodgy.

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

# Wait for the boot screen options
wait_for "Autoboot in"

# Select the 1st option
send_keys '
'

# Wait for the system to boot and present the login prompt
wait_for "FreeBSD/amd64 ("
}

# Shuts VM down and waits until its process finishes
stop_vm()
{
# Turn it off
RUN poweroff

# Wait for qemu process to terminate
while ps aux | grep qemu | grep -vq grep
do
sleep 1
done
}

# Let's see what's in the cache directory
ls -lh

# === Get the VM running, configured to run ssh server and updated ===

# Create image if it's not cached
if [ ! -f ./$IMAGE_NAME.tgz ]; then

rm -rf ./*

# https://download.freebsd.org/ftp/releases/VM-IMAGES/11.1-RELEASE/amd64/Latest/
DL_SHA512="c569776334131fdc85cd25a2a0d5aecafdc3e4b2e6e010dffaa2488d934293ce4f091f23481079dd91ad20dfd2dfc3d3487707096c59448f1d8914c5d7d6b582"
# Selecting random mirror from https://www.freebsd.org/doc/handbook/mirrors-ftp.html
# Note that not all mirrors listed on that page are working, so we have removed them
# I'm so sorry, there are no arrays in sh and we are not using bash...
DL_MIRROR_1=1
DL_MIRROR_2=4
DL_MIRROR_3=5
DL_MIRROR_4=6
DL_MIRROR_5=8
DL_MIRROR_6=10
DL_MIRROR_7=14
DL_MIRROR_8=15
# There are 8 mirrors
DL_MIRROR_RANDOM=`expr $(date +%s) % 8 + 1`
DL_URL=ftp://ftp$(eval echo \$DL_MIRROR_$DL_MIRROR_RANDOM).us.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/${FREEBSD_VERSION}-RELEASE/amd64/Latest/${IMAGE_NAME}.xz

wget $DL_URL

if ! ( echo "$DL_SHA512 $IMAGE_NAME.xz" | sha512sum -c --status - ) ; then
echo "Error: sha512 of $IMAGE_NAME.xz doesn't match the known one"
exit 1
fi

unxz $IMAGE_NAME.xz

# With this we don't have to guess how long a command will run for and sleeping
# for that amount of time, risking either under sleeping or over sleeping, instead
# we will sleep exactly until the command is finished by printing out a unique
# string after the command is executed and then checking if it was printed.
execute_shell_and_wait()
{
# $RANDOM is a bash built-in, so we try to avoid name collision here by using ugly RANDOM_STR name
RANDOM_STR=$(< /dev/urandom tr -dc _A-Za-z0-9 | head -c16)
send_keys "$1;echo $RANDOM_STR

"
# \[1B is a control escape sequence for a new line in the terminal.
# We want to wait for <new-line>$RANDOM_STR instead of just $RANDOM_STR because
# $RANDOM_STR we have inputted with send_keys above would appear in the screenlog.0
# file and we don't want to match our input, we want to match the echo's output.
# The .\? optionally matches any character. Sometimes it happens that there is some
# random character inserved between the new line control escape sequence and $RANDOM_STR.
wait_for "\[1B.\?$RANDOM_STR"
}

start_vm

# Login as root user
send_keys 'root

'

# Wait for the prompt
wait_for "root@:~"

# Configure network, ssh and start changing password
execute_shell_and_wait 'echo "ifconfig_em0=DHCP" >> /etc/rc.conf'
execute_shell_and_wait 'echo "Port 22" >> /etc/ssh/sshd_config'
execute_shell_and_wait 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'
execute_shell_and_wait 'echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config'
execute_shell_and_wait 'echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config'
execute_shell_and_wait 'echo "sshd_enable=YES" >> /etc/rc.conf'
send_keys 'sh /etc/rc.d/netif restart && sh /etc/rc.d/sshd start && passwd
'

# Wait for the password prompt
wait_for "Changing local password for root"

# Reset password to empty for the passwordless ssh to work
send_keys '
'
wait_for "New Password"
send_keys '
'

# Update system
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron fetch
# It fails if there is nothing to install, so we make it always succeed with true
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron install || true

# Update packages
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES pkg upgrade

# Install and set bash as the default shell for the root user
RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES pkg install bash
RUN chsh -s /usr/local/bin/bash root

# Install required toxcore dependencies
RUN PAGER=cat ASSUME_ALWAYS_YES=YES pkg install git \
opus \
libvpx \
libsodium \
gmake \
cmake \
pkgconf \
check \
opencv \
portaudio \
libsndfile \
texinfo \
autotools

# === Cache the VM image ===

stop_vm

# Create cache
tar -Sczvf $IMAGE_NAME.tgz $IMAGE_NAME
rm screenlog.0

cp "$OLD_PWD/GIT_TAGS" .

ls -lh
fi

if [ ! -f ./$IMAGE_NAME ]; then
# Extract the cached image
tar -Sxzvf $IMAGE_NAME.tgz
fi

# === Update the image on new version (tag) of toxcore ===
if ! diff -u ./GIT_TAGS "$OLD_PWD/GIT_TAGS" ; then
start_vm

# Update system
RUN PAGER=cat ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron fetch
RUN PAGER=cat ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron install || true

# Update packages
RUN PAGER=cat ASSUME_ALWAYS_YES=YES pkg upgrade

# === Cache the updated VM image ===

stop_vm

# Create/Update cache
rm $IMAGE_NAME.tgz
tar -Sczvf $IMAGE_NAME.tgz $IMAGE_NAME
rm screenlog.0

cp "$OLD_PWD/GIT_TAGS" .

ls -lh
fi

# Get the image we will be using out of the cached directory
mv $IMAGE_NAME ..
ls -lh

cd ..

ls -lh

# === Get VM ready to build the code ===

start_vm

# Display FreeBSD kernel info and last login
RUN uname -a
RUN last

cd "$OLD_PWD"

# Copy over toxcore code from Travis to qemu
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P $SSH_PORT -r ./* root@localhost:~

RUN ls -lh
6 changes: 3 additions & 3 deletions other/travis/toxcore-script
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for i in `seq 0 7`; do
set_opt ENABLE_SHARED
set -x
RUN $CMAKE -B$BUILD_DIR -H. $opts
rm -rf $BUILD_DIR
RUN rm -rf $BUILD_DIR
done

# Build toxcore and run tests.
Expand All @@ -36,7 +36,7 @@ RUN $CMAKE \

export CTEST_OUTPUT_ON_FAILURE=1

RUN make -C$BUILD_DIR -j$NPROC -k install
RUN $MAKE -C$BUILD_DIR -j$NPROC -k install
if $RUN_TESTS; then
TESTS $MAX_TEST_RETRIES make -C$BUILD_DIR -j$NPROC test ARGS="--rerun-failed"
TESTS $MAX_TEST_RETRIES $MAKE -C$BUILD_DIR -j$NPROC test ARGS="--rerun-failed" CTEST_OUTPUT_ON_FAILURE="$CTEST_OUTPUT_ON_FAILURE"
fi
4 changes: 4 additions & 0 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <assert.h>


#if !defined(INADDR_LOOPBACK)
#define INADDR_LOOPBACK 0x7f000001
#endif

static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata);
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length, uint8_t congestion_control);
Expand Down
3 changes: 2 additions & 1 deletion toxcore/TCP_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#include <sys/epoll.h>
#endif

#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MACH__)
// Disable MSG_NOSIGNAL on systems not supporting it, e.g. Windows, FreeBSD
#if !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
#endif

Expand Down
2 changes: 1 addition & 1 deletion toxcore/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Logger {
/**
* Public Functions
*/
Logger *logger_new()
Logger *logger_new(void)
{
return (Logger *)calloc(1, sizeof(Logger));
}
Expand Down
2 changes: 1 addition & 1 deletion toxcore/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef void logger_cb(void *context, LOGGER_LEVEL level, const char *file, int
/**
* Creates a new logger with logging disabled (callback is NULL) by default.
*/
Logger *logger_new();
Logger *logger_new(void);

void logger_kill(Logger *log);

Expand Down