compare-debug-order.t 12.5 KB
Newer Older
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
use 5.014;
use strict;
use warnings;

# Test comparison operation for sorting modules into debug order

use Test::More;

use ksb::DebugOrderHints;

# Redefine ksb::Module to stub getPersistentOption() results
package ksb::Module {
    no warnings 'redefine';

    sub new
    {
        my ($class, $name, $count) = @_;

        my $self = {
            count => $count,
            name => $name
        };

        bless $self, $class;
        return $self;
    }

    sub getPersistentOption
    {
        my $self = shift;
        my $option = shift;
        Test::More::is($option, 'failure-count', "only the 'failure-count' should be queried");
        return $self->{count};
    }

    sub name
    {
        my $self = shift;
        return $self->{name};
    }
};

my $a1 = new ksb::Module('A:i-d2-v0-c0', 0);
my $b1 = new ksb::Module('B:i-d1-v1-c0', 0);
my $c1 = new ksb::Module('C:i-d0-v0-c0', 0);
my $d1 = new ksb::Module('D:i-d0-v0-c1', 1);
my $e1 = new ksb::Module('E:i-d0-v1-c0', 0);

# test: ordering of modules that fail in the same phase based on dependency info
my $graph1 = {
    $c1->name() => {
        votes => {},
        deps => {},
        module => $c1
    },
    $d1->name() => {
        votes => {},
        deps => {},
        module => $d1
    },
    $e1->name() => {
        votes => {
            $a1->name() => 1
        },
        deps => {},
        module => $e1
    },
    $b1->name() => {
        votes => {
            $a1->name() => 1
        },
        deps => { 'foo' => 1 },
        module => $b1
    },
    $a1->name() => {
        votes => {},
        deps => {
            $e1->name() => 1,
            $b1->name() => 1
        },
        module => $a1
    }
};

my $extraDebugInfo1 = {
    phases => {
        $a1->name() => 'install',
        $b1->name() => 'install',
        $c1->name() => 'install',
        $d1->name() => 'install',
        $e1->name() => 'install'
    }
};

is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $c1, $c1),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $c1, $d1), -1, "No dependency relation ship, root causes, same popularity: the 'newest' failure (lower count) should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $c1, $e1),  1, "No dependency relation ship, root causes: the higher popularity should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $c1, $b1), -1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $c1, $a1), -1, "No dependency relation ship: the root cause should be sorted first");

is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $d1, $c1),  1, "No dependency relation ship, root causes, same popularity: the 'newest' failure (lower count) should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $d1, $d1),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $d1, $e1),  1, "No dependency relation ship, root causes: the higher popularity should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $d1, $b1), -1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $d1, $a1), -1, "No dependency relation ship: the root cause should be sorted first");

is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $e1, $c1), -1, "No dependency relation ship, root causes: the higher popularity should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $e1, $d1), -1, "No dependency relation ship, root causes: the higher popularity should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $e1, $e1),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $e1, $b1), -1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $e1, $a1), -1, "Dependencies should be sorted before dependent modules");

is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $b1, $c1),  1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $b1, $d1),  1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $b1, $e1),  1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $b1, $b1),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $b1, $a1), -1, "Dependencies should be sorted before dependent modules");

is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $a1, $c1),  1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $a1, $d1),  1, "No dependency relation ship: the root cause should be sorted first");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $a1, $e1),  1, "Dependencies should be sorted before dependent modules");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $a1, $b1),  1, "Dependencies should be sorted before dependent modules");
is(ksb::DebugOrderHints::_compareDebugOrder($graph1, $extraDebugInfo1, $a1, $a1),  0, "Comparing the same modules should always yield the same relative position");

# test: ordering of modules that fail in different phases
my $p_b1 = new ksb::Module('build1', 0);
my $p_b2 = new ksb::Module('build2', 0);
my $p_i = new ksb::Module('install', 0);
my $p_t = new ksb::Module('test', 0);
my $p_u = new ksb::Module('update', 0);
my $p_x = new ksb::Module('unknown', 0);

my $graph2 = {
    $p_b1->name() => {
        votes => {},
        deps => {},
        module => $p_b1
    },
    $p_b2->name() => {
        votes => {},
        deps => {},
        module => $p_b2
    },
    $p_i->name() => {
        votes => {},
        deps => {},
        module => $p_i
    },
    $p_t->name() => {
        votes => {},
        deps => {},
        module => $p_t
    },
    $p_u->name() => {
        votes => {},
        deps => {},
        module => $p_u
    },
    $p_x->name() => {
        votes => {},
        deps => {},
        module => $p_x
    }
};

my $extraDebugInfo2 = {
    phases => {
        $p_b1->name() => 'build',
        $p_b2->name() => 'build',
        $p_i->name() => 'install',
        $p_t->name() => 'test',
        $p_u->name() => 'update',
        $p_x->name() => 'unknown'
    }
};

is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b1, $p_b1),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b1, $p_b2), -1, "Same phase: sort by name for reproducibility");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b1, $p_i ),  1, "Phase ordering: 'build' should be sorted after 'install'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b1, $p_t ),  1, "Phase ordering: 'build' should be sorted after 'test'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b1, $p_u ), -1, "Phase ordering: 'build' should be sorted before 'update'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b1, $p_x ), -1, "Phase ordering: 'build' should be sorted before unsupported phases");

is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b2, $p_b1),  1, "Same phase: sort by name for reproducibility");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b2, $p_b2),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b2, $p_i ),  1, "Phase ordering: 'build' should be sorted after 'install'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b2, $p_t ),  1, "Phase ordering: 'build' should be sorted after 'test'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b2, $p_u ), -1, "Phase ordering: 'build' should be sorted before 'update'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_b2, $p_x ), -1, "Phase ordering: 'build' should be sorted before unsupported phases");

is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_i,  $p_b1), -1, "Phase ordering: 'install' should be sorted before 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_i,  $p_b2), -1, "Phase ordering: 'install' should be sorted before 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_i,  $p_i ),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_i,  $p_t ), -1, "Phase ordering: 'install' should be sorted before 'test'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_i,  $p_u ), -1, "Phase ordering: 'install' should be sorted before 'update'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_i,  $p_x ), -1, "Phase ordering: 'install' should be sorted before unsupported phases");

is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_t,  $p_b1), -1, "Phase ordering: 'test' should be sorted before 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_t,  $p_b2), -1, "Phase ordering: 'test' should be sorted before 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_t,  $p_i ),  1, "Phase ordering: 'test' should be sorted after 'install'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_t,  $p_t ),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_t,  $p_u ), -1, "Phase ordering: 'test' should be sorted before 'update'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_t,  $p_x ), -1, "Phase ordering: 'test' should be sorted before unsupported phases");

is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_u,  $p_b1),  1, "Phase ordering: 'update' should be sorted after 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_u,  $p_b2),  1, "Phase ordering: 'update' should be sorted after 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_u,  $p_i ),  1, "Phase ordering: 'update' should be sorted after 'install'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_u,  $p_t ),  1, "Phase ordering: 'update' should be sorted after 'test'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_u,  $p_u ),  0, "Comparing the same modules should always yield the same relative position");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_u,  $p_x ), -1, "Phase ordering: 'update' should be sorted before unsupported phases");

is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_x,  $p_b1),  1, "Phase ordering: unknown phases should be sorted after 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_x,  $p_b2),  1, "Phase ordering: unknown phases should be sorted after 'build'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_x,  $p_i ),  1, "Phase ordering: unknown phases should be sorted after 'install'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_x,  $p_t ),  1, "Phase ordering: unknown phases should be sorted after 'test'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_x,  $p_u ),  1, "Phase ordering: unknown phases should be sorted after 'update'");
is(ksb::DebugOrderHints::_compareDebugOrder($graph2, $extraDebugInfo2, $p_x,  $p_x ),  0, "Comparing the same modules should always yield the same relative position");

done_testing();