#!/bin/sh
# autopkgtest check: Build and run the mbedtls "selftest" program

set -e

# Require $ADTTMP for temporary build files
if [ -z "$ADTTMP" ]
then
	echo "Required envvar \"$ADTTMP\"is not set" >&2
	exit 1
fi

# Build mbedtls_selftest shared / statically
cc -Wall -Werror programs/test/selftest.c -o "$ADTTMP/mbedtls_selftest" -lmbedtls -lmbedx509 -lmbedcrypto
echo "build1: OK"
cc -Wall -Werror -static programs/test/selftest.c -o "$ADTTMP/mbedtls_selftest_static" -lmbedtls -lmbedx509 -lmbedcrypto -pthread
echo "build2: OK"

# Run the testsuite twice
"$ADTTMP/mbedtls_selftest"
echo "run1: OK"
"$ADTTMP/mbedtls_selftest_static"
echo "run2: OK"
