]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: assert that product_serial is preferred over board_serial
authorJelle van der Waa <jvanderwaa@redhat.com>
Wed, 12 Feb 2025 20:39:59 +0000 (21:39 +0100)
committerJelle van der Waa <jvanderwaa@redhat.com>
Wed, 26 Feb 2025 10:18:08 +0000 (11:18 +0100)
test/units/TEST-71-HOSTNAME.sh

index dc3f587ea3906c487b061135d1a8cd02be4871cd..0813a07d46e4e5a8daa3271409547ea17e49f227 100755 (executable)
@@ -104,15 +104,7 @@ restore_sysfs_dmi() {
     stop_hostnamed
 }
 
-testcase_firmware_date() {
-    # No DMI on s390x or ppc
-    if [[ ! -d /sys/class/dmi/id ]]; then
-        echo "/sys/class/dmi/id not found, skipping firmware date tests."
-        return 0
-    fi
-
-    trap restore_sysfs_dmi RETURN
-
+fake_sysfs_dmi() {
     # Ignore /sys being mounted as tmpfs
     mkdir -p /run/systemd/system/systemd-hostnamed.service.d/
     cat >/run/systemd/system/systemd-hostnamed.service.d/override.conf <<EOF
@@ -124,6 +116,18 @@ EOF
 
     mount -t tmpfs none /sys/class/dmi/id
     echo '1' >/sys/class/dmi/id/uevent
+}
+
+testcase_firmware_date() {
+    # No DMI on s390x or ppc
+    if [[ ! -d /sys/class/dmi/id ]]; then
+        echo "/sys/class/dmi/id not found, skipping firmware date tests."
+        return 0
+    fi
+
+    trap restore_sysfs_dmi RETURN
+
+    fake_sysfs_dmi
 
     echo '09/08/2000' >/sys/class/dmi/id/bios_date
     stop_hostnamed
@@ -138,6 +142,27 @@ EOF
     assert_not_in 'Firmware Date' "$(hostnamectl)"
 }
 
+testcase_hardware_serial() {
+    # No DMI on s390x or ppc
+    if [[ ! -d /sys/class/dmi/id ]]; then
+        echo "/sys/class/dmi/id not found, skipping firmware date tests."
+        return 0
+    fi
+
+    trap restore_sysfs_dmi RETURN
+
+    fake_sysfs_dmi
+
+    echo '1234' >/sys/class/dmi/id/board_serial
+    stop_hostnamed
+    assert_eq "$(hostnamectl --json=short | jq --raw-output .HardwareSerial)" "1234"
+
+    # product_serial is preferred over board_serial
+    echo '4321' >/sys/class/dmi/id/product_serial
+    stop_hostnamed
+    assert_eq "$(hostnamectl --json=short | jq --raw-output .HardwareSerial)" "4321"
+}
+
 testcase_nss-myhostname() {
     local database host i