mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 19:20:12 +01:00
core/tests: add unit test for nm_utils_kernel_cmdline_match_check()
This commit is contained in:
parent
e0f4817148
commit
fa56e52a4f
1 changed files with 34 additions and 0 deletions
|
|
@ -2117,6 +2117,39 @@ test_nm_utils_dhcp_client_id_systemd_node_specific (gconstpointer test_data)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
_kernel_cmdline_match (gboolean expected_match,
|
||||
const char *const*proc_cmdline,
|
||||
const char *const*patterns)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
GError **p_error = nmtst_get_rand_bool () ? &error : NULL;
|
||||
gboolean match;
|
||||
|
||||
nm_assert (proc_cmdline);
|
||||
nm_assert (patterns);
|
||||
|
||||
match = nm_utils_kernel_cmdline_match_check (proc_cmdline, patterns, NM_PTRARRAY_LEN (patterns), p_error);
|
||||
if (expected_match)
|
||||
nmtst_assert_success (match, error);
|
||||
else {
|
||||
g_assert (!p_error || error);
|
||||
g_assert (!match);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_kernel_cmdline_match_check (void)
|
||||
{
|
||||
_kernel_cmdline_match (TRUE, NM_MAKE_STRV (""), NM_MAKE_STRV (""));
|
||||
_kernel_cmdline_match (FALSE, NM_MAKE_STRV (""), NM_MAKE_STRV ("a"));
|
||||
_kernel_cmdline_match (TRUE, NM_MAKE_STRV ("a"), NM_MAKE_STRV ("a"));
|
||||
_kernel_cmdline_match (TRUE, NM_MAKE_STRV ("a=b"), NM_MAKE_STRV ("a"));
|
||||
_kernel_cmdline_match (TRUE, NM_MAKE_STRV ("a=b", "b"), NM_MAKE_STRV ("a", "b"));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_connectivity_state_cmp (void)
|
||||
{
|
||||
|
|
@ -2229,6 +2262,7 @@ main (int argc, char **argv)
|
|||
g_test_add_data_func ("/general/nm_utils_dhcp_client_id_systemd_node_specific/1", GINT_TO_POINTER (1), test_nm_utils_dhcp_client_id_systemd_node_specific);
|
||||
|
||||
g_test_add_func ("/core/general/test_connectivity_state_cmp", test_connectivity_state_cmp);
|
||||
g_test_add_func ("/core/general/test_kernel_cmdline_match_check", test_kernel_cmdline_match_check);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue