chiark / gitweb /
test: udev - add gdb support
[elogind.git] / test / udev-test.pl
index 14f11df8af94d53e1860ffb135cc2f52ac160a19..126eab98691cc2d400dc00d2efa22d161a2d3c78 100755 (executable)
@@ -22,11 +22,14 @@ use strict;
 
 my $udev_bin            = "./test-udev";
 my $valgrind            = 0;
+my $gdb                 = 0;
 my $udev_bin_valgrind   = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
+my $udev_bin_gdb        = "gdb --args $udev_bin";
 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 = (
         {
@@ -1232,8 +1235,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
         },
         {
@@ -1325,6 +1328,8 @@ sub udev {
 
         if ($valgrind > 0) {
                 system("$udev_bin_valgrind $action $devpath");
+        } elsif ($gdb > 0) {
+                system("$udev_bin_gdb $action $devpath");
         } else {
                 system("$udev_bin", "$action", "$devpath");
         }
@@ -1485,6 +1490,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;
@@ -1494,6 +1506,9 @@ foreach my $arg (@ARGV) {
         if ($arg =~ m/--valgrind/) {
                 $valgrind = 1;
                 printf("using valgrind\n");
+        } elsif ($arg =~ m/--gdb/) {
+                $gdb = 1;
+                printf("using gdb\n");
         } else {
                 push(@list, $arg);
         }