10 # Define your gmake. Needed for Unixes which have both gmake and make installed.
11 # On Linux it could be named just 'make'.
14 # define your path here if run_test.pl is not in path
16 # my $run_test = '/Users/klink/dev/openxpki/tools/automated_test_reports/run_test.pl';
19 # define an installation prefix (passed to perl Makefile.PL) if necessary
21 # my $PREFIX = 'PREFIX=~/usr/local';
24 # add installation prefix to PERL5LIB
25 my $PREFIX_DIR = $PREFIX;
26 $PREFIX_DIR =~ s{ \A \s* PREFIX=}{}xms if ($PREFIX ne '');
28 if ($PREFIX_DIR ne '') {
29 my $installstyle = $Config{installstyle
};
30 my $perlversion = $Config{version
};
31 my $archname = $Config{archname
};
32 $ENV{"PERL5LIB"} = $PREFIX_DIR . "/$installstyle/site_perl/$perlversion/:" .
33 $PREFIX_DIR . "/$installstyle/site_perl/$perlversion/$archname/:" .
34 $PREFIX_DIR . "/$installstyle/site_perl/$perlversion/mach/";
35 print STDERR
"PERL5LIB contains the following dirs: ".$ENV{"PERL5LIB"}."\n";
38 # define a deployment prefix (passed to ./configure in trunk/deployment)
41 # my $DEPLOYMENT_PREFIX = '--prefix ~/usr/local';
42 my $DEPLOYMENT_PREFIX = '';
44 # add deployment prefix to PATH
45 # define DEPLOYMENT_PREFIX variable (to be used in OpenXPKI/Tests.pm)
46 my $DEPLOYMENT_DIR = $DEPLOYMENT_PREFIX;
47 $DEPLOYMENT_DIR =~ s{ \A \s* --prefix \s* (\S+)}{$1}xms if ($DEPLOYMENT_PREFIX ne '');
49 if ($DEPLOYMENT_DIR ne '') {
50 $ENV{"PATH"} = $DEPLOYMENT_DIR."/bin:" . $ENV{"PATH"};
51 $ENV{"DEPLOYMENT_PREFIX"} = $DEPLOYMENT_DIR."/bin";
54 # define the format of the feed (see XML::Feed)
55 my $FEED_FORMAT = 'Atom';
57 # define the title and location of the feed
58 my $FEED_TITLE = "OpenXPKI tests at " . `hostname`;
59 my $FEED_LINK = "http://build0.cynops.de/openxpki_tests/";
61 # define how many revisions you want to show at the HTML page and how
62 # many you want in the Atom feed
63 my $MAX_HTML_REVISIONS = 20;
64 my $MAX_ATOM_REVISIONS = 20;
66 if (! defined $run_test) {
67 $run_test = `which run_test.pl`;
70 die "Could not find run_test.pl, configure it in generate_report.pl or put it in your PATH";
74 if (! -e
'perl-modules/core/trunk/t') {
75 # only run from the correct directory
76 die "Please start from main OpenXPKI trunk directory\n";
81 my $output_dir = $ARGV[0];
82 if (! defined $output_dir) {
83 die "Usage: $0 <output directory>";
86 # Numbers added to the test names to provide correct sequence of installation:
87 # server, client, other clients. Needed for testing on machines with no
88 # pre-installed OpenXPKI.
92 DIRECTORY
=> $basedir . "/perl-modules/core/trunk",
96 DIRECTORY
=> $basedir . "/clients/perl/OpenXPKI-Client",
100 DIRECTORY
=> $basedir . "/clients/perl/OpenXPKI-Client-HTML-Mason",
101 NAME
=> 'Mason client',
104 DIRECTORY
=> $basedir . "/clients/perl/OpenXPKI-Client-SCEP",
105 NAME
=> 'SCEP client',
109 my $revision = sprintf("%04d", `vergen --format SVN_REVISION`);
111 die "Could not determine SVN revision";
113 if (! -x
$run_test) {
114 die "run_test.pl not found or not executable";
117 # will contain test name without a number
121 foreach my $testname (sort keys %{ $tests }) {
123 $test =~ s{\d_}{}xms;
125 print STDERR
"Compiling and installing for $test\n";
126 chdir $tests->{$testname}->{DIRECTORY
};
127 if (system("perl Makefile.PL $PREFIX && $MAKE && $MAKE install") != 0) {
128 die "Could not compile for $test test";
132 # install new deployment tools before testing
133 chdir $basedir . '/deployment';
134 if (system("./configure $DEPLOYMENT_PREFIX && $MAKE && $MAKE install") != 0) {
135 die "Could not install new deployment tools";
139 foreach my $testname (sort keys %{ $tests }) {
141 $test =~ s{\d_}{}xms;
143 print STDERR
"Running test for $test (revision $revision)\n";
144 chdir $tests->{$testname}->{DIRECTORY
};
146 # compile and run each test
147 my $output_filename = $revision . '_output.txt';
148 if (-e
$output_filename) {
149 # test has already been run, skip
153 if ($test eq 'client_mason') {
154 # we need to set this here, because any attempt to set it within
155 # the test file itself fails for some reason ...
156 $ENV = 'OPENXPKI_SOCKET_FILE=t/20_webserver/test_instance/var/openxpki/openxpki.socket';
158 system("$ENV $run_test $revision $test");
161 chdir $tests->{'0_server'}->{DIRECTORY
};
162 my @tested_revisions = reverse glob('*_output.txt');
163 map { s/_output.txt// } @tested_revisions;
165 open INDEX
, '>', $output_dir . '/index.html';
166 print INDEX
<< "XEOF";
167 <?xml version
="1.0" encoding
="utf-8"?
>
168 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
169 <html xmlns
="http://www.w3.org/1999/xhtml" lang
="en" xml
:lang
="en">
171 <title
>OpenXPKI automated test report
</title
>
174 <table border
=0 cellspacing
=0 cellpadding
=5>
176 <th
>Coverage report
</th
>
180 <th
>Skipped files
</th
>
185 <th
>passed TODO tests
</th
>
186 <th
>skipped tests
</th
>
187 <th
>CPU
time used
</th
>
191 print STDERR
"Generating report ... ";
193 foreach my $rev (@tested_revisions[0..$MAX_HTML_REVISIONS-1]) {
194 next REV_REPORT
if (!$rev);
195 print STDERR
"r$rev ";
197 open my $SVN, "svn log -qr $rev ..|";
200 # my $svn_info = <$SVN>;
201 ## execution of the two previous lines fails on FreeBSD
202 ## with 'Broken pipe' error message
206 while (my $line = <$SVN>) {
208 $svn_info = $line if ($i == 1);
212 $svn_info =~ s{ (.*) \|\ \d+\ lines}{$1}xms;
214 print INDEX
"<tr><td colspan=12>Report for $svn_info</td></tr>";
215 foreach my $testname (sort keys %{ $tests }) {
217 $test =~ s{\d_}{}xms;
219 chdir $tests->{$testname}->{DIRECTORY
};
220 my $files = $rev . '_coverage ' . $rev . '_output.txt ';
221 system("mkdir $output_dir/$test 2>/dev/null");
223 ## 'cp -r' does not work on FreeBSD
224 system("cp -R $files $output_dir/$test");
226 my $summary_filename = $rev . '_summary.html';
227 my $opened = open my $SUMMARY, '<', $summary_filename;
230 $summary = '<tr color="303030"><td colspan=12>' . $tests->{$testname}->{NAME
} . ' summary unavailable</td></tr>' . "\n";
233 $summary = <$SUMMARY>;
234 $summary =~ s{Coverage\ report}{$tests->{$testname}->{NAME
} coverage report
}xms
;
237 print INDEX
$summary;
243 print STDERR
"Generating feed ... ";
244 my $feed = XML
::Feed
->new($FEED_FORMAT);
245 $feed->title($FEED_TITLE);
246 $feed->link($FEED_LINK);
249 foreach my $rev (@tested_revisions[0..$MAX_ATOM_REVISIONS-1]) {
250 next REV_FEED
if (!$rev);
251 my $entry = XML
::Feed
::Entry
->new($FEED_FORMAT);
253 print STDERR
"r$rev ";
255 open my $SVN, "svn log -qr $rev ..|";
258 # my $svn_info = <$SVN>;
259 ## execution of the two previous lines fails on FreeBSD
260 ## with 'Broken pipe' error message
264 while (my $line = <$SVN>) {
266 $svn_info = $line if ($i == 1);
271 my @svn_info = split(/ \| /, $svn_info);
272 my $author = $svn_info[1];
273 my $date = $svn_info[2];
274 my ($year, $month, $day, $hour, $minute, $second, $tz) =
275 ($date =~ m{\A (\d{4}) \
- (\d
{2}) \
- (\d
{2}) [ ]
276 (\d
{2}) : (\d
{2}) : (\d
{2}) [ ] ([\
+\
-]\d
{4})}xms
);
277 my $dt = DateTime
->new(
287 my $svn_changes = do {
288 local $INPUT_RECORD_SEPARATOR;
289 open my $SVN, "svn log -vr $rev ..|";
294 my $all_summaries = '<table border=0 cellspacing=0 cellpadding=5>';
296 foreach my $testname (sort keys %{ $tests }) {
298 $test =~ s{\d_}{}xms;
300 chdir $tests->{$testname}->{DIRECTORY
};
301 my $summary_filename = $rev . '_summary.html';
302 my $opened = open my $SUMMARY, '<', $summary_filename;
305 push @failed, "$test n/a";
308 my $summary = <$SUMMARY>;
309 $summary =~ s{Coverage\ report}{$tests->{$testname}->{NAME
} coverage report
}xms
;
310 my $xs = XML
::Simple
->new();
311 my $summary_ref = $xs->XMLin($summary);
312 if ($summary_ref->{'td'}->[6] ne '0 (0.00%)') {
314 # push failed total tests
315 push @failed, "$test: " . $summary_ref->{'td'}->[6];
317 $all_summaries .= $summary;
321 $all_summaries .= '</table>';
323 $entry->title("$rev: All green");
326 $entry->title("$rev: Failed: " . join q{, }, @failed);
328 $entry->author($author);
329 my $body = "<H1>Report for $rev</H1>" . $all_summaries;
330 $body .= "<H1>Changes</H1><pre>" . $svn_changes . "</pre>";
331 $entry->content(XML
::Feed
::Content
->new({body
=> $body }));
332 $entry->modified($dt);
333 $entry->link($FEED_LINK);
335 $feed->add_entry($entry);
337 $feed->modified(DateTime
->now);
338 open FEED
, '>', "$output_dir/" . lc($FEED_FORMAT);
339 print FEED
$feed->as_xml();