#!/bin/sh
#Upstream makes use of “clknetsim” to test how well “chronyd” controls the
#system clocks in various conditions. Due to “clknetsim” not being available
#in Debian, let’s use autopkgtest facility to build it in a container and
#test “chronyd” from there.

set -e

if ! dpkg-architecture -ilinux-any; then
    echo "Simulation tests supported only on Linux…"
    exit 0
fi

cd test/simulation

if [ ! -d clknetsim ]; then
    if git clone https://github.com/mlichvar/clknetsim; then
        cd clknetsim && git checkout 58c5e8b
    fi
fi

if [ ! -x "clknetsim" ] && [ ! -e "clknetsim.so" ]; then
    make
fi

cd - && ./run -i 20 -m 2
