From: Daan De Meyer Date: Wed, 21 May 2025 09:34:41 +0000 (+0200) Subject: test-tables: Pass enum type to test_table() as well X-Git-Tag: v258-rc1~555^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f74f56f3624e962fa7f51bc22df070a3678c942;p=thirdparty%2Fsystemd.git test-tables: Pass enum type to test_table() as well 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. --- diff --git a/src/journal/test-journald-tables.c b/src/journal/test-journald-tables.c index 60b3ed59dd4..c066cbd5a0d 100644 --- a/src/journal/test-journald-tables.c +++ b/src/journal/test-journald-tables.c @@ -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; } diff --git a/src/login/test-login-tables.c b/src/login/test-login-tables.c index 76b62aa621e..fcba4334ea6 100644 --- a/src/login/test-login-tables.c +++ b/src/login/test-login-tables.c @@ -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(); diff --git a/src/machine/test-machine-tables.c b/src/machine/test-machine-tables.c index d0b73358bf8..997e593977b 100644 --- a/src/machine/test-machine-tables.c +++ b/src/machine/test-machine-tables.c @@ -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; } diff --git a/src/network/test-network-tables.c b/src/network/test-network-tables.c index 2939f344bae..5ad028bd3b5 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -21,33 +21,33 @@ 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)); diff --git a/src/nspawn/test-nspawn-tables.c b/src/nspawn/test-nspawn-tables.c index daea4695e3c..671429c40eb 100644 --- a/src/nspawn/test-nspawn-tables.c +++ b/src/nspawn/test-nspawn-tables.c @@ -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; } diff --git a/src/resolve/test-resolve-tables.c b/src/resolve/test-resolve-tables.c index 6b8618103f9..ec660379f44 100644 --- a/src/resolve/test-resolve-tables.c +++ b/src/resolve/test-resolve-tables.c @@ -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++) { diff --git a/src/shared/test-tables.h b/src/shared/test-tables.h index 3f20318db16..bf8c9134378 100644 --- a/src/shared/test-tables.h +++ b/src/shared/test-tables.h @@ -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) diff --git a/src/test/test-tables.c b/src/test/test-tables.c index cd05b179890..d6e38c04d25 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -44,87 +44,87 @@ 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)); diff --git a/src/udev/net/test-link-config-tables.c b/src/udev/net/test-link-config-tables.c index a4332320f68..499778505c4 100644 --- a/src/udev/net/test-link-config-tables.c +++ b/src/udev/net/test-link-config-tables.c @@ -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; }