Debian Codegraph @

src/test/test-varlink-idl-unit.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "automount.h"
4 #include "cgroup.h"
5 #include "ioprio-util.h"
6 #include "kill.h"
7 #include "mount.h"
8 #include "numa-util.h"
9 #include "path.h"
10 #include "process-util.h"
11 #include "scope.h"
12 #include "service.h"
13 #include "socket.h"
14 #include "swap.h"
15 #include "tests.h"
16 #include "test-varlink-idl-util.h"
17 #include "timer.h"
18 #include "unit.h"
19 #include "varlink-idl-common.h"
20 #include "varlink-io.systemd.Unit.h"
21
22 TEST(unit_enums_idl) {
23 /* ExecContext enums */
24 TEST_IDL_ENUM(ExecInput, exec_input, vl_type_ExecInputType);
25 TEST_IDL_ENUM_TO_STRING(ExecOutput, exec_output, vl_type_ExecOutputType);
26 TEST_IDL_ENUM(ExecUtmpMode, exec_utmp_mode, vl_type_ExecUtmpMode);
27 TEST_IDL_ENUM(ExecPreserveMode, exec_preserve_mode, vl_type_ExecPreserveMode);
28 TEST_IDL_ENUM(ExecKeyringMode, exec_keyring_mode, vl_type_ExecKeyringMode);
29 TEST_IDL_ENUM(ExecMemoryTHP, exec_memory_thp, vl_type_MemoryTHP);
30 TEST_IDL_ENUM(ProtectProc, protect_proc, vl_type_ProtectProc);
31 TEST_IDL_ENUM(ProcSubset, proc_subset, vl_type_ProcSubset);
32 TEST_IDL_ENUM(ProtectSystem, protect_system, vl_type_ProtectSystem);
33 TEST_IDL_ENUM(ProtectHome, protect_home, vl_type_ProtectHome);
34 TEST_IDL_ENUM(PrivateTmp, private_tmp, vl_type_PrivateTmp);
35 TEST_IDL_ENUM(PrivateUsers, private_users, vl_type_PrivateUsers);
36 TEST_IDL_ENUM(ProtectHostname, protect_hostname, vl_type_ProtectHostname);
37 TEST_IDL_ENUM(ProtectControlGroups, protect_control_groups, vl_type_ProtectControlGroups);
38 TEST_IDL_ENUM(PrivatePIDs, private_pids, vl_type_PrivatePIDs);
39 TEST_IDL_ENUM(PrivateBPF, private_bpf, vl_type_PrivateBPF);
40
41 /* sched_policy table has gaps (SCHED_IDLE=5, SCHED_EXT=7), so only test from_string direction */
42 TEST_IDL_ENUM_FROM_STRING(int, sched_policy, vl_type_CPUSchedulingPolicy);
43 /* ioprio_class uses _alloc variant for to_string, so only test from_string direction */
44 TEST_IDL_ENUM_FROM_STRING(int, ioprio_class, vl_type_IOSchedulingClass);
45 TEST_IDL_ENUM(int, mpol, vl_type_NUMAPolicy);
46
47 /* mount_propagation_flag has non-standard from_string API, test manually */
48 test_enum_to_string_name("shared", &vl_type_MountPropagationFlag);
49 test_enum_to_string_name("slave", &vl_type_MountPropagationFlag);
50 test_enum_to_string_name("private", &vl_type_MountPropagationFlag);
51
52 /* KillContext enums */
53 TEST_IDL_ENUM(KillMode, kill_mode, vl_type_KillMode);
54
55 /* CGroupContext enums */
56 TEST_IDL_ENUM(CGroupDevicePolicy, cgroup_device_policy, vl_type_CGroupDevicePolicy);
57 TEST_IDL_ENUM(ManagedOOMMode, managed_oom_mode, vl_type_ManagedOOMMode);
58 TEST_IDL_ENUM(ManagedOOMPreference, managed_oom_preference, vl_type_ManagedOOMPreference);
59 TEST_IDL_ENUM(CGroupPressureWatch, cgroup_pressure_watch, vl_type_CGroupPressureWatch);
60 TEST_IDL_ENUM(CGroupController, cgroup_controller, vl_type_CGroupController);
61
62 /* AutomountRuntime enums */
63 TEST_IDL_ENUM(AutomountResult, automount_result, vl_type_AutomountResult);
64
65 /* MountRuntime enums */
66 TEST_IDL_ENUM(MountResult, mount_result, vl_type_MountResult);
67
68 /* ServiceContext enums */
69 TEST_IDL_ENUM(ServiceType, service_type, vl_type_ServiceType);
70 TEST_IDL_ENUM(ServiceExitType, service_exit_type, vl_type_ServiceExitType);
71 TEST_IDL_ENUM(ServiceRestart, service_restart, vl_type_ServiceRestart);
72 TEST_IDL_ENUM(ServiceRestartMode, service_restart_mode, vl_type_ServiceRestartMode);
73 TEST_IDL_ENUM(ServiceTimeoutFailureMode, service_timeout_failure_mode, vl_type_ServiceTimeoutFailureMode);
74
75 /* ServiceRuntime enums */
76 TEST_IDL_ENUM(NotifyAccess, notify_access, vl_type_NotifyAccess);
77 TEST_IDL_ENUM(ServiceResult, service_result, vl_type_ServiceResult);
78
79 /* PathContext enums */
80 TEST_IDL_ENUM(PathType, path_type, vl_type_PathType);
81
82 /* PathRuntime enums */
83 TEST_IDL_ENUM(PathResult, path_result, vl_type_PathResult);
84
85 /* ScopeRuntime enums */
86 TEST_IDL_ENUM(ScopeResult, scope_result, vl_type_ScopeResult);
87
88 /* SocketContext enums */
89 TEST_IDL_ENUM(SocketAddressBindIPv6Only, socket_address_bind_ipv6_only, vl_type_SocketBindIPv6Only);
90 TEST_IDL_ENUM(SocketTimestamping, socket_timestamping, vl_type_SocketTimestamping);
91 TEST_IDL_ENUM(SocketDeferTrigger, socket_defer_trigger, vl_type_SocketDeferTrigger);
92
93 /* SocketRuntime enums */
94 TEST_IDL_ENUM(SocketResult, socket_result, vl_type_SocketResult);
95
96 /* SwapRuntime enums */
97 TEST_IDL_ENUM(SwapResult, swap_result, vl_type_SwapResult);
98
99 /* TimerContext enums */
100 for (TimerBase b = 0; b < _TIMER_BASE_MAX; b++) {
101 _cleanup_free_ char *s = timer_base_to_usec_string(b);
102 assert_se(s);
103 test_enum_to_string_name(s, &vl_type_TimerBase);
104 }
105
106 /* TimerRuntime enums */
107 TEST_IDL_ENUM(TimerResult, timer_result, vl_type_TimerResult);
108
109 /* UnitContext enums */
110 TEST_IDL_ENUM(CollectMode, collect_mode, vl_type_CollectMode);
111 TEST_IDL_ENUM(EmergencyAction, emergency_action, vl_type_EmergencyAction);
112 TEST_IDL_ENUM(JobMode, job_mode, vl_type_JobMode);
113 }
114
115 DEFINE_TEST_MAIN(LOG_DEBUG);