line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SmokeRunner::Multi::TestSet; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Represents a set of tests |
4
|
|
|
|
|
|
|
$SmokeRunner::Multi::TestSet::VERSION = '0.21'; |
5
|
7
|
|
|
7
|
|
54691
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
181
|
|
6
|
7
|
|
|
7
|
|
33
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
207
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
33
|
use base 'Class::Accessor::Fast'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
2840
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw( name set_dir test_dir last_run_time is_prioritized ) ); |
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
|
15335
|
use Class::Factory::Util; |
|
7
|
|
|
|
|
4062
|
|
|
7
|
|
|
|
|
56
|
|
12
|
7
|
|
|
7
|
|
256
|
use File::Basename qw( basename ); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
471
|
|
13
|
7
|
|
|
7
|
|
4951
|
use File::Find::Rule; |
|
7
|
|
|
|
|
56195
|
|
|
7
|
|
|
|
|
1159
|
|
14
|
7
|
|
|
7
|
|
365
|
use File::Path qw( rmtree ); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
390
|
|
15
|
7
|
|
|
7
|
|
34
|
use File::Spec; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
163
|
|
16
|
7
|
|
|
7
|
|
30
|
use List::Util qw( max ); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
568
|
|
17
|
7
|
|
|
7
|
|
4039
|
use SmokeRunner::Multi::DBI; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
270
|
|
18
|
7
|
|
|
7
|
|
1769
|
use SmokeRunner::Multi::Validate qw( validate DIR_TYPE ); |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
61
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN |
22
|
|
|
|
|
|
|
{ |
23
|
7
|
|
|
7
|
|
48
|
for my $subclass ( map { __PACKAGE__ . '::' . $_ } __PACKAGE__->subclasses() ) |
|
7
|
|
|
|
|
3633
|
|
24
|
|
|
|
|
|
|
{ |
25
|
7
|
50
|
|
|
|
490
|
eval "require $subclass" or die $@; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
my $spec = { set_dir => DIR_TYPE }; |
31
|
|
|
|
|
|
|
sub new |
32
|
|
|
|
|
|
|
{ |
33
|
48
|
|
|
48
|
1
|
26234
|
my $class = shift; |
34
|
48
|
|
|
|
|
1379
|
my %p = validate( @_, $spec ); |
35
|
|
|
|
|
|
|
|
36
|
48
|
|
|
|
|
753
|
my $test_dir = File::Spec->catdir( $p{set_dir}, 't' ); |
37
|
48
|
100
|
|
|
|
1275
|
die "A test set's directory must have a 't' subdirectory" |
38
|
|
|
|
|
|
|
unless -d $test_dir; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my %subclass_p = ( %p, |
41
|
46
|
|
|
|
|
2485
|
name => basename( $p{set_dir} ), |
42
|
|
|
|
|
|
|
test_dir => $test_dir, |
43
|
|
|
|
|
|
|
dbh => SmokeRunner::Multi::DBI::handle(), |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
46
|
|
|
|
|
122
|
my $self; |
47
|
46
|
|
|
|
|
390
|
for my $subclass ( map { __PACKAGE__ . '::' . $_ } $class->subclasses() ) |
|
46
|
|
|
|
|
29707
|
|
48
|
|
|
|
|
|
|
{ |
49
|
46
|
|
|
|
|
507
|
$self = $subclass->_new(%subclass_p); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
46
|
|
66
|
|
|
396
|
$self ||= __PACKAGE__->_new(%subclass_p); |
53
|
|
|
|
|
|
|
|
54
|
46
|
|
|
|
|
237
|
$self->_instantiate_in_db(); |
55
|
46
|
|
|
|
|
716498
|
$self->_get_db_data(); |
56
|
|
|
|
|
|
|
|
57
|
46
|
|
|
|
|
1256
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _new |
62
|
|
|
|
|
|
|
{ |
63
|
43
|
|
|
43
|
|
107
|
my $class = shift; |
64
|
|
|
|
|
|
|
|
65
|
43
|
|
|
|
|
539
|
return bless { @_ }, $class; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _instantiate_in_db |
69
|
|
|
|
|
|
|
{ |
70
|
46
|
|
|
46
|
|
111
|
my $self = shift; |
71
|
|
|
|
|
|
|
|
72
|
46
|
|
|
|
|
106
|
my $insert_sql = 'INSERT OR IGNORE INTO TestSet (name) VALUES (?)'; |
73
|
|
|
|
|
|
|
|
74
|
46
|
|
|
|
|
286
|
$self->{dbh}->do( $insert_sql, {}, $self->name() ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _get_db_data |
78
|
|
|
|
|
|
|
{ |
79
|
55
|
|
|
55
|
|
262
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
55
|
|
|
|
|
138
|
my $select_sql = 'SELECT last_run_time, is_prioritized FROM TestSet WHERE name = ?'; |
82
|
|
|
|
|
|
|
|
83
|
55
|
|
|
|
|
13188
|
@{ $self }{ qw( last_run_time is_prioritized ) } = |
84
|
55
|
|
|
|
|
434
|
$self->{dbh}->selectrow_array( $select_sql, {}, $self->name() ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub test_files |
88
|
|
|
|
|
|
|
{ |
89
|
36
|
|
|
36
|
1
|
2557
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
36
|
|
|
|
|
1758
|
return sort File::Find::Rule->file()->name( '*.t' )->in( $self->test_dir() ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub last_mod_time |
95
|
|
|
|
|
|
|
{ |
96
|
56
|
|
|
56
|
1
|
2365
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
56
|
100
|
|
|
|
255
|
return $self->{last_mod_time} if exists $self->{last_mod_time}; |
99
|
|
|
|
|
|
|
|
100
|
30
|
|
100
|
|
|
98
|
$self->{last_mod_time} = $self->_last_mod_time() || 0; |
101
|
|
|
|
|
|
|
|
102
|
30
|
|
|
|
|
1983
|
return $self->{last_mod_time}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _last_mod_time |
106
|
|
|
|
|
|
|
{ |
107
|
29
|
|
|
29
|
|
54
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
29
|
|
|
|
|
91
|
return max map { ( stat $_ )[9] } $self->test_files(); |
|
62
|
|
|
|
|
31685
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub is_out_of_date |
113
|
|
|
|
|
|
|
{ |
114
|
4
|
|
|
4
|
1
|
2315
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
4
|
100
|
|
|
|
18
|
return $self->seconds_out_of_date() > 0 ? 1 : 0; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub seconds_out_of_date |
120
|
|
|
|
|
|
|
{ |
121
|
55
|
|
|
55
|
1
|
498
|
my $self = shift; |
122
|
|
|
|
|
|
|
|
123
|
55
|
|
|
|
|
171
|
return $self->last_mod_time() - $self->last_run_time(); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub update_last_run_time |
127
|
|
|
|
|
|
|
{ |
128
|
3
|
|
|
3
|
1
|
626
|
my $self = shift; |
129
|
3
|
|
|
|
|
9
|
my $time = shift; |
130
|
|
|
|
|
|
|
|
131
|
3
|
|
|
|
|
12
|
my $update_sql = 'UPDATE TestSet SET last_run_time = ? WHERE name = ?'; |
132
|
|
|
|
|
|
|
|
133
|
3
|
|
|
|
|
24
|
$self->{dbh}->do( $update_sql, {}, $time, $self->name() ); |
134
|
|
|
|
|
|
|
|
135
|
3
|
|
|
|
|
508273
|
$self->_get_db_data(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub prioritize |
139
|
|
|
|
|
|
|
{ |
140
|
4
|
|
|
4
|
1
|
750
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
4
|
|
|
|
|
8
|
my $update_sql = 'UPDATE TestSet SET is_prioritized = ? WHERE name = ?'; |
143
|
|
|
|
|
|
|
|
144
|
4
|
|
|
|
|
21
|
$self->{dbh}->do( $update_sql, {}, 1, $self->name() ); |
145
|
|
|
|
|
|
|
|
146
|
4
|
|
|
|
|
417122
|
$self->_get_db_data(); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub unprioritize |
150
|
|
|
|
|
|
|
{ |
151
|
2
|
|
|
2
|
1
|
623
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
2
|
|
|
|
|
66
|
my $update_sql = 'UPDATE TestSet SET is_prioritized = ? WHERE name = ?'; |
154
|
|
|
|
|
|
|
|
155
|
2
|
|
|
|
|
20
|
$self->{dbh}->do( $update_sql, {}, 0, $self->name() ); |
156
|
|
|
|
|
|
|
|
157
|
2
|
|
|
|
|
76922
|
$self->_get_db_data(); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub update_files |
161
|
|
|
|
|
|
|
{ |
162
|
1
|
|
|
1
|
1
|
3
|
return; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub remove |
166
|
|
|
|
|
|
|
{ |
167
|
2
|
|
|
2
|
1
|
19
|
my $self = shift; |
168
|
|
|
|
|
|
|
|
169
|
2
|
|
|
|
|
8
|
my $delete_sql = 'DELETE FROM TestSet WHERE name = ?'; |
170
|
|
|
|
|
|
|
|
171
|
2
|
|
|
|
|
14
|
$self->{dbh}->do( $delete_sql, {}, $self->name() ); |
172
|
|
|
|
|
|
|
|
173
|
2
|
50
|
|
|
|
23695
|
rmtree( $self->set_dir(), 0, 0 ) |
174
|
|
|
|
|
|
|
or die "Cannot rmtree " . $self->set_dir() . "\n"; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub All |
178
|
|
|
|
|
|
|
{ |
179
|
10
|
|
|
10
|
1
|
26709
|
my $class = shift; |
180
|
|
|
|
|
|
|
|
181
|
10
|
|
|
|
|
127
|
my $root_dir = SmokeRunner::Multi::Config->instance()->root_dir(); |
182
|
|
|
|
|
|
|
|
183
|
10
|
50
|
|
|
|
1100
|
opendir my $dh, $root_dir |
184
|
|
|
|
|
|
|
or die "Cannot read $root_dir: $!"; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
return |
187
|
|
|
|
|
|
|
( sort _sort_sets |
188
|
33
|
100
|
|
|
|
81
|
map { eval { $class->new( set_dir => $_ ) } || () } |
|
33
|
|
|
|
|
186
|
|
189
|
52
|
|
|
|
|
1054
|
grep { -d } |
190
|
10
|
|
|
|
|
700
|
map { File::Spec->catdir( $root_dir, $_ ) } |
|
52
|
|
|
|
|
483
|
|
191
|
|
|
|
|
|
|
File::Spec->no_upwards( readdir $dh ) |
192
|
|
|
|
|
|
|
); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _sort_sets |
196
|
|
|
|
|
|
|
{ |
197
|
|
|
|
|
|
|
return |
198
|
30
|
|
66
|
30
|
|
331
|
( $b->is_prioritized() <=> $a->is_prioritized() |
199
|
|
|
|
|
|
|
or |
200
|
|
|
|
|
|
|
$b->seconds_out_of_date() <=> $a->seconds_out_of_date() |
201
|
|
|
|
|
|
|
or |
202
|
|
|
|
|
|
|
# This last clause simply ensures that the sort order is |
203
|
|
|
|
|
|
|
# unique and repeatable. |
204
|
|
|
|
|
|
|
$a->name() cmp $b->name() |
205
|
|
|
|
|
|
|
); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
__END__ |