From 0dc82e84d841b2df335d3608f64f5d191da2a84b Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Fri, 10 Oct 2014 21:39:57 +0100 Subject: [PATCH 1/5] Use a _{IN,OUT}_ naming convention in "port" names to validate direction of data flow when linking nodes with fifos. --- bin/viv.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/viv.pl b/bin/viv.pl index e794f29b7..1f5bd7f0f 100755 --- a/bin/viv.pl +++ b/bin/viv.pl @@ -236,6 +236,11 @@ sub _update_node_data_xfer { if($node->{type} eq q[EXEC] and $data_xfer_name ne q[]) { if(defined $port) { + if(my($inout) = grep {$_} $port=~/_(IN|OUT)__\z/smx , $port=~/\A__(IN|OUT)_/smx ){ # || $port=~/\A__(IN|OUT)_/smx ) { + croak 'Node '.($node->{'id'})." port $port connected as ".($edge_side == $FROM?q("from"):q("to")) if (($inout eq q(OUT))^($edge_side == $FROM)); + } else { + $logger->($VLMED, 'Node '.($node->{'id'})." has poorly described port $port (no _{IN,OUT}__ {suf,pre}fix)\n"); + } my $cmd = $node->{'cmd'}; for my$cmd_part ( ref $cmd eq 'ARRAY' ? @{$cmd}[1..$#{$cmd}] : ($node->{'cmd'}) ){ $cmd_part =~ s/\Q$port\E/$data_xfer_name/; From 2a402d8c8bd3c8e7f1eba8f501d8fcf475afac35 Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Fri, 10 Oct 2014 22:18:38 +0100 Subject: [PATCH 2/5] Abort if trying to link a node's port which doesn't exist (or which has already been used) --- bin/viv.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/viv.pl b/bin/viv.pl index 1f5bd7f0f..45798c3d9 100755 --- a/bin/viv.pl +++ b/bin/viv.pl @@ -243,8 +243,9 @@ sub _update_node_data_xfer { } my $cmd = $node->{'cmd'}; for my$cmd_part ( ref $cmd eq 'ARRAY' ? @{$cmd}[1..$#{$cmd}] : ($node->{'cmd'}) ){ - $cmd_part =~ s/\Q$port\E/$data_xfer_name/; + return if ($cmd_part =~ s/\Q$port\E/$data_xfer_name/smx); } + croak 'Node '.($node->{'id'})." has no port $port"; } else { my $node_edge_std = $edge_side == $FROM? q[STDOUT]: q[STDIN]; From 22927b7308b7dbbe403573838da5a21ed793fe13 Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Sat, 11 Oct 2014 09:08:02 +0100 Subject: [PATCH 3/5] Tidy and enhance comments --- bin/viv.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/viv.pl b/bin/viv.pl index 45798c3d9..746c59f0f 100755 --- a/bin/viv.pl +++ b/bin/viv.pl @@ -236,7 +236,8 @@ sub _update_node_data_xfer { if($node->{type} eq q[EXEC] and $data_xfer_name ne q[]) { if(defined $port) { - if(my($inout) = grep {$_} $port=~/_(IN|OUT)__\z/smx , $port=~/\A__(IN|OUT)_/smx ){ # || $port=~/\A__(IN|OUT)_/smx ) { + if(my($inout) = grep {$_} $port=~/_(IN|OUT)__\z/smx , $port=~/\A__(IN|OUT)_/smx ){ # if port has _{IN,OUT}_ {suf,pre}fix convention + #ensure port is connected to in manner suggested by naming convention croak 'Node '.($node->{'id'})." port $port connected as ".($edge_side == $FROM?q("from"):q("to")) if (($inout eq q(OUT))^($edge_side == $FROM)); } else { $logger->($VLMED, 'Node '.($node->{'id'})." has poorly described port $port (no _{IN,OUT}__ {suf,pre}fix)\n"); @@ -244,7 +245,7 @@ sub _update_node_data_xfer { my $cmd = $node->{'cmd'}; for my$cmd_part ( ref $cmd eq 'ARRAY' ? @{$cmd}[1..$#{$cmd}] : ($node->{'cmd'}) ){ return if ($cmd_part =~ s/\Q$port\E/$data_xfer_name/smx); - } + } #if link for port has not been made (port never defined, or already substituted, in node cmd) bail out croak 'Node '.($node->{'id'})." has no port $port"; } else { From 288ff756872b9e272b075d116a356b1a505b03a2 Mon Sep 17 00:00:00 2001 From: Kevin Lewis Date: Tue, 14 Oct 2014 15:26:43 +0100 Subject: [PATCH 4/5] small amendments to existing test pipeline vtf files, added three more to test new warnings and failures (new port checks in viv.pl) --- t/data/simple_failing_pipeline.vtf | 2 +- t/data/simple_pipeline.vtf | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/t/data/simple_failing_pipeline.vtf b/t/data/simple_failing_pipeline.vtf index 16b0cbd85..dac3cb42d 100644 --- a/t/data/simple_failing_pipeline.vtf +++ b/t/data/simple_failing_pipeline.vtf @@ -1,5 +1,5 @@ { - "description": "minimal failing test pipeline", + "description": "minimal failing test pipeline. Fails because of false in cmd. Also carps about poorly named __IN1__ and __IN2__ ports", "nodes":[ { "id": "n1", "type": "EXEC", diff --git a/t/data/simple_pipeline.vtf b/t/data/simple_pipeline.vtf index d5f138f3d..631f2835d 100644 --- a/t/data/simple_pipeline.vtf +++ b/t/data/simple_pipeline.vtf @@ -21,7 +21,7 @@ }, { "id": "d", "type": "EXEC", - "cmd": "diff __IN1__ __IN2__", + "cmd": "diff __IN_1__ __IN_2__", "use_STDIN": 0, "use_STDOUT": 0 } @@ -31,10 +31,10 @@ "to": "n2" }, { "from": "n2", - "to": "d:__IN1__" + "to": "d:__IN_1__" }, { "from": "m", - "to": "d:__IN2__" + "to": "d:__IN_2__" } ] } From e9c85f7d0215efb10c347b9abb5511132e19b80a Mon Sep 17 00:00:00 2001 From: Kevin Lewis Date: Tue, 14 Oct 2014 15:32:21 +0100 Subject: [PATCH 5/5] new files were not added by git -a --- t/data/simple_carping_pipeline1.vtf | 40 ++++++++++++++++++++++++++ t/data/simple_failing_io_pipeline1.vtf | 40 ++++++++++++++++++++++++++ t/data/simple_failing_io_pipeline2.vtf | 40 ++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 t/data/simple_carping_pipeline1.vtf create mode 100644 t/data/simple_failing_io_pipeline1.vtf create mode 100644 t/data/simple_failing_io_pipeline2.vtf diff --git a/t/data/simple_carping_pipeline1.vtf b/t/data/simple_carping_pipeline1.vtf new file mode 100644 index 000000000..28915b833 --- /dev/null +++ b/t/data/simple_carping_pipeline1.vtf @@ -0,0 +1,40 @@ +{ + "description": "minimal carping test pipeline - works, but I/O port names are poorly named. See log for warning", + "nodes":[ + { "id": "n1", + "type": "EXEC", + "cmd": "echo stuff", + "use_STDIN": 0, + "use_STDOUT": 1 + }, + { "id": "n2", + "type": "EXEC", + "cmd": ["cat"], + "use_STDIN": 1, + "use_STDOUT": 1 + }, + { "id": "m", + "type": "EXEC", + "cmd": ["echo", "stuff"], + "use_STDIN": false, + "use_STDOUT": true + }, + { "id": "d", + "type": "EXEC", + "cmd": "diff __IN1__ __IN2__", + "use_STDIN": 0, + "use_STDOUT": 0 + } + ], + "edges":[ + { "from": "n1", + "to": "n2" + }, + { "from": "n2", + "to": "d:__IN1__" + }, + { "from": "m", + "to": "d:__IN2__" + } + ] +} diff --git a/t/data/simple_failing_io_pipeline1.vtf b/t/data/simple_failing_io_pipeline1.vtf new file mode 100644 index 000000000..1b946d304 --- /dev/null +++ b/t/data/simple_failing_io_pipeline1.vtf @@ -0,0 +1,40 @@ +{ + "description": "minimal failing test pipeline. Port name in edge does not match one in node definition. Also carps about poorly named __IN1__ and __INN2__ ports", + "nodes":[ + { "id": "n1", + "type": "EXEC", + "cmd": "echo stuff", + "use_STDIN": 0, + "use_STDOUT": 1 + }, + { "id": "n2", + "type": "EXEC", + "cmd": ["cat"], + "use_STDIN": 1, + "use_STDOUT": 1 + }, + { "id": "m", + "type": "EXEC", + "cmd": ["echo", "stuff"], + "use_STDIN": false, + "use_STDOUT": true + }, + { "id": "d", + "type": "EXEC", + "cmd": "diff __IN1__ __IN2__", + "use_STDIN": 0, + "use_STDOUT": 0 + } + ], + "edges":[ + { "from": "n1", + "to": "n2" + }, + { "from": "n2", + "to": "d:__IN1__" + }, + { "from": "m", + "to": "d:__INN2__" + } + ] +} diff --git a/t/data/simple_failing_io_pipeline2.vtf b/t/data/simple_failing_io_pipeline2.vtf new file mode 100644 index 000000000..91b9b683f --- /dev/null +++ b/t/data/simple_failing_io_pipeline2.vtf @@ -0,0 +1,40 @@ +{ + "description": "minimal failing test pipeline. Port names in edges match the node definitions, but are of the wrong type", + "nodes":[ + { "id": "n1", + "type": "EXEC", + "cmd": "echo stuff", + "use_STDIN": 0, + "use_STDOUT": 1 + }, + { "id": "n2", + "type": "EXEC", + "cmd": ["cat"], + "use_STDIN": 1, + "use_STDOUT": 1 + }, + { "id": "m", + "type": "EXEC", + "cmd": ["echo", "stuff"], + "use_STDIN": false, + "use_STDOUT": true + }, + { "id": "d", + "type": "EXEC", + "cmd": "diff __IN_1__ __OUT_2__", + "use_STDIN": 0, + "use_STDOUT": 0 + } + ], + "edges":[ + { "from": "n1", + "to": "n2" + }, + { "from": "n2", + "to": "d:__IN_1__" + }, + { "from": "m", + "to": "d:__OUT_2__" + } + ] +}