3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio 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)
12 * GNU Radio 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.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #include <cppunit/TestAssert.h>
24 #include <qa_atsci_data_interleaver.h>
29 * write an easy to identify pattern into the packet
32 qa_atsci_data_interleaver::init_test_packet (int counter,
33 atsc_mpeg_packet_rs_encoded &out)
37 out.data[2] = (counter >> 8) & 0xff;
38 out.data[3] = counter & 0xff;
40 for (int i = 4; i < 205; i++)
48 qa_atsci_data_interleaver::print_packet (FILE *fp,
52 const atsc_mpeg_packet_rs_encoded &in)
54 fprintf (fp, "%04d:%d:%03d ", frame_number, field_number, segment_number);
56 const unsigned char *p = &in.data[0];
57 for (int i = 0; i < 8; i++)
58 fprintf (fp, "%02X", p[i]);
62 for (int i = 0; i < 8; i++)
63 fprintf (fp, "%02X", p[i]);
66 fprintf (fp, " ... ");
68 for (int i = 0; i < 8; i++)
69 fprintf (fp, "%02X", p[i]);
73 for (int i = 0; i < 8; i++)
74 fprintf (fp, "%02X", p[i]);
80 qa_atsci_data_interleaver::chk_assert (const atsc_mpeg_packet_rs_encoded &expected,
81 const atsc_mpeg_packet_rs_encoded &actual)
83 if (expected == actual)
88 fprintf (fp, "Expected: ");
89 print_packet (fp, 0, 0, 0, expected);
91 fprintf (fp, "Actual: ");
92 print_packet (fp, 0, 0, 0, actual);
94 CPPUNIT_ASSERT (expected == actual);
98 qa_atsci_data_interleaver::t0 ()
101 atsc_mpeg_packet_rs_encoded in, enc, out;
102 atsc_mpeg_packet_rs_encoded zero;
104 memset (&zero, 0, sizeof (zero));
106 for (int frame = 0; frame < 4; frame++){
107 for (int field = 0; field < 2; field++){
108 for (int segment = 0; segment < 312; segment++, counter++){
111 init_test_packet (counter, in);
112 in.pli.set_regular_seg (field == 1, segment);
115 outbound.interleave (enc, in);
118 inbound.deinterleave (out, enc);
121 // CPPUNIT_ASSERT (zero == out);
122 chk_assert (zero, out);
124 else if (counter >= 52){
125 atsc_mpeg_packet_rs_encoded expected;
126 init_test_packet (counter - 52, expected);
127 // CPPUNIT_ASSERT (expected == out);
128 chk_assert (expected, out);
136 // Note, this assumes that the interleaver and deinterleaver
137 // have the state left by t0.
139 // This test pushes crap into the interleaver, and then confirms that
140 // the deinterleaver recovers. This would be part of what you'd see
141 // on a channel change.
145 qa_atsci_data_interleaver::t1 ()
148 atsc_mpeg_packet_rs_encoded in, enc, out;
149 atsc_mpeg_packet_rs_encoded zero;
151 memset (&zero, 0, sizeof (zero));
153 static const int NCRAP = 13;
155 // push NCRAP segments of crap into the interleaver,
156 // but don't change the deinterleaver state
158 for (int i = 0; i < NCRAP; i++){
159 init_test_packet (i + 2758, in);
160 in.pli.set_regular_seg (false, i + 5);
162 outbound.interleave (enc, in);
165 // now run the normal test.
166 // we should get good segments after NCRAP + 52
168 int starting_counter = 3141;
169 counter = starting_counter;
171 for (int frame = 0; frame < 4; frame++){
172 for (int field = 0; field < 2; field++){
173 for (int segment = 0; segment < 312; segment++, counter++){
176 init_test_packet (counter, in);
177 in.pli.set_regular_seg (field == 1, segment);
180 outbound.interleave (enc, in);
183 inbound.deinterleave (out, enc);
185 if (counter < starting_counter + 52 + NCRAP){
188 else if (counter >= starting_counter + 52 + NCRAP){
189 atsc_mpeg_packet_rs_encoded expected;
190 init_test_packet (counter - 52, expected);
191 // CPPUNIT_ASSERT (expected == out);
192 chk_assert (expected, out);