Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Tests keep no temp files in /tmp: run.py gives a run its own on-disk TMPDIR, removed when it passes

islandmed73c68ff14458
diff --git a/src/app/main.cpp b/src/app/main.cpp
index 3781eae5..05933410 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -150,9 +150,13 @@ bool automatedRun() {
int finishIsolated(int code) {
// The isolated folder (settings, the log, autosaves: a benchmark's 33M mesh is over a gigabyte) goes with a run
// that passed; a failed one keeps it, log included, to look at.
- if (code == 0 && !g_isolatedDir.empty()) {
- std::error_code ec;
+ if (g_isolatedDir.empty()) return code;
+ std::error_code ec;
+ if (code == 0) {
std::filesystem::remove_all(g_isolatedDir, ec);
+ if (ec) std::fprintf(stderr, "sculptforge: couldn't remove the test folder %s: %s\n", g_isolatedDir.string().c_str(), ec.message().c_str());
+ } else {
+ std::fprintf(stderr, "sculptforge: exit %d, test folder kept for a look: %s\n", code, g_isolatedDir.string().c_str());
}
return code;
}
diff --git a/tools/test/run.py b/tools/test/run.py
index e1721977..d33f894b 100644
--- a/tools/test/run.py
+++ b/tools/test/run.py
@@ -261,7 +261,7 @@ def results(junit):
return out
-def main(argv=None):
+def run_tests(argv=None):
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--build", default="build")
ap.add_argument("--cache", default=os.environ.get("SF_TEST_CACHE", ""))
@@ -481,5 +481,36 @@ def self_test():
return 0
+def disk_tmp():
+ """A temp folder on disk: /tmp is RAM (tmpfs) on some machines, and UI tests write hundreds of MB each."""
+ for d in ("/var/tmp",):
+ if os.path.isdir(d) and os.access(d, os.W_OK):
+ return d
+ return tempfile.gettempdir()
+
+
+def main(argv=None):
+ # Every test of this run writes its temp files (the app's sculptforge-ui-test-* folders: settings, logs, autosaves of
+ # big meshes) under one private folder, removed when the run passes and kept, with its path printed, when it fails
+ # (11-06: thousands of leftover folders in a RAM /tmp helped run the laptop out of memory).
+ tmp = tempfile.mkdtemp(prefix="sf-tests-", dir=disk_tmp())
+ saved = {k: os.environ.get(k) for k in ("TMPDIR", "TMP", "TEMP")}
+ os.environ.update(TMPDIR=tmp, TMP=tmp, TEMP=tmp)
+ rc = 1
+ try:
+ rc = run_tests(argv)
+ return rc
+ finally:
+ for k, v in saved.items():
+ if v is None: os.environ.pop(k, None)
+ else: os.environ[k] = v
+ if rc == 0:
+ shutil.rmtree(tmp, ignore_errors=True)
+ elif os.path.isdir(tmp) and os.listdir(tmp):
+ print(f"run.py: the tests' temp files are kept for a look: {tmp}")
+ else:
+ shutil.rmtree(tmp, ignore_errors=True)
+
+
if __name__ == "__main__":
sys.exit(main())