summaryrefslogtreecommitdiffstats
path: root/NPTest.pm
diff options
context:
space:
mode:
Diffstat (limited to 'NPTest.pm')
-rw-r--r--NPTest.pm53
1 files changed, 33 insertions, 20 deletions
diff --git a/NPTest.pm b/NPTest.pm
index 440e7343..4036a9d0 100644
--- a/NPTest.pm
+++ b/NPTest.pm
@@ -44,23 +44,17 @@ default via the C<use NPTest;> statement.
44 44
45=over 45=over
46 46
47=item C<getTestParameter(...)> 47=item getTestParameter( "ENV_VARIABLE", $brief_description, $default )
48 48
49A flexible and user override-able method of collecting, storing and 49This function allows the test harness
50retrieving test parameters. This function allows the test harness
51developer to interactively request test parameter information from the 50developer to interactively request test parameter information from the
52user, when the no means of obtaining the information automatically has 51user. The user can accept the developer's default value or reply "none"
53been successful. The user is provided with the option of accepting 52which will then be returned as "" for the test to skip if appropriate.
54test harness developer's default value for the parameter, if a suggested 53
55default is provided. 54Responses are stored in an external, file-based
56 55cache so subsequent test runs will use these values. The user is able
57User supplied responses are stored in an external (file-based) 56to change the values by amending the values in the file /var/tmp/NPTest.pm,
58cache. These values are retrieved on subsequent runs alleviating the 57or by setting the appropriate environment variable before running the test.
59user of reconfirming the previous entered responses. The user is able
60to override the value of a parameter on any given run by setting the
61associated environment variable. These environment variable based
62overrides are not stored in the cache, allowing one-time and what-if
63based tests on the command line without polluting the cache.
64 58
65The option exists to store parameters in a scoped means, allowing a 59The option exists to store parameters in a scoped means, allowing a
66test harness to a localise a parameter should the need arise. This 60test harness to a localise a parameter should the need arise. This
@@ -73,7 +67,7 @@ called "check_disk.t" requesting the parameter "mountpoint_valid", the
73cache is first searched for "check_disk"/"mountpoint_valid", if this 67cache is first searched for "check_disk"/"mountpoint_valid", if this
74fails, then a search is conducted for "mountpoint_valid". 68fails, then a search is conducted for "mountpoint_valid".
75 69
76The facilitate quick testing setup, it is possible to accept all the 70To facilitate quick testing setup, it is possible to accept all the
77developer provided defaults by setting the environment variable 71developer provided defaults by setting the environment variable
78"NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note 72"NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note
79that, such defaults are not stored in the cache, as there is currently 73that, such defaults are not stored in the cache, as there is currently
@@ -306,7 +300,16 @@ sub skipMissingCmd
306 300
307sub getTestParameter 301sub getTestParameter
308{ 302{
309 my( $param, $envvar, $default, $brief, $scoped ) = @_; 303 my( $param, $envvar, $default, $brief, $scoped );
304 my $new_style;
305 if (scalar @_ == 3) {
306 ($param, $brief, $default) = @_;
307 $envvar = $param;
308 $new_style = 1;
309 } else {
310 ( $param, $envvar, $default, $brief, $scoped ) = @_;
311 $new_style = 0;
312 }
310 313
311 # Apply default values for optional arguments 314 # Apply default values for optional arguments
312 $scoped = ( defined( $scoped ) && $scoped ); 315 $scoped = ( defined( $scoped ) && $scoped );
@@ -319,8 +322,13 @@ sub getTestParameter
319 } 322 }
320 323
321 my $cachedValue = SearchCache( $param, $testharness ); 324 my $cachedValue = SearchCache( $param, $testharness );
322 if ( defined( $cachedValue ) && $cachedValue ) 325 if ( defined( $cachedValue ) )
323 { 326 {
327 # This save required to convert to new style because the key required is
328 # changing to the environment variable
329 if ($new_style == 0) {
330 SetCacheParameter( $envvar, undef, $cachedValue );
331 }
324 return $cachedValue; 332 return $cachedValue;
325 } 333 }
326 334
@@ -339,9 +347,9 @@ sub getTestParameter
339 print STDERR "\n"; 347 print STDERR "\n";
340 print STDERR "Test Harness : $testharness\n"; 348 print STDERR "Test Harness : $testharness\n";
341 print STDERR "Test Parameter : $param\n"; 349 print STDERR "Test Parameter : $param\n";
342 print STDERR "Environment Variable : $envvar\n"; 350 print STDERR "Environment Variable : $envvar\n" if ($param ne $envvar);
343 print STDERR "Brief Description : $brief\n"; 351 print STDERR "Brief Description : $brief\n";
344 print STDERR "Enter value ", ($defaultValid ? "[${default}]" : "[]"), " => "; 352 print STDERR "Enter value (or 'none') ", ($defaultValid ? "[${default}]" : "[]"), " => ";
345 $userResponse = <STDIN>; 353 $userResponse = <STDIN>;
346 $userResponse = "" if ! defined( $userResponse ); # Handle EOF 354 $userResponse = "" if ! defined( $userResponse ); # Handle EOF
347 chomp( $userResponse ); 355 chomp( $userResponse );
@@ -353,6 +361,10 @@ sub getTestParameter
353 361
354 print STDERR "\n"; 362 print STDERR "\n";
355 363
364 if ($userResponse =~ /^(na|none)$/) {
365 $userResponse = "";
366 }
367
356 # define all user responses at global scope 368 # define all user responses at global scope
357 SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse ); 369 SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse );
358 370
@@ -378,6 +390,7 @@ sub SearchCache
378 { 390 {
379 return $CACHE{$param}; 391 return $CACHE{$param};
380 } 392 }
393 return undef; # Need this to say "nothing found"
381} 394}
382 395
383sub SetCacheParameter 396sub SetCacheParameter