Vasil Velichkov | 89585b3 | 2018-09-11 14:15:53 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # @file |
| 4 | # @author (C) 2018 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 | from gnuradio import gr, gr_unittest, blocks |
| 25 | import grgsm_swig as grgsm |
| 26 | import tempfile |
| 27 | |
| 28 | class qa_burst_file_sink (gr_unittest.TestCase): |
| 29 | |
| 30 | def setUp (self): |
| 31 | self.tb = gr.top_block () |
| 32 | |
| 33 | def tearDown (self): |
| 34 | self.tb = None |
| 35 | |
| 36 | def test_blob_only (self): |
| 37 | # prepare the input burst file |
| 38 | temp = tempfile.NamedTemporaryFile() |
| 39 | handle = open(temp.name, "wb") |
| 40 | handle.write(bytearray([ |
| 41 | 0x07, 0x06, 0x0a, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x01, 0x00, 0x02, 0x04, 0x03, 0x01, 0x00, 0x6f, |
| 42 | 0xcd, 0x00, 0x00, 0x25, 0xc9, 0x82, 0x06, 0x1c, 0xf5, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 43 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, |
| 44 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 45 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, |
| 46 | 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, |
| 47 | 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, |
| 48 | 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, |
| 49 | 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, |
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, |
| 51 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01 |
| 52 | ])) |
| 53 | handle.flush(); |
| 54 | |
| 55 | src = grgsm.burst_file_source(temp.name); |
| 56 | dst = grgsm.burst_sink(); |
| 57 | self.tb.msg_connect(src, "out", dst, "in") |
| 58 | self.tb.run () |
| 59 | |
| 60 | self.assertEqual([2476418], list(dst.get_framenumbers())) |
| 61 | self.assertEqual([1], list(dst.get_timeslots())) |
| 62 | self.assertEqual([ |
| 63 | "0000001000000101010111111110101000000000010101010111101010101001011011101111000101101111100000000001010101111010101010000000010101011101111010101001"], |
| 64 | list(dst.get_burst_data())) |
| 65 | |
| 66 | def test_fn_time (self): |
| 67 | # prepare the input burst file |
| 68 | temp = tempfile.NamedTemporaryFile() |
| 69 | handle = open(temp.name, "wb") |
| 70 | handle.write(bytearray([ |
| 71 | 0x07, |
| 72 | # the additional fn_time field - 51 bytes |
| 73 | 0x07, 0x07, 0x02, 0x00, 0x07, 0x66, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x07, 0x07, 0x0b, |
| 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x3b, 0x73, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 75 | 0x01, 0x07, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x3f, 0xe4, 0x99, 0x45, |
| 76 | 0xbe, 0x81, 0xc0, 0xf4, |
| 77 | # the 173 original 173 bytes |
| 78 | 0x06, 0x0a, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x01, 0x00, 0x02, 0x04, 0x03, 0x01, 0x00, 0x6f, |
| 79 | 0xcd, 0x00, 0x00, 0x25, 0xc9, 0x82, 0x06, 0x1c, 0xf5, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 80 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, |
| 81 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 82 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, |
| 83 | 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, |
| 84 | 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, |
| 85 | 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, |
| 86 | 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, |
| 87 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, |
| 88 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01 |
| 89 | ])) |
| 90 | handle.flush(); |
| 91 | |
| 92 | src = grgsm.burst_file_source(temp.name); |
| 93 | dst = grgsm.burst_sink(); |
| 94 | self.tb.msg_connect(src, "out", dst, "in") |
| 95 | self.tb.run () |
| 96 | |
| 97 | self.assertEqual([2476418], list(dst.get_framenumbers())) |
| 98 | self.assertEqual([1], list(dst.get_timeslots())) |
| 99 | self.assertEqual([ |
| 100 | "0000001000000101010111111110101000000000010101010111101010101001011011101111000101101111100000000001010101111010101010000000010101011101111010101001"], |
| 101 | list(dst.get_burst_data())) |
| 102 | |
| 103 | if __name__ == '__main__': |
| 104 | gr_unittest.run(qa_burst_file_sink, "qa_burst_file_sink.xml") |