Patch Detail
Show a patch.
GET /api/1.1/patches/1601/?format=api
{ "id": 1601, "url": "https://patchwork.libcamera.org/api/1.1/patches/1601/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1601/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20190704013004.14600-1-niklas.soderlund@ragnatech.se>", "date": "2019-07-04T01:30:04", "name": "[libcamera-devel,RFC] test: Move resource locking to test cases", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "706720377e7426d3d5eeb4ae7dbc88d2bf93fa37", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": { "id": 16, "url": "https://patchwork.libcamera.org/api/1.1/users/16/?format=api", "username": "neg", "first_name": "Niklas", "last_name": "Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "mbox": "https://patchwork.libcamera.org/patch/1601/mbox/", "series": [ { "id": 397, "url": "https://patchwork.libcamera.org/api/1.1/series/397/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=397", "date": "2019-07-04T01:30:04", "name": "[libcamera-devel,RFC] test: Move resource locking to test cases", "version": 1, "mbox": "https://patchwork.libcamera.org/series/397/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1601/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1601/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5A7CC60BEE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 4 Jul 2019 03:30:10 +0200 (CEST)", "from bismarck.berto.se (unknown [145.14.112.32])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 31a845c4-9dfb-11e9-8601-0050569116f7;\n\tThu, 04 Jul 2019 03:29:43 +0200 (CEST)" ], "X-Halon-ID": "31a845c4-9dfb-11e9-8601-0050569116f7", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 4 Jul 2019 03:30:04 +0200", "Message-Id": "<20190704013004.14600-1-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.22.0", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC] test: Move resource locking to test cases", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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>", "X-List-Received-Date": "Thu, 04 Jul 2019 01:30:10 -0000" }, "content": "Instead of blocking any test which require access to a kernel resource\n(vimc or vivid) from running in parallel move the resource locking into\ntest library and allow meson to execute them in parallel.\n\nResource locking is achieve using a lockfile for each resource in /tmp\nand lockf(). The call to lockf() blocks until it can acquire the\nresource and it keeps to lock until the test executable terminates\nclosing the file descriptor to the lock file and freeing the lock. This\ndesign ensures the process never deadlocks. The reason a separate lock\nfile is needed instead of locking the media device associated with the\nresource is that such a locking scheme is already used by libcamera\nitself.\n\nWith this change I cut down the runtime of tests by 50%. The largest\nincrease is from allowing self-contained tests in parallel with tests\nwhich require a kernel resource. This is because most of the tests who\nneeds a kernel resource needs vimc so there is heavy contention for that\nsingle resource and little gain from meson to execute them in parallel.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n test/camera/camera_test.h | 2 +-\n test/camera/meson.build | 2 +-\n test/controls/control_list.cpp | 4 ++\n test/controls/meson.build | 2 +-\n test/libtest/test.cpp | 37 ++++++++++++++++++-\n test/libtest/test.h | 15 +++++++-\n test/media_device/media_device_test.h | 2 +-\n test/media_device/meson.build | 2 +-\n test/v4l2_subdevice/meson.build | 2 +-\n test/v4l2_subdevice/v4l2_subdevice_test.h | 2 +-\n test/v4l2_videodevice/buffer_sharing.cpp | 2 +-\n test/v4l2_videodevice/capture_async.cpp | 2 +-\n test/v4l2_videodevice/double_open.cpp | 2 +-\n test/v4l2_videodevice/formats.cpp | 2 +-\n test/v4l2_videodevice/meson.build | 2 +-\n test/v4l2_videodevice/request_buffers.cpp | 2 +-\n test/v4l2_videodevice/stream_on_off.cpp | 2 +-\n .../v4l2_videodevice_test.cpp | 16 +++++++-\n test/v4l2_videodevice/v4l2_videodevice_test.h | 4 +-\n 19 files changed, 85 insertions(+), 19 deletions(-)", "diff": "diff --git a/test/camera/camera_test.h b/test/camera/camera_test.h\nindex ffc8a485bfaff836..0f3c15cc3dd34f3c 100644\n--- a/test/camera/camera_test.h\n+++ b/test/camera/camera_test.h\n@@ -17,7 +17,7 @@ class CameraTest : public Test\n {\n public:\n \tCameraTest()\n-\t\t: cm_(nullptr) {}\n+\t\t: Test(VIMC), cm_(nullptr) {}\n \n protected:\n \tint init();\ndiff --git a/test/camera/meson.build b/test/camera/meson.build\nindex 35e97ce5de1a72ca..b10b1e76aaec0233 100644\n--- a/test/camera/meson.build\n+++ b/test/camera/meson.build\n@@ -12,5 +12,5 @@ foreach t : camera_tests\n dependencies : libcamera_dep,\n link_with : test_libraries,\n include_directories : test_includes_internal)\n- test(t[0], exe, suite : 'camera', is_parallel : false)\n+ test(t[0], exe, suite : 'camera')\n endforeach\ndiff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp\nindex c834edc352f5d7d4..0fc3ded2545df2e1 100644\n--- a/test/controls/control_list.cpp\n+++ b/test/controls/control_list.cpp\n@@ -18,6 +18,10 @@ using namespace libcamera;\n \n class ControlListTest : public Test\n {\n+public:\n+\tControlListTest()\n+\t\t: Test(VIMC) {}\n+\n protected:\n \tint init()\n \t{\ndiff --git a/test/controls/meson.build b/test/controls/meson.build\nindex f4fc7b947dd9e2a6..724871e3136f369b 100644\n--- a/test/controls/meson.build\n+++ b/test/controls/meson.build\n@@ -9,5 +9,5 @@ foreach t : control_tests\n dependencies : libcamera_dep,\n link_with : test_libraries,\n include_directories : test_includes_internal)\n- test(t[0], exe, suite : 'controls', is_parallel : false)\n+ test(t[0], exe, suite : 'controls')\n endforeach\ndiff --git a/test/libtest/test.cpp b/test/libtest/test.cpp\nindex b119cf19273900d2..cf13fa42dd9fdc5a 100644\n--- a/test/libtest/test.cpp\n+++ b/test/libtest/test.cpp\n@@ -5,11 +5,15 @@\n * test.cpp - libcamera test base class\n */\n \n+#include <fcntl.h>\n+#include <iostream>\n #include <stdlib.h>\n+#include <sys/stat.h>\n \n #include \"test.h\"\n \n-Test::Test()\n+Test::Test(TestResource resource)\n+\t: resource_(resource)\n {\n }\n \n@@ -25,6 +29,9 @@ int Test::execute()\n \tif (ret)\n \t\treturn errno;\n \n+\tif (!resourceLock())\n+\t\treturn TestFail;\n+\n \tret = init();\n \tif (ret)\n \t\treturn ret;\n@@ -35,3 +42,31 @@ int Test::execute()\n \n \treturn ret;\n }\n+\n+bool Test::resourceLock()\n+{\n+\tconst char *path;\n+\n+\tswitch (resource_) {\n+\tcase None:\n+\t\treturn true;\n+\tcase VIMC:\n+\t\tpath = \"/tmp/libcamera-test-vimc\";\n+\t\tbreak;\n+\tcase VIVID:\n+\t\tpath = \"/tmp/libcamera-test-vivid\";\n+\t\tbreak;\n+\t}\n+\n+\tint fd = ::open(path, O_CREAT | O_RDWR, 0666);\n+\tif (fd < 0) {\n+\t\tstd::cerr << \"Failed to open resource lockfile\" << std::endl;\n+\t\tperror(\"FOO\");\n+\t\treturn false;\n+\t}\n+\n+\tif (lockf(fd, F_LOCK, 0))\n+\t\treturn false;\n+\n+\treturn true;\n+}\ndiff --git a/test/libtest/test.h b/test/libtest/test.h\nindex ec08bf97c03d563e..259fb589eb621489 100644\n--- a/test/libtest/test.h\n+++ b/test/libtest/test.h\n@@ -15,10 +15,16 @@ enum TestStatus {\n \tTestSkip = 77,\n };\n \n+enum TestResource {\n+\tNone,\n+\tVIMC,\n+\tVIVID,\n+};\n+\n class Test\n {\n public:\n-\tTest();\n+\tTest(TestResource resource = None);\n \tvirtual ~Test();\n \n \tint execute();\n@@ -27,6 +33,13 @@ protected:\n \tvirtual int init() { return 0; }\n \tvirtual int run() = 0;\n \tvirtual void cleanup() { }\n+\n+\tTestResource resource() { return resource_; }\n+\n+private:\n+\tbool resourceLock();\n+\n+\tTestResource resource_;\n };\n \n #define TEST_REGISTER(klass)\t\t\t\t\t\t\\\ndiff --git a/test/media_device/media_device_test.h b/test/media_device/media_device_test.h\nindex cdbd14841d5ccca2..9e34ba86c397a99c 100644\n--- a/test/media_device/media_device_test.h\n+++ b/test/media_device/media_device_test.h\n@@ -20,7 +20,7 @@ class MediaDeviceTest : public Test\n {\n public:\n \tMediaDeviceTest()\n-\t\t: media_(nullptr), enumerator_(nullptr) {}\n+\t\t: Test(VIMC), media_(nullptr), enumerator_(nullptr) {}\n \n protected:\n \tint init();\ndiff --git a/test/media_device/meson.build b/test/media_device/meson.build\nindex 6a0e468434b58efe..6a5b24d27aa0f618 100644\n--- a/test/media_device/meson.build\n+++ b/test/media_device/meson.build\n@@ -18,5 +18,5 @@ foreach t : media_device_tests\n link_with : [test_libraries, lib_mdev_test],\n include_directories : test_includes_internal)\n \n- test(t[0], exe, suite : 'media_device', is_parallel : false)\n+ test(t[0], exe, suite : 'media_device')\n endforeach\ndiff --git a/test/v4l2_subdevice/meson.build b/test/v4l2_subdevice/meson.build\nindex 0521984b2a787ab9..47676adbe5a33f7e 100644\n--- a/test/v4l2_subdevice/meson.build\n+++ b/test/v4l2_subdevice/meson.build\n@@ -8,5 +8,5 @@ foreach t : v4l2_subdevice_tests\n dependencies : libcamera_dep,\n link_with : test_libraries,\n include_directories : test_includes_internal)\n- test(t[0], exe, suite : 'v4l2_subdevice', is_parallel : false)\n+ test(t[0], exe, suite : 'v4l2_subdevice')\n endforeach\ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.h b/test/v4l2_subdevice/v4l2_subdevice_test.h\nindex 96646a155536aadf..a9002834bf8959b2 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.h\n+++ b/test/v4l2_subdevice/v4l2_subdevice_test.h\n@@ -21,7 +21,7 @@ class V4L2SubdeviceTest : public Test\n {\n public:\n \tV4L2SubdeviceTest()\n-\t\t: scaler_(nullptr){};\n+\t\t: Test(VIMC), scaler_(nullptr){};\n \n protected:\n \tint init() override;\ndiff --git a/test/v4l2_videodevice/buffer_sharing.cpp b/test/v4l2_videodevice/buffer_sharing.cpp\nindex 1bc478fe8f8e1163..d619713257055fd5 100644\n--- a/test/v4l2_videodevice/buffer_sharing.cpp\n+++ b/test/v4l2_videodevice/buffer_sharing.cpp\n@@ -23,7 +23,7 @@ class BufferSharingTest : public V4L2VideoDeviceTest\n {\n public:\n \tBufferSharingTest()\n-\t\t: V4L2VideoDeviceTest(\"vivid\", \"vivid-000-vid-cap\"),\n+\t\t: V4L2VideoDeviceTest(VIVID, \"vivid-000-vid-cap\"),\n \t\t output_(nullptr), framesCaptured_(0), framesOutput_(0) {}\n \n protected:\ndiff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp\nindex cea4fffbf7a5603d..9ae8043b31a68f0e 100644\n--- a/test/v4l2_videodevice/capture_async.cpp\n+++ b/test/v4l2_videodevice/capture_async.cpp\n@@ -18,7 +18,7 @@ class CaptureAsyncTest : public V4L2VideoDeviceTest\n {\n public:\n \tCaptureAsyncTest()\n-\t\t: V4L2VideoDeviceTest(\"vimc\", \"Raw Capture 0\"), frames(0) {}\n+\t\t: V4L2VideoDeviceTest(VIMC, \"Raw Capture 0\"), frames(0) {}\n \n \tvoid receiveBuffer(Buffer *buffer)\n \t{\ndiff --git a/test/v4l2_videodevice/double_open.cpp b/test/v4l2_videodevice/double_open.cpp\nindex 5768d4043d0ba03f..ff1c7b136e803929 100644\n--- a/test/v4l2_videodevice/double_open.cpp\n+++ b/test/v4l2_videodevice/double_open.cpp\n@@ -15,7 +15,7 @@ class DoubleOpen : public V4L2VideoDeviceTest\n {\n public:\n \tDoubleOpen()\n-\t\t: V4L2VideoDeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideoDeviceTest(VIMC, \"Raw Capture 0\") {}\n protected:\n \tint run()\n \t{\ndiff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp\nindex ee7d357de0752cae..25cd147f804ba0d5 100644\n--- a/test/v4l2_videodevice/formats.cpp\n+++ b/test/v4l2_videodevice/formats.cpp\n@@ -19,7 +19,7 @@ class Format : public V4L2VideoDeviceTest\n {\n public:\n \tFormat()\n-\t\t: V4L2VideoDeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideoDeviceTest(VIMC, \"Raw Capture 0\") {}\n protected:\n \tint run()\n \t{\ndiff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\nindex 76be5e142bb63aa6..dc8204872efdc038 100644\n--- a/test/v4l2_videodevice/meson.build\n+++ b/test/v4l2_videodevice/meson.build\n@@ -14,5 +14,5 @@ foreach t : v4l2_videodevice_tests\n dependencies : libcamera_dep,\n link_with : test_libraries,\n include_directories : test_includes_internal)\n- test(t[0], exe, suite : 'v4l2_videodevice', is_parallel : false)\n+ test(t[0], exe, suite : 'v4l2_videodevice')\n endforeach\ndiff --git a/test/v4l2_videodevice/request_buffers.cpp b/test/v4l2_videodevice/request_buffers.cpp\nindex c4aedf7b3cd61e80..bbc4073c363c128a 100644\n--- a/test/v4l2_videodevice/request_buffers.cpp\n+++ b/test/v4l2_videodevice/request_buffers.cpp\n@@ -11,7 +11,7 @@ class RequestBuffersTest : public V4L2VideoDeviceTest\n {\n public:\n \tRequestBuffersTest()\n-\t\t: V4L2VideoDeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideoDeviceTest(VIMC, \"Raw Capture 0\") {}\n \n protected:\n \tint run()\ndiff --git a/test/v4l2_videodevice/stream_on_off.cpp b/test/v4l2_videodevice/stream_on_off.cpp\nindex 7664adc4c1f07046..fe021667c44559fa 100644\n--- a/test/v4l2_videodevice/stream_on_off.cpp\n+++ b/test/v4l2_videodevice/stream_on_off.cpp\n@@ -11,7 +11,7 @@ class StreamOnStreamOffTest : public V4L2VideoDeviceTest\n {\n public:\n \tStreamOnStreamOffTest()\n-\t\t: V4L2VideoDeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideoDeviceTest(VIMC, \"Raw Capture 0\") {}\n protected:\n \tint run()\n \t{\ndiff --git a/test/v4l2_videodevice/v4l2_videodevice_test.cpp b/test/v4l2_videodevice/v4l2_videodevice_test.cpp\nindex b26d06ad45197c8f..aa39e455360c868c 100644\n--- a/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n+++ b/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n@@ -28,6 +28,20 @@ bool exists(const std::string &path)\n \n int V4L2VideoDeviceTest::init()\n {\n+\tconst char *driver;\n+\n+\tswitch (resource()) {\n+\tcase VIMC:\n+\t\tdriver = \"vimc\";\n+\t\tbreak;\n+\tcase VIVID:\n+\t\tdriver = \"vivid\";\n+\t\tbreak;\n+\tdefault:\n+\t\tstd::cerr << \"Unkown driver for resource\" << std::endl;\n+\t\treturn TestFail;\n+\t}\n+\n \tenumerator_ = DeviceEnumerator::create();\n \tif (!enumerator_) {\n \t\tcerr << \"Failed to create device enumerator\" << endl;\n@@ -39,7 +53,7 @@ int V4L2VideoDeviceTest::init()\n \t\treturn TestFail;\n \t}\n \n-\tDeviceMatch dm(driver_);\n+\tDeviceMatch dm(driver);\n \tdm.add(entity_);\n \n \tmedia_ = enumerator_->search(dm);\ndiff --git a/test/v4l2_videodevice/v4l2_videodevice_test.h b/test/v4l2_videodevice/v4l2_videodevice_test.h\nindex 3321b5a4f98fdb1d..b90a5fca6ce48fdd 100644\n--- a/test/v4l2_videodevice/v4l2_videodevice_test.h\n+++ b/test/v4l2_videodevice/v4l2_videodevice_test.h\n@@ -22,8 +22,8 @@ using namespace libcamera;\n class V4L2VideoDeviceTest : public Test\n {\n public:\n-\tV4L2VideoDeviceTest(const char *driver, const char *entity)\n-\t\t: driver_(driver), entity_(entity), capture_(nullptr)\n+\tV4L2VideoDeviceTest(TestResource resource, const char *entity)\n+\t\t: Test(resource), entity_(entity), capture_(nullptr)\n \t{\n \t}\n \n", "prefixes": [ "libcamera-devel", "RFC" ] }