Skip to content

Commit 921428d

Browse files
committed
Add HBS_EXIT_SEVERITY environment variable
1 parent c63db0f commit 921428d

6 files changed

Lines changed: 43 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Please check the official [HBS user manual](https://github.com/m-kru/hbs/blob/ma
2828
- Questa simulator support.
2929
- `HBS_DEBUG` environment variable for debugging prints.
3030
- `HBS_DEVICE` environment variable for enforcing device.
31+
- `HBS_EXIT_SEVERITY` environment variable for enforcing exit severity.
3132
- `HBS_BUILD_DIR` environment variable for enforcing build directory.
3233
- `HBS_TOOL` environment variable for enforcing tool.
3334
- `HBS_STD` environment variable for enforcing HDL standard revision.

hbs.tcl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ namespace eval hbs {
8181
# See also 'hbs doc SetTop'.
8282
set Top ""
8383

84+
# True (1) if ExitSeverity is enforced via the HBS_EXIT_SEVERITY environment variable.
85+
set ExitSeverityEnvSet 0
86+
8487
# Exit severity level for simulators.
8588
#
8689
# ExitSeverity is not supported by xsim.
@@ -254,6 +257,11 @@ namespace eval hbs {
254257
# If simulator does not support exit severity changing, for example xsim,
255258
# then a call to this function has no effect.
256259
proc SetExitSeverity {sev} {
260+
if {$hbs::ExitSeverityEnvSet} {
261+
hbs::Debug "ignoring setting exit severity to '$sev', exit severity was enforced to '$hbs::ExitSeverity' via HBS_EXIT_SEVERITY environment variable"
262+
return
263+
}
264+
257265
set err [hbs::isValidExitSeverity $sev]
258266
if {$err ne ""} {
259267
hbs::panic "$err"
@@ -971,6 +979,18 @@ namespace eval hbs {
971979
set hbs::Device $dev
972980
}
973981

982+
# Handle HBS_EXIT_SEVERITY environment variable.
983+
if {[info exists ::env(HBS_EXIT_SEVERITY)]} {
984+
set sev $::env(HBS_EXIT_SEVERITY)
985+
hbs::Debug "HBS_EXIT_SEVERITY environment variable discovered, enforcing exit severity '$sev'"
986+
set err [isValidExitSeverity $sev]
987+
if {$err ne ""} {
988+
hbs::panic "cannot set exit severity from HBS_EXIT_SEVERITY environment variable: $err"
989+
}
990+
set hbs::ExitSeverityEnvSet 1
991+
set hbs::ExitSeverity $sev
992+
}
993+
974994
# Handle HBS_STD environment variable.
975995
if {[info exists ::env(HBS_STD)]} {
976996
set std $::env(HBS_STD)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
export HBS_EXIT_SEVERITY=foo
3+
../../../hbs run my-core::my-target 2> output.txt
4+
if [[ $? == 1 ]]; then
5+
exit 0
6+
else
7+
exit 1
8+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hbs::init: cannot set exit severity from HBS_EXIT_SEVERITY environment variable: invalid exit severity 'foo', valid exit severities are: 'note', 'warning', 'error', 'failure'

user-manual/architecture.typ

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,26 @@ The dry runs and `HBS_DEBUG` are probably more than enough for debugging build f
752752

753753
By setting the `HBS_DEVICE` environment variable, you can enforce the value of the `hbs::Device`.
754754
If `HBS_DEVICE` is set, then `hbs.tcl` during initialization (before any hbs file is sourced) sets the value of `hbs::Device` to the value of `HBS_DEVICE`.
755-
If `HBS_DEVICE` is set, any call to `hbs::SetDevice` is ignored.
755+
If `HBS_DEVICE` is set, any call to the `hbs::SetDevice` is ignored.
756756

757757
The `HBS_DEVICE` variable might be useful for determining the target device for the build from the shell.
758758
Similar functionality can be achieved using the target parameters described in @arch-target-parameters.
759759
However, you may want to utilize target parameters for different purposes.
760760

761+
=== HBS\_EXIT\_SEVERITY - enforcing exit severity
762+
763+
By setting the `HBS_EXIT_SEVERITY` environment variable, you can enforce the value of the `hbs::ExitSeverity`.
764+
If `HBS_EXIT_SEVERITY` is set, then `hbs.tcl` during initialization (before any hbs file is sourced) sets the value of `hbs::ExitSeverity` to the value of `HBS_EXIT_SEVERITY`.
765+
If `HBS_EXIT_SEVERITY` is set, any call to the `hbs::ExitSeverity` is ignored.
766+
767+
The `HBS_EXIT_SEVERITY` environment variable is useful for quickly running testbenches with modified exit severity.
768+
For example, your simulation suddenly starts failing, and you would like to stop it when the first warning is encountered.
769+
761770
=== HBS\_TOOL - enforcing tool <hbs-tool>
762771

763772
By setting the `HBS_TOOL` environment variable, you can enforce the value of the `hbs::Tool`.
764773
If `HBS_TOOL` is set, then `hbs.tcl` during initialization (before any hbs file is sourced) sets the value of `hbs::Tool` to the value of `HBS_TOOL`.
765-
If `HBS_TOOL` is set, any call to `hbs::SetTool` is ignored.
774+
If `HBS_TOOL` is set, any call to the `hbs::SetTool` is ignored.
766775

767776
The `HBS_TOOL` environment variable is helpful in running testbench targets with different simulators.
768777
If you want to run just a single testbench target with multiple simulators, then you can use a target parameter (see @arch-target-parameters) for your testbench target, or you can set the `HBS_TOOL` environment variable.
@@ -791,7 +800,7 @@ hbs test
791800

792801
By setting the `HBS_STD` environment variable, you can enforce the value of the `hbs::Std`.
793802
If `HBS_STD` is set, then `hbs.tcl` during initialization (before any hbs file is sourced) sets the value of `hbs::Std` to the value of `HBS_STD`.
794-
If `HBS_STD` is set, any call to `hbs::SetStd` is ignored.
803+
If `HBS_STD` is set, any call to the `hbs::SetStd` is ignored.
795804

796805
The `HBS_STD` environment variable is analogous to the `HBS_TOOL` environment variable.
797806
However, running multiple, or even one, testbench targets with different HDL standard revisions is probably not useful.
@@ -801,5 +810,5 @@ The `HBS_STD` environment variable is rather handy for quickly checking if a giv
801810

802811
By setting the `HBS_BUILD_DIR` environment variable, you can enforce the value of the `hbs::BuildDir`.
803812
If `HBS_BUILD_DIR` is set, then `hbs.tcl` during initialization (before any hbs file is sourced) sets the value of `hbs::BuildDir` to the value of `HBS_BUILD_DIR`.
804-
If `HBS_BUILD_DIR` is set, any call to `hbs::SetBuildDir` is ignored.
813+
If `HBS_BUILD_DIR` is set, any call to the `hbs::SetBuildDir` is ignored.
805814
The usefulness and functionality of `HBS_BUILD_DIR` are described in @hbs-tool

user-manual/hbs-user-manual.pdf

4.96 KB
Binary file not shown.

0 commit comments

Comments
 (0)