chiark / gitweb /
sysv-generator: Replace Provides: symlinks with real units
[elogind.git] / test / udev-test.pl
index ef3707e..d9b7967 100755 (executable)
@@ -14,7 +14,7 @@
 # After creation and removal the result is checked against the
 # expected value and the result is printed.
 #
-# Copyright (C) 2004-2012 Kay Sievers <kay.sievers@vrfy.org>
+# Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
 # Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
 
 use warnings;
@@ -27,6 +27,7 @@ my $udev_dev            = "test/dev";
 my $udev_run            = "test/run";
 my $udev_rules_dir      = "$udev_run/udev/rules.d";
 my $udev_rules          = "$udev_rules_dir/udev-test.rules";
+my $EXIT_TEST_SKIP      = 77;
 
 my @tests = (
         {
@@ -549,21 +550,21 @@ KERNEL=="tty33", OWNER="bad", GROUP="name"
 EOF
         },
         {
-                desc            => "permissions OWNER=5000",
+                desc            => "permissions OWNER=1",
                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                 exp_name        => "node",
-                exp_perms       => "5000::0600",
+                exp_perms       => "1::0600",
                 rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000"
+SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
 EOF
         },
         {
-                desc            => "permissions GROUP=100",
+                desc            => "permissions GROUP=1",
                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                 exp_name        => "node",
-                exp_perms       => ":100:0660",
+                exp_perms       => ":1:0660",
                 rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="100"
+SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
 EOF
         },
         {
@@ -603,30 +604,30 @@ SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
 EOF
         },
         {
-                desc            => "permissions OWNER=5000 GROUP=100 MODE=0777",
+                desc            => "permissions OWNER=1 GROUP=1 MODE=0777",
                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                 exp_name        => "node",
-                exp_perms       => "5000:100:0777",
+                exp_perms       => "1:1:0777",
                 rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000", GROUP="100", MODE="0777"
+SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
 EOF
         },
         {
-                desc            => "permissions OWNER to 5000",
+                desc            => "permissions OWNER to 1",
                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                 exp_name        => "ttyACM0",
-                exp_perms       => "5000::",
+                exp_perms       => "1::",
                 rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000"
+KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
 EOF
         },
         {
-                desc            => "permissions GROUP to 100",
+                desc            => "permissions GROUP to 1",
                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                 exp_name        => "ttyACM0",
-                exp_perms       => ":100:0660",
+                exp_perms       => ":1:0660",
                 rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="100"
+KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
 EOF
         },
         {
@@ -642,19 +643,19 @@ EOF
                 desc            => "permissions OWNER, GROUP, MODE",
                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                 exp_name        => "ttyACM0",
-                exp_perms       => "5000:100:0777",
+                exp_perms       => "1:1:0777",
                 rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000", GROUP="100", MODE="0777"
+KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
 EOF
         },
         {
                 desc            => "permissions only rule",
                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                 exp_name        => "ttyACM0",
-                exp_perms       => "5000:100:0777",
+                exp_perms       => "1:1:0777",
                 rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", OWNER="5000", GROUP="100", MODE="0777"
-KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
+KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
+KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
 EOF
         },
@@ -662,12 +663,12 @@ EOF
                 desc            => "multiple permissions only rule",
                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                 exp_name        => "ttyACM0",
-                exp_perms       => "3000:4000:0777",
+                exp_perms       => "1:1:0777",
                 rules           => <<EOF
-SUBSYSTEM=="tty", OWNER="3000"
-SUBSYSTEM=="tty", GROUP="4000"
+SUBSYSTEM=="tty", OWNER="1"
+SUBSYSTEM=="tty", GROUP="1"
 SUBSYSTEM=="tty", MODE="0777"
-KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
+KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
 EOF
         },
@@ -675,13 +676,13 @@ EOF
                 desc            => "permissions only rule with override at SYMLINK+ rule",
                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                 exp_name        => "ttyACM0",
-                exp_perms       => "3000:8000:0777",
+                exp_perms       => "1:2:0777",
                 rules           => <<EOF
-SUBSYSTEM=="tty", OWNER="3000"
-SUBSYSTEM=="tty", GROUP="4000"
+SUBSYSTEM=="tty", OWNER="1"
+SUBSYSTEM=="tty", GROUP="1"
 SUBSYSTEM=="tty", MODE="0777"
-KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
-KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="8000"
+KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
+KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
 EOF
         },
         {
@@ -1232,8 +1233,8 @@ EOF
                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                 exp_name        => "there",
                 rules           => <<EOF
-TEST=="/etc/hosts", SYMLINK+="there"
-TEST!="/etc/hosts", SYMLINK+="notthere"
+TEST=="/etc/machine-id", SYMLINK+="there"
+TEST!="/etc/machine-id", SYMLINK+="notthere"
 EOF
         },
         {
@@ -1274,11 +1275,11 @@ EOF
                 desc            => "TEST PROGRAM feeds OWNER, GROUP, MODE",
                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                 exp_name        => "sda",
-                exp_perms       => "5000:100:0400",
+                exp_perms       => "1:1:0400",
                 exp_rem_error   => "yes",
                 rules           => <<EOF
 KERNEL=="sda", MODE="666"
-KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
+KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
 EOF
         },
         {
@@ -1485,6 +1486,13 @@ if (!($<==0)) {
         exit;
 }
 
+# skip the test when running in a container
+system("systemd-detect-virt", "-c", "-q");
+if ($? >> 8 == 0) {
+    print "Running in a container, skipping the test.\n";
+    exit($EXIT_TEST_SKIP);
+}
+
 udev_setup();
 
 my $test_num = 1;
@@ -1518,7 +1526,7 @@ if ($list[0]) {
         }
 }
 
-print "$error errors occured\n\n";
+print "$error errors occurred\n\n";
 
 # cleanup
 system("rm", "-rf", "$udev_dev");