2d1f8014 |
1 | #! /usr/bin/perl |
2 | |
3 | # Subroutines for automatic tests |
4 | # |
5 | # Copyright (C) 2009 Thomas Lange, lange@informatik.uni-koeln.de |
6 | # Based on the first version by Sebastian Hetze, 08/2008 |
7 | |
8 | package FAITEST; |
9 | |
10 | $errors = 0; |
11 | |
12 | use Getopt::Long; |
13 | use Pod::Usage; |
14 | # - - - - - - - - - - - - - - - - - - - - - - - - - - |
15 | sub setup_test { |
16 | |
17 | my $verbose = 0; |
18 | my $help = 0; |
19 | my $man = 0; |
20 | $verbose = $ENV{'debug'} if $ENV{'debug'}; |
21 | |
22 | my $result = GetOptions ( |
23 | "verbose=i" => \$verbose, |
24 | "help" => \$help, |
25 | "man" => \$man, |
26 | |
27 | ); |
28 | |
29 | pod2usage(1) if $help; |
30 | pod2usage(-exitstatus => 0, -verbose => 2) if $man; |
31 | |
32 | open(LOGFILE,">> $ENV{LOGDIR}/test.log") || die "Can't open test.log. $!"; |
33 | print LOGFILE "------------ Test $0 starting ------------\n"; |
34 | } |
35 | |
36 | sub printresult { |
37 | |
38 | # write test result and set next test |
39 | my ($nexttest) = @_; |
40 | |
41 | if ($errors > 0) { |
42 | print STDERR "\n===> $0 FAILED with $errors errors\n"; |
43 | print LOGFILE "\n===> $0 FAILED with $errors errors\n"; |
44 | } else { |
45 | print STDERR "\n===> $0 PASSED successfully\n"; |
46 | print LOGFILE "\n===> $0 PASSED successfully\n"; |
47 | print LOGFILE "NEXTTEST=$nexttest\n" if $nexttest; |
48 | } |
49 | close (LOGFILE); |
50 | return $errors; |
51 | } |
52 | |
53 | sub getDevByMount { |
54 | |
55 | my $mount = shift; |
56 | my $dev = qx#mount|grep $mount|cut -d' ' -f1#; |
57 | chomp $dev; |
58 | return $dev |
59 | } |
60 | |
61 | sub checkMdStat { |
62 | |
63 | my ($device, $expected) = @_; |
64 | my ($value) = qx#grep -i "^$device\\b" /proc/mdstat# =~ m/$device\s*:\s*(.*)/i; |
65 | |
66 | if ($value eq $expected) { |
67 | print LOGFILE "Check raid $device success\n"; |
68 | return 0; |
69 | } else { |
70 | print LOGFILE "Check raid $device FAILED.\n Expect <$expected>\n Found <$value>\n"; |
71 | $errors++; |
72 | return 1; |
73 | } |
74 | } |
75 | |
76 | sub checkE2fsAttribute { |
77 | |
78 | my ($device, $attribute, $expected) = @_; |
79 | |
80 | # since attribute is a space separated list of attributes, IMO we must loop over |
81 | # the list. Ask Sebastian again |
82 | my ($value) = qx#tune2fs -l $device |grep -i "$attribute"# =~ m/$attribute:\s+(.*)/i; |
83 | |
84 | if ($value eq $expected) { |
85 | print LOGFILE "Check $attribute for $device success\n"; |
86 | return 0; |
87 | } else { |
88 | print LOGFILE "Check $attribute for $device FAILED.\n Expect <$expected>\n Found <$value>\n"; |
89 | |
90 | $errors++; |
91 | return 1; |
92 | } |
93 | } |
94 | |
95 | 1; |