Subversion Repositories DevTools

Rev

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