]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-tables: Pass enum type to test_table() as well
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 May 2025 09:34:41 +0000 (11:34 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 May 2025 11:24:42 +0000 (13:24 +0200)
clang-include-cleaner has a hard time figuring out unused includes
with all the macro string concatentation we're doing in test_table().
Let's help it out a little by also passing the enum type into test_table().

While technically not needed, this makes the tests a bit more self-descriptive
and not really much more verbose so it feels like a good chance regardless,
even if the primary purpose is to help clang-include-cleaner figure out
used and unused includes.

src/journal/test-journald-tables.c
src/login/test-login-tables.c
src/machine/test-machine-tables.c
src/network/test-network-tables.c
src/nspawn/test-nspawn-tables.c
src/resolve/test-resolve-tables.c
src/shared/test-tables.h
src/test/test-tables.c
src/udev/net/test-link-config-tables.c

index 60b3ed59dd408387bbc4dc8b4b497fd36e02c239..c066cbd5a0dda4d90998f46521facf972572cf15 100644 (file)
@@ -7,8 +7,8 @@
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(split_mode, SPLIT);
-        test_table(storage, STORAGE);
+        test_table(SplitMode, split_mode, SPLIT);
+        test_table(Storage, storage, STORAGE);
 
         return EXIT_SUCCESS;
 }
index 76b62aa621e08934a91ace61e7c92acd7d131e85..fcba4334ea63c15b83ad220d41e1116d968873d3 100644 (file)
@@ -24,13 +24,13 @@ static void test_sleep_handle_action(void) {
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(handle_action, HANDLE_ACTION);
-        test_table(inhibit_mode, INHIBIT_MODE);
-        test_table(kill_whom, KILL_WHOM);
-        test_table(session_class, SESSION_CLASS);
-        test_table(session_state, SESSION_STATE);
-        test_table(session_type, SESSION_TYPE);
-        test_table(user_state, USER_STATE);
+        test_table(HandleAction, handle_action, HANDLE_ACTION);
+        test_table(InhibitMode, inhibit_mode, INHIBIT_MODE);
+        test_table(KillWhom, kill_whom, KILL_WHOM);
+        test_table(SessionClass, session_class, SESSION_CLASS);
+        test_table(SessionState, session_state, SESSION_STATE);
+        test_table(SessionType, session_type, SESSION_TYPE);
+        test_table(UserState, user_state, USER_STATE);
 
         test_sleep_handle_action();
 
index d0b73358bf8e0dcfa7e937c6befdd43b60a5571c..997e593977b7af800cd989aedc527eed1338ea4b 100644 (file)
@@ -7,9 +7,9 @@
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(kill_whom, KILL_WHOM);
-        test_table(machine_class, MACHINE_CLASS);
-        test_table(machine_state, MACHINE_STATE);
+        test_table(KillWhom, kill_whom, KILL_WHOM);
+        test_table(MachineClass, machine_class, MACHINE_CLASS);
+        test_table(MachineState, machine_state, MACHINE_STATE);
 
         return EXIT_SUCCESS;
 }
index 2939f344bae68d34b6243377dd7d62baee73e2b9..5ad028bd3b5190d552f0c55d3d682c9449f35b65 100644 (file)
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(bond_ad_select, NETDEV_BOND_AD_SELECT);
-        test_table(bond_arp_all_targets, NETDEV_BOND_ARP_ALL_TARGETS);
-        test_table(bond_arp_validate, NETDEV_BOND_ARP_VALIDATE);
-        test_table(bond_fail_over_mac, NETDEV_BOND_FAIL_OVER_MAC);
-        test_table(bond_lacp_rate, NETDEV_BOND_LACP_RATE);
-        test_table(bond_mode, NETDEV_BOND_MODE);
-        test_table(bond_primary_reselect, NETDEV_BOND_PRIMARY_RESELECT);
-        test_table(bond_xmit_hash_policy, NETDEV_BOND_XMIT_HASH_POLICY);
-        test_table(dhcp6_message_status, DHCP6_STATUS);
-        test_table_sparse(dhcp6_message_type, DHCP6_MESSAGE_TYPE); /* enum starts from 1 */
-        test_table(use_domains, USE_DOMAINS);
-        test_table(duplex, DUP);
-        test_table(ip6tnl_mode, NETDEV_IP6_TNL_MODE);
-        test_table(ipv6_privacy_extensions, IPV6_PRIVACY_EXTENSIONS);
-        test_table(ipvlan_flags, NETDEV_IPVLAN_FLAGS);
-        test_table(link_operstate, LINK_OPERSTATE);
+        test_table(BondAdSelect, bond_ad_select, NETDEV_BOND_AD_SELECT);
+        test_table(BondArpAllTargets, bond_arp_all_targets, NETDEV_BOND_ARP_ALL_TARGETS);
+        test_table(BondArpValidate, bond_arp_validate, NETDEV_BOND_ARP_VALIDATE);
+        test_table(BondFailOverMac, bond_fail_over_mac, NETDEV_BOND_FAIL_OVER_MAC);
+        test_table(BondLacpRate, bond_lacp_rate, NETDEV_BOND_LACP_RATE);
+        test_table(BondMode, bond_mode, NETDEV_BOND_MODE);
+        test_table(BondPrimaryReselect, bond_primary_reselect, NETDEV_BOND_PRIMARY_RESELECT);
+        test_table(BondXmitHashPolicy, bond_xmit_hash_policy, NETDEV_BOND_XMIT_HASH_POLICY);
+        test_table(DHCP6Status, dhcp6_message_status, DHCP6_STATUS);
+        test_table_sparse(DHCP6MessageType, dhcp6_message_type, DHCP6_MESSAGE_TYPE); /* enum starts from 1 */
+        test_table(UseDomains, use_domains, USE_DOMAINS);
+        test_table(Duplex, duplex, DUP);
+        test_table(Ip6TnlMode, ip6tnl_mode, NETDEV_IP6_TNL_MODE);
+        test_table(IPv6PrivacyExtensions, ipv6_privacy_extensions, IPV6_PRIVACY_EXTENSIONS);
+        test_table(IPVlanFlags, ipvlan_flags, NETDEV_IPVLAN_FLAGS);
+        test_table(LinkOperationalState, link_operstate, LINK_OPERSTATE);
         /* test_table(link_state, LINK_STATE);  — not a reversible mapping */
-        test_table(lldp_mode, LLDP_MODE);
-        test_table(netdev_kind, NETDEV_KIND);
-        test_table(radv_prefix_delegation, RADV_PREFIX_DELEGATION);
-        test_table(lldp_rx_event, SD_LLDP_RX_EVENT);
-        test_table(ndisc_event, SD_NDISC_EVENT);
-        test_table(dhcp_lease_server_type, SD_DHCP_LEASE_SERVER_TYPE);
+        test_table(LLDPMode, lldp_mode, LLDP_MODE);
+        test_table(NetDevKind, netdev_kind, NETDEV_KIND);
+        test_table(RADVPrefixDelegation, radv_prefix_delegation, RADV_PREFIX_DELEGATION);
+        test_table(sd_lldp_rx_event_t, lldp_rx_event, SD_LLDP_RX_EVENT);
+        test_table(sd_ndisc_event_t, ndisc_event, SD_NDISC_EVENT);
+        test_table(sd_dhcp_lease_server_type_t, dhcp_lease_server_type, SD_DHCP_LEASE_SERVER_TYPE);
 
-        test_table_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE);
-        test_table_sparse(macvlan_mode, NETDEV_MACVLAN_MODE);
-        test_table_sparse(address_family, ADDRESS_FAMILY);
+        test_table_sparse(IPVlanMode, ipvlan_mode, NETDEV_IPVLAN_MODE);
+        test_table_sparse(MacVlanMode, macvlan_mode, NETDEV_MACVLAN_MODE);
+        test_table_sparse(AddressFamily, address_family, ADDRESS_FAMILY);
 
         assert_cc(sizeof(sd_lldp_rx_event_t) == sizeof(int64_t));
         assert_cc(sizeof(sd_ndisc_event_t) == sizeof(int64_t));
index daea4695e3c5409b8b76ae99641e4e77ef1fe330..671429c40eb5cfc9971b626f670f55ec7534fdf2 100644 (file)
@@ -7,8 +7,8 @@
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(resolv_conf_mode, RESOLV_CONF_MODE);
-        test_table(timezone_mode, TIMEZONE_MODE);
+        test_table(ResolvConfMode, resolv_conf_mode, RESOLV_CONF_MODE);
+        test_table(TimezoneMode, timezone_mode, TIMEZONE_MODE);
 
         return 0;
 }
index 6b8618103f970b307b60440fe9ce4abbc3a32619..ec660379f44b02dfa6cd1131af3f669f09a241ba 100644 (file)
@@ -11,12 +11,12 @@ int main(int argc, char **argv) {
 
         test_setup_logging(LOG_DEBUG);
 
-        test_table(dns_protocol, DNS_PROTOCOL);
-        test_table(dnssec_result, DNSSEC_RESULT);
-        test_table(dnssec_verdict, DNSSEC_VERDICT);
+        test_table(DnsProtocol, dns_protocol, DNS_PROTOCOL);
+        test_table(DnssecResult, dnssec_result, DNSSEC_RESULT);
+        test_table(DnssecVerdict, dnssec_verdict, DNSSEC_VERDICT);
 
-        test_table_sparse(dns_rcode, DNS_RCODE);
-        test_table_sparse(dns_type, DNS_TYPE);
+        test_table_sparse(int, dns_rcode, DNS_RCODE);
+        test_table_sparse(int, dns_type, DNS_TYPE);
 
         log_info("/* DNS_TYPE */");
         for (i = 0; i < _DNS_TYPE_MAX; i++) {
index 3f20318db16511081ec983a567b4f3b439f7eb60..bf8c91343784a7810e9840f276a49e45c17e2fd5 100644 (file)
@@ -9,10 +9,10 @@
 
 #include "string-util.h"
 
-#define _test_table(name, lookup, reverse, size, sparse)                \
-        for (int64_t _i = -EINVAL, _boring = 0; _i < size + 1; _i++) {  \
+#define _test_table(type, name, lookup, reverse, size, sparse)          \
+        for (type _i = -EINVAL, _boring = 0; _i < size + 1; _i++) {     \
                 const char* _val;                                       \
-                int64_t _rev;                                           \
+                type _rev;                                              \
                                                                         \
                 _val = lookup(_i);                                      \
                 if (_val) {                                             \
@@ -23,7 +23,7 @@
                         _boring += _i >= 0;                             \
                 }                                                       \
                 if (_boring == 0 || _i == size)                         \
-                        printf("%s: %" PRIi64 " → %s → %" PRIi64 "\n", name, _i, strnull(_val), _rev); \
+                        printf("%s: %" PRIi64 " → %s → %" PRIi64 "\n", name, (int64_t) _i, strnull(_val), (int64_t) _rev); \
                 else if (_boring == 1)                                  \
                         printf("%*s  ...\n", (int) strlen(name), "");   \
                                                                         \
@@ -36,8 +36,8 @@
                         assert_se(!_val && _rev == -EINVAL);            \
         }
 
-#define test_table(lower, upper)                                        \
-        _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, false)
+#define test_table(type, lower, upper)                                  \
+        _test_table(type, STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, false)
 
-#define test_table_sparse(lower, upper)                                 \
-        _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, true)
+#define test_table_sparse(type, lower, upper)                           \
+        _test_table(type, STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, true)
index cd05b179890832c9926b3a2fea380019b7c70a1c..d6e38c04d25f00c4df6f9e6dabc767350d117be2 100644 (file)
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(architecture, ARCHITECTURE);
-        test_table(assert_type, CONDITION_TYPE);
-        test_table(automount_result, AUTOMOUNT_RESULT);
-        test_table(automount_state, AUTOMOUNT_STATE);
-        test_table(cgroup_controller, CGROUP_CONTROLLER);
-        test_table(cgroup_device_policy, CGROUP_DEVICE_POLICY);
-        test_table(cgroup_io_limit_type, CGROUP_IO_LIMIT_TYPE);
-        test_table(collect_mode, COLLECT_MODE);
-        test_table(condition_result, CONDITION_RESULT);
-        test_table(condition_type, CONDITION_TYPE);
-        test_table(confidential_virtualization, CONFIDENTIAL_VIRTUALIZATION);
-        test_table(device_action, SD_DEVICE_ACTION);
-        test_table(device_state, DEVICE_STATE);
-        test_table(dns_over_tls_mode, DNS_OVER_TLS_MODE);
-        test_table(dnssec_mode, DNSSEC_MODE);
-        test_table(emergency_action, EMERGENCY_ACTION);
-        test_table(exec_directory_type, EXEC_DIRECTORY_TYPE);
-        test_table(exec_input, EXEC_INPUT);
-        test_table(exec_keyring_mode, EXEC_KEYRING_MODE);
-        test_table(exec_output, EXEC_OUTPUT);
-        test_table(exec_preserve_mode, EXEC_PRESERVE_MODE);
-        test_table(exec_utmp_mode, EXEC_UTMP_MODE);
-        test_table(image_type, IMAGE_TYPE);
-        test_table(import_verify, IMPORT_VERIFY);
-        test_table(job_mode, JOB_MODE);
-        test_table(job_result, JOB_RESULT);
-        test_table(job_state, JOB_STATE);
-        test_table(job_type, JOB_TYPE);
-        test_table(kill_mode, KILL_MODE);
-        test_table(kill_whom, KILL_WHOM);
-        test_table(locale_variable, VARIABLE_LC);
-        test_table(log_target, LOG_TARGET);
-        test_table(managed_oom_mode, MANAGED_OOM_MODE);
-        test_table(managed_oom_preference, MANAGED_OOM_PREFERENCE);
-        test_table(manager_state, MANAGER_STATE);
-        test_table(manager_timestamp, MANAGER_TIMESTAMP);
-        test_table(mount_exec_command, MOUNT_EXEC_COMMAND);
-        test_table(mount_result, MOUNT_RESULT);
-        test_table(mount_state, MOUNT_STATE);
-        test_table(name_policy, NAMEPOLICY);
-        test_table(notify_access, NOTIFY_ACCESS);
-        test_table(notify_state, NOTIFY_STATE);
-        test_table(output_mode, OUTPUT_MODE);
-        test_table(partition_designator, PARTITION_DESIGNATOR);
-        test_table(path_result, PATH_RESULT);
-        test_table(path_state, PATH_STATE);
-        test_table(path_type, PATH_TYPE);
-        test_table(protect_home, PROTECT_HOME);
-        test_table(protect_system, PROTECT_SYSTEM);
-        test_table(resolve_support, RESOLVE_SUPPORT);
-        test_table(rlimit, RLIMIT);
-        test_table(scope_result, SCOPE_RESULT);
-        test_table(scope_state, SCOPE_STATE);
-        test_table(service_exec_command, SERVICE_EXEC_COMMAND);
-        test_table(service_restart, SERVICE_RESTART);
-        test_table(service_restart_mode, SERVICE_RESTART_MODE);
-        test_table(service_result, SERVICE_RESULT);
-        test_table(service_state, SERVICE_STATE);
-        test_table(service_type, SERVICE_TYPE);
-        test_table(show_status, SHOW_STATUS);
-        test_table(slice_state, SLICE_STATE);
-        test_table(socket_address_bind_ipv6_only, SOCKET_ADDRESS_BIND_IPV6_ONLY);
-        test_table(socket_exec_command, SOCKET_EXEC_COMMAND);
-        test_table(socket_result, SOCKET_RESULT);
-        test_table(socket_state, SOCKET_STATE);
-        test_table(swap_exec_command, SWAP_EXEC_COMMAND);
-        test_table(swap_result, SWAP_RESULT);
-        test_table(swap_state, SWAP_STATE);
-        test_table(target_state, TARGET_STATE);
-        test_table(timer_base, TIMER_BASE);
-        test_table(timer_result, TIMER_RESULT);
-        test_table(timer_state, TIMER_STATE);
-        test_table(unit_active_state, UNIT_ACTIVE_STATE);
-        test_table(unit_dependency, UNIT_DEPENDENCY);
-        test_table(install_change_type, INSTALL_CHANGE_TYPE);
-        test_table(unit_file_preset_mode, UNIT_FILE_PRESET_MODE);
-        test_table(unit_file_state, UNIT_FILE_STATE);
-        test_table(unit_load_state, UNIT_LOAD_STATE);
-        test_table(unit_type, UNIT_TYPE);
-        test_table(virtualization, VIRTUALIZATION);
-        test_table(compression, COMPRESSION);
+        test_table(Architecture, architecture, ARCHITECTURE);
+        test_table(ConditionType, assert_type, CONDITION_TYPE);
+        test_table(AutomountResult, automount_result, AUTOMOUNT_RESULT);
+        test_table(AutomountState, automount_state, AUTOMOUNT_STATE);
+        test_table(CGroupController, cgroup_controller, CGROUP_CONTROLLER);
+        test_table(CGroupDevicePolicy, cgroup_device_policy, CGROUP_DEVICE_POLICY);
+        test_table(CGroupIOLimitType, cgroup_io_limit_type, CGROUP_IO_LIMIT_TYPE);
+        test_table(CollectMode, collect_mode, COLLECT_MODE);
+        test_table(ConditionResult, condition_result, CONDITION_RESULT);
+        test_table(ConditionType, condition_type, CONDITION_TYPE);
+        test_table(ConfidentialVirtualization, confidential_virtualization, CONFIDENTIAL_VIRTUALIZATION);
+        test_table(sd_device_action_t, device_action, SD_DEVICE_ACTION);
+        test_table(DeviceState, device_state, DEVICE_STATE);
+        test_table(DnsOverTlsMode, dns_over_tls_mode, DNS_OVER_TLS_MODE);
+        test_table(DnssecMode, dnssec_mode, DNSSEC_MODE);
+        test_table(EmergencyAction, emergency_action, EMERGENCY_ACTION);
+        test_table(ExecDirectoryType, exec_directory_type, EXEC_DIRECTORY_TYPE);
+        test_table(ExecInput, exec_input, EXEC_INPUT);
+        test_table(ExecKeyringMode, exec_keyring_mode, EXEC_KEYRING_MODE);
+        test_table(ExecOutput, exec_output, EXEC_OUTPUT);
+        test_table(ExecPreserveMode, exec_preserve_mode, EXEC_PRESERVE_MODE);
+        test_table(ExecUtmpMode, exec_utmp_mode, EXEC_UTMP_MODE);
+        test_table(ImageType, image_type, IMAGE_TYPE);
+        test_table(ImportVerify, import_verify, IMPORT_VERIFY);
+        test_table(JobMode, job_mode, JOB_MODE);
+        test_table(JobResult, job_result, JOB_RESULT);
+        test_table(JobState, job_state, JOB_STATE);
+        test_table(JobType, job_type, JOB_TYPE);
+        test_table(KillMode, kill_mode, KILL_MODE);
+        test_table(KillWhom, kill_whom, KILL_WHOM);
+        test_table(LocaleVariable, locale_variable, VARIABLE_LC);
+        test_table(LogTarget, log_target, LOG_TARGET);
+        test_table(ManagedOOMMode, managed_oom_mode, MANAGED_OOM_MODE);
+        test_table(ManagedOOMPreference, managed_oom_preference, MANAGED_OOM_PREFERENCE);
+        test_table(ManagerState, manager_state, MANAGER_STATE);
+        test_table(ManagerTimestamp, manager_timestamp, MANAGER_TIMESTAMP);
+        test_table(MountExecCommand, mount_exec_command, MOUNT_EXEC_COMMAND);
+        test_table(MountResult, mount_result, MOUNT_RESULT);
+        test_table(MountState, mount_state, MOUNT_STATE);
+        test_table(NamePolicy, name_policy, NAMEPOLICY);
+        test_table(NotifyAccess, notify_access, NOTIFY_ACCESS);
+        test_table(NotifyState, notify_state, NOTIFY_STATE);
+        test_table(OutputMode, output_mode, OUTPUT_MODE);
+        test_table(PartitionDesignator, partition_designator, PARTITION_DESIGNATOR);
+        test_table(PathResult, path_result, PATH_RESULT);
+        test_table(PathState, path_state, PATH_STATE);
+        test_table(PathType, path_type, PATH_TYPE);
+        test_table(ProtectHome, protect_home, PROTECT_HOME);
+        test_table(ProtectSystem, protect_system, PROTECT_SYSTEM);
+        test_table(ResolveSupport, resolve_support, RESOLVE_SUPPORT);
+        test_table(int, rlimit, RLIMIT);
+        test_table(ScopeResult, scope_result, SCOPE_RESULT);
+        test_table(ScopeState, scope_state, SCOPE_STATE);
+        test_table(ServiceExecCommand, service_exec_command, SERVICE_EXEC_COMMAND);
+        test_table(ServiceRestart, service_restart, SERVICE_RESTART);
+        test_table(ServiceRestartMode, service_restart_mode, SERVICE_RESTART_MODE);
+        test_table(ServiceResult, service_result, SERVICE_RESULT);
+        test_table(ServiceState, service_state, SERVICE_STATE);
+        test_table(ServiceType, service_type, SERVICE_TYPE);
+        test_table(ShowStatus, show_status, SHOW_STATUS);
+        test_table(SliceState, slice_state, SLICE_STATE);
+        test_table(SocketAddressBindIPv6Only, socket_address_bind_ipv6_only, SOCKET_ADDRESS_BIND_IPV6_ONLY);
+        test_table(SocketExecCommand, socket_exec_command, SOCKET_EXEC_COMMAND);
+        test_table(SocketResult, socket_result, SOCKET_RESULT);
+        test_table(SocketState, socket_state, SOCKET_STATE);
+        test_table(SwapExecCommand, swap_exec_command, SWAP_EXEC_COMMAND);
+        test_table(SwapResult, swap_result, SWAP_RESULT);
+        test_table(SwapState, swap_state, SWAP_STATE);
+        test_table(TargetState, target_state, TARGET_STATE);
+        test_table(TimerBase, timer_base, TIMER_BASE);
+        test_table(TimerResult, timer_result, TIMER_RESULT);
+        test_table(TimerState, timer_state, TIMER_STATE);
+        test_table(UnitActiveState, unit_active_state, UNIT_ACTIVE_STATE);
+        test_table(UnitDependency, unit_dependency, UNIT_DEPENDENCY);
+        test_table(InstallChangeType, install_change_type, INSTALL_CHANGE_TYPE);
+        test_table(UnitFilePresetMode, unit_file_preset_mode, UNIT_FILE_PRESET_MODE);
+        test_table(UnitFileState, unit_file_state, UNIT_FILE_STATE);
+        test_table(UnitLoadState, unit_load_state, UNIT_LOAD_STATE);
+        test_table(UnitType, unit_type, UNIT_TYPE);
+        test_table(Virtualization, virtualization, VIRTUALIZATION);
+        test_table(Compression, compression, COMPRESSION);
 
         assert_cc(sizeof(sd_device_action_t) == sizeof(int64_t));
 
index a4332320f6890b4e8b01275f783f93c9c4b951be..499778505c4424946bea514c484c557b3529021b 100644 (file)
@@ -7,7 +7,7 @@
 int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
-        test_table(mac_address_policy, MAC_ADDRESS_POLICY);
+        test_table(MACAddressPolicy, mac_address_policy, MAC_ADDRESS_POLICY);
 
         return EXIT_SUCCESS;
 }