[libcamera-devel] [PATCH 2/2] test: meson: Use dictionaries instead of arrays to store test information

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Oct 5 21:39:44 CEST 2022


Tests are listed in meson.build using arrays that contain the test name
and source files at fixed positions. This isn't very readable, leading
to code using test[0], test[1] and test[2]. Replace the arrays with
dictionaries to improve readability.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 test/camera/meson.build           | 16 +++---
 test/controls/meson.build         | 12 ++---
 test/gstreamer/meson.build        |  8 +--
 test/ipa/meson.build              |  8 +--
 test/ipc/meson.build              |  8 +--
 test/log/meson.build              |  8 +--
 test/media_device/meson.build     | 10 ++--
 test/meson.build                  | 84 +++++++++++++++----------------
 test/pipeline/ipu3/meson.build    |  6 +--
 test/pipeline/rkisp1/meson.build  |  6 +--
 test/process/meson.build          |  6 +--
 test/serialization/meson.build    |  8 +--
 test/stream/meson.build           |  8 +--
 test/v4l2_subdevice/meson.build   |  8 +--
 test/v4l2_videodevice/meson.build | 24 ++++-----
 15 files changed, 110 insertions(+), 110 deletions(-)

diff --git a/test/camera/meson.build b/test/camera/meson.build
index df0520293bdb..4f9f8c8c4784 100644
--- a/test/camera/meson.build
+++ b/test/camera/meson.build
@@ -3,18 +3,18 @@
 # Tests are listed in order of complexity.
 # They are not alphabetically sorted.
 camera_tests = [
-    ['configuration_default',   'configuration_default.cpp'],
-    ['configuration_set',       'configuration_set.cpp'],
-    ['buffer_import',           'buffer_import.cpp'],
-    ['statemachine',            'statemachine.cpp'],
-    ['capture',                 'capture.cpp'],
-    ['camera_reconfigure',      'camera_reconfigure.cpp'],
+    {'name': 'configuration_default', 'sources': ['configuration_default.cpp']},
+    {'name': 'configuration_set', 'sources': ['configuration_set.cpp']},
+    {'name': 'buffer_import', 'sources': ['buffer_import.cpp']},
+    {'name': 'statemachine', 'sources': ['statemachine.cpp']},
+    {'name': 'capture', 'sources': ['capture.cpp']},
+    {'name': 'camera_reconfigure', 'sources': ['camera_reconfigure.cpp']},
 ]
 
 foreach test : camera_tests
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
-    test(test[0], exe, suite : 'camera', is_parallel : false)
+    test(test['name'], exe, suite : 'camera', is_parallel : false)
 endforeach
diff --git a/test/controls/meson.build b/test/controls/meson.build
index 8cf23be6487c..763f8905e7c1 100644
--- a/test/controls/meson.build
+++ b/test/controls/meson.build
@@ -1,16 +1,16 @@
 # SPDX-License-Identifier: CC0-1.0
 
 control_tests = [
-    ['control_info',                'control_info.cpp'],
-    ['control_info_map',            'control_info_map.cpp'],
-    ['control_list',                'control_list.cpp'],
-    ['control_value',               'control_value.cpp'],
+    {'name': 'control_info', 'sources': ['control_info.cpp']},
+    {'name': 'control_info_map', 'sources': ['control_info_map.cpp']},
+    {'name': 'control_list', 'sources': ['control_list.cpp']},
+    {'name': 'control_value', 'sources': ['control_value.cpp']},
 ]
 
 foreach test : control_tests
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_public,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
-    test(test[0], exe, suite : 'controls', is_parallel : false)
+    test(test['name'], exe, suite : 'controls', is_parallel : false)
 endforeach
diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build
index 46f6a77a771e..745725864eef 100644
--- a/test/gstreamer/meson.build
+++ b/test/gstreamer/meson.build
@@ -5,16 +5,16 @@ if not gst_enabled
 endif
 
 gstreamer_tests = [
-    ['single_stream_test',   'gstreamer_single_stream_test.cpp'],
-    ['multi_stream_test',    'gstreamer_multi_stream_test.cpp'],
+    {'name': 'single_stream_test', 'sources': ['gstreamer_single_stream_test.cpp']},
+    {'name': 'multi_stream_test', 'sources': ['gstreamer_multi_stream_test.cpp']},
 ]
 gstreamer_dep = dependency('gstreamer-1.0', required: true)
 
 foreach test : gstreamer_tests
-    exe = executable(test[0], test[1], 'gstreamer_test.cpp',
+    exe = executable(test['name'], test['sources'], 'gstreamer_test.cpp',
                      dependencies : [libcamera_private, gstreamer_dep],
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'gstreamer', is_parallel : false)
+    test(test['name'], exe, suite : 'gstreamer', is_parallel : false)
 endforeach
diff --git a/test/ipa/meson.build b/test/ipa/meson.build
index 295807fd8a45..180b0da0a51a 100644
--- a/test/ipa/meson.build
+++ b/test/ipa/meson.build
@@ -1,15 +1,15 @@
 # SPDX-License-Identifier: CC0-1.0
 
 ipa_test = [
-    ['ipa_module_test',     'ipa_module_test.cpp'],
-    ['ipa_interface_test',  'ipa_interface_test.cpp'],
+    {'name': 'ipa_module_test', 'sources': ['ipa_module_test.cpp']},
+    {'name': 'ipa_interface_test', 'sources': ['ipa_interface_test.cpp']},
 ]
 
 foreach test : ipa_test
-    exe = executable(test[0], [test[1], libcamera_generated_ipa_headers],
+    exe = executable(test['name'], test['sources'], libcamera_generated_ipa_headers,
                      dependencies : libcamera_private,
                      link_with : [libipa, test_libraries],
                      include_directories : [libipa_includes, test_includes_internal])
 
-    test(test[0], exe, suite : 'ipa')
+    test(test['name'], exe, suite : 'ipa')
 endforeach
diff --git a/test/ipc/meson.build b/test/ipc/meson.build
index ce21135b701d..8e447d228201 100644
--- a/test/ipc/meson.build
+++ b/test/ipc/meson.build
@@ -1,15 +1,15 @@
 # SPDX-License-Identifier: CC0-1.0
 
 ipc_tests = [
-    ['unixsocket_ipc', 'unixsocket_ipc.cpp'],
-    ['unixsocket',     'unixsocket.cpp'],
+    {'name': 'unixsocket_ipc', 'sources': ['unixsocket_ipc.cpp']},
+    {'name': 'unixsocket', 'sources': ['unixsocket.cpp']},
 ]
 
 foreach test : ipc_tests
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'ipc')
+    test(test['name'], exe, suite : 'ipc')
 endforeach
diff --git a/test/log/meson.build b/test/log/meson.build
index d2d51e471d52..2298ff84ee62 100644
--- a/test/log/meson.build
+++ b/test/log/meson.build
@@ -1,15 +1,15 @@
 # SPDX-License-Identifier: CC0-1.0
 
 log_test = [
-    ['log_api',     'log_api.cpp'],
-    ['log_process', 'log_process.cpp'],
+    {'name': 'log_api', 'sources': ['log_api.cpp']},
+    {'name': 'log_process', 'sources': ['log_process.cpp']},
 ]
 
 foreach test : log_test
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'log')
+    test(test['name'], exe, suite : 'log')
 endforeach
diff --git a/test/media_device/meson.build b/test/media_device/meson.build
index 7d34509d6797..84966c976192 100644
--- a/test/media_device/meson.build
+++ b/test/media_device/meson.build
@@ -5,9 +5,9 @@ lib_mdev_test_sources = files([
 ])
 
 media_device_tests = [
-    ['media_device_acquire',            'media_device_acquire.cpp'],
-    ['media_device_print_test',         'media_device_print_test.cpp'],
-    ['media_device_link_test',          'media_device_link_test.cpp'],
+    {'name': 'media_device_acquire', 'sources': ['media_device_acquire.cpp']},
+    {'name': 'media_device_print_test', 'sources': ['media_device_print_test.cpp']},
+    {'name': 'media_device_link_test', 'sources': ['media_device_link_test.cpp']},
 ]
 
 lib_mdev_test = static_library('lib_mdev_test', lib_mdev_test_sources,
@@ -15,10 +15,10 @@ lib_mdev_test = static_library('lib_mdev_test', lib_mdev_test_sources,
                                include_directories : test_includes_internal)
 
 foreach test : media_device_tests
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : [test_libraries, lib_mdev_test],
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'media_device', is_parallel : false)
+    test(test['name'], exe, suite : 'media_device', is_parallel : false)
 endforeach
diff --git a/test/meson.build b/test/meson.build
index 4bc01d78f4e6..05a54d5cad2f 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -26,82 +26,82 @@ subdir('v4l2_subdevice')
 subdir('v4l2_videodevice')
 
 public_tests = [
-    ['color-space',                     'color-space.cpp'],
-    ['geometry',                        'geometry.cpp'],
-    ['public-api',                      'public-api.cpp'],
-    ['signal',                          'signal.cpp'],
-    ['span',                            'span.cpp'],
+    {'name': 'color-space', 'sources': ['color-space.cpp']},
+    {'name': 'geometry', 'sources': ['geometry.cpp']},
+    {'name': 'public-api', 'sources': ['public-api.cpp']},
+    {'name': 'signal', 'sources': ['signal.cpp']},
+    {'name': 'span', 'sources': ['span.cpp']},
 ]
 
 internal_tests = [
-    ['bayer-format',                    'bayer-format.cpp'],
-    ['byte-stream-buffer',              'byte-stream-buffer.cpp'],
-    ['camera-sensor',                   'camera-sensor.cpp'],
-    ['delayed_controls',                'delayed_controls.cpp'],
-    ['event',                           'event.cpp'],
-    ['event-dispatcher',                'event-dispatcher.cpp'],
-    ['event-thread',                    'event-thread.cpp'],
-    ['file',                            'file.cpp'],
-    ['flags',                           'flags.cpp'],
-    ['hotplug-cameras',                 'hotplug-cameras.cpp'],
-    ['message',                         'message.cpp'],
-    ['object',                          'object.cpp'],
-    ['object-delete',                   'object-delete.cpp'],
-    ['object-invoke',                   'object-invoke.cpp'],
-    ['pixel-format',                    'pixel-format.cpp'],
-    ['shared-fd',                       'shared-fd.cpp'],
-    ['signal-threads',                  'signal-threads.cpp'],
-    ['threads',                         'threads.cpp', [libthreads]],
-    ['timer',                           'timer.cpp'],
-    ['timer-thread',                    'timer-thread.cpp'],
-    ['unique-fd',                       'unique-fd.cpp'],
-    ['utils',                           'utils.cpp'],
-    ['yaml-parser',                     'yaml-parser.cpp'],
+    {'name': 'bayer-format', 'sources': ['bayer-format.cpp']},
+    {'name': 'byte-stream-buffer', 'sources': ['byte-stream-buffer.cpp']},
+    {'name': 'camera-sensor', 'sources': ['camera-sensor.cpp']},
+    {'name': 'delayed_controls', 'sources': ['delayed_controls.cpp']},
+    {'name': 'event', 'sources': ['event.cpp']},
+    {'name': 'event-dispatcher', 'sources': ['event-dispatcher.cpp']},
+    {'name': 'event-thread', 'sources': ['event-thread.cpp']},
+    {'name': 'file', 'sources': ['file.cpp']},
+    {'name': 'flags', 'sources': ['flags.cpp']},
+    {'name': 'hotplug-cameras', 'sources': ['hotplug-cameras.cpp']},
+    {'name': 'message', 'sources': ['message.cpp']},
+    {'name': 'object', 'sources': ['object.cpp']},
+    {'name': 'object-delete', 'sources': ['object-delete.cpp']},
+    {'name': 'object-invoke', 'sources': ['object-invoke.cpp']},
+    {'name': 'pixel-format', 'sources': ['pixel-format.cpp']},
+    {'name': 'shared-fd', 'sources': ['shared-fd.cpp']},
+    {'name': 'signal-threads', 'sources': ['signal-threads.cpp']},
+    {'name': 'threads', 'sources': 'threads.cpp', 'dependencies': [libthreads]},
+    {'name': 'timer', 'sources': ['timer.cpp']},
+    {'name': 'timer-thread', 'sources': ['timer-thread.cpp']},
+    {'name': 'unique-fd', 'sources': ['unique-fd.cpp']},
+    {'name': 'utils', 'sources': ['utils.cpp']},
+    {'name': 'yaml-parser', 'sources': ['yaml-parser.cpp']},
 ]
 
 internal_non_parallel_tests = [
-    ['fence',                           'fence.cpp'],
-    ['mapped-buffer',                   'mapped-buffer.cpp'],
+    {'name': 'fence', 'sources': ['fence.cpp']},
+    {'name': 'mapped-buffer', 'sources': ['mapped-buffer.cpp']},
 ]
 
 foreach test : public_tests
     deps = [libcamera_public]
-    if test.length() > 2
-        deps += test[2]
+    if 'dependencies' in test
+        deps += test['dependencies']
     endif
 
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : deps,
                      link_with : test_libraries,
                      include_directories : test_includes_public)
 
-    test(test[0], exe)
+    test(test['name'], exe)
 endforeach
 
 foreach test : internal_tests
     deps = [libcamera_private]
-    if test.length() > 2
-        deps += test[2]
+    if 'dependencies' in test
+        deps += test['dependencies']
     endif
 
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : deps,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe)
+    test(test['name'], exe)
 endforeach
 
 foreach test : internal_non_parallel_tests
     deps = [libcamera_private]
-    if test.length() > 2
-        deps += test[2]
+    if 'dependencies' in test
+        deps += test['dependencies']
     endif
 
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : deps,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, is_parallel : false)
+    test(test['name'], exe, is_parallel : false)
 endforeach
diff --git a/test/pipeline/ipu3/meson.build b/test/pipeline/ipu3/meson.build
index 5fcf5730b0b0..af075707f505 100644
--- a/test/pipeline/ipu3/meson.build
+++ b/test/pipeline/ipu3/meson.build
@@ -1,14 +1,14 @@
 # SPDX-License-Identifier: CC0-1.0
 
 ipu3_test = [
-    ['ipu3_pipeline_test',            'ipu3_pipeline_test.cpp'],
+    {'name': 'ipu3_pipeline_test', 'sources': ['ipu3_pipeline_test.cpp']},
 ]
 
 foreach test : ipu3_test
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'ipu3', is_parallel : false)
+    test(test['name'], exe, suite : 'ipu3', is_parallel : false)
 endforeach
diff --git a/test/pipeline/rkisp1/meson.build b/test/pipeline/rkisp1/meson.build
index c82cc78972f6..1d178ad9da6f 100644
--- a/test/pipeline/rkisp1/meson.build
+++ b/test/pipeline/rkisp1/meson.build
@@ -1,14 +1,14 @@
 # SPDX-License-Identifier: CC0-1.0
 
 rkisp1_test = [
-    ['rkisp1_pipeline_test',            'rkisp1_pipeline_test.cpp'],
+    {'name': 'rkisp1_pipeline_test', 'sources': ['rkisp1_pipeline_test.cpp']},
 ]
 
 foreach test : rkisp1_test
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'rkisp1', is_parallel : false)
+    test(test['name'], exe, suite : 'rkisp1', is_parallel : false)
 endforeach
diff --git a/test/process/meson.build b/test/process/meson.build
index c656d7343e54..a80dc2d99fdd 100644
--- a/test/process/meson.build
+++ b/test/process/meson.build
@@ -1,14 +1,14 @@
 # SPDX-License-Identifier: CC0-1.0
 
 process_tests = [
-    ['process_test',   'process_test.cpp'],
+    {'name': 'process_test', 'sources': ['process_test.cpp']},
 ]
 
 foreach test : process_tests
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
 
-    test(test[0], exe, suite : 'process', is_parallel : false)
+    test(test['name'], exe, suite : 'process', is_parallel : false)
 endforeach
diff --git a/test/serialization/meson.build b/test/serialization/meson.build
index c4206cb3632b..a6e8d79358d9 100644
--- a/test/serialization/meson.build
+++ b/test/serialization/meson.build
@@ -3,14 +3,14 @@
 subdir('generated_serializer')
 
 serialization_tests = [
-    ['control_serialization',     'control_serialization.cpp'],
-    ['ipa_data_serializer_test',  'ipa_data_serializer_test.cpp'],
+    {'name': 'control_serialization', 'sources': ['control_serialization.cpp']},
+    {'name': 'ipa_data_serializer_test', 'sources': ['ipa_data_serializer_test.cpp']},
 ]
 
 foreach test : serialization_tests
-    exe = executable(test[0], [test[1], 'serialization_test.cpp'],
+    exe = executable(test['name'], test['sources'], 'serialization_test.cpp',
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
-    test(test[0], exe, suite : 'serialization', is_parallel : false)
+    test(test['name'], exe, suite : 'serialization', is_parallel : false)
 endforeach
diff --git a/test/stream/meson.build b/test/stream/meson.build
index 3a97868bce1c..a3b19bf592a5 100644
--- a/test/stream/meson.build
+++ b/test/stream/meson.build
@@ -1,14 +1,14 @@
 # SPDX-License-Identifier: CC0-1.0
 
 stream_tests = [
-    ['stream_colorspace', 'stream_colorspace.cpp'],
-    ['stream_formats',  'stream_formats.cpp'],
+    {'name': 'stream_colorspace', 'sources': ['stream_colorspace.cpp']},
+    {'name': 'stream_formats', 'sources': ['stream_formats.cpp']},
 ]
 
 foreach test : stream_tests
-    exe = executable(test[0], test[1],
+    exe = executable(test['name'], test['sources'],
                      dependencies : libcamera_public,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
-    test(test[0], exe, suite: 'stream')
+    test(test['name'], exe, suite: 'stream')
 endforeach
diff --git a/test/v4l2_subdevice/meson.build b/test/v4l2_subdevice/meson.build
index 4e607d41fc54..277f29bbcc41 100644
--- a/test/v4l2_subdevice/meson.build
+++ b/test/v4l2_subdevice/meson.build
@@ -1,14 +1,14 @@
 # SPDX-License-Identifier: CC0-1.0
 
 v4l2_subdevice_tests = [
-  ['list_formats',              'list_formats.cpp'],
-  ['test_formats',              'test_formats.cpp'],
+    {'name': 'list_formats', 'sources': ['list_formats.cpp']},
+    {'name': 'test_formats', 'sources': ['test_formats.cpp']},
 ]
 
 foreach test : v4l2_subdevice_tests
-    exe = executable(test[0], [test[1], 'v4l2_subdevice_test.cpp'],
+    exe = executable(test['name'], test['sources'], 'v4l2_subdevice_test.cpp',
         dependencies : libcamera_private,
         link_with : test_libraries,
         include_directories : test_includes_internal)
-    test(test[0], exe, suite : 'v4l2_subdevice', is_parallel : false)
+    test(test['name'], exe, suite : 'v4l2_subdevice', is_parallel : false)
 endforeach
diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build
index f85374854c48..87ea4f966ff1 100644
--- a/test/v4l2_videodevice/meson.build
+++ b/test/v4l2_videodevice/meson.build
@@ -3,22 +3,22 @@
 # Tests are listed in order of complexity.
 # They are not alphabetically sorted.
 v4l2_videodevice_tests = [
-    ['double_open',         'double_open.cpp'],
-    ['controls',            'controls.cpp'],
-    ['formats',             'formats.cpp'],
-    ['dequeue_watchdog',    'dequeue_watchdog.cpp'],
-    ['request_buffers',     'request_buffers.cpp'],
-    ['buffer_cache',        'buffer_cache.cpp'],
-    ['stream_on_off',       'stream_on_off.cpp'],
-    ['capture_async',       'capture_async.cpp'],
-    ['buffer_sharing',      'buffer_sharing.cpp'],
-    ['v4l2_m2mdevice',      'v4l2_m2mdevice.cpp'],
+    {'name': 'double_open', 'sources': ['double_open.cpp']},
+    {'name': 'controls', 'sources': ['controls.cpp']},
+    {'name': 'formats', 'sources': ['formats.cpp']},
+    {'name': 'dequeue_watchdog', 'sources': ['dequeue_watchdog.cpp']},
+    {'name': 'request_buffers', 'sources': ['request_buffers.cpp']},
+    {'name': 'buffer_cache', 'sources': ['buffer_cache.cpp']},
+    {'name': 'stream_on_off', 'sources': ['stream_on_off.cpp']},
+    {'name': 'capture_async', 'sources': ['capture_async.cpp']},
+    {'name': 'buffer_sharing', 'sources': ['buffer_sharing.cpp']},
+    {'name': 'v4l2_m2mdevice', 'sources': ['v4l2_m2mdevice.cpp']},
 ]
 
 foreach test : v4l2_videodevice_tests
-    exe = executable(test[0], [test[1], 'v4l2_videodevice_test.cpp'],
+    exe = executable(test['name'], [test['sources'], 'v4l2_videodevice_test.cpp'],
                      dependencies : libcamera_private,
                      link_with : test_libraries,
                      include_directories : test_includes_internal)
-    test(test[0], exe, suite : 'v4l2_videodevice', is_parallel : false)
+    test(test['name'], exe, suite : 'v4l2_videodevice', is_parallel : false)
 endforeach
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list