tbb-testsuite 3.71 KB
Newer Older
1
2
#!/usr/bin/perl -w
use strict;
3
4
use FindBin;
use lib "$FindBin::Bin";
5
use Data::Dump qw/dd/;
6
use File::Path qw(make_path);
boklm's avatar
boklm committed
7
use YAML::Syck;
8
use TBBTestSuite::Common qw(exit_error run_alone rm_pidfile);
9
use TBBTestSuite::Options qw($options);
boklm's avatar
boklm committed
10
use TBBTestSuite::Reports qw(report_dir report_path save_report);
11
12
use TBBTestSuite::Reports::Receive;
use TBBTestSuite::Reports::Send;
boklm's avatar
boklm committed
13
use TBBTestSuite::Tests;
14
use TBBTestSuite::BrowserBundleTests qw(tbb_filename_infos);
15

boklm's avatar
boklm committed
16
17
18
sub set_report_success {
    my ($report) = @_;
    $report->{success} = 1;
boklm's avatar
boklm committed
19
    $report->{error_tests} = {};
boklm's avatar
boklm committed
20
    $report->{warning_tests} = {};
21
22
    foreach my $tbbfile_name (keys %{$report->{tbbfiles}}) {
        my $tbbfile = $report->{tbbfiles}{$tbbfile_name};
boklm's avatar
boklm committed
23
        $report->{success} = 0 unless $tbbfile->{success};
24
        foreach my $test (@{$tbbfile->{tests}}) {
boklm's avatar
boklm committed
25
            if (TBBTestSuite::Tests::is_test_error($test)) {
boklm's avatar
boklm committed
26
                push @{$report->{error_tests}{$test->{name}}}, $tbbfile_name;
27
            }
boklm's avatar
boklm committed
28
29
30
            if (TBBTestSuite::Tests::is_test_warning($test)) {
                push @{$report->{warning_tests}{$test->{name}}}, $tbbfile_name;
            }
31
32
33
            if (TBBTestSuite::Tests::is_test_known($test)) {
                push @{$report->{known_tests}{$test->{name}}}, $tbbfile_name;
            }
boklm's avatar
boklm committed
34
35
36
37
        }
    }
}

38
sub run_tests {
39
    return unless @{$options->{args}};
40
41
42
43
    my $report = {
        tbbfiles => {},
        options  => $options,
        time     => time,
boklm's avatar
boklm committed
44
        system_infos => TBBTestSuite::Common::system_infos,
45
        report_format => '1',
46
    };
boklm's avatar
boklm committed
47
    foreach my $tbbfile (@{$options->{args}}) {
48
49
        my $tbbinfos = ref $tbbfile eq 'HASH' ? $tbbfile
                         : tbb_filename_infos($tbbfile);
boklm's avatar
boklm committed
50
        TBBTestSuite::Tests::test_start($report, $tbbinfos);
51
    }
boklm's avatar
boklm committed
52
    set_report_success($report);
boklm's avatar
boklm committed
53
    save_report($report);
54
    print 'Report directory: ', report_dir($report), "\n";
55
    TBBTestSuite::Reports::make_report($report);
56
    TBBTestSuite::Reports::make_reports_index($report);
57
    TBBTestSuite::Reports::Send::send_report if $options->{'upload-to'};
58
}
59

boklm's avatar
boklm committed
60
sub load_report_from_file {
boklm's avatar
boklm committed
61
62
    exit_error "--name is not set" unless $options->{name};
    my $report = { options => $options };
boklm's avatar
boklm committed
63
    $report = YAML::Syck::LoadFile(report_path($report, 'report.yml'));
boklm's avatar
boklm committed
64
    $report->{options} = { %{$report->{options}}, %$options };
boklm's avatar
boklm committed
65
66
67
68
69
    return $report;
}

sub make_report {
    my $report = load_report_from_file;
boklm's avatar
boklm committed
70
71
72
    TBBTestSuite::Reports::make_report($report);
}

73
sub receive_report {
74
75
    my $report = TBBTestSuite::Reports::Receive::receive_report;
    TBBTestSuite::Reports::make_reports_index($report);
76
77
}

boklm's avatar
boklm committed
78
79
80
81
82
sub email_report {
    my $report = load_report_from_file;
    TBBTestSuite::Reports::email_report($report);
}

boklm's avatar
boklm committed
83
84
85
86
87
sub show_report {
    my $report = load_report_from_file;
    print TBBTestSuite::Reports::text_report($report);
}

boklm's avatar
boklm committed
88
89
90
91
sub dump_options {
    dd $options;
}

92
93
my %actions = (
    run_tests => \&run_tests,
94
    list_tests => \&TBBTestSuite::BrowserBundleTests::list_tests,
95
    reports_index => \&TBBTestSuite::Reports::make_reports_index,
boklm's avatar
boklm committed
96
    make_report => \&make_report,
97
98
99
    send_report => \&TBBTestSuite::Reports::Send::send_report,
    receive_report => \&receive_report,
    update_authkeys => \&TBBTestSuite::Reports::Receive::update_authkeys,
boklm's avatar
boklm committed
100
    email_report => \&email_report,
boklm's avatar
boklm committed
101
    show_report  => \&show_report,
boklm's avatar
boklm committed
102
    dump_options => \&dump_options,
103
104
);

105
106
107
108
109
110
111
112
113
114
sub usage {
    print STDERR "$0 [--action=action_name] [OPTIONS...]\n\n";
    print STDERR "Possible actions:\n";
    foreach my $act (keys %actions) {
        print STDERR " - $act\n";
    }
    exit 1;
}

usage unless @ARGV;
115
exit_error "Unknow action $options->{action}" unless $actions{$options->{action}};
116
run_alone;
117
make_path($options->{tmpdir});
118
$actions{$options->{action}}->();
119
rm_pidfile;