Commit 61aee227 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

Refine error handling of Tests.pm's internal functions

Before some hash key/value pairs have slipped without being
initialized at all. This caused for example:
"Use of uninitialized value" warnings in FIJITestsViewer.pm line 1137
parent 0d9c13bc
......@@ -48,8 +48,8 @@ use FIJI qw(:all);
# \param fiji_ini_file (optional) Path to the configuration file to read.
# \param existing_settings (optional) A reference to reuse and return
# with values read from file. Any contained data will be cleared.
# \returns The new settings instance or a string describing the reason
# why it could not be created.
# \returns The new settings instance or undef in case of errors, and
# a string describing the reason if it could not be created.
sub new {
my $logger = get_logger("");
my ($class, $phase, $global_settings_ref, $fiji_ini_file, $existing_settings, $num_tests) = @_;
......@@ -244,7 +244,8 @@ sub save {
# is a strictly increasing integer starting with 0 containing
# the constants for the respective TEST, see \ref _sanitize_test
#
# \returns a reference to the hash containing the read constants.
# \returns a reference to the hash containing the read constants or undef in case of errors, and
# a list of reasons if it could not be read successfully.
sub _read_settingsfile {
my $logger = get_logger("");
my ($self, $phase, $global_settings_ref, $fiji_ini_file) = @_;
......@@ -290,13 +291,11 @@ sub _read_settingsfile {
$self->{'design'} = $design_ref;
$self->{'tests'} = [];
my $warn;
my $msg;
# sanitize and validate read design constants
($design_ref, $warn) = _sanitize_design($global_settings_ref, $design_ref, $phase);
if (defined($warn)) {
push(@$msg_ref, @$warn);
}
if (!ref($design_ref)) {
$msg = _sanitize_design($global_settings_ref, $design_ref, $phase);
if (defined($msg)) {
push(@$msg_ref, $msg);
return (undef, $msg_ref);
}
......@@ -326,16 +325,12 @@ sub _read_settingsfile {
}
$test_ref = $tmp_test;
my $warn;
($test_ref, $warn) = _sanitize_test($global_settings_ref, $self->{'TESTPATMAP'}, $test_ref, $phase);
if (!ref($test_ref)) {
my $msg = "(Some) constants for $test_name in Tests Settings are invalid.";
$logger->error($msg);
push(@$msg_ref, unshift(@$warn, $msg));
}
my $msg = _sanitize_test($global_settings_ref, $self->{'TESTPATMAP'}, $test_ref, $phase);
# $msg = join("\n", @$msg) if defined($msg);
push(@$msg_ref, @$msg) if defined($msg);
$self->{'tests'}->[$test_num] = $test_ref;
$test_num++;
$logger->trace("Read in $test_name from FIJI Tests file successfully.");
$logger->trace(sprintf("Read in $test_name from FIJI Tests file%s.", !defined($msg) ? "successfully" : ""));
}
if ($test_num == 0) {
......@@ -579,15 +574,14 @@ sub _rename_import {
# single TEST.
# \param phase the current design phase
#
# \returns A new hash with all constants required in the TEST settings
# in sanitized form, or undef on errors.
# \returns a reference to a list of diagnostic strings describing the reasons why sanitation failed (undef if successful)
sub _sanitize_test {
my $logger = get_logger("");
my ($global_settings_ref, $testpatmap, $test_ref, $phase) = @_;
if (ref($test_ref) ne 'HASH') {
my $msg = "Parameter is not a reference to a hash (containing TEST constants).";
$logger->error($msg);
return (undef, $msg);
return \[$msg];
}
return _validate_hashmap($global_settings_ref, $testpatmap, $test_ref, $phase);
......@@ -599,7 +593,8 @@ sub _disabled_via_dependency ($$$) {
return defined($dependency) && !$consts_ref->{$dependency};
}
sub _validate_hashmap ($$$;$) {
# \returns a reference to a list of diagnostic strings describing the reasons why validation failed (undef if successful),
sub _validate_hashmap {
my $logger = get_logger("");
my ($global_settings_ref, $map_ref, $consts_ref, $phase) = @_;
my @map_keys = keys(%{$map_ref});
......@@ -627,7 +622,7 @@ sub _validate_hashmap ($$$;$) {
# If there is no phase we are creating an "empty" hash that has
# all possible defaults set earlier already and the there is
# nothing we can or should do here.
return ($consts_ref, $msg_ref);
return $msg_ref;
}
# Iterate over the constants defined in FIJI.pm that apparently are
......@@ -643,7 +638,7 @@ sub _validate_hashmap ($$$;$) {
push(@$msg_ref, $msg);
}
}
return ($consts_ref, $msg_ref);
return $msg_ref;
}
## @function public _sanitize_design (%$consts_ref, $phase)
......@@ -666,31 +661,28 @@ sub _sanitize_design {
if (ref($consts_ref) ne 'HASH') {
my $msg = "Parameter is not a reference to a hash (containing design constants).";
$logger->error($msg);
return (undef, ($msg));
return $msg;
}
my $warn;
my $errors;
# check for sane values
($consts_ref, $warn) = _validate_hashmap($global_settings_ref, TESTCONSTMAP, $consts_ref, $phase);
if (!ref($consts_ref)) {
my $msg = "Could not validate Design Constants.";
$logger->error("$msg $consts_ref");
return (undef, "$msg $consts_ref");
}
my $msgs = _validate_hashmap($global_settings_ref, TESTCONSTMAP, $consts_ref, $phase);
push(@$errors, "Could not validate Design Constants.\n".join("\n", @$msgs)) if (defined($msgs));
if (($consts_ref->{'NUM_TESTS'} <= 0)) {
my $msg = "NUM_TESTS is <= 0.";
$logger->error($msg);
push(@$warn, $msg);
push(@$errors, $msg);
}
if (($consts_ref->{'REPEAT_OFFSET'} < 0) || ($consts_ref->{'REPEAT_OFFSET'} >= $consts_ref->{'NUM_TESTS'})) {
my $msg = "REPEAT_OFFSET (" . $consts_ref->{'REPEAT_OFFSET'} . ") is out of range [0 - NUM_TESTS].";
$logger->error($msg);
push(@$warn, $msg);
push(@$errors, $msg);
}
return ($consts_ref, $warn);
$errors = join("\n", @$errors) if defined($errors);
return $errors;
}
sub export_gate_level {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment