Skip to content

Commit 32a6c4f

Browse files
authored
Merge pull request #12057 from zzf2024/fix/read-upf-exceptions
upf: propagate SWIG exceptions as Tcl errors
2 parents e891333 + e0923b4 commit 32a6c4f

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

‎src/upf/BUILD‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ cc_library(
5151
"//:ord",
5252
"//src/odb/src/db",
5353
"//src/utl",
54+
"@boost.stacktrace",
5455
"@tcl_lang//:tcl",
5556
],
5657
)

‎src/upf/src/upf.i‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using namespace upf;
1515
%}
1616

17+
%include "../../Exception.i"
1718

1819

1920
%inline %{

‎src/upf/test/BUILD‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ filegroup(
5959
for test_name in ALL_TESTS
6060
]
6161

62+
regression_test(
63+
name = "read_upf_errors",
64+
check_log = False,
65+
check_passfail = True,
66+
data = [":regression_resources"],
67+
visibility = ["//visibility:public"],
68+
)
69+
6270
cc_test(
6371
name = "TestPowerSwitch",
6472
size = "small",

‎src/upf/test/read_upf_errors.tcl‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Check that read_upf errors cross the C++/Tcl boundary without aborting.
2+
set test_name read_upf_errors
3+
source "helpers.tcl"
4+
5+
read_liberty data/sky130hd/sky130_fd_sc_hd__tt_025C_1v80.lib
6+
read_lef data/sky130hd/sky130_fd_sc_hd.tlef
7+
read_lef data/sky130hd/sky130_fd_sc_hd_merged.lef
8+
read_verilog data/mpd_top/mpd_top.v
9+
link_design mpd_top
10+
11+
read_upf -file data/mpd_top/mpd_top.upf
12+
13+
set upf_file [make_result_file "${test_name}.upf"]
14+
15+
foreach {description command expected_error} {
16+
"missing master"
17+
{map_power_switch psw_aes_1 -lib_cells {no_such_cell} -port_map {{vin1 A}}}
18+
UPF-0043
19+
20+
"missing master terminal"
21+
{map_power_switch psw_aes_1 -lib_cells {sky130_fd_sc_hd__and2_0} -port_map {{vin1 NOPE}}}
22+
ODB-0154
23+
24+
"missing isolation domain"
25+
{set_isolation iso_x}
26+
UPF-0073
27+
} {
28+
set ::read_upf_after_error 0
29+
set stream [open $upf_file w]
30+
puts $stream $command
31+
puts $stream {set ::read_upf_after_error 1}
32+
close $stream
33+
34+
set status [catch { read_upf -file $upf_file } message]
35+
check "$description returns a Tcl error" { set status } 1
36+
check "$description preserves the error ID" { set message } $expected_error
37+
check "$description stops the UPF file" { set ::read_upf_after_error } 0
38+
39+
set stream [open $upf_file w]
40+
puts $stream {
41+
map_power_switch psw_aes_1 \
42+
-lib_cells {sky130_fd_sc_hd__and2_0} \
43+
-port_map {{vin1 A}}
44+
}
45+
puts $stream {set ::read_upf_after_error 1}
46+
close $stream
47+
48+
check "valid UPF succeeds after $description" {
49+
catch { read_upf -file $upf_file }
50+
} 0
51+
check "valid UPF completes after $description" { set ::read_upf_after_error } 1
52+
}
53+
54+
exit_summary

0 commit comments

Comments
 (0)