[libcamera-devel,13/17] test: stream: Add test for StreamFormat

Message ID 20190527001543.13593-14-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: Add support for format information and validation
Related show

Commit Message

Niklas Söderlund May 27, 2019, 12:15 a.m. UTC
Test that both discrete and range based stream format descriptions
result in good discrete frame sizes. The range based stream formats
needs to be fitted with a table of resolutions inside libcamera so if
that table is update this test might need to be updated.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 test/meson.build               |   1 +
 test/stream/meson.build        |  11 ++++
 test/stream/stream_formats.cpp | 102 +++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 test/stream/meson.build
 create mode 100644 test/stream/stream_formats.cpp

Comments

Laurent Pinchart June 10, 2019, 6:56 a.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Mon, May 27, 2019 at 02:15:39AM +0200, Niklas Söderlund wrote:
> Test that both discrete and range based stream format descriptions
> result in good discrete frame sizes. The range based stream formats
> needs to be fitted with a table of resolutions inside libcamera so if
> that table is update this test might need to be updated.

s/is update/is updated/

> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  test/meson.build               |   1 +
>  test/stream/meson.build        |  11 ++++
>  test/stream/stream_formats.cpp | 102 +++++++++++++++++++++++++++++++++
>  3 files changed, 114 insertions(+)
>  create mode 100644 test/stream/meson.build
>  create mode 100644 test/stream/stream_formats.cpp
> 
> diff --git a/test/meson.build b/test/meson.build
> index 609aeab80e7d0f4f..5370f3028a4fe39d 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -4,6 +4,7 @@ subdir('camera')
>  subdir('ipa')
>  subdir('media_device')
>  subdir('pipeline')
> +subdir('stream')
>  subdir('v4l2_device')
>  subdir('v4l2_subdevice')
>  
> diff --git a/test/stream/meson.build b/test/stream/meson.build
> new file mode 100644
> index 0000000000000000..5b42fe32b341970f
> --- /dev/null
> +++ b/test/stream/meson.build
> @@ -0,0 +1,11 @@
> +stream_tests = [
> +  [ 'stream_formats', 'stream_formats.cpp' ],

Four spaces for indentation please.

> +]
> +
> +foreach t : stream_tests
> +  exe = executable(t[0], t[1],
> +                   dependencies : libcamera_dep,
> +                   link_with : test_libraries,
> +                   include_directories : test_includes_internal)
> +  test(t[0], exe, suite: 'stream', is_parallel: false)
> +endforeach
> diff --git a/test/stream/stream_formats.cpp b/test/stream/stream_formats.cpp
> new file mode 100644
> index 0000000000000000..42a596cc69893b20
> --- /dev/null
> +++ b/test/stream/stream_formats.cpp
> @@ -0,0 +1,102 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2019, Google Inc.
> + *
> + * stream_formats.cpp - StreamFormats test
> + */
> +
> +#include <iostream>
> +
> +#include <libcamera/geometry.h>
> +#include <libcamera/stream.h>
> +
> +#include "test.h"
> +
> +using namespace std;
> +using namespace libcamera;
> +
> +class StreamFormatsTest : public Test
> +{
> +protected:
> +	int testSizes(std::string name, std::vector<Size> test, std::vector<Size> valid)
> +	{
> +		bool pass = false;
> +
> +		for (Size &size : test) {
> +			pass = false;
> +
> +			for (Size &validSize : valid) {
> +				if (size == validSize) {
> +					pass = true;
> +					break;
> +				}
> +			}
> +
> +			if (!pass)
> +				break;
> +		}
> +
> +		if (!pass) {
> +			cout << "Failed " << name << endl;
> +			cout << "Sizes to test:" << endl;
> +			for (Size &size : test)
> +				cout << size.toString() << endl;
> +			cout << "Valid sizes:" << endl;
> +			for (Size &size : valid)
> +				cout << size.toString() << endl;
> +
> +			return TestFail;
> +		}
> +
> +		return TestPass;
> +	}
> +
> +	int run()
> +	{
> +		/* Test discrete sizes */
> +		StreamFormats discrete({
> +			{ 1, { SizeRange(100, 100), SizeRange(200, 200) } },
> +			{ 2, { SizeRange(300, 300), SizeRange(400, 400) } },
> +		});
> +
> +		if (testSizes("discrete 1", discrete.sizes(1),
> +			      { Size(100, 100), Size(200, 200) }))
> +			return TestFail;
> +		if (testSizes("discrete 2", discrete.sizes(2),
> +			      { Size(300, 300), Size(400, 400) }))
> +			return TestFail;
> +
> +		/* Test range sizes */
> +		StreamFormats range({
> +			{ 1, { SizeRange(640, 480, 640, 480) } },
> +			{ 2, { SizeRange(640, 480, 800, 600, 8, 8) } },
> +			{ 3, { SizeRange(640, 480, 800, 600, 16, 16) } },
> +			{ 4, { SizeRange(128, 128, 4096, 4096, 128, 128) } },
> +		});
> +
> +		if (testSizes("range 1", range.sizes(1), { Size(640, 480) }))
> +			return TestFail;
> +
> +		if (testSizes("range 2", range.sizes(2), {
> +			      Size(640, 480), Size(720, 480),
> +			      Size(720, 576), Size(768, 480),
> +			      Size(800, 600) }))
> +			return TestFail;
> +
> +

Extra blank line.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +		if (testSizes("range 3", range.sizes(3), {
> +			      Size(640, 480), Size(720, 480),
> +			      Size(720, 576), Size(768, 480) }))
> +			return TestFail;
> +
> +		if (testSizes("range 4", range.sizes(4), {
> +			      Size(1024, 768), Size(1280, 1024),
> +			      Size(2048, 1152), Size(2048, 1536),
> +			      Size(2560, 2048), Size(3200, 2048), }))
> +			return TestFail;
> +
> +		return TestPass;
> +	}
> +};
> +
> +TEST_REGISTER(StreamFormatsTest)

Patch

diff --git a/test/meson.build b/test/meson.build
index 609aeab80e7d0f4f..5370f3028a4fe39d 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -4,6 +4,7 @@  subdir('camera')
 subdir('ipa')
 subdir('media_device')
 subdir('pipeline')
+subdir('stream')
 subdir('v4l2_device')
 subdir('v4l2_subdevice')
 
diff --git a/test/stream/meson.build b/test/stream/meson.build
new file mode 100644
index 0000000000000000..5b42fe32b341970f
--- /dev/null
+++ b/test/stream/meson.build
@@ -0,0 +1,11 @@ 
+stream_tests = [
+  [ 'stream_formats', 'stream_formats.cpp' ],
+]
+
+foreach t : stream_tests
+  exe = executable(t[0], t[1],
+                   dependencies : libcamera_dep,
+                   link_with : test_libraries,
+                   include_directories : test_includes_internal)
+  test(t[0], exe, suite: 'stream', is_parallel: false)
+endforeach
diff --git a/test/stream/stream_formats.cpp b/test/stream/stream_formats.cpp
new file mode 100644
index 0000000000000000..42a596cc69893b20
--- /dev/null
+++ b/test/stream/stream_formats.cpp
@@ -0,0 +1,102 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * stream_formats.cpp - StreamFormats test
+ */
+
+#include <iostream>
+
+#include <libcamera/geometry.h>
+#include <libcamera/stream.h>
+
+#include "test.h"
+
+using namespace std;
+using namespace libcamera;
+
+class StreamFormatsTest : public Test
+{
+protected:
+	int testSizes(std::string name, std::vector<Size> test, std::vector<Size> valid)
+	{
+		bool pass = false;
+
+		for (Size &size : test) {
+			pass = false;
+
+			for (Size &validSize : valid) {
+				if (size == validSize) {
+					pass = true;
+					break;
+				}
+			}
+
+			if (!pass)
+				break;
+		}
+
+		if (!pass) {
+			cout << "Failed " << name << endl;
+			cout << "Sizes to test:" << endl;
+			for (Size &size : test)
+				cout << size.toString() << endl;
+			cout << "Valid sizes:" << endl;
+			for (Size &size : valid)
+				cout << size.toString() << endl;
+
+			return TestFail;
+		}
+
+		return TestPass;
+	}
+
+	int run()
+	{
+		/* Test discrete sizes */
+		StreamFormats discrete({
+			{ 1, { SizeRange(100, 100), SizeRange(200, 200) } },
+			{ 2, { SizeRange(300, 300), SizeRange(400, 400) } },
+		});
+
+		if (testSizes("discrete 1", discrete.sizes(1),
+			      { Size(100, 100), Size(200, 200) }))
+			return TestFail;
+		if (testSizes("discrete 2", discrete.sizes(2),
+			      { Size(300, 300), Size(400, 400) }))
+			return TestFail;
+
+		/* Test range sizes */
+		StreamFormats range({
+			{ 1, { SizeRange(640, 480, 640, 480) } },
+			{ 2, { SizeRange(640, 480, 800, 600, 8, 8) } },
+			{ 3, { SizeRange(640, 480, 800, 600, 16, 16) } },
+			{ 4, { SizeRange(128, 128, 4096, 4096, 128, 128) } },
+		});
+
+		if (testSizes("range 1", range.sizes(1), { Size(640, 480) }))
+			return TestFail;
+
+		if (testSizes("range 2", range.sizes(2), {
+			      Size(640, 480), Size(720, 480),
+			      Size(720, 576), Size(768, 480),
+			      Size(800, 600) }))
+			return TestFail;
+
+
+		if (testSizes("range 3", range.sizes(3), {
+			      Size(640, 480), Size(720, 480),
+			      Size(720, 576), Size(768, 480) }))
+			return TestFail;
+
+		if (testSizes("range 4", range.sizes(4), {
+			      Size(1024, 768), Size(1280, 1024),
+			      Size(2048, 1152), Size(2048, 1536),
+			      Size(2560, 2048), Size(3200, 2048), }))
+			return TestFail;
+
+		return TestPass;
+	}
+};
+
+TEST_REGISTER(StreamFormatsTest)