From 89f49269f64728739b82bb8cd49ca12f144dfedb Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 28 Sep 2017 18:57:33 +0000 Subject: [PATCH] tests/libostreetest: check $PWD not / for overlay This was originally part of #1199, but never got in. The work in #1218 is awesome for CI, though for the developer workflow, I find it much easier to just set $TEST_TMPDIR to a non-overlayfs mount point. Teach the test libraries to just look at $PWD rather than /. Also export the function that does the overlayfs checking. Prep for a future patch. Closes: #1170 Approved by: cgwalters --- tests/libostreetest.c | 47 ++++++++++++++++++++++++++++--------------- tests/libostreetest.h | 3 +++ tests/libtest.sh | 2 +- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/tests/libostreetest.c b/tests/libostreetest.c index 6186a73a13..d3a2651018 100644 --- a/tests/libostreetest.c +++ b/tests/libostreetest.c @@ -72,6 +72,23 @@ ot_test_setup_repo (GCancellable *cancellable, return g_steal_pointer (&ret_repo); } +gboolean +ot_check_for_overlay (gboolean *on_overlay, + GError **error) +{ + /* Keep this in sync with the overlayfs bits in libtest.sh */ + struct statfs stbuf; + const char *pwd = g_getenv ("PWD"); + g_assert (pwd); + if (statfs (pwd, &stbuf) < 0) + return glnx_throw_errno (error); +#ifndef OVERLAYFS_SUPER_MAGIC +#define OVERLAYFS_SUPER_MAGIC 0x794c7630 +#endif + *on_overlay = (stbuf.f_type == OVERLAYFS_SUPER_MAGIC); + return TRUE; +} + OstreeSysroot * ot_test_setup_sysroot (GCancellable *cancellable, GError **error) @@ -79,22 +96,20 @@ ot_test_setup_sysroot (GCancellable *cancellable, if (!ot_test_run_libtest ("setup_os_repository \"archive\" \"syslinux\"", error)) return FALSE; - struct statfs stbuf; - { g_autoptr(GString) buf = g_string_new ("mutable-deployments"); - if (statfs ("/", &stbuf) < 0) - return glnx_null_throw_errno (error); - /* Keep this in sync with the overlayfs bits in libtest.sh */ -#ifndef OVERLAYFS_SUPER_MAGIC -#define OVERLAYFS_SUPER_MAGIC 0x794c7630 -#endif - if (stbuf.f_type == OVERLAYFS_SUPER_MAGIC) - { - g_print ("libostreetest: detected overlayfs\n"); - g_string_append (buf, ",no-xattrs"); - } - /* Make sure deployments are mutable */ - g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE); - } + /* Keep this in sync with the overlayfs bits in libtest.sh */ + gboolean on_overlay; + if (!ot_check_for_overlay (&on_overlay, error)) + return FALSE; + + g_autoptr(GString) buf = g_string_new ("mutable-deployments"); + if (on_overlay) + { + g_print ("libostreetest: detected overlayfs\n"); + g_string_append (buf, ",no-xattrs"); + } + + /* Make sure deployments are mutable */ + g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE); g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot"); return ostree_sysroot_new (sysroot_path); diff --git a/tests/libostreetest.h b/tests/libostreetest.h index d5512d553e..274b7b1747 100644 --- a/tests/libostreetest.h +++ b/tests/libostreetest.h @@ -31,6 +31,9 @@ gboolean ot_test_run_libtest (const char *cmd, GError **error); OstreeRepo *ot_test_setup_repo (GCancellable *cancellable, GError **error); +gboolean ot_check_for_overlay (gboolean *on_overlay, + GError **error); + OstreeSysroot *ot_test_setup_sysroot (GCancellable *cancellable, GError **error); diff --git a/tests/libtest.sh b/tests/libtest.sh index 6993629d6d..1ca179c3f7 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -73,7 +73,7 @@ export OSTREE_GPG_HOME=${test_tmpdir}/gpghome/trusted # See comment in ot-builtin-commit.c and https://github.com/ostreedev/ostree/issues/758 # Also keep this in sync with the bits in libostreetest.c echo evaluating for overlayfs... -case $(stat -f --printf '%T' /) in +case $(stat -f --printf '%T' $PWD) in overlayfs) echo "overlayfs found; enabling OSTREE_NO_XATTRS" export OSTREE_SYSROOT_DEBUG="${OSTREE_SYSROOT_DEBUG},no-xattrs"