Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # @file |
| 4 | # @author (C) 2019 by Vasil Velichkov <vvvelichkov@gmail.com> |
| 5 | # @section LICENSE |
| 6 | # |
| 7 | # Gr-gsm is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 3, or (at your option) |
| 10 | # any later version. |
| 11 | # |
| 12 | # Gr-gsm is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with gr-gsm; see the file COPYING. If not, write to |
| 19 | # the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | # Boston, MA 02110-1301, USA. |
| 21 | # |
| 22 | # |
| 23 | |
| 24 | import unittest |
| 25 | import numpy as np |
| 26 | from gnuradio import gr, gr_unittest, blocks |
| 27 | import grgsm |
| 28 | import pmt |
| 29 | import qa_gsm_demapper_data as test_data |
| 30 | |
| 31 | class qa_gsm_bcch_ccch_demapper (gr_unittest.TestCase): |
| 32 | |
| 33 | def setUp (self): |
| 34 | self.tb = gr.top_block () |
| 35 | self.maxDiff = None |
| 36 | |
| 37 | def tearDown (self): |
| 38 | self.tb = None |
| 39 | |
| 40 | def test_downlink (self): |
| 41 | """ |
| 42 | BCCH_CCCH demapper downlink test |
| 43 | """ |
| 44 | src = grgsm.burst_source(test_data.frames, test_data.timeslots, test_data.bursts) |
| 45 | src.set_arfcn(0); # downlink |
| 46 | demapper = grgsm.gsm_bcch_ccch_demapper(timeslot_nr=0) |
| 47 | dst = grgsm.burst_sink() |
| 48 | |
| 49 | self.tb.msg_connect(src, "out", demapper, "bursts") |
| 50 | self.tb.msg_connect(demapper, "bursts", dst, "in") |
| 51 | self.tb.run () |
| 52 | |
| 53 | b = test_data.bursts |
| 54 | self.assertEqual([ |
| 55 | b[ 2], b[ 3], b[ 4], b[ 5], #BCCH |
| 56 | b[ 6], b[ 7], b[ 8], b[ 9], #CCCH skip 10-11 |
| 57 | b[ 12], b[ 13], b[ 14], b[ 15], |
| 58 | b[ 16], b[ 17], b[ 18], b[ 19], #skip 20-21 |
| 59 | b[ 22], b[ 23], b[ 24], b[ 25], |
| 60 | b[ 26], b[ 27], b[ 28], b[ 29], #skip 30-31 |
| 61 | b[ 32], b[ 33], b[ 34], b[ 35], |
| 62 | b[ 36], b[ 37], b[ 38], b[ 39], #skip 40-41 |
| 63 | b[ 42], b[ 43], b[ 44], b[ 45], |
| 64 | b[ 46], b[ 47], b[ 48], b[ 49], #skip 50-52 |
| 65 | b[ 53], b[ 54], b[ 55], b[ 56], #BCCH |
| 66 | b[ 57], b[ 58], b[ 59], b[ 60], #CCCH skip 61-62 |
| 67 | b[ 63], b[ 64], b[ 65], b[ 66], |
| 68 | b[ 67], b[ 68], b[ 69], b[ 70], #skip 71-72 |
| 69 | b[ 73], b[ 74], b[ 75], b[ 76], |
| 70 | b[ 77], b[ 78], b[ 79], b[ 80], #skip 81-82 |
| 71 | b[ 83], b[ 84], b[ 85], b[ 86], |
| 72 | b[ 87], b[ 88], b[ 89], b[ 90], #skip 91-92 |
| 73 | b[ 93], b[ 94], b[ 95], b[ 96], |
| 74 | b[ 97], b[ 98], b[ 99], b[100], #skip 101-103 |
| 75 | b[104], b[105], b[106], b[107] #BCCH |
| 76 | ], list(dst.get_burst_data())) |
| 77 | |
| 78 | self.assertEqual([ |
| 79 | 1, 1, 1, 1, #BCCH |
| 80 | 2, 2, 2, 2, #CCCH |
| 81 | 2, 2, 2, 2, |
| 82 | 2, 2, 2, 2, |
| 83 | 2, 2, 2, 2, |
| 84 | 2, 2, 2, 2, |
| 85 | 2, 2, 2, 2, |
| 86 | 2, 2, 2, 2, |
| 87 | 2, 2, 2, 2, |
| 88 | 2, 2, 2, 2, |
| 89 | 1, 1, 1, 1, #BCCH |
| 90 | 2, 2, 2, 2, #CCCH |
| 91 | 2, 2, 2, 2, |
| 92 | 2, 2, 2, 2, |
| 93 | 2, 2, 2, 2, |
| 94 | 2, 2, 2, 2, |
| 95 | 2, 2, 2, 2, |
| 96 | 2, 2, 2, 2, |
| 97 | 2, 2, 2, 2, |
| 98 | 2, 2, 2, 2, |
| 99 | 1, 1, 1, 1, #BCCH |
| 100 | ], list(dst.get_sub_types())) |
| 101 | |
| 102 | self.assertEqual([ |
| 103 | 0, 0, 0, 0, #BCCH |
| 104 | 0, 0, 0, 0, #CCCH 0 |
| 105 | 1, 1, 1, 1, |
| 106 | 2, 2, 2, 2, |
| 107 | 3, 3, 3, 3, |
| 108 | 4, 4, 4, 4, |
| 109 | 5, 5, 5, 5, |
| 110 | 6, 6, 6, 6, |
| 111 | 7, 7, 7, 7, |
| 112 | 8, 8, 8, 8, #CCCH 8 |
| 113 | 0, 0, 0, 0, #BCCH |
| 114 | 0, 0, 0, 0, #CCCH 0 |
| 115 | 1, 1, 1, 1, |
| 116 | 2, 2, 2, 2, |
| 117 | 3, 3, 3, 3, |
| 118 | 4, 4, 4, 4, |
| 119 | 5, 5, 5, 5, |
| 120 | 6, 6, 6, 6, |
| 121 | 7, 7, 7, 7, |
| 122 | 8, 8, 8, 8, #CCCH 8 |
| 123 | 0, 0, 0, 0, #BCCH |
| 124 | ], list(dst.get_sub_slots())) |
| 125 | |
Vasil Velichkov | ff88ba4 | 2019-07-20 23:33:08 +0300 | [diff] [blame] | 126 | def test_uplink (self): |
| 127 | """ |
| 128 | BCCH_CCCH demapper uplink test |
| 129 | """ |
| 130 | src = grgsm.burst_source(test_data.frames, test_data.timeslots, test_data.bursts) |
| 131 | src.set_arfcn(0x2240); #uplink flag is 40 |
| 132 | demapper = grgsm.gsm_bcch_ccch_demapper(timeslot_nr=0) |
| 133 | dst = grgsm.burst_sink() |
| 134 | |
| 135 | self.tb.msg_connect(src, "out", demapper, "bursts") |
| 136 | self.tb.msg_connect(demapper, "bursts", dst, "in") |
| 137 | self.tb.run () |
| 138 | |
| 139 | b = test_data.bursts |
| 140 | self.assertEqual(b, list(dst.get_burst_data())) |
| 141 | self.assertEqual([3]*len(b), list(dst.get_sub_types())) |
| 142 | self.assertEqual([0]*len(b), list(dst.get_sub_slots())) |
| 143 | |
| 144 | if __name__ == '__main__': |
| 145 | gr_unittest.run(qa_gsm_bcch_ccch_demapper, "qa_gsm_bcch_ccch_demapper.xml") |