From: Igor Opaniuk Date: Mon, 9 Mar 2026 11:04:07 +0000 (+0100) Subject: tests: Respect TEST_TMPDIR for temporary directories X-Git-Tag: archive/raspbian/2026.2-1+rpi1^2~9^2~1^2~7^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=e2f583f56a57d024db54e501829122abd4ff531d;p=ostree.git tests: Respect TEST_TMPDIR for temporary directories Several C tests hardcoded /var/tmp as the base path for temporary working directories, ignoring the TEST_TMPDIR environment variable used by the shell test suite. This caused tests to create their ostree repos on the overlayfs filesystem even when TEST_TMPDIR points to a real filesystem, bypassing the intended workaround for overlayfs's inaccurate free-space reporting. As a result, ostree's min-free-space-percent check (default 3%) would fire when writing content objects, making tests fail in containerized environments where the rootfs is overlayfs. Fix by reading TEST_TMPDIR at runtime and falling back to /var/tmp when it is not set, consistent with how the shell test suite handles this. Affected tests: - tests/test-libarchive-import.c - tests/test-basic-c.c Signed-off-by: Igor Opaniuk --- diff --git a/tests/libostreetest.c b/tests/libostreetest.c index a1953561..075456a2 100644 --- a/tests/libostreetest.c +++ b/tests/libostreetest.c @@ -24,6 +24,15 @@ #include "libglnx.h" #include "libostreetest.h" +/* Return a newly-allocated mkdtemp/g_mkdtemp template path under TEST_TMPDIR + * (falling back to /var/tmp), e.g. "ostree-xattrs-test.XXXXXX". */ +char * +ot_test_tmpdir_template (const char *basename_template) +{ + const char *test_tmpdir = g_getenv ("TEST_TMPDIR") ?: "/var/tmp"; + return g_build_filename (test_tmpdir, basename_template, NULL); +} + /* This function hovers in a quantum superposition of horrifying and * beautiful. Future generations may interpret it as modern art. */ diff --git a/tests/libostreetest.h b/tests/libostreetest.h index e593ac13..e2a077a7 100644 --- a/tests/libostreetest.h +++ b/tests/libostreetest.h @@ -28,6 +28,8 @@ G_BEGIN_DECLS gboolean ot_test_run_libtest (const char *cmd, GError **error); +char *ot_test_tmpdir_template (const char *basename_template); + OstreeRepo *ot_test_setup_repo (GCancellable *cancellable, GError **error); gboolean ot_check_relabeling (gboolean *can_relabel, GError **error); diff --git a/tests/test-basic-c.c b/tests/test-basic-c.c index a27dbc8f..555c5802 100644 --- a/tests/test-basic-c.c +++ b/tests/test-basic-c.c @@ -525,8 +525,9 @@ test_read_xattrs (void) g_auto (GLnxTmpDir) tmpd = { 0, }; - // Use /var/tmp to hope we get xattr support - glnx_mkdtempat (AT_FDCWD, "/var/tmp/ostree-xattrs-test.XXXXXX", 0700, &tmpd, error); + // Use TEST_TMPDIR (or /var/tmp as fallback) to hope we get xattr support + g_autofree char *tmpd_tmpl = ot_test_tmpdir_template ("ostree-xattrs-test.XXXXXX"); + glnx_mkdtempat (AT_FDCWD, tmpd_tmpl, 0700, &tmpd, error); g_assert_no_error (local_error); const char value[] = "foo"; @@ -539,8 +540,8 @@ test_read_xattrs (void) if (r != 0) { - g_autofree gchar *message = g_strdup_printf ( - "Unable to set extended attributes in /var/tmp: %s", g_strerror (errno)); + g_autofree gchar *message = g_strdup_printf ("Unable to set extended attributes in %s: %s", + tmpd_tmpl, g_strerror (errno)); g_test_skip (message); return; } diff --git a/tests/test-libarchive-import.c b/tests/test-libarchive-import.c index 5643db70..d7524821 100644 --- a/tests/test-libarchive-import.c +++ b/tests/test-libarchive-import.c @@ -24,6 +24,7 @@ #include #include +#include "libostreetest.h" #include "ostree-libarchive-private.h" #include #include @@ -47,7 +48,7 @@ test_data_init (TestData *td) uid_t uid = getuid (); gid_t gid = getgid (); - td->tmpd = g_mkdtemp (g_strdup ("/var/tmp/test-libarchive-import-XXXXXX")); + td->tmpd = g_mkdtemp (ot_test_tmpdir_template ("test-libarchive-import-XXXXXX")); g_assert_cmpint (0, ==, chdir (td->tmpd)); td->fd = openat (AT_FDCWD, "foo.tar.gz", O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, 0644);