]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add core-specific varlink enum sync test
authorIvan Kruglov <mail@ikruglov.com>
Thu, 5 Mar 2026 11:05:00 +0000 (03:05 -0800)
committerIvan Kruglov <mail@ikruglov.com>
Fri, 10 Apr 2026 15:37:04 +0000 (08:37 -0700)
Add test-varlink-idl-unit that validates all varlink enum types in
io.systemd.Unit match their corresponding C string tables. This
catches drift between varlink IDL enum definitions and internal
enum values.

Uses core_test_template since it links against libcore for access
to the string table lookup functions.

ExecOutput uses TEST_IDL_ENUM_TO_STRING only because the '+' in
'kmsg+console' doesn't survive the underscorify/dashify round-trip.

src/test/meson.build
src/test/test-varlink-idl-unit.c [new file with mode: 0644]

index fbb730ab5e14801c475ad8586dd89c8b523f35fd..4cb77505f3dce82b8d42a106cc3fd3b10b52ebae 100644 (file)
@@ -493,6 +493,9 @@ executables += [
                 'sources' : files('test-varlink-idl.c'),
                 'dependencies' : threads,
         },
+        core_test_template + {
+                'sources' : files('test-varlink-idl-unit.c'),
+        },
         test_template + {
                 'sources' : files('test-watchdog.c'),
                 'type' : 'unsafe',
diff --git a/src/test/test-varlink-idl-unit.c b/src/test/test-varlink-idl-unit.c
new file mode 100644 (file)
index 0000000..408396a
--- /dev/null
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "cgroup.h"
+#include "tests.h"
+#include "test-varlink-idl-util.h"
+#include "unit.h"
+#include "varlink-io.systemd.Unit.h"
+
+TEST(unit_enums_idl) {
+        /* ExecContext enums */
+        TEST_IDL_ENUM(ExecInput, exec_input, vl_type_ExecInputType);
+        TEST_IDL_ENUM_TO_STRING(ExecOutput, exec_output, vl_type_ExecOutputType);
+        TEST_IDL_ENUM(ExecUtmpMode, exec_utmp_mode, vl_type_ExecUtmpMode);
+        TEST_IDL_ENUM(ExecPreserveMode, exec_preserve_mode, vl_type_ExecPreserveMode);
+        TEST_IDL_ENUM(ExecKeyringMode, exec_keyring_mode, vl_type_ExecKeyringMode);
+        TEST_IDL_ENUM(MemoryTHP, memory_thp, vl_type_MemoryTHP);
+        TEST_IDL_ENUM(ProtectProc, protect_proc, vl_type_ProtectProc);
+        TEST_IDL_ENUM(ProcSubset, proc_subset, vl_type_ProcSubset);
+        TEST_IDL_ENUM(ProtectSystem, protect_system, vl_type_ProtectSystem);
+        TEST_IDL_ENUM(ProtectHome, protect_home, vl_type_ProtectHome);
+        TEST_IDL_ENUM(PrivateTmp, private_tmp, vl_type_PrivateTmp);
+        TEST_IDL_ENUM(PrivateUsers, private_users, vl_type_PrivateUsers);
+        TEST_IDL_ENUM(ProtectHostname, protect_hostname, vl_type_ProtectHostname);
+        TEST_IDL_ENUM(ProtectControlGroups, protect_control_groups, vl_type_ProtectControlGroups);
+        TEST_IDL_ENUM(PrivatePIDs, private_pids, vl_type_PrivatePIDs);
+        TEST_IDL_ENUM(PrivateBPF, private_bpf, vl_type_PrivateBPF);
+
+        /* CGroupContext enums */
+        TEST_IDL_ENUM(CGroupDevicePolicy, cgroup_device_policy, vl_type_CGroupDevicePolicy);
+        TEST_IDL_ENUM(ManagedOOMMode, managed_oom_mode, vl_type_ManagedOOMMode);
+        TEST_IDL_ENUM(ManagedOOMPreference, managed_oom_preference, vl_type_ManagedOOMPreference);
+        TEST_IDL_ENUM(CGroupPressureWatch, cgroup_pressure_watch, vl_type_CGroupPressureWatch);
+        TEST_IDL_ENUM(CGroupController, cgroup_controller, vl_type_CGroupController);
+
+        /* UnitContext enums */
+        TEST_IDL_ENUM(CollectMode, collect_mode, vl_type_CollectMode);
+        TEST_IDL_ENUM(EmergencyAction, emergency_action, vl_type_EmergencyAction);
+        TEST_IDL_ENUM(JobMode, job_mode, vl_type_JobMode);
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);