aboutsummaryrefslogtreecommitdiff
path: root/tests/Faitest.pm
blob: 022b4075cd1cc71d6200ed2d6bb41e5a5e7f6064 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/perl

# Subroutines for automatic tests
#
# Copyright (C) 2009 Thomas Lange, lange@informatik.uni-koeln.de
# Based on the first version by Sebastian Hetze, 08/2008

package FAITEST;

my $errors = 0;

use strict;
use Getopt::Long;
use Pod::Usage;
#  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
sub setup_test {

  my $verbose = 0;
  my $help = 0;
  my $man  = 0;
  $verbose = $ENV{'debug'} if $ENV{'debug'};

  my $result = GetOptions (
        "verbose=i" => \$verbose,
        "help" => \$help,
        "man" => \$man,

        );

  pod2usage(1) if $help;
  pod2usage(-exitstatus => 0, -verbose => 2) if $man;

  open(LOGFILE,">> $ENV{LOGDIR}/test.log") || die "Can't open test.log. $!";
  print LOGFILE "------------   Test $0 starting  ------------\n";
}

sub printresult {

  # write test result and set next test
  my ($nexttest) = @_;

  if ($errors > 0) {
    print STDERR  "\n===>  $0 FAILED with $errors errors\n";
    print LOGFILE "\n===>  $0 FAILED with $errors errors\n";
  } else {
    print STDERR  "\n===>  $0 PASSED successfully\n";
    print LOGFILE "\n===>  $0 PASSED successfully\n";
    print LOGFILE "NEXTTEST=$nexttest\n" if $nexttest;
  }
  close (LOGFILE);
  return $errors;
}

sub getDevByMount {

  my $mount = shift;
  my $dev = qx#mount|grep $mount|cut -d' ' -f1#;
  chomp $dev;
  return $dev
}

sub checkMdStat {

  my ($device, $expected) = @_;
  my ($value) = qx#grep -i "^$device\\b" /proc/mdstat# =~ m/$device\s*:\s*(.*)/i;

  if ($value eq $expected) {
    print LOGFILE "Check raid $device success\n";
    return 0;
  } else {
    print LOGFILE "Check raid $device FAILED.\n   Expect <$expected>\n   Found <$value>\n";
    $errors++;
    return 1;
  }
}

sub checkE2fsAttribute {

  my ($device, $attribute, $expected) = @_;

  # since attribute is a space separated list of attributes, IMO we must loop over
  # the list. Ask Sebastian again
  my ($value) = qx#tune2fs -l $device |grep -i "$attribute"# =~ m/$attribute:\s+(.*)/i;

  if ($value eq $expected) {
    print LOGFILE "Check $attribute for $device success\n";
    return 0;
  } else {
    print LOGFILE "Check $attribute for $device FAILED.\n   Expect <$expected>\n   Found  <$value>\n";

    $errors++;
    return 1;
  }
}

1;