[PATCH] test: controls: control_info: Add test for enum controls

Umang Jain umang.jain at ideasonboard.com
Wed Sep 11 06:34:24 CEST 2024


Hi Paul

On 10/09/24 7:01 pm, Paul Elder wrote:
> Add a test for enum controls to test that the ranges and values are set
> properly.
>
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
>   test/controls/control_info.cpp | 39 ++++++++++++++++++++++++++++++++++
>   1 file changed, 39 insertions(+)
>
> diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp
> index e1bb43f0e..460aaa345 100644
> --- a/test/controls/control_info.cpp
> +++ b/test/controls/control_info.cpp
> @@ -6,6 +6,7 @@
>    */
>   
>   #include <iostream>
> +#include <vector>
>   
>   #include <libcamera/control_ids.h>
>   #include <libcamera/controls.h>
> @@ -79,6 +80,44 @@ protected:
>   			return TestFail;
>   		}
>   
> +		/*
> +		 * Test information retrieval from an enum control.
> +		 */
> +		ControlInfo awbMode(static_cast<int32_t>(controls::AwbTungsten),
> +				    static_cast<int32_t>(controls::AwbDaylight));
> +		if (awbMode.min().get<int32_t>() != controls::AwbTungsten ||
> +		    awbMode.max().get<int32_t>() != controls::AwbDaylight) {
> +			cout << "Invalid control range for AwbMode" << endl;
> +			return TestFail;
> +		}
> +
> +		std::vector<ControlValue> modes = {
> +			static_cast<int32_t>(controls::AwbTungsten),
> +			static_cast<int32_t>(controls::AwbFluorescent),
> +			static_cast<int32_t>(controls::AwbDaylight),
> +		};
> +		ControlInfo awbModes(Span<const ControlValue>{ modes });
> +
> +		if (awbModes.min() != modes.front() ||
> +		    awbModes.def() != modes.front() ||
> +		    awbModes.max() != modes.back()) {
> +			cout << "Invalid control range for AwbModes" << endl;
> +			return TestFail;
> +		}
> +
> +		if (awbModes.values().size() != modes.size()) {

Are we really comparing the awbModes with the modes vector ?

Shouldn't we be comparing awbModes with awbMode ?
> +			cout << "Invalid size for AwbModes" << endl;
> +			return TestFail;
> +		}
> +
> +		unsigned int i = 0;
> +		for (const auto &value : awbModes.values()) {
> +			if (value != modes.at(i++)) {

Similar comment here:

Shouldn't we be comparing enum values :

ControlInfo awbModes

vs

ControlInfo awbMode

My idea of the test would be to equate the values of the range vs values 
from modes vector. Does it make sense?

> +				cout << "Invalid control values for AwbModes" << endl;
> +				return TestFail;
> +			}
> +		}
> +
>   		return TestPass;
>   	}
>   };



More information about the libcamera-devel mailing list