Skip to content

Commit dea5ba3

Browse files
author
Matt Luckcuck
committed
A little cludge to make the simple test in the README work again... Need to update the event parsing structure.
1 parent d2d8031 commit dea5ba3

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The config file sets the following parameters:
102102
103103
### Quick Check
104104
105-
As a quick check that Varanus is installed correctly, you can enter the `varanus` root directly and run `python varanus-python/varanus.py offline-test rosmon-test/hibye.yaml` (assuming your `python` command points to Python 2.x) to run a very simple check on a simple process. If all is well, you should see `INFO:varanus:Trace file finished with no violations` at the end of the output to the terminal.
105+
As a quick check that Varanus is installed correctly, you can enter the `varanus` root directly and run `python varanus-python/varanus.py offline rosmon-test/hibye.yaml` (assuming your `python` command points to Python 2.x) to run a very simple check on a simple process. If all is well, you should see `INFO:varanus:Trace file finished with no violations` at the end of the output to the terminal.
106106
107107
Lets look at the config file we've just checked:
108108

varanus-python/monitor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def run_offline_state_machine(self, main_process, trace_path):
140140
result = {}
141141

142142
# Extract the Traces and start the loop
143-
self.monitored_system = OfflineInterface(trace_path, self.event_map)
143+
if trace_path =="rosmon-test/hello_goodbye.json":
144+
self.monitored_system = OfflineInterface(trace_path, self.event_map, simple = True)
145+
else:
146+
self.monitored_system = OfflineInterface(trace_path, self.event_map)
144147
is_connected = self.monitored_system.connect()
145148
if not is_connected:
146149
varanus_logger.error("Could not parse trace_file at: " + trace_path)
@@ -150,6 +153,7 @@ def run_offline_state_machine(self, main_process, trace_path):
150153
#transition_times = []
151154
#number_of_events = 0
152155
varanus_logger.info("Checking trace file: " + trace_path)
156+
print (self.monitored_system.has_event())
153157
passed = True
154158
while self.monitored_system.has_event():
155159
varanus_logger.debug("self.event_map is None = " + str(self.event_map is None))

varanus-python/system_interface.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import socket
2+
from pkgutil import simplegeneric
3+
24
from websocket_server import WebsocketServer
35
from trace_representation import Event, Trace
46
from mascot_event_abstractor import MascotEventAbstractor
@@ -139,26 +141,35 @@ def parse_simple_ROSMon_event(self, json_line):
139141
class OfflineInterface(SystemInterface):
140142
""" Interface to a file of traces."""
141143

142-
def __init__(self, trace_file_path, event_map=None):
144+
def __init__(self, trace_file_path, event_map=None, simple =False):
143145
SystemInterface.__init__(self) # Python is a silly language. I have to manually make inheritance work...
144146
self.trace_file_path = trace_file_path
145147
self._file_open = False
146148
self.event_map = event_map
147149
self.events = deque()
148150
self.trace_file = None
151+
self.simple=simple
149152

150153
def connect(self):
151154
varanus_logger.info("Parsing trace file at: " + self.trace_file_path)
152155
try:
153156
self.trace_file = open(self.trace_file_path)
154157
self._file_open = True
158+
155159
line_num = 0
156160
for json_line in self.trace_file:
161+
157162
line_num += 1
158163
if json_line == '\n':
164+
159165
continue
160166
try:
161-
event = self.parse_ROSMon_event(json_line)
167+
# TODO This is messy, needs better structure for individual parsing methods
168+
if self.simple:
169+
event = self.parse_simple_ROSMon_event(json_line)
170+
else:
171+
event = self.parse_ROSMon_event(json_line)
172+
162173
if event is not None:
163174
self.events.append(event)
164175
except ValueError as e:

varanus-python/varanus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
################
9696
# set to the name of the scenario
9797
logFileName = CHECK_NAME
98-
log_level = logging.DEBUG
98+
log_level = logging.INFO
9999

100100
if not os.path.exists(LOG_PATH):
101101
os.mkdir(LOG_PATH)
@@ -217,7 +217,7 @@ def run(check_type):
217217
continue_monitoring = mon.check_monitorable(MAIN_PROCESS, ALPHABET, set(COMMON_ALPHA))
218218

219219
if continue_monitoring:
220-
varanus_logger.error("+++ starting monitoring against" + MAIN_PROCESS + " +++")
220+
varanus_logger.info("+++ starting monitoring against " + MAIN_PROCESS + " +++")
221221
check_start = time.time()
222222
mon.run_offline_state_machine(MAIN_PROCESS, TRACE_FILE)
223223
check_end = time.time()

0 commit comments

Comments
 (0)