Skip to content

Commit e294a86

Browse files
authored
Update OSI submodule (#24)
* Fix typo in travis ci * Install PyYaml and update osi * Add test for the txt2osi convert in ci * Fixed indentaion * Move unit test below trace compression * Added closing file and eof if clause
1 parent ec9811a commit e294a86

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

.travis.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,45 @@ script:
4141
- pip install .
4242

4343
# Generate parsed rules
44-
python rules2yml.py -d rules
44+
- python rules2yml.py -d rules
4545

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

49-
# Check rule correctness with unittests
50-
- python -m unittest discover tests
51-
5249
# Show validator usage
5350
- osivalidator -h
5451

55-
# Run validator on a small test with already existing rules
56-
- osivalidator data/small_test.osi.lzma
57-
- osivalidator data/small_test.osi.lzma -p
58-
- osivalidator data/small_test.txt.lzma -f separated
59-
- osivalidator data/small_test.txt.lzma -f separated -p
60-
61-
# Run validator on a small test with parsed rules
62-
- osivalidator data/small_test.osi.lzma -r rules
63-
- osivalidator data/small_test.osi.lzma -p -r rules
64-
- osivalidator data/small_test.txt.lzma -f separated -r rules
65-
- osivalidator data/small_test.txt.lzma -f separated -p -r rules
66-
67-
# Decompress both traces
68-
- lzma -d data/small_test.osi.lzma
52+
# Convert decompress small_test.txt and convert to small_test.osi
6953
- lzma -d data/small_test.txt.lzma
54+
- python open-simulation-interface/format/txt2osi.py -d data/small_test.txt
7055

7156
# Run the validator on decompressed data
7257
- osivalidator data/small_test.osi
7358
- osivalidator data/small_test.osi -p
7459
- osivalidator data/small_test.txt -f separated
75-
- osivalidator data/small_test.txt -f separated -p
60+
- osivalidator data/small_test.txt -f separated -p
7661

7762
# Run the validator on decompressed data with parsed rules
7863
- osivalidator data/small_test.osi -r rules
7964
- osivalidator data/small_test.osi -p -r rules
8065
- osivalidator data/small_test.txt -f separated -r rules
8166
- osivalidator data/small_test.txt -f separated -p -r rules
67+
68+
# Compress *.osi and *.txt with lzma
69+
- lzma -z data/small_test.txt
70+
- lzma -z data/small_test.osi
71+
72+
# Check rule correctness with unittests
73+
- python -m unittest discover tests
74+
75+
# Run validator on a small test with already existing rules
76+
- osivalidator data/small_test.osi.lzma
77+
- osivalidator data/small_test.osi.lzma -p
78+
- osivalidator data/small_test.txt.lzma -f separated
79+
- osivalidator data/small_test.txt.lzma -f separated -p
80+
81+
# Run validator on a small test with parsed rules
82+
- osivalidator data/small_test.osi.lzma -r rules
83+
- osivalidator data/small_test.osi.lzma -p -r rules
84+
- osivalidator data/small_test.txt.lzma -f separated -r rules
85+
- osivalidator data/small_test.txt.lzma -f separated -p -r rules

data/small_test.osi.lzma

Lines changed: 0 additions & 3 deletions
This file was deleted.

osivalidator/osi_general_validator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,15 @@ def main():
167167
except Exception as e:
168168
print(str(e))
169169

170-
LOGGER.flush(LOGS)
170+
LOGGER.flush(LOGS)
171171
MESSAGE_CACHE.clear()
172172

173173
BAR.finish()
174-
175-
# Grab major OSI version
174+
DATA.trace_file.close()
176175

177176
# Synthetize
178177
LOGGER.synthetize_results_from_sqlite()
179178

180-
181179
def close_pool(pool):
182180
"""Cleanly close a pool to free the memory"""
183181
pool.close()

osivalidator/osi_trace.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ def __init__(self, buffer_size, show_progress=True, path=None, type_name="Sensor
5353
self.show_progress = show_progress
5454
self.retrieved_trace_size = 0
5555

56-
if path is not None and type_name is not None:
57-
self.from_file(path)
58-
5956
# Open and Read text file
6057
def from_file(self, path, type_name="SensorView", max_index=-1, format_type=None):
6158
"""Import a trace from a file"""
@@ -101,7 +98,7 @@ def retrieve_message(self):
10198
counter = 0 # Counter is needed to enable correct buffer parsing of serialized messages
10299

103100
# Check if user decided to use buffer
104-
if self.buffer_size != 0 and type(self.buffer_size)==int:
101+
if self.buffer_size != 0 and type(self.buffer_size) == int:
105102

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

116113
# Get the message offset of the next message
117-
message_offset += message_length + self._int_length
118-
114+
message_offset += message_length + self._int_length
119115
self.message_offsets.append(message_offset)
120116
self.update_bar(progress_bar, message_offset)
121117
before_tell = self.trace_file.tell()
122118
self.trace_file.seek(message_offset)
123119
after_tell = self.trace_file.tell()
124120
eof = self.trace_file.tell() > self.buffer_size * (counter + 1)
125121

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

133128
while eof:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
install_requires=[
3737
'iso3166',
3838
'ruamel.yaml',
39+
'PyYaml',
3940
'asteval',
4041
'sphinx_rtd_theme',
4142
'recommonmark',

0 commit comments

Comments
 (0)