BrowserUnitTests.pm 3.39 KB
Newer Older
boklm's avatar
boklm committed
1
2
3
package TBBTestSuite::BrowserUnitTests;

use strict;
boklm's avatar
boklm committed
4
use FindBin;
boklm's avatar
boklm committed
5
6
7
use IO::CaptureOutput qw(capture_exec);
use File::Spec;
use File::Find;
boklm's avatar
boklm committed
8
9
use File::Copy;
use TBBTestSuite::Common qw(exit_error get_nbcpu run_to_file);
boklm's avatar
boklm committed
10
11
12

my $test_types = {
    xpcshell => \&xpcshell_test,
boklm's avatar
boklm committed
13
    build_firefox => \&build_firefox,
boklm's avatar
boklm committed
14
15
};

16
17
18
19
20
21
our %testsuite = (
    test_types => $test_types,
    pre_tests  => \&pre_tests,
    post_tests => \&post_tests,
);

boklm's avatar
boklm committed
22
23
24
25
sub get_tbbinfos {
    my ($infos) = @_;
    my %tbbinfos = (
        %$infos,
26
        type => 'browserunit',
boklm's avatar
boklm committed
27
        filename => "browser-$infos->{commit}",
boklm's avatar
boklm committed
28
29
30
31
32
33
34
35
        tests => [
            {
                name => 'build_firefox',
                type => 'build_firefox',
                fail_type => 'fatal',
                descr => 'Build Firefox',
            },
        ],
boklm's avatar
boklm committed
36
37
38
39
40
41
42
43
    );
    push @{$tbbinfos{tests}}, find_xpcshell_tests(\%tbbinfos);
    return \%tbbinfos;
}

sub pre_tests {
    my ($tbbinfos) = @_;
    chdir $tbbinfos->{browserdir};
boklm's avatar
boklm committed
44
45
    system('git', 'clean', '-fxd');
    system('git', 'reset', '--hard');
boklm's avatar
boklm committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    system('git', 'checkout', $tbbinfos->{commit}) == 0
        or exit_error "Error checking out $tbbinfos->{commit}";
    my ($out, $err, $success) = capture_exec('git', 'show', '-s',
        '--abbrev=20', '--format=%p', $tbbinfos->{commit});
    exit_error "Error checking parents of $tbbinfos->{commit}" unless $success;
    $tbbinfos->{parent_commits} = [ split(' ', $out) ];
    ($out, $err, $success) = capture_exec('git', 'show', '-s',
        '--format=%s', $tbbinfos->{commit});
    exit_error "Error getting commit subject" unless $success;
    $tbbinfos->{commit_subject} = $out;
    ($out, $err, $success) = capture_exec('git', 'show', '-s',
        '--format=%an', $tbbinfos->{commit});
    exit_error "Error getting commit author" unless $success;
    $tbbinfos->{commit_author} = $out;
boklm's avatar
boklm committed
60
61
62
63
64
65
66
67
68
69
70
71
72
}

sub post_tests {
}

sub find_xpcshell_tests {
    my ($tbbinfos) = @_;
    my @res;
    my $wanted = sub {
        return unless -f $File::Find::name;
        my (undef, $dir, $file) = File::Spec->splitpath($File::Find::name);
        return unless $file eq 'xpcshell.ini';
        $dir =~ s{^$tbbinfos->{browserdir}/}{};
boklm's avatar
boklm committed
73
        $dir =~ s{/$}{};
boklm's avatar
boklm committed
74
75
76
77
78
        return if $dir =~ m/^obj-/;
        push @res, {
            name  => "xpcshell:$dir",
            type  => 'xpcshell',
            descr => "xpcshell test in directory $dir",
boklm's avatar
boklm committed
79
            dir   => $dir,
boklm's avatar
boklm committed
80
81
82
83
84
85
86
87
88
        };
    };
    find($wanted, $tbbinfos->{browserdir});
    return @res;
}

sub xpcshell_test {
    my ($tbbinfos, $test) = @_;
    my ($out, $err, $success) =
boklm's avatar
boklm committed
89
                capture_exec('./mach', 'xpcshell-test', $test->{dir});
boklm's avatar
boklm committed
90
91
92
93
94
95
96
97
98
99
100
    $test->{results}{success} = $success;
    $test->{results}{out} = $out;
    $test->{results}{failed} = [];
    foreach my $line (split "\n", $out) {
        if ($line =~ m{TEST-UNEXPECTED-FAIL \| /([^\|]+) \|}) {
            my (undef, undef, $file) = File::Spec->splitpath($1);
            push @{$test->{results}{failed}}, $file;
        }
    }
}

boklm's avatar
boklm committed
101
102
103
104
105
106
107
108
109
110
111
sub build_firefox {
    my ($tbbinfos, $test) = @_;
    $test->{results}{success} = 0;
    copy("$FindBin::Bin/data/mozconfig", '.mozconfig');
    run_to_file("$tbbinfos->{'results-dir'}/$test->{name}.configure.txt",
        'make', '-f', 'client.mk', 'configure') or return;
    run_to_file("$tbbinfos->{'results-dir'}/$test->{name}.build.txt",
        'make', '-j' . get_nbcpu, '-f', 'client.mk', 'build') or return;
    $test->{results}{success} = 1;
}

boklm's avatar
boklm committed
112
1;