]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: move unit test for dhcp_identifier_set_iaid() to test-dhcp-duid.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 2 May 2026 21:58:10 +0000 (06:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 May 2026 18:02:24 +0000 (03:02 +0900)
src/libsystemd-network/meson.build
src/libsystemd-network/test-dhcp-client.c
src/libsystemd-network/test-dhcp-duid.c [new file with mode: 0644]

index b21f138aa6bc9edfa2f69a9839f9f937cf92e16f..9a2d1bc77651727b197f85f205a83d2980f0e49d 100644 (file)
@@ -78,6 +78,9 @@ executables += [
         network_test_template + {
                 'sources' : files('test-dhcp-client.c'),
         },
+        network_test_template + {
+                'sources' : files('test-dhcp-duid.c'),
+        },
         network_test_template + {
                 'sources' : files('test-dhcp-message.c'),
         },
index 957e43d76274d8a41f744d97ec6b4fd9b345da76..d7dd01cc813ae45ac0087f3ab37253b923602af3 100644 (file)
@@ -108,23 +108,6 @@ TEST(dhcp_client_anonymize) {
         ASSERT_OK_ZERO(sd_dhcp_client_set_request_option(client, 101));
 }
 
-TEST(dhcp_identifier_set_iaid) {
-        uint32_t iaid_legacy;
-        be32_t iaid;
-
-        ASSERT_OK(dhcp_identifier_set_iaid(NULL, &hw_addr, /* legacy_unstable_byteorder= */ true, &iaid_legacy));
-        ASSERT_OK(dhcp_identifier_set_iaid(NULL, &hw_addr, /* legacy_unstable_byteorder= */ false, &iaid));
-
-        /* we expect, that the MAC address was hashed. The legacy value is in native endianness. */
-        ASSERT_EQ(iaid_legacy, 0x8dde4ba8u);
-        ASSERT_EQ(iaid, htole32(0x8dde4ba8u));
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-        ASSERT_EQ(iaid, iaid_legacy);
-#else
-        ASSERT_EQ(iaid, bswap_32(iaid_legacy));
-#endif
-}
-
 static int check_options(uint8_t code, uint8_t len, const void *option, void *userdata) {
         switch (code) {
         case SD_DHCP_OPTION_CLIENT_IDENTIFIER: {
diff --git a/src/libsystemd-network/test-dhcp-duid.c b/src/libsystemd-network/test-dhcp-duid.c
new file mode 100644 (file)
index 0000000..3632957
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "dhcp-duid-internal.h"
+#include "ether-addr-util.h"
+#include "tests.h"
+
+TEST(dhcp_identifier_set_iaid) {
+        uint32_t iaid_legacy;
+        be32_t iaid;
+
+        static struct hw_addr_data hw_addr = {
+                .length = ETH_ALEN,
+                .ether = {{ 'A', 'B', 'C', '1', '2', '3' }},
+        };
+
+        ASSERT_OK(dhcp_identifier_set_iaid(/* dev= */ NULL, &hw_addr, /* legacy_unstable_byteorder= */ true, &iaid_legacy));
+        ASSERT_OK(dhcp_identifier_set_iaid(/* dev= */ NULL, &hw_addr, /* legacy_unstable_byteorder= */ false, &iaid));
+
+        /* we expect, that the MAC address was hashed. The legacy value is in native endianness. */
+        ASSERT_EQ(iaid_legacy, 0x8dde4ba8u);
+        ASSERT_EQ(iaid, htole32(0x8dde4ba8u));
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+        ASSERT_EQ(iaid, iaid_legacy);
+#else
+        ASSERT_EQ(iaid, bswap_32(iaid_legacy));
+#endif
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);