Class: OrigenSim::StdoutReader
- Inherits:
-
Thread
- Object
- Thread
- OrigenSim::StdoutReader
- Defined in:
- lib/origen_sim/stdout_reader.rb
Instance Attribute Summary collapse
-
#logged_errors ⇒ Object
readonly
Returns the value of attribute logged_errors.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(socket, simulator) ⇒ StdoutReader
constructor
A new instance of StdoutReader.
- #stop ⇒ Object
- #time_since_last_message ⇒ Object
Constructor Details
#initialize(socket, simulator) ⇒ StdoutReader
Returns a new instance of StdoutReader.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/origen_sim/stdout_reader.rb', line 6 def initialize(socket, simulator) @socket = socket @continue = true @logged_errors = false @last_message_at = Time.now super do begin line = nil while @continue loop do out = @socket.gets break if out.nil? unless !line || line.empty? # If there's already stuff in the current line, # remove the VPI cruft and leave just the remainder of the message. out = out.split(' ', 2)[-1] end line ||= '' if out.chomp.end_with?(OrigenSim::Simulator::MULTIPART_LOGGER_TOKEN) # Part of a multipart message. Add this to the current line # and grab the next piece. line += out.chomp.gsub(OrigenSim::Simulator::MULTIPART_LOGGER_TOKEN, '') else # Either a single message or the end of a multi-part message. # Add this to the line break to print the output to the console. line += out break end end if line line = line.chomp # If line has been sent from Origen for logging # https://rubular.com/r/1czQZnlhBq9YtK if line =~ /^!(\d)!\[\s*((\d+),)?\s*(\d+)\]\s*(.*)/ if Regexp.last_match(3) time_in_sim_units = (Regexp.last_match(3).to_i << 32) | Regexp.last_match(4).to_i time_in_ns = simulator.send(:simtime_units_to_ns, time_in_sim_units) else # Messages sent from the Origen testbench already have a timestamp in ns time_in_ns = Regexp.last_match(4).to_i end msg = "#{time_in_ns}".rjust(11) + ' ns: ' + Regexp.last_match(5) Origen.log.send(Simulator::LOG_CODES_[Regexp.last_match(1).to_i], msg, from_origen_sim: true) simulator.send(:max_error_abort) if line =~ /!MAX_ERROR_ABORT!/ else if OrigenSim.error_strings.any? { |s| s.is_a?(Regexp) ? s.match?(line) : line =~ /#{s}/i } && !OrigenSim.error_string_exceptions.any? { |s| s.is_a?(Regexp) ? s.match?(line) : line =~ /#{s}/i } @logged_errors = true Origen.log.error "(STDOUT): #{line}", from_origen_sim: true elsif OrigenSim.warning_strings.any? { |s| s.is_a?(Regexp) ? s.match?(line) : line =~ /#{s}/i } && !OrigenSim.warning_string_exceptions.any? { |s| s.is_a?(Regexp) ? s.match?(line) : line =~ /#{s}/i } Origen.log.warn line, from_origen_sim: true else if OrigenSim.verbose? || OrigenSim.log_strings.any? { |s| s.is_a?(Regexp) ? s.match?(line) : line =~ /#{s}/i } Origen.log.info line, from_origen_sim: true else Origen.log.debug line, from_origen_sim: true end end end line = nil @last_message_at = Time.now end end rescue IOError => e unless e. =~ /stream closed/ raise e end end end end |
Instance Attribute Details
#logged_errors ⇒ Object (readonly)
Returns the value of attribute logged_errors.
4 5 6 |
# File 'lib/origen_sim/stdout_reader.rb', line 4 def logged_errors @logged_errors end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
4 5 6 |
# File 'lib/origen_sim/stdout_reader.rb', line 4 def socket @socket end |
Instance Method Details
#stop ⇒ Object
84 85 86 |
# File 'lib/origen_sim/stdout_reader.rb', line 84 def stop @continue = false end |
#time_since_last_message ⇒ Object
88 89 90 |
# File 'lib/origen_sim/stdout_reader.rb', line 88 def Time.now - @last_message_at end |