selftest: Add copyright headers
[sfrench/samba-autobuild/.git] / selftest / output / buildfarm.pm
1 #!/usr/bin/perl
2 # Buildfarm output for selftest
3 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 package output::buildfarm;
19
20 use Exporter;
21 @ISA = qw(Exporter);
22
23 use FindBin qw($RealBin);
24 use lib "$RealBin/..";
25
26 use Subunit qw(parse_results);
27
28 use strict;
29
30 sub new($$$) {
31         my ($class) = @_;
32         my $self = {
33                 test_output => {},
34                 start_time => time()
35         };
36         bless($self, $class);
37 }
38
39 sub start_testsuite($$)
40 {
41         my ($self, $name) = @_;
42         my $out = "";
43
44         $self->{NAME} = $name;
45         $self->{START_TIME} = time();
46
47         my $duration = $self->{START_TIME} - $self->{start_time};
48         $out .= "--==--==--==--==--==--==--==--==--==--==--\n";
49         $out .= "Running test $name (level 0 stdout)\n";
50         $out .= "--==--==--==--==--==--==--==--==--==--==--\n";
51         $out .= scalar(localtime())."\n";
52         $out .= "SELFTEST RUNTIME: " . $duration . "s\n";
53         $out .= "NAME: $name\n";
54
55         $self->{test_output}->{$name} = "";
56
57         print $out;
58 }
59
60 sub output_msg($$)
61 {
62         my ($self, $output) = @_;
63
64         $self->{test_output}->{$self->{NAME}} .= $output;
65 }
66
67 sub control_msg($$)
68 {
69         my ($self, $output) = @_;
70
71         $self->{test_output}->{$self->{NAME}} .= $output;
72 }
73
74 sub end_testsuite($$$$$$)
75 {
76         my ($self, $name, $result, $unexpected, $reason) = @_;
77         my $out = "";
78
79         $out .= "TEST RUNTIME: " . (time() - $self->{START_TIME}) . "s\n";
80
81         if (not $unexpected) {
82                 $out .= "ALL OK\n";
83         } else {
84                 $out .= "ERROR: $reason\n";
85                 $out .= $self->{test_output}->{$name};
86         }
87
88         $out .= "==========================================\n";
89         if (not $unexpected) {
90                 $out .= "TEST PASSED: $name\n";
91         } else {
92                 $out .= "TEST FAILED: $name (status $reason)\n";
93         }
94         $out .= "==========================================\n";
95
96         print $out;
97 }
98
99 sub start_test($$$)
100 {
101         my ($self, $parents, $testname) = @_;
102
103         if ($#$parents == -1) {
104                 $self->start_testsuite($testname);
105         }
106 }
107
108 sub end_test($$$$$)
109 {
110         my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
111
112         if ($unexpected) {
113                 $self->{test_output}->{$self->{NAME}} .= "UNEXPECTED($result): $testname\n";
114         }
115
116         if ($#$parents == -1) {
117                 $self->end_testsuite($testname, $result, $unexpected, $reason); 
118         }
119 }
120
121 sub summary($)
122 {
123         my ($self) = @_;
124
125         print "DURATION: " . (time() - $self->{start_time}) . " seconds\n";
126 }
127
128 sub skip_testsuite($$$$)
129 {
130         my ($self, $name, $reason) = @_;
131
132         print "SKIPPED: $name\n";
133 }
134
135 1;