From 59a96ba8507d3399e3e877600223d1300bc00f32 Mon Sep 17 00:00:00 2001 From: Lars Asplund Date: Mon, 17 Jul 2023 11:50:54 +0200 Subject: [PATCH] Replaced no-name parameters in common log interface with VUnit-specific parameters. --- .../osvvm_integration/AlertLogPkg.vhd | 26 ++------- .../osvvm_to_vunit_common_log_pkg-body.vhd | 7 +-- .../osvvm_to_vunit_common_log_pkg.vhd | 39 ++++++++++++++ .../vunit_to_osvvm_common_log_pkg-body.vhd | 39 +++++++------- examples/vhdl/osvvm_log_integration/run.py | 2 +- .../vhdl/logging/src/common_log_pkg-body.vhd | 53 +++++++++---------- vunit/vhdl/logging/src/common_log_pkg.vhd | 41 +++++++------- vunit/vhdl/logging/src/file_pkg.vhd | 49 +++++++++++++---- .../vhdl/logging/src/log_handler_pkg-body.vhd | 33 +++++++++--- 9 files changed, 175 insertions(+), 114 deletions(-) create mode 100644 examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg.vhd diff --git a/examples/vhdl/osvvm_log_integration/osvvm_integration/AlertLogPkg.vhd b/examples/vhdl/osvvm_log_integration/osvvm_integration/AlertLogPkg.vhd index 6b0beb18c..66e453ee7 100644 --- a/examples/vhdl/osvvm_log_integration/osvvm_integration/AlertLogPkg.vhd +++ b/examples/vhdl/osvvm_log_integration/osvvm_integration/AlertLogPkg.vhd @@ -1005,12 +1005,7 @@ package body AlertLogPkg is msg => message, log_time => log_time, log_level => alert_level, - log_source_name => log_source_name, - int_1 => AlertLogJustifyAmountVar, - int_2 => error_count, - str_1 => AlertPrefixVar.Get(OSVVM_DEFAULT_ALERT_PREFIX), - str_2 => prefix, - str_3 => suffix + log_source_name => log_source_name ); end if; @@ -1021,12 +1016,7 @@ package body AlertLogPkg is msg => message, log_time => log_time, log_level => alert_level, - log_source_name => log_source_name, - int_1 => AlertLogJustifyAmountVar, - int_2 => error_count, - str_1 => AlertPrefixVar.Get(OSVVM_DEFAULT_ALERT_PREFIX), - str_2 => prefix, - str_3 => suffix + log_source_name => log_source_name ); end if; end if ; @@ -2286,11 +2276,7 @@ package body AlertLogPkg is msg => Message, log_time => log_time, log_level => log_level, - log_source_name => log_source_name, - int_1 => AlertLogJustifyAmountVar, - int_2 => error_count, - str_1 => LogPrefixVar.Get(OSVVM_DEFAULT_LOG_PREFIX), - str_3 => suffix + log_source_name => log_source_name ); end if; @@ -2301,11 +2287,7 @@ package body AlertLogPkg is msg => Message, log_time => log_time, log_level => log_level, - log_source_name => log_source_name, - int_1 => AlertLogJustifyAmountVar, - int_2 => error_count, - str_1 => LogPrefixVar.Get(OSVVM_DEFAULT_LOG_PREFIX), - str_3 => suffix + log_source_name => log_source_name ); end if; end procedure LocalLog ; diff --git a/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg-body.vhd b/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg-body.vhd index 7a86fbb85..2f4d56a31 100644 --- a/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg-body.vhd +++ b/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg-body.vhd @@ -22,10 +22,7 @@ package body common_log_pkg is msg : string := no_string; log_time : time := no_time; log_level : string := no_string; - log_source_name : string := no_string; - str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := ""; - int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8, int_9, int_10 : integer := 0; - bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false + log_source_name : string := no_string ) is constant stripped_log_level : string := strip(log_level); @@ -74,7 +71,7 @@ package body common_log_pkg is vunit_log_level := info; end if; - log(logger, msg, vunit_log_level, path_offset => 4); + log(logger, msg, vunit_log_level, path_offset => 4, line_num => 0, file_name => ""); if reenable_display_handler then set_log_handlers(osvvm, (display_handler, file_log_handler)); diff --git a/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg.vhd b/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg.vhd new file mode 100644 index 000000000..45b5859d5 --- /dev/null +++ b/examples/vhdl/osvvm_log_integration/osvvm_integration/osvvm_to_vunit_common_log_pkg.vhd @@ -0,0 +1,39 @@ +-- 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 lars.anders.asplund@gmail.com + +use std.textio.all; + +package common_log_pkg is + -- Deferred constant set to true in the native implementation of the package. + -- Must be set to false in alternative implementations. + constant is_original_pkg : boolean; + + -- Default interface values. + constant no_time : time := -1 ns; + constant no_string : string := ""; + + -- Converts a log message and associated metadata to a string written to the specified log destination. + procedure write_to_log( + ---------------------------------------------------------------------- + -- Log entry items mandatory for all implementations of this interface + ---------------------------------------------------------------------- + + -- Destination of the log message is either std.textio.output (std output) or a text file object previously opened + -- for writing + file log_destination : text; + -- Path to log_destination if it's a file, empty string otherwise + log_destination_path : string := no_string; + -- Log message + msg : string := no_string; + -- Simulation time associated with the log message + log_time : time := no_time; + -- Level associated with the log message. For example "DEBUG" or "WARNING". + log_level : string := no_string; + -- Name of the producer of the log message. Hierarchical names use colon as the delimiter. + -- For example "parent_component:child_component". + log_source_name : string := no_string + ); +end package; diff --git a/examples/vhdl/osvvm_log_integration/osvvm_integration/vunit_to_osvvm_common_log_pkg-body.vhd b/examples/vhdl/osvvm_log_integration/osvvm_integration/vunit_to_osvvm_common_log_pkg-body.vhd index dcac406d5..26139940e 100644 --- a/examples/vhdl/osvvm_log_integration/osvvm_integration/vunit_to_osvvm_common_log_pkg-body.vhd +++ b/examples/vhdl/osvvm_log_integration/osvvm_integration/vunit_to_osvvm_common_log_pkg-body.vhd @@ -36,21 +36,24 @@ package body common_log_pkg is log_time : time := no_time; log_level : string := no_string; log_source_name : string := no_string; - str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := ""; - int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8, int_9, int_10 : integer := 0; - bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false + log_source_path : string; + log_format : natural range 0 to 3; + log_source_line_number : natural; + log_sequence_number : natural; + use_color : boolean; + max_logger_name_length : natural + ) is - alias sequence_number is int_3; constant stdout : boolean := log_destination_path = no_string; constant current_mode : natural range init_mode to mirror_mode := get(mode, 0); variable reopen_transcript : boolean := false; variable enable_mirror : boolean := false; begin - if stdout and (get(last_sequence_number, stdout_idx) = sequence_number) then + if stdout and (get(last_sequence_number, stdout_idx) = log_sequence_number) then return; end if; - if not stdout and (get(last_sequence_number, file_idx) = sequence_number) then + if not stdout and (get(last_sequence_number, file_idx) = log_sequence_number) then return; end if; @@ -61,45 +64,45 @@ package body common_log_pkg is TranscriptClose; SetTranscriptMirror(false); if stdout then - set(last_sequence_number, stdout_idx, sequence_number); + set(last_sequence_number, stdout_idx, log_sequence_number); set(mode, 0, stdout_mode); else TranscriptOpen(join(get_string(run_db, "output_path"), "osvvm_transcript.txt")); - set(last_sequence_number, file_idx, sequence_number); + set(last_sequence_number, file_idx, log_sequence_number); set(mode, 0, file_mode); end if; when stdout_mode => if not stdout then TranscriptOpen(join(get_string(run_db, "output_path"), "osvvm_transcript.txt")); - set(last_sequence_number, file_idx, sequence_number); + set(last_sequence_number, file_idx, log_sequence_number); set(mode, 0, mirror_mode); - if get(last_sequence_number, stdout_idx) /= sequence_number then + if get(last_sequence_number, stdout_idx) /= log_sequence_number then SetTranscriptMirror; - set(last_sequence_number, stdout_idx, sequence_number); + set(last_sequence_number, stdout_idx, log_sequence_number); else enable_mirror := true; end if; else - set(last_sequence_number, stdout_idx, sequence_number); + set(last_sequence_number, stdout_idx, log_sequence_number); end if; when file_mode => if stdout then - set(last_sequence_number, stdout_idx, sequence_number); + set(last_sequence_number, stdout_idx, log_sequence_number); set(mode, 0, mirror_mode); - if get(last_sequence_number, file_idx) /= sequence_number then + if get(last_sequence_number, file_idx) /= log_sequence_number then SetTranscriptMirror; - set(last_sequence_number, file_idx, sequence_number); + set(last_sequence_number, file_idx, log_sequence_number); else TranscriptClose; reopen_transcript := true; end if; else - set(last_sequence_number, file_idx, sequence_number); + set(last_sequence_number, file_idx, log_sequence_number); end if; when mirror_mode => - set(last_sequence_number, stdout_idx, sequence_number); - set(last_sequence_number, file_idx, sequence_number); + set(last_sequence_number, stdout_idx, log_sequence_number); + set(last_sequence_number, file_idx, log_sequence_number); end case; if (log_level = "warning") or (log_level = "error") or (log_level = "failure") then diff --git a/examples/vhdl/osvvm_log_integration/run.py b/examples/vhdl/osvvm_log_integration/run.py index 98295e1f7..90bb67cc1 100644 --- a/examples/vhdl/osvvm_log_integration/run.py +++ b/examples/vhdl/osvvm_log_integration/run.py @@ -52,7 +52,7 @@ 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.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: diff --git a/vunit/vhdl/logging/src/common_log_pkg-body.vhd b/vunit/vhdl/logging/src/common_log_pkg-body.vhd index 51e38c6e3..300fe6a2e 100644 --- a/vunit/vhdl/logging/src/common_log_pkg-body.vhd +++ b/vunit/vhdl/logging/src/common_log_pkg-body.vhd @@ -18,19 +18,14 @@ package body common_log_pkg is log_time : time := no_time; log_level : string := no_string; log_source_name : string := no_string; - str_1, str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := ""; - int_1, int_2, int_3, int_4, int_5, int_6, int_7, int_8, int_9, int_10 : integer := 0; - bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false + log_source_path : string; + log_format : natural range 0 to 3; + log_source_line_number : natural; + log_sequence_number : natural; + use_color : boolean; + max_logger_name_length : natural ) is - alias file_name is str_1; - - alias format is int_1; - alias line_num is int_2; - alias sequence_number is int_3; - alias use_color is int_4; - alias get_max_logger_name_length is int_5; - constant max_time_str : string := time'image(1 sec); constant max_time_length : natural := max_time_str'length; @@ -53,13 +48,13 @@ package body common_log_pkg is pad(l, max_time_length - time_string'length); end if; - if use_color = 1 then + if use_color then write(l, color_start(fg => lightcyan)); end if; write(l, time_string); - if use_color = 1 then + if use_color then write(l, color_end); end if; end procedure; @@ -72,21 +67,21 @@ package body common_log_pkg is pad(l, max_level_length - level_name'length); end if; - if use_color = 1 then + if use_color then color := get_color(log_level_t'value(log_level)); write(l, color_start(fg => color.fg, bg => color.bg, style => color.style)); end if; write(l, upper(level_name)); - if use_color = 1 then + if use_color then write(l, color_end); end if; end; procedure write_source(variable l : inout line; justify : boolean := false) is begin - if use_color = 1 then + if use_color then write(l, color_start(fg => white, style => bright)); for i in log_source_name 'range loop @@ -102,20 +97,20 @@ package body common_log_pkg is write(l, log_source_name); end if; - if use_color = 1 then + if use_color then write(l, color_end); end if; if justify then - pad(l, get_max_logger_name_length - log_source_name'length); + pad(l, max_logger_name_length - log_source_name'length); end if; end; procedure write_location(variable l : inout line) is begin - if file_name /= "" then - write(l, " (" & file_name & ":" & integer'image(line_num) & ")"); + if log_source_path /= "" then + write(l, " (" & log_source_path & ":" & integer'image(log_source_line_number) & ")"); end if; end; @@ -150,15 +145,15 @@ package body common_log_pkg is variable l : line; begin - if format = raw_format then + if log_format = raw_format then write_message(l); - elsif format = level_format then + elsif log_format = level_format then write_level(l, justify => true); write(l, string'(" - ")); write_message(l, multi_line_align => true); - elsif format = verbose_format then + elsif log_format = verbose_format then write_time(l, justify => true); write(l, string'(" - ")); write_source(l, justify => true); @@ -167,19 +162,19 @@ package body common_log_pkg is write(l, string'(" - ")); write_message(l, multi_line_align => true); - elsif format = csv_format then - write(l, string'(integer'image(sequence_number) & ',')); + elsif log_format = csv_format then + write(l, string'(integer'image(log_sequence_number) & ',')); write_time(l); write(l, ','); write_level(l); write(l, ','); - if line_num = 0 then + if log_source_line_number = 0 then write(l, string'(",,")); else - write(l, file_name); + write(l, log_source_path); write(l, ','); - write(l, integer'image(line_num)); + write(l, integer'image(log_source_line_number)); write(l, ','); end if; @@ -188,7 +183,7 @@ package body common_log_pkg is write(l, msg); else - assert false report "Illegal format: " & integer'image(format) severity failure; + assert false report "Illegal format: " & integer'image(log_format) severity failure; end if; writeline(log_destination, l); end; diff --git a/vunit/vhdl/logging/src/common_log_pkg.vhd b/vunit/vhdl/logging/src/common_log_pkg.vhd index 9320f514c..b0658c0bd 100644 --- a/vunit/vhdl/logging/src/common_log_pkg.vhd +++ b/vunit/vhdl/logging/src/common_log_pkg.vhd @@ -17,9 +17,9 @@ package common_log_pkg is -- Converts a log message and associated metadata to a string written to the specified log destination. procedure write_to_log( - ---------------------------------------------------- - -- Log entry items common to many logging frameworks - ---------------------------------------------------- + ---------------------------------------------------------------------- + -- Log entry items mandatory for all implementations of this interface + ---------------------------------------------------------------------- -- Destination of the log message is either std.textio.output (std output) or a text file object previously opened -- for writing @@ -36,23 +36,22 @@ package common_log_pkg is -- For example "parent_component:child_component". log_source_name : string := no_string; - ---------------------------------------------------------------------------------------------------------------------------- - -- Log entry items less commonly used are passed to the procedure with no-name string and integer parameters which - -- meaning is specific to an implementation of the procedure. The documentation below is valid for VUnit only - ---------------------------------------------------------------------------------------------------------------------------- - - str_1, -- File name from which the log entry was issued if the location is known, empty string otherwise - - str_2, str_3, str_4, str_5, str_6, str_7, str_8, str_9, str_10 : string := ""; -- Not used - - int_1, -- Log format raw, level, verbose, or csv expressed as an integer 0 - 3. - int_2, -- Line number in file from which the log entry was issued if the location is known, 0 otherwise - int_3, -- Sequence number for log entry - int_4, -- 1 if log entry is to be in color, 0 otherwise - int_5, -- Max length of logger names (used for alignment) - - int_6, int_7, int_8, int_9, int_10 : integer := 0; -- Not used - - bool_1, bool_2, bool_3, bool_4, bool_5, bool_6, bool_7, bool_8, bool_9, bool_10 : boolean := false -- Not used + ----------------------------------------------------------------------------------------------------------------- + -- Parameters specific to an implementation of this interface. Only standard IEEE, non-custom, types are allowed. + -- The documentation below is valid for VUnit only + ----------------------------------------------------------------------------------------------------------------- + + -- Path to file from which the log entry was issued if the location is known, empty string otherwise + log_source_path : string; + -- Log format raw, level, verbose, or csv expressed as an integer 0 - 3. + log_format : natural range 0 to 3; + -- Line number in file from which the log entry was issued if the location is known, 0 otherwise + log_source_line_number : natural; + -- Sequence number for log entry + log_sequence_number : natural; + -- True if log entry is to be in color + use_color : boolean; + -- Max length of logger names (used for alignment) + max_logger_name_length : natural ); end package; diff --git a/vunit/vhdl/logging/src/file_pkg.vhd b/vunit/vhdl/logging/src/file_pkg.vhd index cf5443690..1f6b89bd7 100644 --- a/vunit/vhdl/logging/src/file_pkg.vhd +++ b/vunit/vhdl/logging/src/file_pkg.vhd @@ -31,8 +31,12 @@ package file_pkg is log_time : time; log_level : string; log_source_name : string; - str_1: string; - int_1, int_2, int_3, int_4, int_5 : integer); + log_source_path: string; + log_format : natural range 0 to 4; + log_source_line_number : natural; + log_sequence_number : natural; + use_color : boolean; + max_logger_name_length : integer); end package; @@ -225,8 +229,12 @@ package body file_pkg is log_time : time; log_level : string; log_source_name : string; - str_1: string; - int_1, int_2, int_3, int_4, int_5 : integer) is + log_source_path: string; + log_format : natural range 0 to 4; + log_source_line_number : natural; + log_sequence_number : natural; + use_color : boolean; + max_logger_name_length : integer) is constant id : natural := get(file_id.p_data, id_idx); variable name_ptr : string_ptr_t; @@ -236,14 +244,35 @@ package body file_pkg is procedure write_to_log_i(file log_destination : text) is begin if is_original_pkg then - write_to_log(log_destination, "", msg, log_time, log_level, log_source_name, int_1 => int_1, int_2 => int_2, - int_3 => int_3, int_4 => int_4, int_5 => int_5, str_1 => str_1); + write_to_log( + log_destination => log_destination, + log_destination_path => "", + msg => msg, + log_time => log_time, + log_level => log_level, + log_source_name => log_source_name, + log_source_path => log_source_path, + log_format => log_format, + log_source_line_number => log_source_line_number, + log_sequence_number => log_sequence_number, + use_color => use_color, + max_logger_name_length => max_logger_name_length + ); else write_to_log( - log_destination, - to_string(to_string_ptr(get(file_id.p_data, name_idx))), - msg, log_time, log_level, log_source_name, int_1 => int_1, int_2 => int_2, - int_3 => int_3, int_4 => int_4, int_5 => int_5, str_1 => str_1); + log_destination => log_destination, + log_destination_path => to_string(to_string_ptr(get(file_id.p_data, name_idx))), + msg => msg, + log_time => log_time, + log_level => log_level, + log_source_name => log_source_name, + log_source_path => log_source_path, + log_format => log_format, + log_source_line_number => log_source_line_number, + log_sequence_number => log_sequence_number, + use_color => use_color, + max_logger_name_length => max_logger_name_length + ); end if; end; begin diff --git a/vunit/vhdl/logging/src/log_handler_pkg-body.vhd b/vunit/vhdl/logging/src/log_handler_pkg-body.vhd index 4f9b94461..5f1a68b0d 100644 --- a/vunit/vhdl/logging/src/log_handler_pkg-body.vhd +++ b/vunit/vhdl/logging/src/log_handler_pkg-body.vhd @@ -156,15 +156,32 @@ package body log_handler_pkg is if log_file_name = null_file_name then null; elsif log_file_name = stdout_file_name then - write_to_log(OUTPUT, "", msg, log_time, log_level_t'image(log_level), logger_name, - int_1 => get(log_handler.p_data, format_idx), str_1 => file_name, - int_2 => line_num, int_3 => sequence_number, int_4 => get(log_handler.p_data, use_color_idx), - int_5 => get_max_logger_name_length(log_handler)); + write_to_log( + log_destination => OUTPUT, + log_destination_path => "", + msg => msg, + log_time => log_time, + log_level => log_level_t'image(log_level), + log_source_name => logger_name, + log_source_path => file_name, + log_format => get(log_handler.p_data, format_idx), + log_source_line_number => line_num, + log_sequence_number => sequence_number, + use_color => get(log_handler.p_data, use_color_idx) = 1, + max_logger_name_length => get_max_logger_name_length(log_handler)); else - write_to_log(to_file_id(get(log_handler.p_data, file_id_idx)), msg, log_time, log_level_t'image(log_level), logger_name, - int_1 => get(log_handler.p_data, format_idx), str_1 => file_name, - int_2 => line_num, int_3 => sequence_number, int_4 => get(log_handler.p_data, use_color_idx), - int_5 => get_max_logger_name_length(log_handler)); + write_to_log( + file_id => to_file_id(get(log_handler.p_data, file_id_idx)), + msg => msg, + log_time => log_time, + log_level => log_level_t'image(log_level), + log_source_name => logger_name, + log_source_path => file_name, + log_format => get(log_handler.p_data, format_idx), + log_source_line_number => line_num, + log_sequence_number => sequence_number, + use_color => get(log_handler.p_data, use_color_idx) = 1, + max_logger_name_length => get_max_logger_name_length(log_handler)); end if; end;