From 51a8eb6410461c94c8e0f2b59e3417cfb5d7da75 Mon Sep 17 00:00:00 2001 From: Igor Ostapenko Date: Sun, 23 Feb 2025 10:41:58 +0000 Subject: [PATCH] kyua: Pass unprivileged user config prop to ATF using all known names Kyua and ATF speak different naming styles. In this case, the unprivileged user property can be named with underscore on the Kyua side, and with a hyphen on the ATF side. Sometimes it is not obvious which style should be used in which situation. For instance, a test case may require this configuration property being set using require.config. Also, a test case may want to read the property using something like atf_tc_get_config_var(). Which names should be used in these cases? From the perspective of the original code, it is expected to be this: require.config unprivileged-user atf_tc_get_config_var(tc, "unprivileged-user") But, as long as Kyua is the main interface, its users expect to work with kyua.conf(5), which says that it must be named as unprivileged_user (with underscore). As a result, test authors tend to do this instead: require.config unprivileged_user atf_tc_get_config_var(tc, "unprivileged_user") Kyua already has hacks to understand both unprivileged_user and unprivileged-user coming from require.config. And this patch covers the missing second part -- make Kyua pass both names back to ATF as two identical configuration properties named different ways. Reviewed by: ngie, asomers MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D49039 --- contrib/kyua/engine/scheduler.cpp | 3 ++ contrib/kyua/engine/scheduler_test.cpp | 1 + contrib/kyua/integration/cmd_test_test.sh | 43 +++++++++++++++++++++ contrib/kyua/integration/helpers/config.cpp | 10 +++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/contrib/kyua/engine/scheduler.cpp b/contrib/kyua/engine/scheduler.cpp index e75091a40e3..d4507a24732 100644 --- a/contrib/kyua/engine/scheduler.cpp +++ b/contrib/kyua/engine/scheduler.cpp @@ -1632,7 +1632,10 @@ scheduler::generate_config(const config::tree& user_config, if (user_config.is_set("unprivileged_user")) { const passwd::user& user = user_config.lookup< engine::user_node >("unprivileged_user"); + // The property is duplicated using both ATF and Kyua naming styles + // for better UX. props["unprivileged-user"] = user.name; + props["unprivileged_user"] = user.name; } return props; diff --git a/contrib/kyua/engine/scheduler_test.cpp b/contrib/kyua/engine/scheduler_test.cpp index e144761d8f0..d91c448f2e5 100644 --- a/contrib/kyua/engine/scheduler_test.cpp +++ b/contrib/kyua/engine/scheduler_test.cpp @@ -1192,6 +1192,7 @@ ATF_TEST_CASE_BODY(generate_config__some_matches) config::properties_map exp_props; exp_props["unprivileged-user"] = "nobody"; + exp_props["unprivileged_user"] = "nobody"; exp_props["var1"] = "value 1"; ATF_REQUIRE_EQ(exp_props, diff --git a/contrib/kyua/integration/cmd_test_test.sh b/contrib/kyua/integration/cmd_test_test.sh index f0862cf2958..4c2fe863a4f 100644 --- a/contrib/kyua/integration/cmd_test_test.sh +++ b/contrib/kyua/integration/cmd_test_test.sh @@ -596,6 +596,48 @@ EOF } +utils_test_case config_unprivileged_user +config_unprivileged_user_body() { + cat >"my-config" <Kyuafile <