blob: 15a7fc89d22965df3ee10b8bfaf58116787d6814 [file] [log] [blame]
Roman Khassrafb94cc812015-07-25 14:30:28 +02001#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004# @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassrafb94cc812015-07-25 14:30:28 +02005# @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
24from gnuradio import gr, gr_unittest, blocks
Piotr Krysik5c7b3742016-06-21 07:12:32 +020025import grgsm_swig as grgsm
Roman Khassrafb94cc812015-07-25 14:30:28 +020026import os
27import pmt
28import sys
29import tempfile
30
31class qa_burst_printer (gr_unittest.TestCase):
32
33 def setUp (self):
34 self.tb = gr.top_block()
35 self.tmpfile = tempfile.NamedTemporaryFile()
36 self.prevfd = os.dup(sys.stdout.fileno())
37 os.dup2(self.tmpfile.fileno(), sys.stdout.fileno())
38 self.prev = sys.stdout
39 sys.stdout = os.fdopen(self.prevfd, "w")
40
41 def tearDown (self):
42 self.tb = None
43 os.dup2(self.prevfd, self.prev.fileno())
44 sys.stdout = self.prev
45 self.tmpfile.close()
46
47 def getOutput(self):
48 self.tmpfile.seek(0)
49 return self.tmpfile.read()
50
51 def getOutputExpected(self, expected_lines):
52 out = ""
53 for l in expected_lines:
54 out = out + l + "\n"
Vasil Velichkov1789ae22019-08-13 20:32:05 +000055 return out.encode('utf-8')
Roman Khassrafb94cc812015-07-25 14:30:28 +020056
57 def test_001_complete_bursts_prefix (self):
58 """
59 Complete bursts, without any prefix
60 """
61 framenumbers_input = [2569043, 2569044, 2569045, 2569046]
62 timeslots_input = [2, 2, 2, 2]
63 bursts_input = [
64 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
65 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
66 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
67 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
68 ]
69
70 expected_lines = [
71 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
72 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
73 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
74 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
75 ]
76
Roman Khassraff163ca52015-08-05 12:58:00 +020077 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +020078 printer = grgsm.bursts_printer(pmt.intern(""), False, False, False, False)
79 self.tb.msg_connect(src, "out", printer, "bursts")
80 self.tb.run()
81
82 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
83
84 def test_002_complete_bursts_prefix (self):
85 """
86 Complete bursts, with a string prefix
87 """
88 framenumbers_input = [2569043, 2569044, 2569045, 2569046]
89 timeslots_input = [2, 2, 2, 2]
90 bursts_input = [
91 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
92 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
93 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
94 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
95 ]
96
97 expected_lines = [
98 "Test 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
99 "Test 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
100 "Test 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
101 "Test 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
102 ]
103
Roman Khassraff163ca52015-08-05 12:58:00 +0200104 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200105 printer = grgsm.bursts_printer(pmt.intern("Test "), False, False, False, False)
106 self.tb.msg_connect(src, "out", printer, "bursts")
107 self.tb.run()
108
109 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
110
111 def test_003_complete_bursts_fnr (self):
112 """
113 Complete bursts, no prefix, with frame number
114 """
115 framenumbers_input = [2569043, 2569044, 2569045, 2569046]
116 timeslots_input = [2, 2, 2, 2]
117 bursts_input = [
118 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
119 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
120 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
121 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
122 ]
123
124 expected_lines = [
125 "2569043: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
126 "2569044: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
127 "2569045: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
128 "2569046: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
129 ]
130
Roman Khassraff163ca52015-08-05 12:58:00 +0200131 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200132 printer = grgsm.bursts_printer(pmt.intern(""), True, False, False, False)
133 self.tb.msg_connect(src, "out", printer, "bursts")
134 self.tb.run()
135
136 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
137
138 def test_004_complete_bursts_fcount (self):
139 """
140 Complete bursts, no prefix, with frame count
141 """
142 framenumbers_input = [2569043, 2569044, 2569045, 2569046]
143 timeslots_input = [2, 2, 2, 2]
144 bursts_input = [
145 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
146 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
147 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
148 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
149 ]
150
151 expected_lines = [
152 "3967625: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
153 "3967658: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
154 "3967691: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
155 "3967724: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
156 ]
157
Roman Khassraff163ca52015-08-05 12:58:00 +0200158 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200159 printer = grgsm.bursts_printer(pmt.intern(""), False, True, False, False)
160 self.tb.msg_connect(src, "out", printer, "bursts")
161 self.tb.run()
162
163 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
164
165 def test_005_complete_bursts_fnr_fcount (self):
166 """
167 Complete bursts, no prefix, with frame number and frame count
168 """
169 framenumbers_input = [2569043, 2569044, 2569045, 2569046]
170 timeslots_input = [2, 2, 2, 2]
171 bursts_input = [
172 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
173 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
174 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
175 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
176 ]
177
178 expected_lines = [
179 "2569043 3967625: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
180 "2569044 3967658: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
181 "2569045 3967691: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
182 "2569046 3967724: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
183 ]
184
Roman Khassraff163ca52015-08-05 12:58:00 +0200185 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200186 printer = grgsm.bursts_printer(pmt.intern(""), True, True, False, False)
187 self.tb.msg_connect(src, "out", printer, "bursts")
188 self.tb.run()
189
190 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
191
192 def test_006_payload_prefix_fnr_fcount (self):
193 """
194 Payload only, no prefix, with frame number and frame count
195 Bursts 4-7 are dummy bursts
196 """
197 framenumbers_input = [2569043, 2569044, 2569045, 2569046, 1099602, 1099603, 1099604, 1099605]
198 timeslots_input = [2, 2, 2, 2, 4, 4, 4, 4]
199 bursts_input = [
200 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
201 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
202 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
203 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000",
204 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
205 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
206 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
207 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000"
208
209 ]
210
211 expected_lines = [
212 "test_006: 2569043 3967625: 110000001001001111011111001111100000000101000111100000000100101101010000001111010100010110111101011101011100000101",
213 "test_006: 2569044 3967658: 100010111110111111000001010000101101111101011111010101110110110111101101111110000011011010111011111001011101000011",
214 "test_006: 2569045 3967691: 000100001111011111010101100100011000000000011011010110001001010100101011111001000111100000100000111111000000101110",
215 "test_006: 2569046 3967724: 110101011111001000101011010110000001110110001111111010010111000000001010010111001111111011001000000001001000011101",
216 "test_006: 1099602 1699146: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010",
217 "test_006: 1099603 1699179: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010",
218 "test_006: 1099604 1699212: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010",
219 "test_006: 1099605 1699245: 111110110111011000001010010011100000100100010000000111110111010010100011001100111001111010011111000100101111101010"
220 ]
221
Roman Khassraff163ca52015-08-05 12:58:00 +0200222 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200223 printer = grgsm.bursts_printer(pmt.intern("test_006: "), True, True, True, False)
224 self.tb.msg_connect(src, "out", printer, "bursts")
225 self.tb.run()
226
227 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
228
229 def test_007_payload_prefix_fnr_fcount (self):
230 """
231 Payload only, no prefix, with frame number, frame count, and ignoring dummy bursts
232 Bursts 4-7 are dummy bursts
233 """
234 framenumbers_input = [2569043, 2569044, 2569045, 2569046, 1099602, 1099603, 1099604, 1099605]
235 timeslots_input = [2, 2, 2, 2, 4, 4, 4, 4]
236 bursts_input = [
237 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
238 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
239 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
240 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000",
241 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
242 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
243 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
244 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000"
245
246 ]
247
248 expected_lines = [
249 "test_007: 2569043 3967625: 110000001001001111011111001111100000000101000111100000000100101101010000001111010100010110111101011101011100000101",
250 "test_007: 2569044 3967658: 100010111110111111000001010000101101111101011111010101110110110111101101111110000011011010111011111001011101000011",
251 "test_007: 2569045 3967691: 000100001111011111010101100100011000000000011011010110001001010100101011111001000111100000100000111111000000101110",
252 "test_007: 2569046 3967724: 110101011111001000101011010110000001110110001111111010010111000000001010010111001111111011001000000001001000011101"
253 ]
254
Roman Khassraff163ca52015-08-05 12:58:00 +0200255 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200256 printer = grgsm.bursts_printer(pmt.intern("test_007: "), True, True, True, True)
257 self.tb.msg_connect(src, "out", printer, "bursts")
258 self.tb.run()
259
260 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
261
262 def test_008_complete_prefix_fnr_fcount (self):
263 """
264 Complete bursts, no prefix, with frame number, frame count, and ignoring dummy bursts
265 Bursts 4-7 are dummy bursts
266 """
267 framenumbers_input = [2569043, 2569044, 2569045, 2569046, 1099602, 1099603, 1099604, 1099605]
268 timeslots_input = [2, 2, 2, 2, 4, 4, 4, 4]
269 bursts_input = [
270 "0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
271 "0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
272 "0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
273 "0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000",
274 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
275 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
276 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000",
277 "0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000"
278
279 ]
280
281 expected_lines = [
282 "test_008: 2569043 3967625: 0001100000010010011110111110011111000000001010001111000000001000110101110010000011010111100101101010000001111010100010110111101011101011100000101000",
283 "test_008: 2569044 3967658: 0001000101111101111110000010100001011011111010111110101011101000110101110010000011010111110110111101101111110000011011010111011111001011101000011000",
284 "test_008: 2569045 3967691: 0000001000011110111110101011001000110000000000110110101100011000110101110010000011010111001010100101011111001000111100000100000111111000000101110000",
285 "test_008: 2569046 3967724: 0001101010111110010001010110101100000011101100011111110100101000110101110010000011010111111000000001010010111001111111011001000000001001000011101000"
286 ]
287
Roman Khassraff163ca52015-08-05 12:58:00 +0200288 src = grgsm.burst_source(framenumbers_input, timeslots_input, bursts_input)
Roman Khassrafb94cc812015-07-25 14:30:28 +0200289 printer = grgsm.bursts_printer(pmt.intern("test_008: "), True, True, False, True)
290 self.tb.msg_connect(src, "out", printer, "bursts")
291 self.tb.run()
292
293 self.assertEqual(self.getOutput(), self.getOutputExpected(expected_lines))
294
295
296if __name__ == '__main__':
Vasil Velichkov0c284562019-09-09 22:38:21 +0300297 gr_unittest.run(qa_burst_printer)