Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,45 @@ script:
- pip install .

# Generate parsed rules
python rules2yml.py -d rules
- python rules2yml.py -d rules

# Check if rule syntax in osi is correct
# - python test_cases.py

# Check rule correctness with unittests
- python -m unittest discover tests

# Show validator usage
- osivalidator -h

# Run validator on a small test with already existing rules
- osivalidator data/small_test.osi.lzma
- osivalidator data/small_test.osi.lzma -p
- osivalidator data/small_test.txt.lzma -f separated
- osivalidator data/small_test.txt.lzma -f separated -p

# Run validator on a small test with parsed rules
- osivalidator data/small_test.osi.lzma -r rules
- osivalidator data/small_test.osi.lzma -p -r rules
- osivalidator data/small_test.txt.lzma -f separated -r rules
- osivalidator data/small_test.txt.lzma -f separated -p -r rules

# Decompress both traces
- lzma -d data/small_test.osi.lzma
# Convert decompress small_test.txt and convert to small_test.osi
- lzma -d data/small_test.txt.lzma
- python open-simulation-interface/format/txt2osi.py -d data/small_test.txt

# Run the validator on decompressed data
- osivalidator data/small_test.osi
- osivalidator data/small_test.osi -p
- osivalidator data/small_test.txt -f separated
- osivalidator data/small_test.txt -f separated -p
- osivalidator data/small_test.txt -f separated -p

# Run the validator on decompressed data with parsed rules
- osivalidator data/small_test.osi -r rules
- osivalidator data/small_test.osi -p -r rules
- osivalidator data/small_test.txt -f separated -r rules
- osivalidator data/small_test.txt -f separated -p -r rules

# Compress *.osi and *.txt with lzma
- lzma -z data/small_test.txt
- lzma -z data/small_test.osi

# Check rule correctness with unittests
- python -m unittest discover tests

# Run validator on a small test with already existing rules
- osivalidator data/small_test.osi.lzma
- osivalidator data/small_test.osi.lzma -p
- osivalidator data/small_test.txt.lzma -f separated
- osivalidator data/small_test.txt.lzma -f separated -p

# Run validator on a small test with parsed rules
- osivalidator data/small_test.osi.lzma -r rules
- osivalidator data/small_test.osi.lzma -p -r rules
- osivalidator data/small_test.txt.lzma -f separated -r rules
- osivalidator data/small_test.txt.lzma -f separated -p -r rules
3 changes: 0 additions & 3 deletions data/small_test.osi.lzma

This file was deleted.

6 changes: 2 additions & 4 deletions osivalidator/osi_general_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,15 @@ def main():
except Exception as e:
print(str(e))

LOGGER.flush(LOGS)
LOGGER.flush(LOGS)
MESSAGE_CACHE.clear()

BAR.finish()

# Grab major OSI version
DATA.trace_file.close()

# Synthetize
LOGGER.synthetize_results_from_sqlite()


def close_pool(pool):
"""Cleanly close a pool to free the memory"""
pool.close()
Expand Down
15 changes: 5 additions & 10 deletions osivalidator/osi_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def __init__(self, buffer_size, show_progress=True, path=None, type_name="Sensor
self.show_progress = show_progress
self.retrieved_trace_size = 0

if path is not None and type_name is not None:
self.from_file(path)

# Open and Read text file
def from_file(self, path, type_name="SensorView", max_index=-1, format_type=None):
"""Import a trace from a file"""
Expand Down Expand Up @@ -101,7 +98,7 @@ def retrieve_message(self):
counter = 0 # Counter is needed to enable correct buffer parsing of serialized messages

# Check if user decided to use buffer
if self.buffer_size != 0 and type(self.buffer_size)==int:
if self.buffer_size != 0 and type(self.buffer_size) == int:

# Run while the end of file is not reached
while not eof and message_offset < trace_size:
Expand All @@ -114,20 +111,18 @@ def retrieve_message(self):
message_length = struct.unpack("<L", serialized_message[message_offset-counter*self.buffer_size:self._int_length+message_offset-counter*self.buffer_size])[0]

# Get the message offset of the next message
message_offset += message_length + self._int_length

message_offset += message_length + self._int_length
self.message_offsets.append(message_offset)
self.update_bar(progress_bar, message_offset)
before_tell = self.trace_file.tell()
self.trace_file.seek(message_offset)
after_tell = self.trace_file.tell()
eof = self.trace_file.tell() > self.buffer_size * (counter + 1)

# Check if the last INT (length=4) is found and then exit
if after_tell - before_tell == self._int_length:
# Check if reached end of file
if self.trace_file.tell() == trace_size:
self.retrieved_trace_size = self.message_offsets[-1]
self.message_offsets.pop() # Remove the last element since after that there is no message coming
self.trace_file.seek(trace_size) # Set the cursor to the end of the file
self.message_offsets.pop() # Remove the last element since after that there is no message coming
break

while eof:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
install_requires=[
'iso3166',
'ruamel.yaml',
'PyYaml',
'asteval',
'sphinx_rtd_theme',
'recommonmark',
Expand Down