.travis-functions.sh 2.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/bin/bash
#
# .travis-functions.sh:
#   - helper functions to be sourced from .travis.yml
#   - designed to respect travis' environment but testing locally is possible
#   - modified copy from util-linux project
#

if [ ! -f "configure.ac" ]; then
	echo ".travis-functions.sh must be sourced from source dir" >&2
	return 1 || exit 1
fi

## some config settings
# travis docs say we get 1.5 CPUs
MAKE="make -j2"
DUMP_CONFIG_LOG="short"
export TS_OPT_parsable="yes"

function configure_travis
{
	./configure "$@"
	err=$?
	if [ "$DUMP_CONFIG_LOG" = "short" ]; then
		grep -B1 -A10000 "^## Output variables" config.log | grep -v "_FALSE="
	elif [ "$DUMP_CONFIG_LOG" = "full" ]; then
		cat config.log
	fi
	return $err
}

32 33 34 35 36 37 38 39
function check_nonroot
{
	local cfg_opts="$1"

	[ -z "$cfg_opts" ] && return

	configure_travis \
		--enable-cryptsetup-reencrypt \
40
		--enable-internal-sse-argon2 \
41 42 43 44 45
		"$cfg_opts" \
		|| return

	$MAKE || return

46
	make check
47 48
}

49 50 51 52 53 54
function check_root
{
	local cfg_opts="$1"

	[ -z "$cfg_opts" ] && return

55
    configure_travis \
56
		--enable-cryptsetup-reencrypt \
57
		--enable-internal-sse-argon2 \
58 59 60 61 62 63
		"$cfg_opts" \
		|| return

	$MAKE || return

	# FIXME: we should use -E option here
64
	sudo make check
65 66
}

67 68 69 70 71 72 73 74
function check_nonroot_compile_only
{
	local cfg_opts="$1"

	[ -z "$cfg_opts" ] && return

	configure_travis \
		--enable-cryptsetup-reencrypt \
75
		--enable-internal-sse-argon2 \
76 77 78 79 80 81
		"$cfg_opts" \
		|| return

	$MAKE
}

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
function travis_install_script
{
	# install some packages from Ubuntu's default sources
	sudo apt-get -qq update
	sudo apt-get install -qq >/dev/null \
		sharutils \
		libgcrypt20-dev \
		libssl-dev \
		libdevmapper-dev \
		libpopt-dev \
		uuid-dev \
		libsepol1-dev \
		libtool \
		dmsetup \
		autoconf \
		automake \
		pkg-config \
		autopoint \
		gettext \
Milan Broz's avatar
Milan Broz committed
101
		expect \
102
		keyutils \
103
		libjson-c-dev \
104
		libblkid-dev \
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
		|| return
}

function travis_before_script
{
	set -o xtrace

	./autogen.sh
	ret=$?

	set +o xtrace
	return $ret
}

function travis_script
{
	local ret
	set -o xtrace

	case "$MAKE_CHECK" in
	gcrypt)
126
		check_nonroot "--with-crypto_backend=gcrypt" && \
127 128
		check_root "--with-crypto_backend=gcrypt"
		;;
129 130 131
	gcrypt_compile)
		check_nonroot_compile_only "--with-crypto_backend=gcrypt"
		;;
132
	openssl)
133
		check_nonroot "--with-crypto_backend=openssl" && \
134 135
		check_root "--with-crypto_backend=openssl"
		;;
136 137 138
	openssl_compile)
		check_nonroot_compile_only "--with-crypto_backend=openssl"
		;;
139 140 141 142 143 144 145
	kernel)
		check_nonroot "--with-crypto_backend=kernel" && \
		check_root "--with-crypto_backend=kernel"
		;;
	kernel_compile)
		check_nonroot_compile_only "--with-crypto_backend=kernel"
		;;
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	*)
		echo "error, check environment (travis.yml)" >&2
		false
		;;
	esac

	ret=$?
	set +o xtrace
	return $ret
}

function travis_after_script
{
	return 0
}