[libcamera-devel] [PATCH 2/3] test: Add Sequence observer tests
Umang Jain
umang.jain at ideasonboard.com
Mon May 9 14:56:41 CEST 2022
Hello,
Thank you for the patch.
On 4/30/22 01:04, Kieran Bingham via libcamera-devel wrote:
> Validate the Sequence object for a set of possible permutations.
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
> test/meson.build | 1 +
> test/sequence.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 81 insertions(+)
> create mode 100644 test/sequence.cpp
>
> diff --git a/test/meson.build b/test/meson.build
> index fd4c5ca07c15..7c53fe5d0d76 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -47,6 +47,7 @@ internal_tests = [
> ['object-delete', 'object-delete.cpp'],
> ['object-invoke', 'object-invoke.cpp'],
> ['pixel-format', 'pixel-format.cpp'],
> + ['sequence', 'sequence.cpp'],
> ['shared-fd', 'shared-fd.cpp'],
> ['signal-threads', 'signal-threads.cpp'],
> ['threads', 'threads.cpp'],
> diff --git a/test/sequence.cpp b/test/sequence.cpp
> new file mode 100644
> index 000000000000..4afb9998527a
> --- /dev/null
> +++ b/test/sequence.cpp
> @@ -0,0 +1,80 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2022, Ideas on Board Oy.
> + *
> + * sequence.cpp - Sequence observer tests
> + */
> +
> +#include <iostream>
> +
> +#include <libcamera/sequence.h>
> +
> +#include "test.h"
> +
> +using namespace std;
> +using namespace libcamera;
> +
> +class SequenceTest : public Test
> +{
> +private:
> + int Fail(std::string m)
> + {
> + cout << m << endl;
> + return TestFail;
> + }
> +
> +protected:
> + int run()
> + {
> + Sequence seq;
> + int diff;
> +
> + /* Validate non-zero initialization */
> + diff = seq.update(10);
> + if (diff)
> + return Fail("Initialisation test failed");
> +
> + diff = seq.update(11);
> + if (diff)
> + return Fail("Sequential sequence failure");
> +
> + /* Validate 1 drop */
> + diff = seq.update(13);
> + if (diff != 1)
> + return Fail("Sequence gap not detected");
> +
> + /* Validate 10 drops - currently expect sequence 14 */
> + diff = seq.update(24);
> + if (diff != 10)
> + return Fail("Large sequence gap not detected");
> +
> + /* Validate reset */
> + seq.reset();
> + diff = seq.update(50);
> + if (diff)
> + return Fail("Reset failed");
> +
> + /* Validate reverse sequence detected */
> + diff = seq.update(49);
> + if (diff == 0)
> + return Fail("Reverse sequence detection error");
> +
> + /* Validate integer wrap around (Shouldn't ever happen but...) */
> + seq.reset();
> + diff = seq.update(-2);
> + if (diff)
> + return Fail("Integer wrap test reset failed");
> +
> + diff = seq.update(-1);
> + if (diff)
> + return Fail("Negative sequence failed");
> +
> + diff = seq.update(0);
> + if (diff)
> + return Fail("Integer wrap test failed");
> +
> + return TestPass;
> + }
> +};
> +
> +TEST_REGISTER(SequenceTest)
More information about the libcamera-devel
mailing list