Skip to content

Commit 7ab952f

Browse files
authored
Merge pull request #8428 from rafaelmoresco/dev_rafael
Console --db option
2 parents 9b850d5 + 24834e0 commit 7ab952f

File tree

10 files changed

+140
-23
lines changed

10 files changed

+140
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ save_flow_metrics_limits <TEST_NAME>
329329

330330
``` text
331331
openroad [-help] [-version] [-no_init] [-exit] [-gui]
332-
[-threads count|max] [-log file_name] cmd_file
332+
[-threads count|max] [-log file_name] [-db file_name] cmd_file
333333
-help show help and exit
334334
-version show version and exit
335335
-no_init do not read .openroad init file
@@ -339,6 +339,7 @@ openroad [-help] [-version] [-no_init] [-exit] [-gui]
339339
-gui start in gui mode
340340
-python start with python interpreter [limited to db operations]
341341
-log <file_name> write a log in <file_name>
342+
-db <file_name> open a .odb database at startup
342343
cmd_file source cmd_file
343344
```
344345

src/Main.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int cmd_argc;
8888
char** cmd_argv;
8989
static const char* log_filename = nullptr;
9090
static const char* metrics_filename = nullptr;
91+
static const char* read_odb_filename = nullptr;
9192
static bool no_settings = false;
9293
static bool minimize = false;
9394

@@ -243,6 +244,7 @@ int main(int argc, char* argv[])
243244
std::filesystem::remove(metrics_filename, err_ignored);
244245
}
245246

247+
read_odb_filename = findCmdLineKey(argc, argv, "-db");
246248
no_settings = findCmdLineFlag(argc, argv, "-no_settings");
247249
minimize = findCmdLineFlag(argc, argv, "-minimize");
248250

@@ -449,6 +451,21 @@ static int tclAppInit(int& argc,
449451

450452
const bool gui_enabled = gui::Gui::enabled();
451453

454+
if (read_odb_filename) {
455+
std::string cmd = fmt::format("read_db {{{}}}", read_odb_filename);
456+
if (!gui_enabled) {
457+
if (Tcl_Eval(interp, cmd.c_str()) != TCL_OK) {
458+
fprintf(stderr,
459+
"Error: failed to read_db %s: %s\n",
460+
read_odb_filename,
461+
Tcl_GetStringResult(interp));
462+
exit(1);
463+
}
464+
} else {
465+
gui::Gui::get()->addRestoreStateCommand(cmd);
466+
}
467+
}
468+
452469
const char* home = getenv("HOME");
453470
if (!findCmdLineFlag(argc, argv, "-no_init") && home) {
454471
const char* restore_state_cmd = "include -echo -verbose {{{}}}";
@@ -525,7 +542,7 @@ static void showUsage(const char* prog, const char* init_filename)
525542
{
526543
printf("Usage: %s [-help] [-version] [-no_init] [-no_splash] [-exit] ", prog);
527544
printf("[-gui] [-threads count|max] [-log file_name] [-metrics file_name] ");
528-
printf("[-no_settings] [-minimize] cmd_file\n");
545+
printf("[-db file_name] [-no_settings] [-minimize] cmd_file\n");
529546
printf(" -help show help and exit\n");
530547
printf(" -version show version and exit\n");
531548
printf(" -no_init do not read %s init file\n", init_filename);
@@ -543,6 +560,7 @@ static void showUsage(const char* prog, const char* init_filename)
543560
printf(" -log <file_name> write a log in <file_name>\n");
544561
printf(
545562
" -metrics <file_name> write metrics in <file_name> in JSON format\n");
563+
printf(" -db <file_name> open a .odb database at startup\n");
546564
printf(" cmd_file source cmd_file\n");
547565
}
548566

test/gcd_sky130hd.odb

644 KB
Binary file not shown.

test/open_db.ok

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
TEST: Verifying database was loaded via -db flag
2+
PASS: Design loaded: gcd
3+
PASS: Database loaded correctly with 250 instances
4+
PASS: Basic commands work after database load
5+
PASS: Database object accessible
6+
PASS: -db flag test completed successfully

test/open_db.tcl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Test for -db flag functionality
2+
# This test should be run with: openroad -db gcd_sky130hd.odb -exit open_db.tcl
3+
# It verifies that the database was loaded correctly via the -db flag
4+
5+
source "helpers.tcl"
6+
7+
puts "TEST: Verifying database was loaded via -db flag"
8+
9+
# Check that we have a design loaded
10+
if { [current_design] == "" } {
11+
puts "FAIL: No design loaded after -db flag"
12+
exit 1
13+
}
14+
15+
puts "PASS: Design loaded: [current_design]"
16+
17+
# Check that we have some basic design information
18+
set instance_count [sta::network_instance_count]
19+
if { $instance_count == 0 } {
20+
puts "FAIL: No instances found in loaded design"
21+
exit 1
22+
}
23+
24+
puts "PASS: Database loaded correctly with $instance_count instances"
25+
26+
# Test that basic commands work
27+
# Note: all_nets and all_pins might not be available in this context
28+
# Let's test other basic functionality instead
29+
30+
# Test that we can get design information
31+
set design_name [current_design]
32+
if { $design_name == "" } {
33+
puts "FAIL: No design name available"
34+
exit 1
35+
}
36+
37+
puts "PASS: Basic commands work after database load"
38+
39+
# Test that we can access the database
40+
set db [ord::get_db]
41+
if { $db == "" } {
42+
puts "FAIL: Could not access database object"
43+
exit 1
44+
}
45+
46+
puts "PASS: Database object accessible"
47+
48+
puts "PASS: -db flag test completed successfully"

test/open_db_invalid.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[ERROR ORD-0007] nonexistent_file.odb does not exist.
2+
Error: failed to read_db nonexistent_file.odb: ORD-0007

test/open_db_invalid.tcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Test for -db flag with invalid database file
2+
# This test verifies proper error handling when an invalid database file is specified
3+
# Expected behavior: OpenROAD should exit with error message and not reach this script
4+
5+
puts "TEST: Testing -db flag with invalid database file"

test/regression.tcl

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,40 @@ proc run_test_lang { test lang } {
196196
flush stdout
197197
set test_errors [run_test_app $test $cmd_file $log_file $lang]
198198
if { [lindex $test_errors 0] == "ERROR" } {
199-
puts " *ERROR* [lrange $test_errors 1 end]"
200-
append_failure $test
201-
incr errors(error)
202-
203-
# For some reason seg faults aren't echoed in the log - add them.
204-
if { [file exists $log_file] } {
205-
set log_ch [open $log_file "a"]
206-
puts $log_ch "$test_errors"
207-
close $log_ch
208-
}
209-
210-
# Report partial log diff anyway.
211-
if { [file exists $ok_file] } {
199+
# Special handling: allow tests with expected errors to pass
200+
# if their log matches the .ok file.
201+
set pass_crit [test_pass_criteria $test]
202+
if { $pass_crit == "compare_logfile_allow_error" && [file exists $ok_file] } {
203+
# Filter dos '/r's from log file to match normal compare behavior.
204+
set tmp_file [file join $result_dir $test.tmp]
205+
exec tr -d "\r" < $log_file > $tmp_file
206+
file rename -force $tmp_file $log_file
212207
# tclint-disable-next-line command-args
213-
catch [concat exec diff $diff_options $ok_file $log_file \
214-
>> $diff_file]
208+
if { [catch [concat exec diff $diff_options $ok_file $log_file >> $diff_file]] } {
209+
puts " *FAIL*"
210+
append_failure $test
211+
incr errors(fail)
212+
} else {
213+
puts " pass (expected error)"
214+
}
215+
} else {
216+
puts " *ERROR* [lrange $test_errors 1 end]"
217+
append_failure $test
218+
incr errors(error)
219+
220+
# For some reason seg faults aren't echoed in the log - add them.
221+
if { [file exists $log_file] } {
222+
set log_ch [open $log_file "a"]
223+
puts $log_ch "$test_errors"
224+
close $log_ch
225+
}
226+
227+
# Report partial log diff anyway.
228+
if { [file exists $ok_file] } {
229+
# tclint-disable-next-line command-args
230+
catch [concat exec diff $diff_options $ok_file $log_file \
231+
>> $diff_file]
232+
}
215233
}
216234
} else {
217235
set error_msg ""
@@ -311,7 +329,7 @@ proc run_test_app { test cmd_file log_file lang } {
311329
}
312330

313331
proc run_test_plain { test cmd_file log_file lang } {
314-
global app_path app_options result_dir errorCode
332+
global app_path app_options result_dir errorCode test_specific_options
315333

316334
if { ![file exists $app_path] } {
317335
return "ERROR $app_path not found."
@@ -320,9 +338,14 @@ proc run_test_plain { test cmd_file log_file lang } {
320338
} else {
321339
set save_dir [pwd]
322340
cd [file dirname $cmd_file]
341+
# Get test-specific options if they exist
342+
set test_opts $app_options
343+
if { [info exists test_specific_options($test)] } {
344+
set test_opts [concat $test_specific_options($test) $app_options]
345+
}
323346
# tclint-disable command-args
324347
if {
325-
[catch [concat exec $app_path $app_options \
348+
[catch [concat exec $app_path $test_opts \
326349
[lang_flag $lang] \
327350
-metrics [test_metrics_result_file $test $lang] \
328351
[file tail $cmd_file] >& $log_file]]
@@ -351,16 +374,22 @@ proc run_test_plain { test cmd_file log_file lang } {
351374
}
352375

353376
proc run_test_valgrind { test cmd_file log_file lang } {
354-
global app_path app_options valgrind_options result_dir errorCode
377+
global app_path app_options valgrind_options result_dir errorCode test_specific_options
355378

356379
set vg_cmd_file [test_valgrind_cmd_file $test $lang]
357380
set vg_stream [open $vg_cmd_file "w"]
358381
puts $vg_stream "cd [file dirname $cmd_file]"
359382
puts $vg_stream "source [file tail $cmd_file]"
360383
close $vg_stream
361384

385+
# Get test-specific options if they exist
386+
set test_opts $app_options
387+
if { [info exists test_specific_options($test)] } {
388+
set test_opts [concat $test_specific_options($test) $app_options]
389+
}
390+
362391
set cmd [concat exec valgrind $valgrind_options \
363-
$app_path [lang_flag $lang] $app_options \
392+
$app_path [lang_flag $lang] $test_opts \
364393
$vg_cmd_file >& $log_file]
365394
set error_msg ""
366395
if { [catch { $cmd }] } {

test/regression_tests.tcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ record_flow_tests {
1717
jpeg_sky130hs
1818
jpeg_sky130hd
1919
}
20+
21+
# Database loading tests for -db flag functionality
22+
record_test open_db $test_dir "compare_logfile" "-db gcd_sky130hd.odb"
23+
# For invalid DB, allow non-zero exit but require log to match ok
24+
record_test open_db_invalid $test_dir "compare_logfile_allow_error" "-db nonexistent_file.odb"

test/regression_vars.tcl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ proc record_tests1 { tests cmp_logfile } {
8787
}
8888

8989
# Record a test in the regression suite.
90-
proc record_test { test cmd_dir pass_criteria } {
91-
global cmd_dirs test_groups test_pass_criteria test_langs
90+
proc record_test { test cmd_dir pass_criteria { test_options "" } } {
91+
global cmd_dirs test_groups test_pass_criteria test_langs test_specific_options
9292
set cmd_dirs($test) $cmd_dir
9393
lappend test_groups(all) $test
9494
set test_pass_criteria($test) $pass_criteria
9595
set test_langs($test) [list]
96+
if { $test_options != "" } {
97+
set test_specific_options($test) $test_options
98+
}
9699
if { [file exists [file join $cmd_dir "$test.tcl"]] } {
97100
lappend test_langs($test) tcl
98101
}

0 commit comments

Comments
 (0)