From 6f6ba250b0d3ddd3dd2967b3f1ed487f03e0b570 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 17 Sep 2021 15:01:34 -0700 Subject: [PATCH] test: add TestExpectedSeccompVersion This is to ensure we're testing against the expected libseccomp version (as prepared by CI, which sets the _EXPECTED_LIBSECCOMP_VERSION var). Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 8 +++++++- seccomp_test.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eced00e..0ef80d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,7 +51,11 @@ jobs: # - chances are good such version won't ever exist; # - it is easy to spot in tests output; # - the LIBFILE pattern below expects single digits. - sed -i '/^AC_INIT(/s/0\.0\.0/9.9.9/' configure.ac + VER="${{ matrix.libseccomp }}" + if [ "$VER" == "HEAD" ]; then + VER=9.9.9 + sed -i "/^AC_INIT(/s/0\.0\.0/$VER/" configure.ac + fi ./autogen.sh ./configure --prefix="$PREFIX" --libdir="$LIBDIR" make @@ -63,6 +67,8 @@ jobs: echo "PKG_CONFIG_LIBDIR=$LIBDIR/pkgconfig" >> $GITHUB_ENV LIBFILE="$(echo $LIBDIR/libseccomp.so.?.?.?)" echo "LD_PRELOAD=$LIBFILE" >> $GITHUB_ENV + # For TestExpectedSeccompVersion. + echo "_EXPECTED_LIBSECCOMP_VERSION=$VER" >> $GITHUB_ENV - name: build run: make check-build diff --git a/seccomp_test.go b/seccomp_test.go index e5896a7..52af6e8 100644 --- a/seccomp_test.go +++ b/seccomp_test.go @@ -42,6 +42,27 @@ func execInSubprocess(t *testing.T, f func(t *testing.T)) { } } +func TestExpectedSeccompVersion(t *testing.T) { + execInSubprocess(t, subprocessExpectedSeccompVersion) +} + +func subprocessExpectedSeccompVersion(t *testing.T) { + // This environment variable can be set by CI. + const name = "_EXPECTED_LIBSECCOMP_VERSION" + + expVer := os.Getenv(name) + if expVer == "" { + t.Skip(name, "not set") + } + expVer = strings.TrimPrefix(expVer, "v") + + curVer := fmt.Sprintf("%d.%d.%d", verMajor, verMinor, verMicro) + t.Logf("testing against libseccomp %s", curVer) + if curVer != expVer { + t.Fatalf("libseccomp version mismatch: must be %s, got %s", expVer, curVer) + } +} + // Type Function Tests func APILevelIsSupported() bool {