2021-12-09 23:39:07 +01:00
|
|
|
## xschemtest.tcl
|
|
|
|
|
## script for testing various xschem functions:
|
|
|
|
|
## works on xschem versions newer than r1819
|
|
|
|
|
## - drawing and drawing speed, with selections and highlights
|
|
|
|
|
## - netlisting in various formats
|
|
|
|
|
## - show net names on instance pins
|
|
|
|
|
## - logic simulation engine
|
|
|
|
|
## - print png, svg, pdf
|
|
|
|
|
## - trim wires
|
2021-12-10 01:08:31 +01:00
|
|
|
## - copy/paste operations
|
2021-12-09 23:39:07 +01:00
|
|
|
## run:
|
2021-12-10 16:05:11 +01:00
|
|
|
# xschem --script /path/to/xschemtest.tcl
|
2021-12-09 23:39:07 +01:00
|
|
|
## optionally with logging to catch memory leaks:
|
2021-12-10 16:05:11 +01:00
|
|
|
# xschem -d 3 -l log --script /path/to/xschemtest.tcl
|
2021-12-09 23:39:07 +01:00
|
|
|
## and then running: xschemtest
|
|
|
|
|
## running this test with different xschem versions with profiling enabled (-pg)
|
|
|
|
|
## allows to see differences in number of function calls / time spent.
|
|
|
|
|
|
|
|
|
|
## move schematic and redraw in a loop.
|
2021-12-27 05:22:19 +01:00
|
|
|
proc draw_test {{filelist {-}} {hide_graphs 0}} {
|
2021-12-26 04:09:55 +01:00
|
|
|
global show_pin_net_names hide_empty_graphs
|
2021-12-27 05:22:19 +01:00
|
|
|
set hide_empty_graphs $hide_graphs
|
2021-12-10 13:17:21 +01:00
|
|
|
set show_pin_net_names 1
|
2021-12-19 11:57:20 +01:00
|
|
|
foreach f $filelist {
|
2021-12-22 11:11:46 +01:00
|
|
|
if { $f ne {-}} {
|
|
|
|
|
xschem load [abs_sym_path $f]
|
|
|
|
|
}
|
2021-12-10 13:17:21 +01:00
|
|
|
xschem search regex 1 lab . ;# select all nets
|
|
|
|
|
xschem hilight ;# hilight all selected nets and labels
|
|
|
|
|
xschem unselect_all
|
|
|
|
|
set increment 5.0
|
2021-12-22 04:39:23 +01:00
|
|
|
set n 30.0
|
2021-12-10 13:17:21 +01:00
|
|
|
set a [time {
|
2021-12-22 04:39:23 +01:00
|
|
|
for { set i 0 } { $i < $n } { incr i} {
|
2021-12-10 13:17:21 +01:00
|
|
|
set x [xschem get xorigin]
|
|
|
|
|
set y [xschem get yorigin]
|
|
|
|
|
set x [expr {$x +$increment}]
|
|
|
|
|
set y [expr {$y +$increment}]
|
|
|
|
|
xschem origin $x $y
|
|
|
|
|
xschem redraw
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
set a [lindex $a 0]
|
2021-12-22 04:39:23 +01:00
|
|
|
set fps [expr {$n / $a * 1e6} ] ;# calculate drawing frames per second
|
2021-12-10 13:17:21 +01:00
|
|
|
puts "$f: draw speed: $fps fps"
|
|
|
|
|
}
|
|
|
|
|
set show_pin_net_names 0
|
2021-12-09 23:39:07 +01:00
|
|
|
}
|
2022-01-11 01:09:56 +01:00
|
|
|
proc test_windows { {tabs 0} {destroy 1} } {
|
|
|
|
|
global tabbed_interface
|
|
|
|
|
|
|
|
|
|
xschem clear force
|
|
|
|
|
set tabbed_interface $tabs
|
|
|
|
|
setup_tabbed_interface
|
|
|
|
|
xschem load [abs_sym_path testbench.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path poweramp.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path mos_power_ampli.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path rom8k.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path autozero_comp.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path LCC_instances.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path simulate_ff.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path led_driver.sch]
|
|
|
|
|
xschem load_new_window [abs_sym_path solar_panel.sch]
|
|
|
|
|
update
|
|
|
|
|
if {[xschem new_schematic ntabs] == 8} {set res OK} else {set res FAIL}
|
|
|
|
|
if {$tabs} {
|
|
|
|
|
puts "test tabbed windows: $res"
|
|
|
|
|
} else {
|
|
|
|
|
puts "test multiple windows: $res"
|
|
|
|
|
}
|
|
|
|
|
if {$destroy} {
|
|
|
|
|
after 2000
|
|
|
|
|
xschem new_schematic destroy_all
|
|
|
|
|
xschem clear force
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-09 23:39:07 +01:00
|
|
|
|
2021-12-10 13:17:21 +01:00
|
|
|
## select all loaded schematic and paste 32 times in different places,
|
|
|
|
|
## check if number of elements after paste matches.
|
|
|
|
|
proc copy_paste_test {{f mos_power_ampli.sch}} {
|
|
|
|
|
xschem load [abs_sym_path $f]
|
2021-12-09 23:39:07 +01:00
|
|
|
xschem zoom_box -18000 -18000 18000 18000
|
|
|
|
|
xschem select_all
|
|
|
|
|
set n [xschem get lastsel]
|
|
|
|
|
xschem copy
|
|
|
|
|
for { set i 3000 } {$i < 12001} { set i [expr {$i + 3000}]} {
|
|
|
|
|
xschem paste 0 $i
|
|
|
|
|
xschem paste 0 -$i
|
|
|
|
|
xschem paste $i 0
|
|
|
|
|
xschem paste -$i 0
|
|
|
|
|
xschem paste $i $i
|
|
|
|
|
xschem paste $i -$i
|
|
|
|
|
xschem paste -$i $i
|
|
|
|
|
xschem paste -$i -$i
|
|
|
|
|
}
|
|
|
|
|
update
|
|
|
|
|
xschem select_all
|
|
|
|
|
set m [xschem get lastsel]
|
|
|
|
|
if { $m == $n * 33 } {
|
|
|
|
|
puts "Copy / paste 32 additional circuits: $m elements == $n * 33. OK"
|
|
|
|
|
} else {
|
|
|
|
|
puts "Copy / paste 32 additional circuits: $m elements != $n * 33. FAIL"
|
|
|
|
|
}
|
|
|
|
|
xschem unselect_all
|
|
|
|
|
xschem clear force
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## draw a grid of long vertical wires and small horizontal wire segments
|
|
|
|
|
## after a trim wire operation vertical wires are cut at intersection points.
|
|
|
|
|
proc draw_trim_wiregrid {} {
|
|
|
|
|
xschem unhilight_all
|
|
|
|
|
xschem clear force
|
|
|
|
|
xschem set no_undo 1
|
|
|
|
|
for {set i 0} {$i < 129} {incr i} {
|
|
|
|
|
set x [expr {$i * 40.0}]
|
|
|
|
|
set y [expr {128.0*40}]
|
|
|
|
|
xschem wire $x 0 $x $y
|
|
|
|
|
}
|
|
|
|
|
for {set i 0} {$i < 129} {incr i} {
|
|
|
|
|
for {set j 0} {$j < 128} {incr j} {
|
|
|
|
|
set x1 [expr {$j * 40}]
|
|
|
|
|
set x2 [expr {$j * 40 + 40}]
|
|
|
|
|
set y [expr {$i * 40}]
|
|
|
|
|
xschem wire $x1 $y $x2 $y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xschem set no_undo 0
|
|
|
|
|
xschem zoom_full
|
|
|
|
|
update ;# so updated window will be visible.
|
|
|
|
|
xschem trim_wires ;# will also draw result
|
|
|
|
|
update
|
|
|
|
|
xschem select_all
|
|
|
|
|
set n [xschem get lastsel]
|
|
|
|
|
xschem unselect_all
|
|
|
|
|
## if all wires trimmed correctly we should have 129*128*2 = 33024 segments.
|
2021-12-10 13:17:21 +01:00
|
|
|
if {$n == 33024} { puts "Trim wire test: $n segments, OK"} else { puts "Trim wire test FAIL"}
|
|
|
|
|
xschem clear force
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## test print files. Exact file content depend on window size and conversion tool,
|
|
|
|
|
## so we simply check if existing and size > 0.
|
|
|
|
|
## view parameter allows to view print file (works on linux)
|
|
|
|
|
proc print_test {{view 0}} {
|
|
|
|
|
global OS
|
|
|
|
|
foreach {f t} {
|
|
|
|
|
autozero_comp.sch png
|
|
|
|
|
mos_power_ampli.sch svg
|
|
|
|
|
simulate_ff.sch pdf
|
|
|
|
|
} {
|
|
|
|
|
set filepath [abs_sym_path $f]
|
|
|
|
|
set printfile [file rootname $f].$t
|
|
|
|
|
xschem load $filepath
|
|
|
|
|
puts "Printing: $printfile in $t format"
|
|
|
|
|
xschem print $t $printfile
|
|
|
|
|
if {$view && $OS ne {Windows}} {
|
|
|
|
|
execute 0 xdg-open $printfile
|
|
|
|
|
alert_ "Opening print file. Check if $printfile print file looks fine"
|
|
|
|
|
}
|
|
|
|
|
if {[file exists $printfile] && [file size $printfile] > 0} {
|
|
|
|
|
puts "Print file $printfile exists. [file size $printfile] bytes. OK"
|
|
|
|
|
} else {
|
|
|
|
|
puts "Print file $printfile not existing or empty. FAIL"
|
|
|
|
|
}
|
|
|
|
|
file delete $printfile
|
|
|
|
|
}
|
|
|
|
|
xschem clear force
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## test xschem's own simulation engine
|
|
|
|
|
## there is no built in testing, just see if it works.
|
|
|
|
|
proc test_xschem_simulation {{f simulate_ff.sch}} {
|
2022-01-21 02:18:07 +01:00
|
|
|
global tclstop OS
|
2021-12-10 13:17:21 +01:00
|
|
|
xschem load [abs_sym_path $f]
|
|
|
|
|
## search element with tclcommand attribute
|
2022-01-21 02:18:07 +01:00
|
|
|
if {$OS ne {Windows}} {
|
|
|
|
|
xschem search regex 1 tclcommand {}
|
|
|
|
|
} else {
|
|
|
|
|
xschem search exact 1 name h3
|
|
|
|
|
}
|
2021-12-10 13:17:21 +01:00
|
|
|
## join transform a list element {foo} into a plain string foo
|
|
|
|
|
set instname [join [xschem selected_set]]
|
|
|
|
|
## run tcl testbench
|
|
|
|
|
eval [xschem getprop instance $instname tclcommand]
|
|
|
|
|
puts "Xschem simulation test done. OK"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## netlist some files in various formats and check netlist with known gold hashes
|
|
|
|
|
## hashes should be calculated in same way on windows and linux.
|
|
|
|
|
proc netlist_test {} {
|
|
|
|
|
global netlist_dir
|
|
|
|
|
foreach {f t h} {
|
2023-06-30 20:54:07 +02:00
|
|
|
rom8k.sch spice 1998661799
|
|
|
|
|
greycnt.sch verilog 2899796185
|
2022-10-12 01:16:23 +02:00
|
|
|
autozero_comp.sch spice 1181616733
|
2023-06-30 20:54:07 +02:00
|
|
|
loading.sch vhdl 2975204502
|
2022-10-17 12:45:48 +02:00
|
|
|
mos_power_ampli.sch spice 1986885043
|
2023-06-30 20:54:07 +02:00
|
|
|
hierarchical_tedax.sch tedax 280590167
|
2022-10-16 14:21:22 +02:00
|
|
|
LCC_instances.sch spice 268038818
|
2022-01-12 23:44:52 +01:00
|
|
|
pcb_test1.sch tedax 1925087189
|
2023-06-30 20:54:07 +02:00
|
|
|
test_doublepin.sch spice 894741562
|
|
|
|
|
simulate_ff.sch spice 574849766
|
|
|
|
|
test_symbolgen.sch spice 2593807370
|
2023-06-13 23:20:28 +02:00
|
|
|
inst_sch_select.sch spice 801962545
|
2023-05-10 23:29:16 +02:00
|
|
|
test_mosgen.sch spice 21996225
|
2021-12-10 13:17:21 +01:00
|
|
|
} {
|
|
|
|
|
xschem set netlist_type $t
|
|
|
|
|
xschem load [abs_sym_path $f]
|
|
|
|
|
xschem netlist
|
|
|
|
|
if {$t eq {verilog}} { set t v}
|
2021-12-16 00:39:09 +01:00
|
|
|
if {$t eq {tedax}} { set t tdx}
|
2021-12-10 13:17:21 +01:00
|
|
|
set netlist_file $netlist_dir/[file rootname $f].$t
|
|
|
|
|
## check netlist hashes, compare with gold hashes
|
2021-12-15 15:17:45 +01:00
|
|
|
set netlist_hash [xschem hash_file $netlist_file 1]
|
|
|
|
|
if { $netlist_hash == $h } {
|
2021-12-10 13:17:21 +01:00
|
|
|
puts "$f netlist check OK"
|
|
|
|
|
} else {
|
2021-12-15 15:17:45 +01:00
|
|
|
puts "$f netlist check, expected hash: ${h}, calculated hash: ${netlist_hash}, FAIL"
|
2021-12-10 13:17:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-09 23:39:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc xschemtest {{view 0}} {
|
|
|
|
|
set t [time {
|
2021-12-19 10:11:54 +01:00
|
|
|
## make sure ERC window will not pop up above schematic while doing tests
|
2021-12-09 23:39:07 +01:00
|
|
|
wm deiconify .infotext
|
|
|
|
|
lower .infotext
|
|
|
|
|
|
2021-12-10 13:17:21 +01:00
|
|
|
netlist_test
|
|
|
|
|
print_test $view
|
2022-01-19 18:48:22 +01:00
|
|
|
draw_test [list 0_examples_top.sch rom8k.sch greycnt.sch autozero_comp.sch \
|
2021-12-19 11:57:20 +01:00
|
|
|
loading.sch mos_power_ampli.sch LCC_instances.sch simulate_ff.sch]
|
|
|
|
|
|
2021-12-10 13:17:21 +01:00
|
|
|
copy_paste_test mos_power_ampli.sch
|
2021-12-09 23:39:07 +01:00
|
|
|
draw_trim_wiregrid
|
2021-12-10 13:17:21 +01:00
|
|
|
test_xschem_simulation simulate_ff.sch
|
2022-01-11 01:09:56 +01:00
|
|
|
test_windows 0 ;# windows
|
|
|
|
|
test_windows 1 ;# tabs
|
2021-12-09 23:39:07 +01:00
|
|
|
}]
|
2021-12-10 13:17:21 +01:00
|
|
|
puts "Test time: [lindex $t 0] microseconds"
|
2021-12-09 23:39:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## this is the test to run from xschem console after sourcing this file
|
|
|
|
|
# xschemtest
|