Skip to content

Commit

Permalink
Adding some timestamp checks to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PepsConti committed Oct 24, 2023
1 parent 6fd719a commit d5494ea
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_protocol_sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,24 @@ def test_protocol_sniffer(self):

# Send enough pauses to end sniffing
self.network_sdr_plugin_sender.send_raw_data(IQArray(None, np.float32, 10 * 2 * samples_per_symbol), 1)
next_msg_timestamp = time.time() # Due to simulated transmission method used in testing,
# we won't be quite precise on the first timestamp on which data will be received
time.sleep(1)

sniffer.stop()
self.assertEqual(sniffer.plain_bits_str, data)
# Validate timestamps:
for i in range(len(sniffer.messages)):
msg = sniffer.messages[i]
if i == 0:
# For the first message, we can't have much accuracy due to the simulated mechanism used to deliver data.
# Let's just verify the timestamp makes sense with following condition:
# (next_msg_timestamp < msg.timestamp && msg.timestamp < next_msg_timestamp + 1)
self.assertLess(next_msg_timestamp, msg.timestamp)
self.assertLess(msg.timestamp, next_msg_timestamp + 1)
else:
# For each message, verify the timestamp according to the theoretical calculation:
# (next_msg_timestamp - 0.0001 < msg.timestamp && msg.timestamp < next_msg_timestamp + 0.0001)
self.assertLess(next_msg_timestamp - 0.0001, msg.timestamp)
self.assertLess(msg.timestamp, next_msg_timestamp + 0.0001)
next_msg_timestamp = msg.timestamp + len(packages[i]) / modulator.sample_rate

0 comments on commit d5494ea

Please sign in to comment.