sctp_lib: explicitly test for ipv6 support
Change-Id: I662138e6c9ea71cad751e2a057a642b85e6aabc7
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/network/sctp_lib_test.sh b/aos/network/sctp_lib_test.sh
new file mode 100755
index 0000000..aa3fdbc
--- /dev/null
+++ b/aos/network/sctp_lib_test.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+set -euo pipefail
+
+result=0
+verify() {
+ local thisresult=0
+ local family
+ local address
+ family=$(echo "$output" | grep -Po '\] Family [^ ]+' | cut -f3 -d' ')
+ address=$(echo "$output" | grep -Po '\] Address [^ ]+' | cut -f3 -d' ')
+ if [[ "${family}" != "${1}" ]]; then
+ echo "Expected family ${1}, got ${family}" >&2
+ thisresult=1
+ result=1
+ fi
+ if [[ ! "${address}" =~ ${2} ]]; then
+ echo "Expected address ${2}, got ${address}" >&2
+ thisresult=1
+ result=1
+ fi
+ return $thisresult
+}
+
+run_test() {
+ local has_ipv6
+ has_ipv6="${1}"
+ export has_ipv6
+ shift
+ LD_PRELOAD="${SHIM}" "${BINARY}" --host=localhost "$@" 2>&1
+}
+
+BINARY="$1"
+SHIM="$2"
+
+output=$(run_test y)
+verify AF_INET6 "(::ffff:127.0.0.1|::)" || echo "IPv6 allowed with no arguments failed" >&2
+
+output=$(run_test n)
+verify AF_INET "127\\.0\\.0\\.1" || echo "IPv6 disallowed with no arguments failed" >&2
+
+output=$(run_test y --disable_ipv6)
+verify AF_INET "127\\.0\\.0\\.1" || echo "IPv6 allowed with --disable_ipv6 failed" >&2
+
+exit $result