summaryrefslogtreecommitdiffstats
path: root/src/target
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-06-22 23:27:23 +0700
committerfixeria <axilirator@gmail.com>2019-06-24 14:18:09 +0000
commit7a007e82a8a855b5967ffc3edcfc82bbdbe73edc (patch)
tree417b3a837ba81c98809627e88a9cd54da27ccca6 /src/target
parent4269c4d00b80862cf6e92bf0fc5c3809fe5cac59 (diff)
trx_toolkit/data_msg.py: tests: use random reference data
Having fn = 1024 and tn = 0 in all tests decreases the chances to spot encoding / decoding bugs of higher or lower values. Let's randomize the reference data before all the tests. Change-Id: Id3c5be9faaf0bef727b975c7182098af0cec6e71
Diffstat (limited to 'src/target')
-rw-r--r--src/target/trx_toolkit/data_msg.py41
1 files changed, 14 insertions, 27 deletions
diff --git a/src/target/trx_toolkit/data_msg.py b/src/target/trx_toolkit/data_msg.py
index da109d9..5cfb745 100644
--- a/src/target/trx_toolkit/data_msg.py
+++ b/src/target/trx_toolkit/data_msg.py
@@ -432,10 +432,6 @@ if __name__ == '__main__':
log.basicConfig(level = log.DEBUG,
format = "[%(levelname)s] %(filename)s:%(lineno)d %(message)s")
- # Common reference data
- fn = 1024
- tn = 0
-
# Generate two random bursts
burst_l12trx_ref = []
burst_trx2l1_ref = []
@@ -450,17 +446,18 @@ if __name__ == '__main__':
log.info("Generating the reference messages")
# Create messages of both types
- msg_l12trx_ref = DATAMSG_L12TRX(fn = fn, tn = tn)
- msg_trx2l1_ref = DATAMSG_TRX2L1(fn = fn, tn = tn)
+ msg_l12trx_ref = DATAMSG_L12TRX(burst = burst_l12trx_ref)
+ msg_trx2l1_ref = DATAMSG_TRX2L1(burst = burst_trx2l1_ref)
+
+ # Validate header randomization
+ for i in range(0, 100):
+ msg_l12trx_ref.rand_hdr()
+ msg_trx2l1_ref.rand_hdr()
- # Fill in message specific fields
- msg_trx2l1_ref.rssi = -88
- msg_l12trx_ref.pwr = 0x33
- msg_trx2l1_ref.toa256 = -256
+ assert(msg_l12trx_ref.validate())
+ assert(msg_trx2l1_ref.validate())
- # Specify the reference bursts
- msg_l12trx_ref.burst = burst_l12trx_ref
- msg_trx2l1_ref.burst = burst_trx2l1_ref
+ log.info("Validate header randomization: OK")
log.info("Encoding the reference messages")
@@ -493,10 +490,10 @@ if __name__ == '__main__':
log.info("Compare bursts: OK")
# Compare both parsed messages with the reference data
- assert(msg_l12trx_dec.fn == fn)
- assert(msg_trx2l1_dec.fn == fn)
- assert(msg_l12trx_dec.tn == tn)
- assert(msg_trx2l1_dec.tn == tn)
+ assert(msg_l12trx_dec.fn == msg_l12trx_ref.fn)
+ assert(msg_trx2l1_dec.fn == msg_trx2l1_ref.fn)
+ assert(msg_l12trx_dec.tn == msg_l12trx_ref.tn)
+ assert(msg_trx2l1_dec.tn == msg_trx2l1_ref.tn)
log.info("Compare FN / TN: OK")
@@ -507,16 +504,6 @@ if __name__ == '__main__':
log.info("Compare message specific data: OK")
- # Validate header randomization
- for i in range(0, 100):
- msg_l12trx_ref.rand_hdr()
- msg_trx2l1_ref.rand_hdr()
-
- assert(msg_l12trx_ref.validate())
- assert(msg_trx2l1_ref.validate())
-
- log.info("Validate header randomization: OK")
-
# Bit conversation test
usbits_ref = list(range(0, 256))
sbits_ref = list(range(-127, 128))