root/psad/tags/psad-2.1.2/Unix-Syslog/test.pl

Revision 634, 6.8 kB (checked in by mbr, 6 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
3
4 ######################### We start with some black magic to print on failure.
5
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8
9 BEGIN { $| = 1; print "1..54\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11
12 use Unix::Syslog qw(:macros :subs);
13
14 $loaded = 1;
15 print "ok 1\n";
16
17 ######################### End of black magic.
18
19 # Insert your test code below (better if it prints "ok 13"
20 # (correspondingly "not ok 13") depending on the success of chunk 13
21 # of the test code):
22
23 sub check_defined($$) {
24   printf "%-20s", $_[0];
25   if (defined eval "$_[0]") {
26     print " ok $_[1]\n";
27     return 0;
28   }
29   else {
30     print " not ok $_[1]\n";
31     return 1;
32   }
33 }
34
35 sub check_defined_skip($$) {
36   printf "%-20s", $_[0];
37   if (defined eval "$_[0]") {
38     print " ok $_[1]\n";
39     return 0;
40   }
41   else {
42     print " skipped $_[1]\n";
43     return 1;
44   }
45 }
46
47 my $n = 2;
48 my $failures = 0;
49
50 print "Testing priorities:\n";
51 $failures += check_defined('LOG_EMERG', $n++);
52 $failures += check_defined('LOG_EMERG', $n++);
53 $failures += check_defined('LOG_ALERT', $n++);
54 $failures += check_defined('LOG_CRIT', $n++);
55 $failures += check_defined('LOG_ERR', $n++);
56 $failures += check_defined('LOG_WARNING', $n++);
57 $failures += check_defined('LOG_NOTICE', $n++);
58 $failures += check_defined('LOG_INFO', $n++);
59 $failures += check_defined('LOG_DEBUG', $n++);
60
61 $failures += check_defined('LOG_EMERG', $n++);
62 $failures += check_defined('LOG_ALERT', $n++);
63 $failures += check_defined('LOG_CRIT', $n++);
64 $failures += check_defined('LOG_ERR', $n++);
65 $failures += check_defined('LOG_WARNING', $n++);
66 $failures += check_defined('LOG_NOTICE', $n++);
67 $failures += check_defined('LOG_INFO', $n++);
68 $failures += check_defined('LOG_DEBUG', $n++);
69
70 print "\nTesting facilities\n";
71 $fac = 0;
72 $failures += check_defined('LOG_KERN', $n++);
73 $failures += check_defined('LOG_USER', $n++);
74 $failures += check_defined('LOG_MAIL', $n++);
75 $failures += check_defined('LOG_DAEMON', $n++);
76 $failures += check_defined('LOG_AUTH', $n++);
77 $failures += check_defined('LOG_SYSLOG', $n++);
78 $failures += check_defined('LOG_LPR', $n++);
79 $failures += check_defined('LOG_NEWS', $n++);
80 $failures += check_defined('LOG_UUCP', $n++);
81 $failures += check_defined('LOG_CRON', $n++);
82 $failures += check_defined('LOG_LOCAL0', $n++);
83 $failures += check_defined('LOG_LOCAL1', $n++);
84 $failures += check_defined('LOG_LOCAL2', $n++);
85 $failures += check_defined('LOG_LOCAL3', $n++);
86 $failures += check_defined('LOG_LOCAL4', $n++);
87 $failures += check_defined('LOG_LOCAL5', $n++);
88 $failures += check_defined('LOG_LOCAL6', $n++);
89 $failures += check_defined('LOG_LOCAL7', $n++);
90
91 print "\nThese facilities are not defined on all systems:\n";
92 $failures += check_defined_skip('LOG_AUTHPRIV', $n++);
93 $failures += check_defined_skip('LOG_FTP', $n++);
94
95 print "\nThe number of available facilities is:\n";
96 $failures += check_defined('LOG_NFACILITIES ', $n++);
97 $failures += check_defined('LOG_FACMASK', $n++);
98
99 print "\nTesting options\n";
100 $failures += check_defined('LOG_PID', $n++);
101 $failures += check_defined('LOG_CONS', $n++);
102 $failures += check_defined('LOG_ODELAY', $n++);
103 $failures += check_defined('LOG_NDELAY', $n++);
104 $failures += check_defined('LOG_NOWAIT', $n++);
105
106 print "\nThese options are not defined on all systems:\n";
107 $failures += check_defined_skip('LOG_PERROR', $n++);
108
109 print "\nTesting macros for setlogmask()\n";
110 $failures += check_defined('LOG_MASK(1)', $n++);
111 $failures += check_defined('LOG_UPTO(1)', $n++);
112
113 print "\nThese macros are not defined on all systems:\n";
114 $failures += check_defined_skip('LOG_PRI(1)', $n++);
115 $failures += check_defined_skip('LOG_MAKEPRI(1,1)', $n++);
116 $failures += check_defined_skip('LOG_FAC(1)', $n++);
117
118 print "\nOn some systems these functions are undefined and\n",
119       "return just empty strings:\n";
120 $failures += check_defined_skip('priorityname(LOG_EMERG)', $n++);
121 $failures += check_defined_skip('facilityname(LOG_KERN)', $n++);
122
123 print "\nTesting setlogmask:\n";
124 print "Setting mask to ", LOG_MASK(LOG_INFO), "\n";
125 $oldmask = setlogmask(LOG_MASK(LOG_INFO));
126 $newmask = setlogmask($oldmask);
127 print "New mask is     $newmask  ";
128 if ($newmask != LOG_MASK(LOG_INFO)) {
129   $failures++;
130   print "not ";
131 }
132 print "ok ", $n++, "\n";
133
134 if ($failures == 0) {
135   print "\n*** Congratulations! All tests passed.\n\n";
136 }
137 else {
138   print "\n*** Test results: ", $n-1-$failures, " tests of ", $n-1, " passed!\n\n";
139 }
140
141 print <<EOM;
142 Testing functions
143
144 As the functions `openlog', `closelog' and `syslog' do not return any
145 value that indicates success or failure, please have a look at the log
146 file generated by syslogd(8).  The following tests print a message of
147 the facility `local7' and the priority `info'.
148
149 EOM
150
151 sub basename {
152   my $name = shift;
153   $name =~ s@.*/@@;
154   return $name;
155 }
156
157 print "openlog\n";
158 openlog(basename($0), LOG_PID, LOG_LOCAL7);
159
160 print "syslog\n";
161
162 # We need some error message
163 open(DUMMY, "<foo");
164
165 syslog(LOG_INFO, "Unix::Syslog testsuite: The ident string should be \`%s\' (Test %d)", basename($0), $n++);
166 syslog(LOG_INFO, "Unix::Syslog testsuite: Testing quote character \`%%\' (Test %d)", $n++);
167 syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints an error message: %m (Test %d)", $n++);
168 syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints a percent sign followed by the character \`m\': %%m (Test %d)", $n++);
169 syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints a percent sign followed by an error message: %%%m (Test %d)", $n++);
170
171 syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints a percent sign followed by the character \`m\': %s (Test %d)", '%m', $n++);
172 syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints two percent signs followed by the character \`m\': %s (Test %d)", '%%m', $n++);
173 syslog(LOG_INFO, "Unix::Syslog testsuite: This message prints three percent signs followed by the character \`m\': %s (Test %d)", '%%%m', $n++);
174
175 print "setlogmask\n";
176 setlogmask(LOG_MASK(LOG_INFO));
177
178 print "syslog\n";
179 syslog(LOG_INFO,  "Unix::Syslog testsuite: (LOG_MASK) This message should be visible (Test %d)\n", $n++);
180 syslog(LOG_EMERG, "Unix::Syslog testsuite: (LOG_MASK) This message should NOT be visible (Test %d)\n", $n++);
181
182 setlogmask(LOG_UPTO(LOG_INFO));
183 syslog(LOG_INFO,    "Unix::Syslog testsuite: (LOG_UPTO) This message should be visible (Test %d)\n", $n++);
184 syslog(LOG_EMERG,   "Unix::Syslog testsuite: (LOG_UPTO) This message should be visible (Test %d)\n", $n++);
185 syslog((LOG_INFO()+1), "Unix::Syslog testsuite: (LOG_UPTO) This message should NOT be visible (Test %d)\n", $n++);
186
187 print "closelog\n\n";
188 closelog;
189
190 print "Testing pointer handling in closelog().\n";
191 print "Calling closelog() a second time.\n";
192 closelog;
193 print "This message should not be preceeded by an error message\n";
194 print "   about dereferenced pointers.\n\n";
195
Note: See TracBrowser for help on using the browser.