Selection plugin: Add testing tcl procedure

Signed-off-by: Tomasz Michalak <tmichalak@antmicro.com>
diff --git a/selection-plugin/tests/counter/counter.golden.txt b/selection-plugin/tests/counter/counter.golden.txt
index aee0a91..e8183f0 100644
--- a/selection-plugin/tests/counter/counter.golden.txt
+++ b/selection-plugin/tests/counter/counter.golden.txt
@@ -1 +1,3 @@
-{middle/$1\cnt[1:0]} {middle/$add$counter.v:32$5_Y} {middle/$0\cnt[1:0]} middle/clk_int middle/cnt middle/out middle/clk {top/$1\cnt[1:0]} {top/$add$counter.v:14$2_Y} {top/$0\cnt[1:0]} top/ibuf_out top/ibuf_proxy_out top/clk_int_2 top/clk_int_1 top/cnt top/out top/in top/clk2 top/clk
+1
+1
+1
diff --git a/selection-plugin/tests/counter/counter.tcl b/selection-plugin/tests/counter/counter.tcl
index aa5a524..1ec5c87 100644
--- a/selection-plugin/tests/counter/counter.tcl
+++ b/selection-plugin/tests/counter/counter.tcl
@@ -4,15 +4,37 @@
 # Import the commands from the plugins to the tcl interpreter
 yosys -import
 
+proc selection_to_tcl_list_through_file { expression } {
+    set file_name "[pid].txt"
+    select $expression -write $file_name
+    set fh [open $file_name r]
+    set result [list]
+    while {[gets $fh line] >= 0} {
+	lappend result $line
+    }
+    close $fh
+    file delete $file_name
+    return $result
+}
+
+proc test_selection { expression {debug 0} } {
+    if {$debug} {
+    	puts "List from file: [selection_to_tcl_list_through_file $expression]"
+    	puts "List in selection: [selection_to_tcl_list $expression]"
+    }
+    return [expr {[selection_to_tcl_list_through_file $expression] == [selection_to_tcl_list $expression]}]
+}
+
 read_verilog counter.v
 read_verilog -specify -lib -D_EXPLICIT_CARRY +/xilinx/cells_sim.v
 read_verilog -lib +/xilinx/cells_xtra.v
 hierarchy -check -auto-top
 
-puts "List: [selection_to_tcl_list w:*]"
+# Test the selection command and write results to file
+set rfh [open counter.txt w]
 
-# Write the selection to file
-set fh [open counter.txt w]
-set selection_list [selection_to_tcl_list w:*]
-puts $fh $selection_list
-close $fh
+puts $rfh [test_selection "t:*"]
+puts $rfh [test_selection "w:*"]
+puts $rfh [test_selection "*"]
+
+close $rfh