Commit graph

18 commits

Author SHA1 Message Date
Stefan Klug
f623f3ed64 libcamera: yaml-parser: Add failing test for unexpected behavior
When accessing a nonexistent key on a dict the YamlObject returns an
empty element. This element can happily be cast to a string. This is
unexpected. For example the following statement:

yamlDict["nonexistent"].get<string>("default")

is expected to return "default" but actually returns "". Add a (failing)
testcase for that behavior.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2024-09-23 13:03:35 +02:00
Stefan Klug
f2842258d1 libcamera: yaml-parser: Add additional tests
Add additional tests in preparation for upcoming modifications on the
yaml parser. These tests handle the case where the yaml file contains
empty items in dictionaries or lists. E.g.:

dict:
  key_with_value: value
  key_without_value:

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2024-09-23 13:03:35 +02:00
Laurent Pinchart
626172a16b libcamera: Drop file name from header comment blocks
Source files in libcamera start by a comment block header, which
includes the file name and a one-line description of the file contents.
While the latter is useful to get a quick overview of the file contents
at a glance, the former is mostly a source of inconvenience. The name in
the comments can easily get out of sync with the file name when files
are renamed, and copy & paste during development have often lead to
incorrect names being used to start with.

Readers of the source code are expected to know which file they're
looking it. Drop the file name from the header comment block.

The change was generated with the following script:

----------------------------------------

dirs="include/libcamera src test utils"

declare -rA patterns=(
	['c']=' \* '
	['cpp']=' \* '
	['h']=' \* '
	['py']='# '
	['sh']='# '
)

for ext in ${!patterns[@]} ; do
	files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done)
	pattern=${patterns[${ext}]}

	for file in $files ; do
		name=$(basename ${file})
		sed -i "s/^\(${pattern}\)${name} - /\1/" "$file"
	done
done
----------------------------------------

This misses several files that are out of sync with the comment block
header. Those will be addressed separately and manually.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
2024-05-08 22:39:50 +03:00
Laurent Pinchart
a69958fcd6 libcamera: yaml_parser: Enable YamlObject::get() for int8_t and uint8_t
The YamlObject::get() function template is implemented for 16-bit and
32-bit integers. Add an 8-bit specialization that will be used in the
rkisp1 IPA module, and extend the unit tests accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-21 21:47:19 +03:00
Laurent Pinchart
7615f58f9b test: yaml-parser: Test out-of-range checks on integer parsing
Add 16-bit integer parsing tests, including a test to verify the
out-of-range checks when parsing 32-bit integers as 16-bit values. That
test currently fails.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-21 21:47:17 +03:00
Laurent Pinchart
629e65b15b test: yaml-parser: Centralize integer parse checks
Centralize the signed and unsigned integer parse checks to avoid code
duplication. The diffstat isn't very impressive at this point, but this
will help more when adding 8-bit and 16-bit integer tests.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-21 21:47:16 +03:00
Laurent Pinchart
88746ddf94 test: yaml-parser: Simplify code by centralizing parse error checks
Centralize most parse failure checks in a single function to avoid a
larger number of copies of nearly identical checks.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-21 21:47:14 +03:00
Laurent Pinchart
90906ba7fb test: yaml-parser: Test YamlObject::get(const T &defaultValue)
When the YamlObject::get() function override that returns a
std::optional got introduced, all tests were moved to it, leaving no
tests for the override that takes a default value. Reintroduce those
tests.

Reported-by: Florian Sylvestre <fsylvestre@baylibre.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-01 19:39:12 +03:00
Florian Sylvestre
02e387e7b6 libcamera: yaml_parser: Add getList() function
Allow to retrieve a YAML list of any already supported types in a
std::vector.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-07-28 13:48:54 +03:00
Laurent Pinchart
6724800f14 test: yaml-parser: Test dictionary items ordering
While YAML specifies that mappings are unordered, the Raspberry Pi IPA
relies on elements being ordered as in the YAML data. To replace the
dependency on boost with the YamlParser class, we thus need to guarantee
that the order is preserved. Update the corresponding unit test to
ensure this. The test currently fails at the YamlParser doesn't
correctly preserve the order, this will be fixed by the next commit.

This commit should be reverted when the Raspberry Pi IPA updates to a
new tuning data format and drops support for the old format.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
2022-07-28 13:47:48 +03:00
Laurent Pinchart
feb8c9be78 libcamera: yaml_parser: Replace ok flag to get() with std::optional
The YamlObject::get() function takes a default value and an optional
bool ok flag to handle parsing errors. This ad-hoc mechanism complicates
error handling in callers.

A better API is possible by dropping the default value and ok flag and
returning an std::optional. Not only does it simplify the calls, it also
lets callers handle errors through the standard std::optional class
instead of the current ad-hoc mechanism.

Provide a get() wrapper around std::optional::value_or() to further
simplify callers that don't need any specific error handling.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-07-28 13:47:13 +03:00
Laurent Pinchart
9dacead615 libcamera: yaml_parser: Remove memberNames() function
Now that YamlObject supports iteration, the memberNames() function isn't
useful anymore as it can be implemented using utils::map_keys() if
really needed. Drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org>
2022-06-20 15:12:26 +03:00
Laurent Pinchart
90577226aa test: yaml_parser: Extend tests to cover the iterator API
Test iteration over lists and dictionaries to test the YamlObject
iterator API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org>
2022-06-20 15:12:12 +03:00
Laurent Pinchart
1657106b0c test: yaml-parser: Use write() instead of fwrite()
There's no point in wrapping a fd into a FILE to then only call fwrite()
and fclose(). Use write() and close() directly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-16 02:43:47 +03:00
Laurent Pinchart
d6d0a675bf libcamera: yaml_parser: Switch from FILE to File
THe FILE object isn't very user-friendly as it requires manual close.
Replace it with File to provide RAII-style resource management in the
YamlParser API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-16 02:43:47 +03:00
Laurent Pinchart
27fb47f70b libcamera: yaml_parser: Extend YamlObject::size() to dictionaries
Dictionaries have a size too, extend the size() function to support
them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-16 02:43:47 +03:00
Laurent Pinchart
5517ffbff6 libcamera: Use "..." instead of <...> consistently for internal headers
libcamera uses double quotes for #include directives for internal
headers. A few <...> have found their way in the code base over time.
Fix them.

While at it, move an Android header include to the right location.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-01 12:08:36 +03:00
Han-Lin Chen
c4c4ff92b4 test: Add YamlParser test
Add a unit test to exercise the API of the YamlParser class.

Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-10 00:22:36 +03:00