]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Add wrapper around faketime/datefudge
authorAndreas Metzler <ametzler@bebt.de>
Fri, 17 Mar 2023 17:18:46 +0000 (18:18 +0100)
committerAndreas Metzler <ametzler@bebt.de>
Tue, 4 Apr 2023 15:56:05 +0000 (17:56 +0200)
Prefer faketime, fall back to datefudge.

Signed-off-by: Andreas Metzler <ametzler@bebt.de>
tests/scripts/common.sh

index 8afc50f17fd1fd5a42312fe7d26d331f362f130c..cbc57c23c72c76eb1fbf291dd038c0c60f2f6f39 100644 (file)
@@ -109,12 +109,54 @@ check_for_datefudge() {
 }
 
 skip_if_no_datefudge() {
-       if ! check_for_datefudge; then
-               echo "You need datefudge to run this test"
-               exit 77
+       # Prefer faketime, fall back to datefudge.
+       # Allow datefudge/faketime to be manually selected by setting env-var
+       if test -z "${GNUTLS_TIMEWRAPPER_CMD}" ; then
+               if test "$WINDOWS" = 1; then
+                       exit 77
+               fi
+
+               TSTAMP=`faketime -f "2006-09-23 00:00:00" "${top_builddir}/tests/datefudge-check" || true`
+               if test "$TSTAMP" = "1158969600"; then
+                       GNUTLS_TIMEWRAPPER_CMD=faketime
+               else
+                       TSTAMP=`datefudge -s "2006-09-23 00:00:00" "${top_builddir}/tests/datefudge-check" || true`
+                       if test "$TSTAMP" = "1158969600"; then
+                               GNUTLS_TIMEWRAPPER_CMD=datefudge
+                       else
+                               echo "You need faketime/datefudge to run this test"
+                               exit 77
+                       fi
+               fi
        fi
 }
 
+gnutls_timewrapper_standalone() {
+       if test -z "${GNUTLS_TIMEWRAPPER_CMD}" ; then
+               echo "Missing invocation of skip_if_no_datefudge()"
+               exit 1
+       fi
+
+       if [ "$1" = "static" ] ; then
+               shift
+               case  ${GNUTLS_TIMEWRAPPER_CMD} in
+                       faketime)
+                               faketime -f "$@"
+                               ;;
+                       datefudge)
+                               datefudge -s "$@"
+                               ;;
+                       *)
+                               echo "GNUTLS_TIMEWRAPPER_CMD ${GNUTLS_TIMEWRAPPER_CMD} invalid" 1>&2
+                               exit 1
+                               ;;
+               esac
+       else
+               ${GNUTLS_TIMEWRAPPER_CMD} "$@"
+       fi
+}
+
+
 fail() {
    PID="$1"
    shift