-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathctcs2_to_junit.pm
144 lines (132 loc) · 4.66 KB
/
ctcs2_to_junit.pm
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
# SUSE's openQA tests
#
# Copyright 2017-2019 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Summary: base class for convert QA:Head ctcs2 wrapper testsuite test log to junit format
# Maintainer: Yong Sun <[email protected]>
package ctcs2_to_junit;
use strict;
use warnings;
use base "Exporter";
use Exporter;
use testapi;
use utils;
use XML::Writer;
our @EXPORT = qw(analyzeResult generateXML);
sub analyzeResult {
my ($text) = @_;
my $result = ();
foreach (split("\n", $text)) {
if ($_ =~ /(\S+)\s+\.{3}\s+\.{3}\s+(PASSED|FAILED|SKIPPED)\s+\((\S+)\)/g) {
$result->{$1}{status} = $2;
$result->{$1}{time} = $3;
}
}
return $result;
}
sub generateXML {
my ($data) = @_;
my %test_results = %$data;
my $case_status;
my $case_num = scalar(keys %test_results);
my $pass_num = 0;
my $fail_num = 0;
my $skip_num = 0;
my $writer = XML::Writer->new(DATA_MODE => 'true', DATA_INDENT => 2, OUTPUT => "self");
foreach my $test (keys(%test_results)) {
if ($test_results{$test}->{status} =~ m/PASSED/) {
$pass_num += 1;
}
elsif ($test_results{$test}->{status} =~ m/SKIPPED/) {
$skip_num += 1;
}
else {
$fail_num += 1;
}
}
$writer->startTag(
'testsuites',
error => "0",
failures => "$fail_num",
name => "",
skipped => "$skip_num",
tests => "$case_num",
time => ""
);
$writer->startTag(
'testsuite',
error => "0",
failures => "$fail_num",
hostname => `hostname`,
id => "0",
name => get_var('QA_TESTSET', 'xfstests'),
package => get_var('QA_TESTSET', 'test_result'),
skipped => "0",
tests => "$case_num",
time => "",
timestamp => `date`
);
my @tests = sort(keys(%test_results));
foreach my $test (@tests) {
if ($test_results{$test}->{status} =~ m/PASSED/) {
$case_status = "success";
}
elsif ($test_results{$test}->{status} =~ m/SKIPPED/) {
$case_status = "skipped";
}
else {
$case_status = "failure";
}
$writer->startTag(
'testcase',
classname => get_var('QA_TESTSET') || get_var('XFSTESTS'),
name => $test,
status => $case_status,
time => $test_results{$test}->{time});
if ((get_var('XFSTESTS') || get_var('QA_TESTSET')) && ($case_status eq 'failure' || $case_status eq 'skipped')) {
(my $test_path = $test) =~ s/-/\//;
$test_path = '/opt/log/' . $test_path;
my $test_out_content = script_output("if [ -f $test_path ]; then tail -n 200 $test_path | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176'; else echo 'Test Crashed, find log in serial0.txt'; fi", 600);
$writer->startTag('system-out');
$writer->characters($test_out_content);
$writer->endTag('system-out');
if ($case_status eq 'failure') {
my $test_err_content = script_output("
echo '====out.bad log====';
if [ -f $test_path.out.bad ];
then tail -n 200 $test_path.out.bad | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176';
else echo '$test_path.out.bad not exist';
fi;
echo '====full log====';
if [ -f $test_path.full ];
then tail -n 200 $test_path.full | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176';
else echo '$test_path.full not exist';
fi;
", 600);
$writer->startTag('system-err');
$writer->characters($test_err_content);
$writer->endTag('system-err');
}
}
if ((get_var('BTRFS_PROGS')) && ($case_status eq 'failure' || $case_status eq 'skipped')) {
(my $test_path = $test) =~ s/-/\//;
$test_path = '/opt/logs/' . $test_path . '.txt';
my $test_out_content = script_output("
if [ -f $test_path ];
then sed -n -e \"s/'//g\" -e 's/[^[:print:]\\r\\t\\n]//g' -e 'H;/====== RUN /h;\${g;p;}' $test_path | head -n 100;
else echo 'Test Crashed, find log in serial0.txt';
fi
", 600);
$writer->startTag('system-out');
$writer->characters($test_out_content);
$writer->endTag('system-out');
}
$writer->endTag('testcase');
}
$writer->endTag('testsuite');
$writer->endTag('testsuites');
$writer->end();
$writer->to_string();
}
1;