Commit 244dc4d1 authored by Christian Kellner's avatar Christian Kellner

test: bootacl: check handling of an empty boot_acl

Although that should never actually happen, make sure we correctly
handle empty boot_acl files, i.e. the boot_acl files exists, but
does not have any slots.
parent 96114e50
......@@ -321,6 +321,17 @@ test_bootacl_tear_down (TestBootacl *tt, gconstpointer user)
static void
dump_strv (GStrv strv, const char *prefix)
{
if (strv == NULL)
{
g_print ("%s is NULL\n", prefix);
return;
}
else if (*strv == NULL)
{
g_print ("%s is EMPTY\n", prefix);
return;
}
for (guint i = 0; strv[i]; i++)
g_print ("%s[%u] %s\n", prefix, i, strv[i]);
}
......@@ -446,11 +457,14 @@ test_bootacl_del_uuid (TestBootacl *tt,
static void
test_bootacl_basic (TestBootacl *tt, gconstpointer user)
{
g_auto(GStrv) sysacl = NULL;
BoltDomain *dom = tt->dom;
const char **used;
guint slots = tt->slots;
guint n, n_free, n_used;
g_assert_true (bolt_domain_supports_bootacl (dom));
n = bolt_domain_bootacl_slots (dom, &n_free);
g_assert_cmpuint (n, ==, slots);
g_assert_cmpuint (n_free, ==, slots);
......@@ -458,6 +472,42 @@ test_bootacl_basic (TestBootacl *tt, gconstpointer user)
used = bolt_domain_bootacl_get_used (dom, &n_used);
g_assert_cmpuint (g_strv_length ((GStrv) used), ==, 0);
g_assert_cmpuint (n_used, ==, 0);
/* disconnect and reconnect */
bolt_domain_disconnected (dom);
test_bootacl_connect_and_verify (tt, dom, &sysacl);
/* simulate some pathological cases that should not
* actually happen, but should still be handled
*/
/* after we connect, the slot list is empty */
bolt_domain_disconnected (dom);
g_strfreev (tt->acl);
tt->acl = g_strsplit ("", ",", -1);
test_bootacl_write_acl (tt, tt->acl);
test_bootacl_connect_and_verify (tt, dom, &sysacl);
g_assert_false (bolt_domain_supports_bootacl (dom));
n = bolt_domain_bootacl_slots (dom, &n_free);
g_assert_cmpuint (n, ==, 0);
g_assert_cmpuint (n_free, ==, 0);
/* after we connect, the slot list changed */
bolt_domain_disconnected (dom);
g_strfreev (tt->acl);
tt->acl = g_strsplit (",", ",", -1); /* two slots */
test_bootacl_write_acl (tt, tt->acl);
test_bootacl_connect_and_verify (tt, dom, &sysacl);
g_assert_true (bolt_domain_supports_bootacl (dom));
n = bolt_domain_bootacl_slots (dom, &n_free);
g_assert_cmpuint (n, ==, 2);
g_assert_cmpuint (n_free, ==, 2);
}
static void
......@@ -962,7 +1012,6 @@ main (int argc, char **argv)
test_bootacl_update_offline,
test_bootacl_tear_down);
g_test_add ("/sysfs/domain/bootacl/allocate",
TestBootacl,
NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment