Commit 5ac5ee9e authored by Christian Fibich's avatar Christian Fibich Committed by Stefan Tauner
Browse files

Duplicate net validation, non-fatal errors for Settings.pm

parent 375ac2bb
......@@ -78,12 +78,14 @@ sub new(;$$) {
# @returns STRING if an error ocurred
# @returns FIJI::Settings object if sucessful
sub settings_from_file {
my $logger = get_logger("");
my $rv;
my ($self, $cfgname) = @_;
my $fiji_settings = FIJI::Settings->new("download", $cfgname);
if (!ref($fiji_settings)) {
$rv = $fiji_settings . " Aborting.\n";
my ($fiji_settings, $warn) = FIJI::Settings->new("download", $cfgname);
if (!defined($fiji_settings)) {
$rv = $warn . " Aborting.\n";
} else {
$logger->warn($warn) if defined $warn;
$rv = $self->{'fiji_settings'} = $fiji_settings;
}
return $rv;
......
......@@ -50,8 +50,8 @@ my @base_resources;
# \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 the case of an error)
# and a diagnostic string describing the reason why it could not be created (undef if successful)
sub new ($;$$) {
my $logger = get_logger("");
my ($class, $phase, $fiji_ini_file, $existing_settings) = @_;
......@@ -73,14 +73,15 @@ sub new ($;$$) {
$msg = "Given settings are not of type FIJI::Settings.";
}
$logger->error($msg);
return $msg;
return (undef, $msg);
}
my $warn;
# If there is a file given, try to read it. Else just create a default instance.
if (defined($fiji_ini_file)) {
$fiji_settings_ref = read_settingsfile($phase, $fiji_ini_file, $fiji_settings_ref);
if (!ref($fiji_settings_ref)) {
return $fiji_settings_ref; # actually an error message
($fiji_settings_ref, $warn) = read_settingsfile($phase, $fiji_ini_file, $fiji_settings_ref);
if (!defined($fiji_settings_ref)) {
return ($fiji_settings_ref, $warn);
}
$fiji_settings_ref->{'filename'} = $fiji_ini_file;
} else {
......@@ -92,7 +93,7 @@ sub new ($;$$) {
@base_resources = _est_resources(DESIGNMAP->{'FREQUENCY'}->{'default'}, DESIGNMAP->{'BAUDRATE'}->{'default'}, DESIGNMAP->{'TIMER_WIDTH'}->{'default'}, DESIGNMAP->{'RESET_DUT_IN_DURATION'}->{'default'}, DESIGNMAP->{'LFSR_WIDTH'}->{'default'}, 1, "logarithmic");
return $fiji_settings_ref;
return ($fiji_settings_ref, $warn);
}
sub _export_value {
......@@ -206,7 +207,8 @@ sub save ($) {
# is a strictly increasing integer starting with 0 containing
# the constants for the respective FIU, see \ref _sanitize_fiu
#
# @returns a reference to the hash containing the read constants.
# @returns a reference to the hash containing the read constants (or undef in the case of an error)
# and a diagnostic string describing the reason why it could not be created (undef if successful)
sub read_settingsfile ($$$) {
my $logger = get_logger("");
my ($phase, $fiji_ini_file, $existing_settings) = @_;
......@@ -219,14 +221,14 @@ sub read_settingsfile ($$$) {
}
my $msg = "Could not read config file \"$fiji_ini_file\": $submsg";
$logger->error($msg);
return $msg;
return (undef, $msg);
}
my $design_ref = $fiji_ini->get_block("CONSTS");
if (!(%$design_ref)) {
my $msg = "Could not fetch CONSTS block from config file \"$fiji_ini_file\"";
$logger->error($msg);
return $msg;
return (undef, $msg);
}
_set_defaults(DESIGNMAP, $design_ref, $phase);
......@@ -234,7 +236,7 @@ sub read_settingsfile ($$$) {
if (!defined($design_ref)) {
my $msg = "Design constants do not match the FIJI Settings naming scheme.";
$logger->error($msg);
return $msg;
return (undef, $msg);
}
# Create a new instance or reuse the shallow hull of the existing one
......@@ -258,7 +260,7 @@ sub read_settingsfile ($$$) {
$msg = "Given settings are not of type FIJI::Settings.";
}
$logger->error($msg);
return $msg;
return (undef, $msg);
}
$fiji_settings_ref->{'design'} = $design_ref;
$fiji_settings_ref->{'fius'} = [];
......@@ -267,13 +269,15 @@ sub read_settingsfile ($$$) {
$design_ref = _sanitize_design($design_ref, $phase);
if (!ref($design_ref)) {
$logger->error($design_ref);
return $design_ref;
return (undef, $design_ref);
}
my $fiu_num = 0;
my $dup = {};
my $warn;
# loop over all read fius
while (1) {
my $fiu_name = "FIU" . $fiu_num;
my $fiu_ref = $fiji_ini->get_block($fiu_name);
if (!(%$fiu_ref)) {
......@@ -283,7 +287,7 @@ sub read_settingsfile ($$$) {
if (!defined($design_ref)) {
my $msg = "FIU constants of $fiu_name do not match the FIJI Settings naming scheme.";
$logger->error($msg);
return $msg;
return (undef, $msg);
}
my $tmp_fiu = {};
......@@ -299,8 +303,17 @@ sub read_settingsfile ($$$) {
if (!ref($fiu_ref)) {
my $msg = "(Some) constants for $fiu_name in FIJI Settings are invalid.";
$logger->error($msg);
return $msg;
return (undef, $msg);
}
if (defined $dup->{$fiu_ref->{'FIU_NET_NAME'}}) {
my $msg = "More than one FIU attached to ".$fiu_ref->{'FIU_NET_NAME'};
$logger->error($msg);
$warn .= $msg;
} else {
$dup->{$fiu_ref->{'FIU_NET_NAME'}} = 1;
}
$fiji_settings_ref->{'fius'}->[$fiu_num] = $fiu_ref;
$fiu_num++;
$logger->trace("Read in $fiu_name from FIJI Settings file successfully.");
......@@ -315,14 +328,14 @@ sub read_settingsfile ($$$) {
if (defined($design_ref->{'FIU_NUM'}) && $design_ref->{'FIU_NUM'} != $fiu_num) {
my $msg = FIU_NUM->{'ini_name'} . " does not match the numbers of FIU blocks found.";
$logger->error($msg);
return $msg;
return (undef, $msg);
} else {
$design_ref->{'FIU_NUM'} = $fiu_num; # assume the best if FIU_NUM constant is not given
}
splice(@{$fiji_settings_ref->{'fius'}}, $fiu_num);
$logger->info("Successfully read in design constants and $fiu_num FIU definitions from FIJI Settings file \"$fiji_ini_file\".");
return $fiji_settings_ref;
return ($fiji_settings_ref, $warn);
}
## @method public set_fiu_defaults (%$fiu_ref)
......
......@@ -97,9 +97,11 @@ sub generate_config_package {
$logger->debug("=== generate_config_package ===");
$logger->debug(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
my $fiji_settings = FIJI::Settings->new('download', $fiji_settings_filename);
if (!ref($fiji_settings)) {
return $fiji_settings . " Aborting.\n";
my ($fiji_settings, $warn) = FIJI::Settings->new('download', $fiji_settings_filename);
if (!defined($fiji_settings)) {
return $warn . " Aborting.\n";
} elsif (defined($warn)) {
$logger->warn($warn);
}
my $fiji_consts = $fiji_settings->{'design'};
my $fius = $fiji_settings->{'fius'};
......@@ -267,9 +269,11 @@ sub generate_wrapper_module {
$logger->debug("=== generate_wrapper_module ===");
$logger->debug(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
my $fiji_settings = FIJI::Settings->new('download', $fiji_settings_filename);
if (!ref($fiji_settings)) {
return $fiji_settings . " Aborting.";
my ($fiji_settings, $warn) = FIJI::Settings->new('download', $fiji_settings_filename);
if (!defined($fiji_settings)) {
return $warn . " Aborting.\n";
} elsif (defined($warn)) {
$logger->warn($warn);
}
my $fiji_consts = $fiji_settings->{'design'};
my $fius = $fiji_settings->{'fius'};
......
......@@ -963,25 +963,27 @@ sub _add_fiu ($$) {
$d->Show();
} elsif (defined $netname && $netname ne "") {
@{$self->{'settings'}->{'fius'}}[$i]->{'FIU_NET_NAME'} = $netname;
# don't need to validate here, just unhighlight the net text entry
# and enable driver selection
_highlight_widget($net_entry, 0);
$self->_set_fields(1, $net_entry->{'dependents'});
# check if this net is already instrumented
my $rvn = _validate_fiu_net($self,$i);
# try to validate the selected driver
# this will likely fail if a different net has been selected
my $rv = _validate_single_fiu_driver($self,$i);
if (defined $rv) {
$logger->warn($rv);
my $rvd = _validate_single_fiu_driver($self,$i);
_highlight_widget($drv_entry, (defined $rvd));
_highlight_widget($net_entry, (defined $rvn));
if (defined $rvd || defined $rvn) {
my $msg = ((defined $rvd) ? $rvd : "").((defined $rvn) ? $rvn : "");
$logger->warn($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-delete_mw => $self->{'delete_mw'},
-mw => $self->{'mw'},
-image => $alert_image,
-wraplength => $fr_fiu->screenwidth,
-text => "$rv",
-text => "$msg",
-title => "Warning",
-buttons => ["OK"]);
$d->Show();
} else {
_highlight_widget($drv_entry, 0);
}
}
......@@ -1219,6 +1221,33 @@ sub validate_all_design_settings {
return $rv;
}
sub validate_duplicate_nets {
my ($self) = @_;
my $dup = {};
my $rv;
for my $fiu (@{$self->{'settings'}->{'fius'}}) {
$dup->{$fiu->{'FIU_NET_NAME'}}++;
}
for my $k (keys(%{$dup})) {
$rv .= $k." is attached to ".$dup->{$k}." FIUs" if $dup->{$k} > 1;
}
return $rv;
}
sub _validate_fiu_net {
my ($self, $idx) = @_;
my $netname = @{$self->{'settings'}->{'fius'}}[$idx]->{'FIU_NET_NAME'};
my $rv;
for (my $i = 0 ; $i < @{$self->{'settings'}->{'fius'}} ; $i++) {
if ($i != $idx && $netname eq @{$self->{'settings'}->{'fius'}}[$i]->{'FIU_NET_NAME'}) {
$rv .= "Net $netname already attached to FIU $i\n";
}
}
return $rv;
}
## @method validate_all_drivers()
# For each FIU, check if a driver is configured
# - If no, prompt the user to select one
......
......@@ -244,21 +244,23 @@ sub main {
if (defined $settings_filename && (-e $settings_filename)) {
my $filename = $settings_filename;
my $tmp_settings = FIJI::Settings->new('setup', $filename);
if (!ref($tmp_settings)) {
my ($tmp_settings, $warn) = FIJI::Settings->new('setup', $filename);
if (defined($warn)) {
my $msg = "settings file $filename could not be loaded correctly: $tmp_settings";
$logger->error($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-delete_mw => [\&_onexit, $self],
-mw => $self->{'mw'},
-image => $error_image,
-image => (!defined($tmp_settings) ? $error_image : $alert_image),
-wraplength => "200",
-text => $msg,
-text => $warn,
-title => 'Open FIJI Settings failed!',
-buttons => ["OK"]);
$d->Show();
if (!defined($tmp_settings)) {
$ret = 1;
goto bailout;
}
}
$self->{'settings'} = $tmp_settings;
${$self->{'settings_ini_name'}} = $filename;
$current_dir = _setdir($filename);
......@@ -548,16 +550,17 @@ sub _load_settings_prompt {
$current_dir = _setdir($filename);
$tmp_settings = (defined $self->{'settings'}) ? \%{Clone::clone($self->{'settings'})} : undef;
$tmp_settings = FIJI::Settings->new('download', $filename, $tmp_settings);
if (!ref($tmp_settings)) {
my $msg = "tests file $filename could not be loaded correctly: $tmp_settings";
my $warn;
($tmp_settings, $warn) = FIJI::Settings->new('download', $filename, $tmp_settings);
if (defined($warn)) {
my $msg = "settings file $filename could not be loaded correctly: $tmp_settings";
$logger->error($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-delete_mw => [\&_onexit, $self],
-mw => $self->{'mw'},
-image => $error_image,
-image => (!defined($tmp_settings) ? $error_image : $alert_image),
-wraplength => "200",
-text => $msg,
-title => 'Open FIJI Tests failed!',
-text => $warn,
-title => 'Open FIJI Settings failed!',
-buttons => ["OK"]);
$d->Show();
}
......
......@@ -79,11 +79,14 @@ sub main {
my $self = bless(\%hash);
my $output_dir;
my $settings_ref = FIJI::Settings->new("setup", $options->{'fiji_settings_file'});
my ($settings_ref, $msg) = FIJI::Settings->new("setup", $options->{'fiji_settings_file'});
my $netlist_filename = $options->{'netlist_file'};
if (defined $msg) {
$logger->error($msg);
}
if (!ref($settings_ref)) {
$logger->error($settings_ref);
return 1;
}
$self->{'settings'} = $settings_ref;
......
......@@ -26,6 +26,7 @@
use strict;
use warnings;
use diagnostics;
use FindBin;
use lib "$FindBin::Bin";
......@@ -140,9 +141,11 @@ sub main {
#
# Start out with default settings
#
my $settings_ref = FIJI::Settings->new();
if (!ref($settings_ref)) {
$logger->error($settings_ref);
my ($settings_ref, $msg) = FIJI::Settings->new();
if (defined $msg) {
$logger->error($msg);
}
if (!defined($settings_ref)) {
return 1;
}
$self->{'settings'} = $settings_ref;
......@@ -209,19 +212,20 @@ sub main {
my $fr = $mw;
if (-e $filename) {
my $tmp_settings = \%{Clone::clone($self->{'settings'})};
$tmp_settings = FIJI::Settings->new('setup', $filename);
if (!ref($tmp_settings)) {
my $msg = "Settings file $filename could not be loaded correctly: $tmp_settings";
my $warn;
($tmp_settings, $warn) = FIJI::Settings->new('setup', $filename);
if (defined($warn)) {
my $msg = "Settings file $filename could not be loaded correctly: $warn";
$logger->error($msg);
my $d = $self->{'mw'}->FIJIModalDialog(-delete_mw => [\&_onexit, $self],
-mw => $self->{'mw'},
-image => $error_image,
-image => (!defined($tmp_settings) ? $error_image : $alert_image),
-wraplength => "200",
-text => $msg,
-title => 'Open FIJI Settings failed!',
-buttons => ["OK"]);
$d->Show();
goto bailout;
goto bailout if (!defined($tmp_settings));
}
if (!defined($self->{'FIJISettingsViewer'}->settings($tmp_settings))) {
my $msg = "Could not update GUI correctly with new settings.";
......@@ -489,7 +493,8 @@ sub _open_settings_file {
}
$current_dir = _setdir($filename);
my $tmp_settings = \%{Clone::clone($self->{'settings'})};
$tmp_settings = FIJI::Settings->new('setup', $filename, $tmp_settings);
my $warn;
($tmp_settings, $warn) = FIJI::Settings->new('setup', $filename, $tmp_settings);
if (!ref($tmp_settings)) {
my $msg = "Settings file $filename could not be loaded correctly: $tmp_settings";
$logger->error($msg);
......@@ -658,6 +663,7 @@ sub _save_file {
# Check if all drivers are set, prompt for missing ones
my $drv = $self->{'FIJISettingsViewer'}->validate_all_drivers();
my $dup = $self->{'FIJISettingsViewer'}->validate_duplicate_nets();
my $dsgn = $self->{'FIJISettingsViewer'}->validate_all_design_settings();
# Warn the user if not all drivers could be validated successfully
......@@ -670,8 +676,12 @@ sub _save_file {
$rv .= "$dsgn\n";
$logger->error($dsgn);
}
if (defined($dup)) {
$rv .= "$dup\n";
$logger->error($dup);
}
if (defined($drv) || defined($dsgn)) {
if (defined($drv) || defined($dsgn) || defined($dup)) {
my $d = $self->{'mw'}->FIJIModalDialog(-delete_mw => [\&_onexit, $self],
-mw => $self->{'mw'},
-image => $alert_image,
......
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