• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl
2
3####################################################
4#    Copyright (c) Open Source Development Labs, 2004
5#
6#    This program is free software;  you can redistribute it and/or modify
7#    it under the terms of the GNU General Public License as published by
8#    the Free Software Foundation; either version 2 of the License, or
9#    (at your option) any later version.
10#
11#    This program is distributed in the hope that it will be useful,
12#    but WITHOUT ANY WARRANTY;  without even the implied warranty of
13#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14#    the GNU General Public License for more details.
15#
16#    You should have received a copy of the GNU General Public License
17#    along with this program;  if not, write to the Free Software
18#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19#
20#   FILE        : STPfailure_report.pl
21#   DESCRIPTION : A script that will retrieve the run results through the net from
22#		  the STP results and then finds the corresponding source code
23#		  file in your LTP tree for each failure.  It then prints the
24#		  description and details for each to STDOUT.
25#   REQUIREMENTS: LWP::Simple, File::Find, and Text::Wrap must be installed
26#   AUTHOR      : Bryce Harrington <bryce@osdl.org>
27#   HISTORY     :
28#       04/28/2004 Robbie Williamson (robbiew@austin.ibm.com)
29#               Adapted for and added to LTP
30####################################################
31
32use strict;
33use LWP::Simple;
34use File::Find;
35use Text::Wrap;
36
37$Text::Wrap::columns = 72;
38
39my $test_uid = $ARGV[0];
40die "Usage: STPfailure_report.pl TEST_RUN_ID\n"
41    unless ($test_uid =~ /^\d+$/);
42
43# Location from which to retrieve test results
44my $stp_url = "http://khack.osdl.org/stp/$test_uid/";
45
46# Name of the file containing the fail report data
47my $fail_report = $stp_url . "results/FAIL_summary.txt";
48
49# Path to the top dir in the locally checked out version of LTP
50my $ltp_base = "..";
51die "Cannot find testcases directory in '$ltp_base'"
52    unless (-d "$ltp_base/testcases");
53
54# Retrieve the results for the test run
55my $fail_results = get($fail_report)
56    || die "Could not retrieve URL $fail_report\n";
57
58# Process the results, extracting each test name & generating a report
59my $testname    = '';
60my $description = '';
61my $failures    = '';
62foreach my $line (split /\n/, $fail_results) {
63    next unless ($line =~ /^(\w+)\s/);
64
65    # Is this a new testname or continuation of the previous?
66    if ($1 ne $testname) {
67        # Print the current test results
68        print_report($testname, $description, $failures);
69
70        # Init variables for next testcase
71        $testname    = $1;
72        $description = get_description($testname, $ltp_base);
73        $failures    = '';
74    }
75    $failures .= wrap('', ' 'x26, ($line)) . "\n";
76}
77
78# Locates the matching .c file and extracts the DESCRIPTION field
79sub get_description {
80    my $testname = shift || return undef;
81    my $dir = shift || return undef;
82
83    # Find $testname.c
84    my $path = `find $dir -name '$testname.c'`;
85
86    chomp $path;
87    open(FILEHANDLE, "< $path") or return undef;
88
89    # Seek in $testname.c for the DESCRIPTION line
90    my $line;
91    while (defined ($line = <FILEHANDLE>)) {
92        last if ($line =~ /^\s+\*\s+DESCRIPTION/);
93        last if ($line =~ /^\s+\*\s+Test Description/);
94    }
95
96    # Extract the description
97    my $description = '';
98    while (defined ($line = <FILEHANDLE>)) {
99        last if ($line !~ /^\s+\*\s\s+/);
100
101        # Strip off the leading " * "
102        $line =~ s/^\s+\*\s//;
103
104        $description .= $line;
105    }
106    close(FILEHANDLE);
107
108    $path =~ s|^$dir/||;
109    return $description . "\nFor more see '$path'\n";
110}
111
112# Prints out the failed test case report
113sub print_report {
114    my ($testname, $description, $failures) = @_;
115
116    return unless ($testname);
117
118    $description ||= "No description available\n";
119
120    # Remove any trailing newlines
121    chomp $description;
122    chomp $testname;
123    chomp $failures;
124
125    print qq|
126========================================================================
127Test name: $testname
128
129Description:
130
131$description
132
133Test Result: FAIL
134
135Details:
136
137$failures
138
139========================================================================
140
141|;
142}
143