aboutsummaryrefslogtreecommitdiffstats
path: root/python/qa_burst_printer.py
blob: 15a7fc89d22965df3ee10b8bfaf58116787d6814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @file
# @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
# @section LICENSE
# 
# Gr-gsm is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# 
# Gr-gsm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with gr-gsm; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 
# 

from gnuradio import gr, gr_unittest, blocks
import grgsm_swig as grgsm
import os
import pmt
import sys
import tempfile

class qa_burst_printer (gr_unittest.TestCase):
   
    def setUp (self):
        self.tb = gr.top_block()
        self.tmpfile = tempfile.NamedTemporaryFile()
        self.prevfd = os.dup(sys.stdout.fileno())
        os.dup2(self.tmpfile.fileno(), sys.stdout.fileno())
        self.prev = sys.stdout
        sys.stdout = os.fdopen(self.prevfd, "w")
        
    def tearDown (self):
        self.tb = None
        os.dup2(self.prevfd, self.prev.fileno())
        sys.stdout = self.prev
        self.tmpfile.close()
        
    def getOutput(self):
        self.tmpfile.seek(0)
        return self.tmpfile.read()
    
    def getOutputExpected(self, expected_lines):
        out = ""
        for l in expected_lines:
            out = out + l + "\n"
        return out.encode('utf-8')

    def test_001_complete_bursts_prefix (self):
        """
            Complete bursts, without any prefix
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046]
        timeslots_input = [2, 2, 2, 2]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        expected_lines = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern(""), False, False, False, False)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
        
    def test_002_complete_bursts_prefix (self):
        """
            Complete bursts, with a string prefix
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046]
        timeslots_input = [2, 2, 2, 2]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        expected_lines = [
            "Test 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "Test 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "Test 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "Test 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern("Test "), False, False, False, False)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))

    def test_003_complete_bursts_fnr (self):
        """
            Complete bursts, no prefix, with frame number
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046]
        timeslots_input = [2, 2, 2, 2]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        expected_lines = [
            "2569043: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "2569044: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "2569045: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "2569046: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern(""), True, False, False, False)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
        
    def test_004_complete_bursts_fcount (self):
        """
            Complete bursts, no prefix, with frame count
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046]
        timeslots_input = [2, 2, 2, 2]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        expected_lines = [
            "3967625: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "3967658: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "3967691: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "3967724: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern(""), False, True, False, False)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))

    def test_005_complete_bursts_fnr_fcount (self):
        """
            Complete bursts, no prefix, with frame number and frame count
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046]
        timeslots_input = [2, 2, 2, 2]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        expected_lines = [
            "2569043 3967625: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "2569044 3967658: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "2569045 3967691: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "2569046 3967724: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern(""), True, True, False, False)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))

    def test_006_payload_prefix_fnr_fcount (self):
        """
            Payload only, no prefix, with frame number and frame count
            Bursts 4-7 are dummy bursts
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046, 1099602, 1099603, 1099604, 1099605]
        timeslots_input = [2, 2, 2, 2, 4, 4, 4, 4]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000"
            
        ]
        
        expected_lines = [
            "test_006: 2569043 3967625: 110000001001001111011111001111100000000101000111100000000100101101010000001111010100010110111101011101011100000101",
            "test_006: 2569044 3967658: 100010111110111111000001010000101101111101011111010101110110110111101101111110000011011010111011111001011101000011",
            "test_006: 2569045 3967691: 000100001111011111010101100100011000000000011011010110001001010100101011111001000111100000100000111111000000101110",
            "test_006: 2569046 3967724: 110101011111001000101011010110000001110110001111111010010111000000001010010111001111111011001000000001001000011101",
            "test_006: 1099602 1699146: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010",
            "test_006: 1099603 1699179: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010",
            "test_006: 1099604 1699212: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010",
            "test_006: 1099605 1699245: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern("test_006: "), True, True, True, False)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))

    def test_007_payload_prefix_fnr_fcount (self):
        """
            Payload only, no prefix, with frame number, frame count, and ignoring dummy bursts
            Bursts 4-7 are dummy bursts
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046, 1099602, 1099603, 1099604, 1099605]
        timeslots_input = [2, 2, 2, 2, 4, 4, 4, 4]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000"
            
        ]
        
        expected_lines = [
            "test_007: 2569043 3967625: 110000001001001111011111001111100000000101000111100000000100101101010000001111010100010110111101011101011100000101",
            "test_007: 2569044 3967658: 100010111110111111000001010000101101111101011111010101110110110111101101111110000011011010111011111001011101000011",
            "test_007: 2569045 3967691: 000100001111011111010101100100011000000000011011010110001001010100101011111001000111100000100000111111000000101110",
            "test_007: 2569046 3967724: 110101011111001000101011010110000001110110001111111010010111000000001010010111001111111011001000000001001000011101"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern("test_007: "), True, True, True, True)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
        
    def test_008_complete_prefix_fnr_fcount (self):
        """
            Complete bursts, no prefix, with frame number, frame count, and ignoring dummy bursts
            Bursts 4-7 are dummy bursts
        """
        framenumbers_input = [2569043, 2569044, 2569045, 2569046, 1099602, 1099603, 1099604, 1099605]
        timeslots_input = [2, 2, 2, 2, 4, 4, 4, 4]
        bursts_input = [
            "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
            "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000"
            
        ]
        
        expected_lines = [
            "test_008: 2569043 3967625: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
            "test_008: 2569044 3967658: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
            "test_008: 2569045 3967691: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
            "test_008: 2569046 3967724: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
        ]
        
        src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
        printer = grgsm.bursts_printer(pmt.intern("test_008: "), True, True, False, True)
        self.tb.msg_connect(src, "out", printer, "bursts")
        self.tb.run()

        self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))


if __name__ == '__main__':
    gr_unittest.run(qa_burst_printer)