tests: add parametric_color_profile_parsing_errors

This test goes through all the errors one can do in weston.ini
color-profile section, and ensures they give the proper error logging.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2025-09-18 16:36:36 +03:00 committed by Leandro Ribeiro
parent a06ef0f8aa
commit a60169e239

View file

@ -183,6 +183,16 @@ mock_cm_ref_stock_sRGB_color_profile(struct weston_color_manager *mock_cm)
return mock_cprof; return mock_cprof;
} }
static bool
mock_cm_get_color_profile_from_params(struct weston_color_manager *cm,
const struct weston_color_profile_params *params,
const char *name_part,
struct weston_color_profile **cprof_out,
char **errmsg)
{
test_assert_not_reached("This cannot be a valid parametric profile.");
}
static void static void
mock_cm_destroy_color_profile(struct weston_color_profile *mock_cprof) mock_cm_destroy_color_profile(struct weston_color_profile *mock_cprof)
{ {
@ -673,3 +683,289 @@ TEST_P(mode_config_error, mode_config_cases)
return RESULT_OK; return RESULT_OK;
} }
static void
test_creating_output_color_profile(struct weston_config *wc,
const char *profile_name,
uint32_t supported_color_features,
uint32_t supported_primaries_named,
uint32_t supported_tf_named,
const char *expected_error)
{
struct weston_color_profile *cprof;
char *logbuf;
size_t logsize;
struct mock_color_manager mock_cm = {
.base.ref_stock_sRGB_color_profile = mock_cm_ref_stock_sRGB_color_profile,
.base.get_color_profile_from_params = mock_cm_get_color_profile_from_params,
.base.destroy_color_profile = mock_cm_destroy_color_profile,
.base.supported_color_features = supported_color_features,
.base.supported_primaries_named = supported_primaries_named,
.base.supported_tf_named = supported_tf_named,
};
struct weston_compositor mock_compositor = {
.color_manager = &mock_cm.base,
.color_profile_id_generator = weston_idalloc_create(&mock_compositor),
};
struct weston_output mock_output = {};
mock_cm.base.compositor = &mock_compositor;
wl_list_init(&mock_compositor.plane_list);
logfile = open_memstream(&logbuf, &logsize);
weston_log_set_handler(logger, logger);
weston_output_init(&mock_output, &mock_compositor, "mockoutput");
cprof = wet_create_output_color_profile(&mock_output, wc, profile_name);
test_assert_ptr_null(cprof);
test_assert_int_eq(fclose(logfile), 0);
logfile = NULL;
testlog("logs:\n%s\n------\n", logbuf);
test_assert_str_eq(logbuf, expected_error);
free(logbuf);
weston_output_release(&mock_output);
weston_idalloc_destroy(mock_compositor.color_profile_id_generator);
}
struct color_profile_name_testcase {
const char *profile_name;
const char *expected_error;
};
static const struct color_profile_name_testcase color_profile_name_cases[] = {
{
"notexists",
"Config error in weston.ini, output mockoutput: no [color-profile] section with 'name=notexists' found.\n",
},
{
"boo:faa",
"Config error in weston.ini, output mockoutput, color-profile=boo:faa is illegal. The ':' character is legal only for 'srgb:' and 'auto:'.\n",
},
{
"auto:kek",
"Config error in weston.ini, output mockoutput, key color-profile=auto: invalid flag 'kek'.\n",
},
};
/*
* Manufacture various weston.ini and check the error messages that
* wet_create_output_color_profile() generates for bad color-profile names.
*/
TEST_P(parametric_color_profile_name_errors, color_profile_name_cases)
{
const struct color_profile_name_testcase *t = data;
test_creating_output_color_profile(NULL, t->profile_name,
0xffffffff, 0xffffffff, 0xffffffff,
t->expected_error);
return RESULT_OK;
}
struct parameters_testcase {
const char *profile_string;
const char *expected_error;
};
static const struct parameters_testcase param_config_cases[] = {
{
"",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" primaries not set\n"
" transfer function not set\n",
},
{
"tf_named=gamma22\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" primaries not set\n"
},
{
"prim_named=srgb\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" transfer function not set\n",
},
{
"tf_named=kukkuu\n"
"prim_named=jeejee\n",
"Config error in weston.ini [color-profile] name=mydisp, prim_named has unknown value 'jeejee'.\n"
"Config error in weston.ini [color-profile] name=mydisp, tf_named has unknown value 'kukkuu'.\n",
},
{
"prim_named=pal\n"
"tf_named=gamma28\n"
"tf_power=2.4\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" tf was already set\n",
},
{
"prim_named=pal_m\n"
"prim_red=0.67 0.33\n"
"prim_green=0.21 0.71\n"
"prim_blue=0.14 0.08\n"
"prim_white=0.31 0.32\n"
"tf_power=2.4\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" primaries were already set\n",
},
{
"prim_red=0.6 0.3\n"
"prim_blue=0.1 0.05\n"
"min_lum=0\n"
"target_white=0.33 0.33\n"
"target_max_lum=1200\n",
"Config error in weston.ini [color-profile] name=mydisp:\n"
" group: signaling primaries\n"
" prim_red is set.\n"
" prim_green is missing.\n"
" prim_blue is set.\n"
" prim_white is missing.\n"
" group: signaling luminances\n"
" min_lum is set.\n"
" max_lum is missing.\n"
" ref_lum is missing.\n"
" group: target primaries\n"
" target_red is missing.\n"
" target_green is missing.\n"
" target_blue is missing.\n"
" target_white is set.\n"
" group: target luminances\n"
" target_min_lum is missing.\n"
" target_max_lum is set.\n"
"You must set either none or all keys of a group.\n",
},
{
"prim_red=0.67 0.33 0.4\n"
"prim_green=0.21\n"
"prim_blue=0,14 k\n"
"prim_white=\n"
"tf_power=xx\n",
"Config error in weston.ini [color-profile] name=mydisp, parsing prim_red: Needed exactly 2 numbers separated by whitespace, got 3.\n"
"Config error in weston.ini [color-profile] name=mydisp, parsing prim_green: Needed exactly 2 numbers separated by whitespace, got 1.\n"
"Config error in weston.ini [color-profile] name=mydisp, parsing prim_blue: '0,14' is not a number.\n"
"Config error in weston.ini [color-profile] name=mydisp, parsing prim_white: Needed exactly 2 numbers separated by whitespace, got 0.\n"
"Config error in weston.ini [color-profile] name=mydisp, parsing tf_power: 'xx' is not a number.\n",
},
{
"tf_power=50\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" tf power exponent 50.000000 is not in the range [1.0, 10.0]\n"
" primaries not set\n"
" transfer function not set\n",
},
{
"prim_red=Inf 0.33\n"
"prim_green=0.21 7\n"
"prim_blue=-1 NaN\n"
"prim_white=0 -2\n"
"tf_power=3\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" invalid primary color volume, the red primary CIE x value inf is out of range [-1.0, 2.0]\n"
" invalid primary color volume, the green primary CIE y value 7.000000 is out of range [-1.0, 2.0]\n"
" invalid primary color volume, the blue primary CIE y value nan is out of range [-1.0, 2.0]\n"
" invalid primary color volume, the white point CIE y value -2.000000 is out of range [-1.0, 2.0]\n"
" white point out of primary volume\n"
},
{
"prim_named=bt2020\n"
"tf_named=bt1886\n"
"min_lum=10\n"
"ref_lum=5\n"
"max_lum=2\n"
"target_min_lum=55\n"
"target_max_lum=1\n"
"max_fall=-7\n"
"max_cll=0\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" reference luminance (5.000000) must be greater than primary minimum luminance (10.000000)\n"
" primary minimum luminance (10.000000) must be less than primary maximum luminance (2.000000)\n"
" target min luminance (55.000000) must be less than target max luminance (1.000000)\n"
" maxCLL (0.000000) must be in the range (0.0, 1e+6]\n"
" maxCLL (0.000000) should be greater than target min luminance (0.010000)\n"
" maxFALL (-7.000000) must be in the range (0.0, 1e+6]\n"
" maxFALL (-7.000000) must be greater than min luminance (0.010000)\n",
},
};
/*
* Manufacture various weston.ini and check the error messages that
* wet_create_output_color_profile() generates for invalid
* color-profile sections.
*/
TEST_P(parametric_color_profile_parsing_errors, param_config_cases)
{
const struct parameters_testcase *t = data;
struct compositor_setup setup;
struct weston_config *wc;
compositor_setup_defaults(&setup);
weston_ini_setup(&setup,
cfgln("[color-profile]"),
cfgln("name=mydisp"),
cfgln("%s", t->profile_string));
wc = weston_config_parse(setup.config_file);
test_assert_ptr_not_null(wc);
free(setup.config_file);
test_creating_output_color_profile(wc, "mydisp",
0xffffffff, 0xffffffff, 0xffffffff,
t->expected_error);
weston_config_destroy(wc);
return RESULT_OK;
}
static const struct parameters_testcase param_unsupported_cases[] = {
{
"prim_named=ntsc\n"
"tf_named=log100\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" primaries named NTSC (BT.601) not supported by the color manager\n"
" logarithmic 100:1 not supported by the color manager\n"
" primaries not set\n"
" transfer function not set\n",
},
{
"prim_named=srgb\n"
"tf_power=2.3\n",
"Config error in weston.ini [color-profile] name=mydisp, invalid parameter set:\n"
" set_tf_power not supported by the color manager\n"
" transfer function not set\n",
},
};
/*
* Manufacture various weston.ini and check the error messages that
* wet_create_output_color_profile() generates for valid
* color-profile sections that use things the color manager does not
* support.
*/
TEST_P(parametric_color_profile_parsing_unsupported, param_unsupported_cases)
{
const struct parameters_testcase *t = data;
struct compositor_setup setup;
struct weston_config *wc;
compositor_setup_defaults(&setup);
weston_ini_setup(&setup,
cfgln("[color-profile]"),
cfgln("name=mydisp"),
cfgln("%s", t->profile_string));
wc = weston_config_parse(setup.config_file);
test_assert_ptr_not_null(wc);
free(setup.config_file);
test_creating_output_color_profile(wc, "mydisp",
0, (1u << WESTON_PRIMARIES_CICP_SRGB), 0,
t->expected_error);
weston_config_destroy(wc);
return RESULT_OK;
}