Subversion Repositories DevTools

Rev

Rev 4787 | Rev 4996 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4778 dpurdie 1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : jats_runutf.pm
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : JATS Make Time Test Harness Support
10
#                 This package contains fucntions that will be used by JATS
11
#                 to invoke the tests.
12
#
13
#                 This is more powerful that the previous shell-based solution
14
#                 that had problems under windows.
15
#
16
#                 The functions are designed to be invoked as:
17
#                   $(GBE_PERL) -Mjats_runutf -e <function> -- <args>+
18
#
19
#                 The functions in this packages are designed to take parameters
20
#                 from @ARVG as this makes the interface easier to read.
21
#
22
# Usage         : See POD at the end of this file
23
#
24
#......................................................................#
25
 
26
require 5.008_002;
27
use strict;
28
use warnings;
29
 
30
package jats_runutf;
31
 
32
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
33
use Exporter;
34
use JatsError qw(:name=jats_runutf);
4780 dpurdie 35
use Pod::Usage;                             # required for help support
4778 dpurdie 36
use Getopt::Long;
37
use File::Spec;
38
 
39
$VERSION = 1.00;
40
@ISA = qw(Exporter);
41
 
42
# Symbols to autoexport (:DEFAULT tag)
4780 dpurdie 43
@EXPORT = qw( processUtf help man );
4778 dpurdie 44
 
45
#
46
#   Global Variables
47
#
48
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
49
my $opt_utfOuput;
4780 dpurdie 50
my $opt_help = 0;
4778 dpurdie 51
 
52
#   Data to be passed into the filter function
53
#   Defined values are:
4781 dpurdie 54
#       ARGS            - An hash of user arguments
55
#       DIR             - Optional. Name of test subdir
4778 dpurdie 56
#       FILTER          - Name of the filter 
4781 dpurdie 57
#       IDIR            - Path to original directory
4778 dpurdie 58
#       INTERFACE       - Abs Path to Interface directory
59
#       LOCAL           - Abs Path to Local directory
60
#       OUTDIR          - Abs Path to output directory
4780 dpurdie 61
#       OUTFILE         - Abs Path to suggested output file
4778 dpurdie 62
#       PKGDIR          - Abs Path to Packaging directory
63
#       ROOT            - Abs Path to Root of the build
64
#       TARGET          - Current make target
65
#       TYPE            - Built type P or D
4787 dpurdie 66
#       UFTUID          - Unique Test Identifier
4781 dpurdie 67
#       UTFNAME         - Test Name
4778 dpurdie 68
#
4780 dpurdie 69
our %filterData;
4778 dpurdie 70
 
4780 dpurdie 71
#-------------------------------------------------------------------------------
72
# Function        : help
73
#                   man 
74
#
75
# Description     : Utility functions to make is easier for users to get POD
76
#                   from this module
77
#
78
# Inputs          : 
79
#
80
# Returns         : 
81
#
4778 dpurdie 82
 
4780 dpurdie 83
sub help
84
{
85
    pod2usage(-verbose => 0, -input =>  __FILE__);
86
}
87
 
88
sub man
89
{
90
    pod2usage(-verbose => 2, -input =>  __FILE__);
91
}
92
 
4778 dpurdie 93
#-------------------------------------------------------------------------------
94
# Function        : processUtf  
95
#
96
# Description     : Main function to process UTF results
4787 dpurdie 97
#                   This function will locate a suitable filter process and invoke
98
#                   it to process the results
4778 dpurdie 99
#
4787 dpurdie 100
#                   The filter process will be provided in a Perl Module
4778 dpurdie 101
#                   It may be a part of JATS or an external modules provided
4787 dpurdie 102
#                   within an external package. ie(utf may provide its own filter)
4778 dpurdie 103
#
4787 dpurdie 104
#
4778 dpurdie 105
# Inputs          : None. Parameters are passed via @ARGV
106
#
107
# Returns         : Nothing
108
#
109
 
110
sub processUtf
111
{
4780 dpurdie 112
    my $argCount = scalar @ARGV;
4778 dpurdie 113
    my $result = GetOptions (
4780 dpurdie 114
                    "help|h:+"      => \$opt_help,
115
                    "manual:3"      => \$opt_help,
4778 dpurdie 116
                    "verbose:+"     => \$opt_verbose,       # Only set to to 0,1 or 3
4780 dpurdie 117
                    "root=s"        => \$filterData{ROOT},
118
                    "filter=s"      => \$filterData{FILTER},
119
                    "interface=s"   => \$filterData{INTERFACE},
120
                    "local=s"       => \$filterData{LOCAL},
121
                    "target=s"      => \$filterData{TARGET},
122
                    "pkgdir=s"      => \$filterData{PKGDIR},
123
                    "type=s"        => \$filterData{TYPE},
4781 dpurdie 124
                    "dir=s"         => \$filterData{DIR},
125
                    "arg=s"         => sub {my ( $key, $value) = split('=', $_[1], 2); $filterData{ARGS}{$key} = $value;},
4778 dpurdie 126
                    );
127
 
4780 dpurdie 128
    pod2usage(-verbose => 0, -input =>  __FILE__) if ($opt_help == 1 || ! $result || $argCount < 1);
129
    pod2usage(-verbose => 1, -input =>  __FILE__) if ($opt_help == 2 );
130
    pod2usage(-verbose => 2, -input =>  __FILE__) if ($opt_help  > 2);
131
 
4778 dpurdie 132
    #   Reconfigure the verbosity level
133
    ErrorConfig( 'verbose', $opt_verbose);
4780 dpurdie 134
    Error("Internal: No Filter specified") unless defined $filterData{FILTER};
135
    Error("Internal: No PkgDir specified") unless defined $filterData{PKGDIR};
4778 dpurdie 136
 
137
    #
138
    #   Locate the required filter module
139
    #   Filter modules have a name of the form:
140
    #       UtfFilter_<FilterName>.pm
141
    #   And can be located:
142
    #       within JATS
143
    #           in 'TOOLS/LIB'
144
    #       within a Package declared
145
    #           with a BuildPkgArchive or a LinkPkgArchive
146
    #           within the packages 'tools/scripts' subdirectory
147
    #       within the current package
148
    #           Perl modules with ROOT/gbe/utfFilters_*.pm
149
    #                         or  ROOT/gbe/SomeDir/utfFilters_*.pm
150
    #                         or in the current directory
151
 
4787 dpurdie 152
    my $module_name = join('_','UtfFilter', lc $filterData{FILTER});
4778 dpurdie 153
    Verbose("Filter Module: $module_name");
154
 
155
    #   Extend Perl Module search path for package-local filters
156
    #   Check the current directory
157
    #       The current directory is also within @INC, but it is at the end
158
    #       thus local filter will not override external filters. Place the
159
    #       current directory first - if it conatins a filter.
160
 
161
    if (-f "$module_name.pm" )
162
    {
163
        Verbose("Extend the filter module search path: Current Directory");
164
        unshift @INC, '.';
165
    }
166
    else
167
    {
168
        #
169
        #   Check package-local directory
170
        #       <root>/gbe/utfFilters
171
        #
4780 dpurdie 172
        my $localUtfPath = File::Spec->catfile($filterData{ROOT}, 'gbe', 'utfFilters');
4778 dpurdie 173
        if ( -f( "$localUtfPath/$module_name.pm") )
174
        {
175
            Verbose("Extend the filter module search path: $localUtfPath");
176
            unshift @INC, $localUtfPath;
177
        }
178
    }
179
 
180
    #
181
    #   Locate a Perl Module of the required name
182
    #
183
    eval "require $module_name";
184
    if ($@)
185
    {
186
        Error ("Could not load required filter module: $module_name");
187
    }
188
 
189
    #
190
    #   Ensure that the filter contains the required interface methods
191
    #
192
    foreach my $fname ( qw(processUtf))
193
    {
194
        ReportError("Required function DOES NOT exist: $fname")
195
            unless (defined($module_name->can($fname)));
196
    }
197
    ErrorDoExit();
198
 
199
    #
200
    #   Convert potentially local paths to absolute paths
201
    #       Simplifies use when the CWD is changed
202
    #
203
    foreach my $entry ( qw(INTERFACE LOCAL PKGDIR ROOT))
204
    {
4780 dpurdie 205
        $filterData{$entry}  = File::Spec->rel2abs($filterData{$entry} );
4778 dpurdie 206
    }
207
 
208
    #
209
    #   Ensure that the output directory is present
210
    #       Store utf output directly into the packaging directory in a subdirectoy called 'utfResults'
211
    #           This location is known to the buildtool
212
    #       The output path is provided to the filter process
213
    #
4780 dpurdie 214
    $opt_utfOuput = File::Spec->catfile($filterData{PKGDIR}, 'utfResults');
215
    $filterData{OUTDIR} = $opt_utfOuput;
216
    Error("Packaging directory does not exist") unless -d $filterData{PKGDIR};
4778 dpurdie 217
    mkdir $opt_utfOuput;
218
    Error("Creating utfResults directory") unless -d $opt_utfOuput;
219
 
220
    #
221
    #   Add in known values from the environment
222
    #
4780 dpurdie 223
    $filterData{TYPE} = $ENV{'GBE_MAKE_TYPE'};
224
    Error("Internal: EnvVar 'GBE_MAKE_TYPE' not specified") unless $filterData{TYPE};
4778 dpurdie 225
 
4787 dpurdie 226
    $filterData{UFTUID} = $ENV{'GBE_UTFUID'};
227
    Error("Internal: EnvVar 'GBE_UTFUID' not specified") unless $filterData{UFTUID};
4781 dpurdie 228
 
229
    $filterData{UTFNAME} = $ENV{'GBE_UTFNAME'};
230
    Error("Internal: EnvVar 'GBE_UTFNAME' not specified") unless $filterData{UTFNAME};
231
 
232
    $filterData{IDIR} = File::Spec->rel2abs('.');
233
 
4778 dpurdie 234
    #
235
    #   Create a uniq filename as a suggestion to the filter tool
236
    #       The filter is not forced to use it, but it is a good idea
237
    #
4787 dpurdie 238
    my $filename = File::Spec->catfile($opt_utfOuput, "$filterData{TARGET}-$filterData{TYPE}-$filterData{UFTUID}.xml");
4778 dpurdie 239
 
4781 dpurdie 240
    #   Allow the output file to be used
241
    #       Not in the build system, but in a user development area
242
    unlink $filename if -e $filename;
243
    Error("Output file:Cannot delete $filename: $!") if -e $filename;
4778 dpurdie 244
    Verbose("Writing output to $filename");
245
 
4780 dpurdie 246
    $filterData{OUTFILE} = $filename;
4778 dpurdie 247
 
248
    #
4781 dpurdie 249
    #   Change to the test directory
250
    #       Only if required
251
    #       Ensure that the specified directory exists
252
    #
253
    if (defined $filterData{DIR})
254
    {
255
        Verbose("Change directory");
256
        Error("Internal: Test directory does not exist: $filterData{DIR}")
257
            unless (-d $filterData{DIR});
258
        chdir $filterData{DIR} || Error("Internal: Could not chdir to: $filterData{DIR}");
259
    }
260
 
261
    #
4780 dpurdie 262
    #   Diagnostics
263
    #
264
    if (IsVerbose(1))
265
    {
266
        DebugDumpData("Filter Parameters", \%filterData);
267
    }
268
 
269
    #
4778 dpurdie 270
    #   Invoke the process method
271
    #   If it has a problem it should use 'Error(...)' to report it
272
    #   There is no exit code processing
273
    #
4780 dpurdie 274
    Message("Processing UTF test results using filter: $filterData{FILTER}");
4805 dpurdie 275
    $module_name->processUtf(\%filterData);
4778 dpurdie 276
}
277
 
4780 dpurdie 278
=pod 1
4778 dpurdie 279
 
4780 dpurdie 280
=for htmltoc    SYSUTIL::
281
 
282
=head1 NAME
283
 
284
jats_runutf - Post Process UTF results for build system
285
 
286
=head1 SYNOPSIS
287
 
288
  $(GBE_PERL) -Mjats_runutf -e processUtf -- <args>
289
 
290
 Options:
291
    -help[=n]       - Brief help message
292
    -help -help     - Detailed help message
293
    -man            - Full documentation
294
    -verbose[=n]    - Verbose operation
295
    -filter=name    - Name of the required processing filter
296
    -target=name    - Current build target
297
    -root=path      - Path to the root of the build
298
    -pkgdir=path    - Path to the packaging directory
299
    -interface=path - Path to the build interface directory
300
    -local=path     - Path to the local build directory
4781 dpurdie 301
    -dir=path       - Path to test directory
4780 dpurdie 302
 
303
=head1 OPTIONS
304
 
305
=over 8
306
 
307
=item B<-help>
308
 
309
Print a brief help message and exits.
310
 
311
=item B<-help -help>
312
 
313
Print a detailed help message with an explanation for each option.
314
 
315
=item B<-man>
316
 
317
Prints the manual page and exits.
318
 
319
=item B<-verbose>
320
 
321
This option will display progress information as the program executes.
322
 
323
=item B<-filter=name>
324
 
325
Name of the required processing filter.
326
 
327
=item B<-target=name>
328
 
329
The current build target.
330
 
331
=item B<-root=path>
332
 
333
The path to the root of the current build.
334
 
335
=item B<-pkgdir=path>
336
 
337
The path to the packaging directory
338
 
339
=item B<-interface=path>
340
 
341
The path to the build interface directory
342
 
343
=item B<-local=path>
344
 
345
The path to the local build directory
346
 
4781 dpurdie 347
=item B<-dir=path>
348
 
349
The path to the directory in which the test was run.
350
 
351
This is optional. If provided the filter will be invoked with the 
352
current working directory
353
 
4780 dpurdie 354
=back
355
 
356
=head1 DESCRIPTION
357
 
358
This tool is not designed to be run directly by users. It is intended to be run by the 
359
JATS generated makefiles in conjunction with unit tests to process the output from a unit 
360
test to provide a common output format to be passed on the build system.
361
 
362
Normally this process only occurs with the Auto BuildTool environment.
363
 
364
The tool provides the following operations:
365
 
366
=over 4
367
 
368
=item *
369
 
370
Sanitize environment
371
 
372
The environment passed to the filter processing module will be verified. 
373
The path to the output directory will be created if required. All paths will be absolute.
374
 
375
=item *
376
 
377
Locate the required filter processing module. The module must be a Perl Module with a name of the form 'UtfFilter_<name>'
378
 
379
=item *
380
 
381
Invoke the required filter module.
382
 
383
=back
384
 
385
=head2 Locating the Filter Module
386
 
387
The filter module may be located, in order of precedence, within:
388
 
389
=over 4
390
 
391
=item *
392
 
393
The package currently being built.
394
 
395
The package may provide its own UTF post processing module. This is not encouraged.
396
 
397
The following locations will be examined for a suitable module:
398
 
399
=over 4
400
 
401
=item *
402
 
403
The current directory. The directory of the makefile.pl that is running the unit test.
404
 
405
=item *
406
 
407
A directory in the Build Root called 'gbe/UtfFilters'
408
 
409
=back
410
 
411
=item *
412
 
413
An external Package, within the gbe/scripts directory.
414
 
415
The package can be specified with either LinkPkgArchive or BuildPkgArchive directive 
416
within the current packages build.pl file.
417
 
418
=item *
419
 
420
Within JATS.
421
 
422
Jats may provide useful filter modules.
423
 
424
=back
425
 
426
=head2 Filter Module Interface
427
 
428
The filter module Interface consists of four items:
429
 
430
=over 4
431
 
432
=item 1 The name of the Package
433
 
434
=item 1 The named function with the package
435
 
436
=item 1 Arguments passed to the named function
437
 
438
=item 1 The processing expected to be done by the named function
439
 
440
=item 1 The Output Format
441
 
442
=back
443
 
444
=head3 The name of the Package
445
 
446
Each filter function is in its own package. The package name is created by concatenating the 
447
text 'UtfFilter_' with the name of the required filter. 
448
 
449
ie: If the required filter is 'junit4', then the name of the filter package must 
450
be UtfFilter_junit4 and it will be held in a file named UtfFilter_junit4.pm.
451
 
452
=head3 The named function with the package
453
 
454
The filter package must provide a function called 'processUtf'
455
 
456
=head3 Arguments passed to the named function
457
 
458
The processing function 'processUtf' is called with two arguments:
459
 
460
=over 4
461
 
462
=item 1
463
 
464
The name of the package
465
 
466
=item 2
467
 
4787 dpurdie 468
A reference to a Perl hash. The hash will contain the following named items:
4780 dpurdie 469
 
470
=over 4
471
 
4781 dpurdie 472
=item       ARGS          
473
 
474
Optional. A hash of User Arguments passed into the filter. Use of these is filter specific.
475
 
476
Arguments of the form '--UtfArg=UserArg1=Value1' will be stored with a key of 'UserArg1 and a value of 'Value1'.
477
 
478
Arguments of the form '--UtfArg=UserArg2' will be stored with a key of 'UserArg2' and an undefined value.
479
 
480
=item       DIR          
481
 
482
Optional. If the Unit Test is executed in a subdirectory of the current build 
483
location, then DIR will be set to the name of the subdirectory. 
484
 
485
The current working directory will be changed to DIR before the filter function is invoked. 
486
 
487
This item will aways exist, but it may not be defined.
488
 
4780 dpurdie 489
=item       FILTER          
490
 
491
The Name of the filter 
492
 
4781 dpurdie 493
=item       IDIR
494
 
495
The absolute path to the working directory, when the module is invoked, before the working
496
directory has been chnaged to 'DIR'.
497
 
4780 dpurdie 498
=item       INTERFACE       
499
 
4781 dpurdie 500
The absolute path to Interface directory
4780 dpurdie 501
 
502
=item       LOCAL
503
 
4781 dpurdie 504
The absolute path to Local directory
4780 dpurdie 505
 
506
=item       OUTDIR
507
 
4781 dpurdie 508
The absolute path to output directory
4780 dpurdie 509
 
510
=item       OUTFILE
511
 
4781 dpurdie 512
The absolute path to suggested output file. The user does not need to use this name. It is 
4780 dpurdie 513
provided to remove the need for each filter to create a unique name.
514
 
515
This file will not exist.
516
 
517
=item       PKGDIR
518
 
4781 dpurdie 519
The absolute path to Packaging directory. This directory will exist.
4780 dpurdie 520
 
521
=item       ROOT
522
 
4781 dpurdie 523
The absolute path to Root of the build
4780 dpurdie 524
 
525
=item       TARGET
526
 
527
The current make target
528
 
529
=item       TYPE
530
 
531
The build type P or D
532
 
4781 dpurdie 533
=item       UTFNAME
534
 
535
The name of the test.
536
 
537
This may be provided by the user, or it may be system generated. Intended to be used by 
538
test filters that do not have test names generated as a part of the test
539
 
540
=item       UTFUID
541
 
542
A unique test identifier. This is unique with the build and is intended to:
543
 
544
=over 4
545
 
546
=item   *
547
 
548
Allow the generation of test-unique file names for the storage of results.
549
 
550
=item *
551
 
552
Allow the reuse of output file names.
553
 
4780 dpurdie 554
=back
555
 
4781 dpurdie 556
=back
557
 
4787 dpurdie 558
The return value from the function 'processUtf' is ignored. If the function encounters 
559
any error it should use the Jats 'Error' function to report the error.
4780 dpurdie 560
 
561
=back
562
 
563
=head3 The processing expected to be done by the named function
564
 
4787 dpurdie 565
The processing function is expected to transform the results of a unit test into 
566
a constient form so that they can be processed by the remainder of the build tool.
4780 dpurdie 567
 
568
The processing should:
569
 
570
=over 4
571
 
572
=item *
573
 
574
Create information in the OUTDIR directory. 
575
 
576
The filter may create a new file or insert information into an existing file. 
577
 
578
The user may make use of the OUTFILE path, but this is not mandatory.
579
 
580
=item *
581
 
582
Report errors by calling the Jats 'Error' function. This will terminate processing.
583
 
584
=back
585
 
586
=head3 The Output Format
587
 
588
Yet to be defined.
589
 
4781 dpurdie 590
The output format is known to the build system. It should not be 
591
changed without also chnaging it for the consuming tools.
592
 
4780 dpurdie 593
=cut
594
 
595
 
4778 dpurdie 596
1;