{"id":26010,"url":"https://patchwork.libcamera.org/api/patches/26010/?format=json","web_url":"https://patchwork.libcamera.org/patch/26010/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260128145649.890107-1-barnabas.pocze@ideasonboard.com>","date":"2026-01-28T14:56:49","name":"[v1] test: Remove uses of `O_TMPFILE`","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c81ccd793d20cc475b28f3e12c5fba7ae0778dd2","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26010/mbox/","series":[{"id":5750,"url":"https://patchwork.libcamera.org/api/series/5750/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5750","date":"2026-01-28T14:56:49","name":"[v1] test: Remove uses of `O_TMPFILE`","version":1,"mbox":"https://patchwork.libcamera.org/series/5750/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26010/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26010/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BEC16C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jan 2026 14:56:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EE4A761FD0;\n\tWed, 28 Jan 2026 15:56:53 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8BBE261FC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jan 2026 15:56:52 +0100 (CET)","from pb-laptop.local (185.221.142.123.nat.pool.zt.hu\n\t[185.221.142.123])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8244AC6F;\n\tWed, 28 Jan 2026 15:56:15 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"r0m9TWwi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769612175;\n\tbh=N+CnG/3FlOtU/wzXp61LYbd25Dws/VuP5/2WcPoi+Io=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=r0m9TWwiCTuWU1goBMguEk35G0GmW9FSaKRf7jfAWOi6Ut8I1KOf/8vSfHNpy54Mb\n\tfPQpDd3sX5wZjgSIIW3UPUYMSefGWXA2WpLOdJZV9erPjjBpjOS1TC9jdyIElTE1KM\n\tcUqLRNwruXZS9aUhmutSmRd+9kN4KT4/85H/b9fI=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"[PATCH v1] test: Remove uses of `O_TMPFILE`","Date":"Wed, 28 Jan 2026 15:56:49 +0100","Message-ID":"<20260128145649.890107-1-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.52.0","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"`O_TMPFILE` requires file system support, which may not be available in\ncertain environments, usually containerized ones. So do not use it.\n\nIn the ipc/unixsocket and log/log_api tests the temporary file is replaced\nwith a memfd using the `libcamera::MemFd` class since these tests are\nalready internal tests.\n\nIn the unique-fd and shared-fd tests instead of creating a temporary file\nsimply open \"/proc/self/exe\", which should be available and readable in\nmost cases.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n test/ipc/unixsocket.cpp | 34 ++++++++++++++--------------------\n test/log/log_api.cpp    | 14 ++++++--------\n test/shared-fd.cpp      |  2 +-\n test/unique-fd.cpp      |  2 +-\n 4 files changed, 22 insertions(+), 30 deletions(-)","diff":"diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\nindex f39bd986b..28864b829 100644\n--- a/test/ipc/unixsocket.cpp\n+++ b/test/ipc/unixsocket.cpp\n@@ -18,6 +18,7 @@\n #include <vector>\n \n #include <libcamera/base/event_dispatcher.h>\n+#include <libcamera/base/memfd.h>\n #include <libcamera/base/thread.h>\n #include <libcamera/base/timer.h>\n \n@@ -137,11 +138,11 @@ private:\n \t\t}\n \n \t\tcase CMD_JOIN: {\n-\t\t\tint outfd = open(\"/tmp\", O_TMPFILE | O_RDWR,\n-\t\t\t\t\t S_IRUSR | S_IWUSR);\n-\t\t\tif (outfd < 0) {\n+\t\t\tauto outfd = MemFd::create(\"test\", 0);\n+\t\t\tif (!outfd.isValid()) {\n+\t\t\t\tret = errno;\n \t\t\t\tcerr << \"Create out file failed\" << endl;\n-\t\t\t\tstop(outfd);\n+\t\t\t\tstop(ret);\n \t\t\t\treturn;\n \t\t\t}\n \n@@ -152,15 +153,13 @@ private:\n \n \t\t\t\t\tif (num < 0) {\n \t\t\t\t\t\tcerr << \"Read failed\" << endl;\n-\t\t\t\t\t\tclose(outfd);\n \t\t\t\t\t\tstop(-EIO);\n \t\t\t\t\t\treturn;\n \t\t\t\t\t} else if (!num)\n \t\t\t\t\t\tbreak;\n \n-\t\t\t\t\tif (write(outfd, buf, num) < 0) {\n+\t\t\t\t\tif (write(outfd.get(), buf, num) < 0) {\n \t\t\t\t\t\tcerr << \"Write failed\" << endl;\n-\t\t\t\t\t\tclose(outfd);\n \t\t\t\t\t\tstop(-EIO);\n \t\t\t\t\t\treturn;\n \t\t\t\t\t}\n@@ -169,9 +168,9 @@ private:\n \t\t\t\tclose(fd);\n \t\t\t}\n \n-\t\t\tlseek(outfd, 0, 0);\n+\t\t\tlseek(outfd.get(), 0, SEEK_SET);\n \t\t\tresponse.data.push_back(CMD_JOIN);\n-\t\t\tresponse.fds.push_back(outfd);\n+\t\t\tresponse.fds.push_back(outfd.get());\n \n \t\t\tret = ipc_.send(response);\n \t\t\tif (ret < 0) {\n@@ -179,8 +178,6 @@ private:\n \t\t\t\tstop(ret);\n \t\t\t}\n \n-\t\t\tclose(outfd);\n-\n \t\t\tbreak;\n \t\t}\n \n@@ -315,22 +312,21 @@ protected:\n \t\t\t\"Foo\",\n \t\t\t\"Bar\",\n \t\t};\n-\t\tint fds[2];\n+\t\tstd::array<UniqueFD, 2> fds;\n \n \t\tfor (unsigned int i = 0; i < std::size(strings); i++) {\n \t\t\tunsigned int len = strlen(strings[i]);\n \n-\t\t\tfds[i] = open(\"/tmp\", O_TMPFILE | O_RDWR,\n-\t\t\t\t      S_IRUSR | S_IWUSR);\n-\t\t\tif (fds[i] < 0)\n+\t\t\tfds[i] = MemFd::create(\"test\", 0);\n+\t\t\tif (!fds[i].isValid())\n \t\t\t\treturn TestFail;\n \n-\t\t\tret = write(fds[i], strings[i], len);\n+\t\t\tret = write(fds[i].get(), strings[i], len);\n \t\t\tif (ret < 0)\n \t\t\t\treturn TestFail;\n \n-\t\t\tlseek(fds[i], 0, 0);\n-\t\t\tmessage.fds.push_back(fds[i]);\n+\t\t\tlseek(fds[i].get(), 0, SEEK_SET);\n+\t\t\tmessage.fds.push_back(fds[i].get());\n \t\t}\n \n \t\tmessage.data.push_back(CMD_JOIN);\n@@ -343,8 +339,6 @@ protected:\n \t\t\tunsigned int len = strlen(strings[i]);\n \t\t\tstd::vector<char> buf(len);\n \n-\t\t\tclose(fds[i]);\n-\n \t\t\tif (read(response.fds[0], buf.data(), len) <= 0)\n \t\t\t\treturn TestFail;\n \ndiff --git a/test/log/log_api.cpp b/test/log/log_api.cpp\nindex 8d19cf0ce..0eaf67a71 100644\n--- a/test/log/log_api.cpp\n+++ b/test/log/log_api.cpp\n@@ -17,6 +17,7 @@\n #include <unistd.h>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/memfd.h>\n \n #include <libcamera/logging.h>\n \n@@ -109,18 +110,17 @@ protected:\n \n \tint testFile()\n \t{\n-\t\tint fd = open(\"/tmp\", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);\n-\t\tif (fd < 0) {\n+\t\tauto fd = MemFd::create(\"test\", 0);\n+\t\tif (!fd.isValid()) {\n \t\t\tcerr << \"Failed to open tmp log file\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n \t\tchar path[32];\n-\t\tsnprintf(path, sizeof(path), \"/proc/self/fd/%u\", fd);\n+\t\tsnprintf(path, sizeof(path), \"/proc/self/fd/%u\", fd.get());\n \n \t\tif (logSetFile(path) < 0) {\n \t\t\tcerr << \"Failed to set log file\" << endl;\n-\t\t\tclose(fd);\n \t\t\treturn TestFail;\n \t\t}\n \n@@ -128,13 +128,11 @@ protected:\n \n \t\tchar buf[1000];\n \t\tmemset(buf, 0, sizeof(buf));\n-\t\tlseek(fd, 0, SEEK_SET);\n-\t\tif (read(fd, buf, sizeof(buf)) < 0) {\n+\t\tlseek(fd.get(), 0, SEEK_SET);\n+\t\tif (read(fd.get(), buf, sizeof(buf)) < 0) {\n \t\t\tcerr << \"Failed to read tmp log file\" << endl;\n-\t\t\tclose(fd);\n \t\t\treturn TestFail;\n \t\t}\n-\t\tclose(fd);\n \n \t\tistringstream iss(buf);\n \t\treturn verifyOutput(iss);\ndiff --git a/test/shared-fd.cpp b/test/shared-fd.cpp\nindex 57199dfe7..09634f2c2 100644\n--- a/test/shared-fd.cpp\n+++ b/test/shared-fd.cpp\n@@ -27,7 +27,7 @@ protected:\n \t\tdesc1_ = nullptr;\n \t\tdesc2_ = nullptr;\n \n-\t\tfd_ = open(\"/tmp\", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);\n+\t\tfd_ = open(\"/proc/self/exe\", O_RDONLY);\n \t\tif (fd_ < 0)\n \t\t\treturn TestFail;\n \ndiff --git a/test/unique-fd.cpp b/test/unique-fd.cpp\nindex e556439ea..7d7ba1447 100644\n--- a/test/unique-fd.cpp\n+++ b/test/unique-fd.cpp\n@@ -189,7 +189,7 @@ protected:\n private:\n \tint createFd()\n \t{\n-\t\tfd_ = open(\"/tmp\", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);\n+\t\tfd_ = open(\"/proc/self/exe\", O_RDONLY);\n \t\tif (fd_ < 0)\n \t\t\treturn TestFail;\n \n","prefixes":["v1"]}