Patch Detail
Show a patch.
GET /api/patches/26038/?format=api
{ "id": 26038, "url": "https://patchwork.libcamera.org/api/patches/26038/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26038/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260129110007.1221054-1-barnabas.pocze@ideasonboard.com>", "date": "2026-01-29T11:00:07", "name": "[v2] test: Remove uses of `O_TMPFILE`", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "968de62ce2ee638b2eb337319600de1848b643a4", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26038/mbox/", "series": [ { "id": 5755, "url": "https://patchwork.libcamera.org/api/series/5755/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5755", "date": "2026-01-29T11:00:07", "name": "[v2] test: Remove uses of `O_TMPFILE`", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5755/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26038/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26038/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 925E6C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 29 Jan 2026 11:00:12 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3190861FCE;\n\tThu, 29 Jan 2026 12:00:12 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6021D61FC6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Jan 2026 12:00:11 +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 BC7E11AED\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Jan 2026 11:59:33 +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=\"i1Wzre5U\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769684373;\n\tbh=oKX8qomrGLzS5bwYnNC7KHridwvGdmq1Bs7u1spK3iA=;\n\th=From:To:Subject:Date:From;\n\tb=i1Wzre5U44dtFHKuXWBcgGzWbs1eaSnqd4bu/HTsGD3Y4Ke+V4y4wcGKchZnD7VJR\n\tx0duW+BGYYfZOWoG5ZT4sUQuvmWWSTE7HQ2Nv3ovIJFaFBqtnXT5ngD3t4DAxcn9RJ\n\tHSQm+jwvP37lc7x1xVlSH/sNtbNXh0LunlXd6/kU=", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v2] test: Remove uses of `O_TMPFILE`", "Date": "Thu, 29 Jan 2026 12:00:07 +0100", "Message-ID": "<20260129110007.1221054-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\nA new function is added for tests to be able to create unnamed temporary\nfiles using `libcamera::MemFd` as the implementation.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\nchanges in v2:\n * add function to create unnamed temporary files\n\nv1: https://patchwork.libcamera.org/patch/26010/\n---\n test/ipc/unixsocket.cpp | 34 ++++++++++++++--------------------\n test/libtest/meson.build | 1 +\n test/libtest/misc.cpp | 19 +++++++++++++++++++\n test/libtest/misc.h | 17 +++++++++++++++++\n test/log/log_api.cpp | 14 ++++++--------\n test/shared-fd.cpp | 3 ++-\n test/unique-fd.cpp | 3 ++-\n 7 files changed, 61 insertions(+), 30 deletions(-)\n create mode 100644 test/libtest/misc.cpp\n create mode 100644 test/libtest/misc.h\n\n--\n2.52.0", "diff": "diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp\nindex f39bd986b..0e603a69c 100644\n--- a/test/ipc/unixsocket.cpp\n+++ b/test/ipc/unixsocket.cpp\n@@ -23,6 +23,7 @@\n\n #include \"libcamera/internal/ipc_unixsocket.h\"\n\n+#include \"misc.h\"\n #include \"test.h\"\n\n #define CMD_CLOSE\t0\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 = test::createTemporaryFile();\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] = test::createTemporaryFile();\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/libtest/meson.build b/test/libtest/meson.build\nindex 351629f3c..fd89f8047 100644\n--- a/test/libtest/meson.build\n+++ b/test/libtest/meson.build\n@@ -3,6 +3,7 @@\n libtest_sources = files([\n 'buffer_source.cpp',\n 'camera_test.cpp',\n+ 'misc.cpp',\n 'test.cpp',\n ])\n\ndiff --git a/test/libtest/misc.cpp b/test/libtest/misc.cpp\nnew file mode 100644\nindex 000000000..d4506c869\n--- /dev/null\n+++ b/test/libtest/misc.cpp\n@@ -0,0 +1,19 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2026, Ideas on Board Oy\n+ *\n+ * libcamera test miscellaneous utilities\n+ */\n+\n+#include \"misc.h\"\n+\n+#include <libcamera/base/memfd.h>\n+\n+namespace test {\n+\n+libcamera::UniqueFD createTemporaryFile()\n+{\n+\treturn libcamera::MemFd::create(\"libcamera-test-temporary-file\", 0);\n+}\n+\n+} /* namespace test */\ndiff --git a/test/libtest/misc.h b/test/libtest/misc.h\nnew file mode 100644\nindex 000000000..a7b4acbeb\n--- /dev/null\n+++ b/test/libtest/misc.h\n@@ -0,0 +1,17 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2026, Ideas on Board Oy\n+ *\n+ * libcamera test miscellaneous utilities\n+ */\n+\n+#pragma once\n+\n+#include <libcamera/base/unique_fd.h>\n+\n+namespace test {\n+\n+[[nodiscard]]\n+libcamera::UniqueFD createTemporaryFile();\n+\n+}\ndiff --git a/test/log/log_api.cpp b/test/log/log_api.cpp\nindex 8d19cf0ce..684abf8b8 100644\n--- a/test/log/log_api.cpp\n+++ b/test/log/log_api.cpp\n@@ -20,6 +20,7 @@\n\n #include <libcamera/logging.h>\n\n+#include \"misc.h\"\n #include \"test.h\"\n\n using namespace std;\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 = test::createTemporaryFile();\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..26e3140ad 100644\n--- a/test/shared-fd.cpp\n+++ b/test/shared-fd.cpp\n@@ -14,6 +14,7 @@\n #include <libcamera/base/shared_fd.h>\n #include <libcamera/base/utils.h>\n\n+#include \"misc.h\"\n #include \"test.h\"\n\n using namespace libcamera;\n@@ -27,7 +28,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_ = test::createTemporaryFile().release();\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..280205980 100644\n--- a/test/unique-fd.cpp\n+++ b/test/unique-fd.cpp\n@@ -14,6 +14,7 @@\n #include <libcamera/base/unique_fd.h>\n #include <libcamera/base/utils.h>\n\n+#include \"misc.h\"\n #include \"test.h\"\n\n using namespace libcamera;\n@@ -189,7 +190,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_ = test::createTemporaryFile().release();\n \t\tif (fd_ < 0)\n \t\t\treturn TestFail;\n\n", "prefixes": [ "v2" ] }