summaryrefslogtreecommitdiff
path: root/t/Unix-Mknod.t
blob: 66c540d91091ec368fabbd4b71ebe4062fcdde38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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);