From ccaa1bdfa70ddc1587b519420e37f7689081bb58 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 26 Oct 2023 01:39:30 -0400 Subject: GIT THIS --- t/Unix-Mknod.t | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 t/Unix-Mknod.t (limited to 't/Unix-Mknod.t') 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); + -- cgit v1.2.3