Coverage for test/d7a/sp/test_status.py: 91%

22 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-24 08:03 +0200

1# 

2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV. 

3# 

4# This file is part of pyd7a. 

5# See https://github.com/Sub-IoT/pyd7a for further info. 

6# 

7# Licensed under the Apache License, Version 2.0 (the "License"); 

8# you may not use this file except in compliance with the License. 

9# You may obtain a copy of the License at 

10# 

11# http://www.apache.org/licenses/LICENSE-2.0 

12# 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, 

15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

16# See the License for the specific language governing permissions and 

17# limitations under the License. 

18# 

19 

20# author: Christophe VG <contact@christophe.vg> 

21# unit tests for the D7A SP Status information 

22 

23import unittest 

24 

25from d7a.phy.channel_header import ChannelHeader, ChannelClass, ChannelCoding, ChannelBand 

26from d7a.phy.channel_id import ChannelID 

27from d7a.types.ct import CT 

28from d7a.d7anp.addressee import Addressee 

29from d7a.sp.status import Status 

30 

31class TestStatus(unittest.TestCase): 

32 valid_channel_header = ChannelHeader( 

33 channel_class=ChannelClass.NORMAL_RATE, 

34 channel_coding=ChannelCoding.PN9, 

35 channel_band=ChannelBand.BAND_433 

36 ) 

37 

38 def test_byte_generation(self): 

39 expected = [ 

40 40, # channel_header 

41 0, 16, # channel_id 

42 70, # rxlevel (- dBm) 

43 80, # link budget 

44 80, # target rx level 

45 0, # status 

46 100, # fifo token 

47 0, # seq 

48 20, # response timeout 

49 16, # addressee ctrl (NOID) 

50 0 # access class 

51 ] 

52 bytes = bytearray(Status( 

53 channel_id =ChannelID(self.valid_channel_header, channel_index=16), rx_level=70, link_budget=80, target_rx_level=80, 

54 nls=False, missed=False, retry=False, unicast=False, fifo_token=100, 

55 seq_nr=0, response_to=CT(0, 20), addressee=Addressee() 

56 )) 

57 self.assertEqual(len(bytes), 12) 

58 for i in range(10): 

59 self.assertEqual(expected[i], bytes[i]) 

60 

61 bytes = bytearray(Status( 

62 channel_id=ChannelID(channel_header=self.valid_channel_header, channel_index=16), rx_level=70, link_budget=80, target_rx_level=80, 

63 unicast=False, fifo_token=100, seq_nr=0, response_to=CT(0, 20), addressee=Addressee(), 

64 nls=True, missed=True, retry=True)) 

65 

66 expected[6] = int('11100000', 2) # nls, missed, retry, ucast 

67 self.assertEqual(len(bytes), 12) 

68 for i in range(10): 

69 self.assertEqual(expected[i], bytes[i]) 

70 

71if __name__ == '__main__': 

72 suite = unittest.TestLoader().loadTestsFromTestCase(TestStatus) 

73 unittest.TextTestRunner(verbosity=1).run(suite)