-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a common low-level log interface
- Loading branch information
1 parent
8fcbf59
commit 37fd6b3
Showing
16 changed files
with
6,460 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5,841 changes: 5,841 additions & 0 deletions
5,841
examples/vhdl/osvvm_log_integration/osvvm_integration/AlertLogPkg.vhd
Large diffs are not rendered by default.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg-body.vhd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
|
||
library vunit_lib; | ||
context vunit_lib.vunit_context; | ||
|
||
package body common_log_pkg is | ||
procedure write_to_log( | ||
file log_destination : text; | ||
msg : string := ""; | ||
log_time : time := no_time; | ||
log_level : string := ""; | ||
log_source_name : string := ""; | ||
str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := ""; | ||
val_1, val_2, val_3, val_4, val_5, val_6, val_7, val_8, val_9, val_10 : integer := no_val | ||
) is | ||
constant stripped_log_level : string := strip(log_level); | ||
|
||
alias prefix is str_2; | ||
alias suffix is str_3; | ||
|
||
variable logger : logger_t; | ||
variable vunit_log_level : log_level_t; | ||
variable full_msg : line; | ||
begin | ||
logger := get_logger(log_source_name); | ||
|
||
if stripped_log_level = "WARNING" then | ||
vunit_log_level := warning; | ||
elsif stripped_log_level = "ERROR" then | ||
vunit_log_level := error; | ||
elsif stripped_log_level = "FAILURE" then | ||
vunit_log_level := failure; | ||
elsif stripped_log_level = "DEBUG" then | ||
vunit_log_level := debug; | ||
elsif stripped_log_level = "PASSED" then | ||
vunit_log_level := pass; | ||
else | ||
vunit_log_level := info; | ||
end if; | ||
|
||
if prefix /= "" then | ||
write(full_msg, prefix & " "); | ||
end if; | ||
|
||
write(full_msg, msg); | ||
|
||
if suffix /= "" then | ||
write(full_msg, " " & suffix); | ||
end if; | ||
|
||
log(logger, msg, vunit_log_level, path_offset => 4); | ||
end; | ||
|
||
end package body; |
37 changes: 37 additions & 0 deletions
37
examples/vhdl/osvvm_log_integration/osvvm_integration/vunit_to_osvvm_common_log_pkg-body.vhd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
|
||
use work.ansi_pkg.all; | ||
use work.log_levels_pkg.all; | ||
use work.string_ops.upper; | ||
|
||
library osvvm; | ||
use osvvm.AlertLogPkg.all; | ||
|
||
package body common_log_pkg is | ||
|
||
procedure write_to_log( | ||
file log_destination : text; | ||
msg : string := ""; | ||
log_time : time := no_time; | ||
log_level : string := ""; | ||
log_source_name : string := ""; | ||
str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := ""; | ||
val_1, val_2, val_3, val_4, val_5, val_6, val_7, val_8, val_9, val_10 : integer := no_val | ||
) is | ||
begin | ||
if (log_level = "warning") or (log_level = "error") or (log_level = "failure") then | ||
Alert(GetAlertLogID(log_source_name), msg, AlertType'value(upper(log_level))); | ||
elsif (log_level = "debug") then | ||
osvvm.AlertLogPkg.Log(GetAlertLogID(log_source_name), msg, DEBUG); | ||
elsif (log_level = "pass") then | ||
osvvm.AlertLogPkg.Log(GetAlertLogID(log_source_name), msg, PASSED); | ||
else | ||
osvvm.AlertLogPkg.Log(GetAlertLogID(log_source_name), msg); | ||
end if; | ||
end; | ||
|
||
end package body; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
|
||
from pathlib import Path | ||
from itertools import product | ||
from vunit import VUnit, VUnitCLI | ||
|
||
cli = VUnitCLI() | ||
cli.parser.add_argument( | ||
"--use-osvvm-log", | ||
action="store_true", | ||
default=False, | ||
help="Re-direct VUnit log output to OSVVM log handling", | ||
) | ||
cli.parser.add_argument( | ||
"--use-vunit-log", | ||
action="store_true", | ||
default=False, | ||
help="Re-direct OSVVM log output to VUnit log handling", | ||
) | ||
args = cli.parse_args() | ||
if args.use_osvvm_log and args.use_vunit_log: | ||
raise RuntimeError("Only one of --use-osvvm-log and --use-vunit-log can be used at any time.") | ||
args.clean = True | ||
prj = VUnit.from_args(args=args) | ||
root = Path(__file__).parent | ||
if args.use_osvvm_log: | ||
prj.add_vhdl_builtins(use_external_log=Path(root / "osvvm_integration" / "vunit_to_osvvm_common_log_pkg-body.vhd")) | ||
else: | ||
prj.add_vhdl_builtins() | ||
|
||
lib = prj.add_library("lib") | ||
lib.add_source_files(root / "*.vhd") | ||
lib.test_bench("tb_example").set_generic("use_osvvm_log", args.use_osvvm_log) | ||
lib.test_bench("tb_example").set_generic("use_vunit_log", args.use_vunit_log) | ||
|
||
osvvm = prj.add_library("osvvm") | ||
osvvm_files_to_compile = [ | ||
"NamePkg.vhd", | ||
"OsvvmGlobalPkg.vhd", | ||
"TranscriptPkg.vhd", | ||
"TextUtilPkg.vhd", | ||
"OsvvmScriptSettingsPkg.vhd", | ||
"OsvvmScriptSettingsPkg_default.vhd", | ||
] | ||
for osvvm_file in osvvm_files_to_compile: | ||
osvvm.add_source_files(root / ".." / ".." / ".." / "vunit" / "vhdl" / "osvvm" / osvvm_file) | ||
|
||
if args.use_vunit_log: | ||
osvvm.add_source_files(root / ".." / ".." / ".." / "vunit" / "vhdl" / "logging" / "src" / "common_log_pkg.vhd") | ||
osvvm.add_source_files(root / "osvvm_integration" / "osvvm_to_vunit_common_log_pkg-body.vhd") | ||
osvvm.add_source_files(root / "osvvm_integration" / "AlertLogPkg.vhd") | ||
else: | ||
osvvm.add_source_files(root / ".." / ".." / ".." / "vunit" / "vhdl" / "osvvm" / "AlertLogPkg.vhd") | ||
|
||
|
||
prj.set_compile_option("rivierapro.vcom_flags", ["-dbg"]) | ||
prj.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
-- You can obtain one at http://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright (c) 2014-2023, Lars Asplund [email protected] | ||
|
||
library vunit_lib; | ||
context vunit_lib.vunit_context; | ||
|
||
library osvvm; | ||
use osvvm.AlertLogPkg.all; | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
|
||
entity tb_example is | ||
generic ( | ||
runner_cfg : string; | ||
use_osvvm_log : boolean; | ||
use_vunit_log : boolean); | ||
end entity; | ||
|
||
architecture tb of tb_example is | ||
|
||
begin | ||
main : process | ||
constant logger : logger_t := get_logger("A VUnit logger name"); | ||
constant parent_logger : logger_t := get_logger("VUnit parent"); | ||
constant child_logger : logger_t := get_logger("VUnit child", parent_logger); | ||
constant checker : checker_t := new_checker(logger); | ||
|
||
constant id : AlertLogIDType := GetAlertLogID("An OSVVM ID"); | ||
constant parent_id : AlertLogIDType := GetAlertLogID("OSVVM parent"); | ||
constant child_id : AlertLogIDType := GetAlertLogID("OSVVM child", parent_id); | ||
begin | ||
test_runner_setup(runner, runner_cfg); | ||
set_stop_level(failure); | ||
|
||
if use_osvvm_log then | ||
print(LF & "-------------------------------------------------------------------"); | ||
print("This is what VUnit log messages look like when piped through OSVVM:"); | ||
print("-------------------------------------------------------------------" & LF); | ||
else | ||
print(LF & "------------------------------------------------------------------------"); | ||
print("This is what standard VUnit log messages look like. Call run.py"); | ||
print("with --use-osvvm-log to see what is looks like when piped through OSVVM."); | ||
print("------------------------------------------------------------------------" & LF); | ||
end if; | ||
|
||
info(logger, "Hello from VUnit"); | ||
check(checker, false, "An error from VUnit"); | ||
info(child_logger, "Hello from VUnit hierarchy"); | ||
|
||
if use_vunit_log then | ||
print(LF & "-------------------------------------------------------------------"); | ||
print("This is what OSVVM log messages look like when piped through VUnit:"); | ||
print("-------------------------------------------------------------------" & LF); | ||
else | ||
print(LF & "------------------------------------------------------------------------"); | ||
print("This is what standard OSVVM log messages look like. Call run.py"); | ||
print("with --use-vunit-log to see what is looks like when piped through VUnit."); | ||
print("------------------------------------------------------------------------" & LF); | ||
end if; | ||
|
||
osvvm.AlertLogPkg.Log(id, "Hello from OSVVM"); | ||
Alert(id, "An error from OSVVM"); | ||
osvvm.AlertLogPkg.Log(child_id, "Hello from OSVVM hierarchy"); | ||
|
||
if use_osvvm_log then | ||
print(LF & "------------------------------------------------------------------------"); | ||
print("Only log messages are piped through OSVVM. Print messages outside of the"); | ||
print("the logging framework are unaffected. For example this FAILURE"); | ||
print("message."); | ||
print("------------------------------------------------------------------------" & LF); | ||
else | ||
print(LF & ""); | ||
end if; | ||
|
||
test_runner_cleanup(runner); | ||
end process; | ||
|
||
test_runner_watchdog(runner, 1000 ns); | ||
|
||
|
||
end architecture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.