main.pm 6.87 KB
Newer Older
1
# Copyright (C) 2016-2018 Harald Sitter <sitter@kde.org>
Harald Sitter's avatar
Harald Sitter committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License or (at your option) version 3 or any later version
# accepted by the membership of KDE e.V. (or its successor approved
# by the membership of KDE e.V.), which shall act as a proxy
# defined in Section 14 of version 3 of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use warnings;
use testapi;
use autotest;
use File::Basename;
Harald Sitter's avatar
Harald Sitter committed
23
use List::Util qw[min];
Harald Sitter's avatar
Harald Sitter committed
24 25 26 27 28

BEGIN {
    unshift @INC, dirname(__FILE__) . '/../../lib';
}

29 30
$testapi::username = 'user';
$testapi::password = 'password';
31 32
testapi::set_var('OEM_USERNAME', 'oem');
testapi::set_var('OEM_PASSWORD', 'oem');
Harald Sitter's avatar
Harald Sitter committed
33

34 35 36
# Special var to check if run in the cloud. This enables tests to only run
# certain set up bits when run in the cloud rather than a local docker
# container.
37 38 39
if (!testapi::get_var("OPENQA_IN_CLOUD")) {
    testapi::set_var('OPENQA_IN_CLOUD', defined $ENV{'NODE_NAME'});
}
40

Harald Sitter's avatar
Harald Sitter committed
41 42
my $dist = testapi::get_var("CASEDIR") . '/lib/distribution_neon.pm';
require $dist;
Harald Sitter's avatar
Harald Sitter committed
43 44
testapi::set_distribution(distribution_neon->new());

Harald Sitter's avatar
Harald Sitter committed
45 46 47 48 49 50 51 52 53 54 55 56
sub unregister_needle_tags {
    my ($tag) = @_;
    my @a = @{needle::tags($tag)};
    for my $n (@a) { $n->unregister($tag); }
}

sub cleanup_needles {
    if (!testapi::get_var('SECUREBOOT')) {
        unregister_needle_tags('ENV-SECUREBOOT');
    } else {
        unregister_needle_tags('ENV-NO-SECUREBOOT');
    }
Harald Sitter's avatar
Harald Sitter committed
57 58 59 60 61
    if (testapi::get_var('UEFI')) {
        unregister_needle_tags('ENV-BIOS');
    } else { # BIOS mode
        unregister_needle_tags('ENV-UEFI');
    }
Harald Sitter's avatar
Harald Sitter committed
62 63 64
    unless (testapi::get_var('OPENQA_INSTALLATION_OFFLINE')) {
        unregister_needle_tags('ENV-OFFLINE');
    }
65
    unless (testapi::get_var('OPENQA_INSTALLATION_NONENGLISH')) {
66 67
        unregister_needle_tags('ENV-NONENGLISH');
    }
68 69 70 71

    # Drop needles tagged with a different TYPE.
    # This is a bit inflexible right now but the best to be done at short
    # notice.
Harald Sitter's avatar
Harald Sitter committed
72
    my $good_tag = sprintf('ENV-TYPE-%s', testapi::get_var('TYPE'));
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    for my $tag (keys %needle::tags) {
        if ($tag !~ /ENV-TYPE-/) {
            next;
        }

        if ($tag eq $good_tag) {
            next;
        }

        # We've found a disqualified tag. Drop all needles that have it.
        # UNLESS that needle has a qualifier tag (i.e. ENV-TYPE-$TYPE).
        # qualification > disqualification
        my @needles = @{needle::tags($tag)};
        for my $needle (@needles) {
            if ($needle->has_tag($good_tag)) {
                next;
            }
            $needle->unregister($tag);
        }
    }

Harald Sitter's avatar
Harald Sitter committed
94 95 96 97 98 99 100
    # FIXME: workaround for bionic
    #   to get bionic tests quickly off the ground we lower all match limits to
    #   70% . this should give reasonable leeway with most font differences.
    #   additionally TTY is also bugging around and sometimes using wrong colors
    #   we'll want to gradually increase this to 100% and sort out failures
    #   as they pop up.
    if (testapi::get_var('OPENQA_SERIES') eq 'bionic') {
101 102 103 104 105 106 107 108 109
        # needle::needles is <name,needle> so overlapping names are lost.
        # Go through tags instead <tag,needles>
        for my $needles (values %needle::tags) {
            for my $needle (@{$needles}) {
                my @areas = $needle->{area};
                for my $area (@{$needle->{area}}) {
                    $area->{match} //= 95; # os-autoinst doesn't default this.
                    $area->{match} = min($area->{match}, 70);
                }
Harald Sitter's avatar
Harald Sitter committed
110 111 112 113
            }
        }
    }

114 115 116 117 118 119 120 121
    # TODO: implement exclusion of newer needles on older systems
    # Now that we dropped all unsuitable needles. We should restirct the match.
    # For all needles with our good tag we'll drop all needles that have the
    # other tags but not our good tag
    # e.g. n1 [ENV-TYPE-stable, dolphin]
    #      n2 [dolphin]
    #   -> we unregister n2 as it is less suitable than n1

Harald Sitter's avatar
Harald Sitter committed
122 123 124 125
}

$needle::cleanuphandler = \&cleanup_needles;

126 127

if (testapi::get_var("INSTALLATION") && testapi::get_var('OPENQA_PARTITIONING')) {
Jonathan Riddell's avatar
Jonathan Riddell committed
128
    if (testapi::get_var("TYPE") eq 'unstable') {
129 130
        autotest::loadtest('tests/install/calamares_partitioning.pm');
    } else {
131 132 133 134 135 136
        # For ubiquity the partitioning test is the regular install test but
        # it has built-in conditionals for OPENQA_PARTITIONING. This is because
        # with ubiquity we need to run complete installs to conduct our tests,
        # so a separate test would be a huge copy pasta. Cala OTOH has
        # a super simplified much faster test which easily stands up on its own.
        autotest::loadtest('tests/install_ubiquity.pm');
137
    }
138
} elsif (testapi::get_var("INSTALLATION")) {
139
    if (testapi::get_var("INSTALLATION_OEM")) {
Harald Sitter's avatar
Harald Sitter committed
140 141 142 143 144
        my %test = (
            'unstable' => "tests/install/calamares_oem.pm",
            '' => "tests/install/ubiquity_oem.pm"
        );
        autotest::loadtest($test{testapi::get_var("TYPE")} || $test{''});
145
    } else {
Harald Sitter's avatar
Harald Sitter committed
146 147 148 149
        my %test = (
            'unstable' => "tests/install_calamares.pm",
            '' => "tests/install_ubiquity.pm"
        );
Harald Sitter's avatar
Harald Sitter committed
150
        autotest::loadtest($test{testapi::get_var("TYPE")} || $test{''});
151
    }
152
    autotest::loadtest('tests/install/first_start.pm');
153 154 155 156 157 158 159 160 161 162 163
} elsif (testapi::get_var('OPENQA_SNAP_NAME')) {
    print("Running a snap test...\n");
    my $snap_name = testapi::get_var('OPENQA_SNAP_NAME');
    my $script = "tests/snap/$snap_name.pm";
    if (-f join('/', testapi::get_var('CASEDIR'), $script)) {
        print("Found specific test for snap $script\n");
        autotest::loadtest($script);
    } else {
        print("Using generic test for snap $snap_name\n");
        autotest::loadtest("tests/snap/generic.pm");
    }
164
} elsif (testapi::get_var("TESTS_TO_RUN")) {
165 166
    my @testpaths = split /:/, testapi::get_var("TESTS_TO_RUN");
    for my $testpath (@testpaths) {
Harald Sitter's avatar
Harald Sitter committed
167
        autotest::loadtest $testpath;
168
    }
169 170
} elsif (testapi::get_var("PLASMA_DESKTOP")) {
    autotest::loadtest('tests/plasma/plasma_folder.pm');
171
    autotest::loadtest('tests/plasma/plasma_favorite.pm');
172
    autotest::loadtest('tests/plasma/plasma_alternatives.pm');
173 174 175 176 177
    # Do not run tests after the lockscreen. We log into a second session
    # to get away from a switch-user sddm (which has no other means to do so
    # via the GUI). This may have any number of unfortunate side effects in the
    # main session (e.g. cache corruption?).
    autotest::loadtest('tests/plasma/plasma_lockscreen.pm');
Harald Sitter's avatar
Harald Sitter committed
178
} else {
179 180
    testapi::diag 'ERROR FAILURE BAD ERROR no clue what to run!';
    exit 1;
Harald Sitter's avatar
Harald Sitter committed
181 182
}

Harald Sitter's avatar
Harald Sitter committed
183
1;