summaryrefslogtreecommitdiff
path: root/t/Unix-Mknod.t
diff options
context:
space:
mode:
Diffstat (limited to 't/Unix-Mknod.t')
-rw-r--r--t/Unix-Mknod.t72
1 files changed, 72 insertions, 0 deletions
diff --git a/t/Unix-Mknod.t b/t/Unix-Mknod.t
new file mode 100644
index 0000000..66c540d
--- /dev/null
+++ b/t/Unix-Mknod.t
@@ -0,0 +1,72 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl Unix-Mknod.t'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test;
+BEGIN { plan tests => 11 };
+use Unix::Mknod qw(:all);
+use Fcntl qw(:mode);
+use File::stat;
+
+$file='/tmp/special';
+
+#########################
+
+# Check to make sure major maps back to itself
+ok(major(makedev(10,2)), 10);
+
+# Same with minor
+ok(minor(makedev(7,5)), 5);
+
+# Check that makedev does as well, using the rdev from /dev/null
+my ($st)=stat('/dev/null');
+ok(makedev(major($st->rdev), minor($st->rdev)), $st->rdev);
+
+# Can only run mknod if we are root
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ mknod($file, S_IFCHR|0600, makedev(1,2)),
+ 0
+);
+
+$st=stat($file);
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ defined($st) && &S_ISCHR($st->mode)
+);
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ defined($st) && !&S_ISBLK($st->mode)
+);
+skip(
+ ($< != 0? "Test needs to be run as root": 0),
+ defined($st) && ($st->mode & S_IRUSR|S_IWUSR)
+);
+unlink $file
+ if ( -e $file);
+
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ mknod($file, S_IFBLK|0600, makedev(1,2)),
+ 0
+);
+$st=stat($file);
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ defined($st) && &S_ISBLK($st->mode)
+);
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ defined($st) && !&S_ISCHR($st->mode)
+);
+skip (
+ ($< != 0? "Test needs to be run as root": 0),
+ defined($st) && ($st->mode & S_IRUSR|S_IWUSR)
+);
+
+unlink $file
+ if ( -e $file);
+