Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 0f12f84

Browse files
author
Joseph Finnegan
committed
Add jobs to CI which run the unit tests and the testsuite
1 parent ab691ba commit 0f12f84

File tree

4 files changed

+202
-196
lines changed

4 files changed

+202
-196
lines changed

stack/tests/alp/main.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
*/
2121

2222
#include <stdio.h>
23+
#include <stdlib.h>
2324
#include <string.h>
25+
2426
#include "debug.h"
2527

2628
#include "alp.h"
@@ -36,28 +38,29 @@ void test_alp_parse_length_operand()
3638
fifo_init(&fifo, data, sizeof(data));
3739

3840
fifo_put_byte(&fifo, 0x01);
39-
uint32_t length = alp_parse_length_operand(&fifo);
41+
uint32_t length;
42+
assert(alp_parse_length_operand(&fifo, &length));
4043
assert(length == 1);
4144

4245
fifo_clear(&fifo);
4346
fifo_put_byte(&fifo, 0x40);
4447
fifo_put_byte(&fifo, 0x41);
45-
length = alp_parse_length_operand(&fifo);
48+
assert(alp_parse_length_operand(&fifo, &length));
4649
assert(length == 65);
4750

4851
fifo_clear(&fifo);
4952
fifo_put_byte(&fifo, 0x80);
5053
fifo_put_byte(&fifo, 0x40);
5154
fifo_put_byte(&fifo, 0x01);
52-
length = alp_parse_length_operand(&fifo);
55+
assert(alp_parse_length_operand(&fifo, &length));
5356
assert(length == 0x4001);
54-
57+
5558
fifo_clear(&fifo);
5659
fifo_put_byte(&fifo, 0xC0);
5760
fifo_put_byte(&fifo, 0x41);
5861
fifo_put_byte(&fifo, 0x10);
5962
fifo_put_byte(&fifo, 0x00);
60-
length = alp_parse_length_operand(&fifo);
63+
assert(alp_parse_length_operand(&fifo, &length));
6164
assert(length == 4263936);
6265
}
6366

@@ -68,6 +71,8 @@ void bootstrap()
6871
printf("Testing alp_parse_length_operand ... ");
6972
test_alp_parse_length_operand();
7073
printf("Success!\n");
71-
74+
7275
printf("Unit-tests for ALP completed\n");
76+
77+
exit(0);
7378
}

stack/tests/fec/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616
See the License for the specific language governing permissions and
1717
limitations under the License.
1818
]]
19-
project(fec)
19+
project(test_fec)
2020
cmake_minimum_required(VERSION 2.8)
2121
add_executable(${PROJECT_NAME}
2222
fec.c

stack/tests/fec/main.c

Lines changed: 120 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -16,161 +16,153 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
#include <stdio.h>
19+
#include "fec.h"
2020
#include <stdint.h>
21+
#include <stdio.h>
22+
#include <stdlib.h>
2123
#include <string.h>
2224
#include <time.h>
23-
#include <stdlib.h>
24-
#include "fec.h"
2525

2626
#define BINARY 0
2727

28-
29-
const char *byte_to_binary(uint8_t x)
28+
const char* byte_to_binary(uint8_t x)
3029
{
3130
static char b[9];
3231
b[0] = '\0';
3332

3433
uint8_t z;
35-
for (z = 128; z > 0; z >>= 1)
34+
for(z = 128; z > 0; z >>= 1)
3635
{
3736
strcat(b, ((x & z) == z) ? "1" : "0");
3837
}
3938

4039
return b;
4140
}
4241

43-
unsigned char Partab[] = { 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0
44-
,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1
45-
,0,0,1,0,1,1,0,1,0,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 3, 0, 2, 1, 3, 0, 2, 1, 0, 3, 1, 2};
49-
50-
52+
const static uint8_t fec_lut[16] = { 0, 3, 1, 2, 3, 0, 2, 1, 3, 0, 2, 1, 0, 3, 1, 2 };
5153

5254
void test_interleaver()
5355
{
54-
uint8_t fecbuffer[4] = {0xFF,0x00,0xAB,0x00};
55-
uint8_t buffer[4]= {0,0,0,0};
56-
uint8_t buffer2[4]= {0,0,0,0};
57-
uint8_t *output = buffer;
58-
uint8_t *input = buffer;
59-
60-
*output++ = ((fecbuffer[0] & 0x03)) |\
61-
((fecbuffer[1] & 0x03) << 2) |\
62-
((fecbuffer[2] & 0x03) << 4) |\
63-
((fecbuffer[3] & 0x03) << 6);
64-
*output++ = (((fecbuffer[0] >> 2) & 0x03)) |\
65-
(((fecbuffer[1] >> 2) & 0x03) << 2) |\
66-
(((fecbuffer[2] >> 2) & 0x03) << 4) |\
67-
(((fecbuffer[3] >> 2) & 0x03) << 6);
68-
*output++ = (((fecbuffer[0] >> 4) & 0x03)) |\
69-
(((fecbuffer[1] >> 4) & 0x03) << 2) |\
70-
(((fecbuffer[2] >> 4) & 0x03) << 4) |\
71-
(((fecbuffer[3] >> 4) & 0x03) << 6);
72-
*output++ = (((fecbuffer[0] >> 6) & 0x03)) |\
73-
(((fecbuffer[1] >> 6) & 0x03) << 2) |\
74-
(((fecbuffer[2] >> 6) & 0x03) << 4) |\
75-
(((fecbuffer[3] >> 6) & 0x03) << 6);
76-
77-
printf("Input : "); print_array((uint8_t*) fecbuffer, 4, BINARY); printf("\n");
78-
printf("Interl: "); print_array((uint8_t*) buffer, 4, BINARY); printf("\n");
79-
80-
fecbuffer[0] = ((input[0] & 0x03)) |\
81-
((input[1] & 0x03) << 2) |\
82-
((input[2] & 0x03) << 4) |\
83-
((input[3] & 0x03) << 6);
84-
fecbuffer[1] = (((input[0] >> 2) & 0x03)) |\
85-
(((input[1] >> 2) & 0x03) << 2) |\
86-
(((input[2] >> 2) & 0x03) << 4) |\
87-
(((input[3] >> 2) & 0x03) << 6);
88-
fecbuffer[2] = (((input[0] >> 4) & 0x03)) |\
89-
(((input[1] >> 4) & 0x03) << 2) |\
90-
(((input[2] >> 4) & 0x03) << 4) |\
91-
(((input[3] >> 4) & 0x03) << 6);
92-
fecbuffer[3] = (((input[0] >> 6) & 0x03)) |\
93-
(((input[1] >> 6) & 0x03) << 2) |\
94-
(((input[2] >> 6) & 0x03) << 4) |\
95-
(((input[3] >> 6) & 0x03) << 6);
96-
97-
98-
printf("Deint : "); print_array((uint8_t*) fecbuffer, 4, BINARY); printf("\n");
99-
100-
56+
uint8_t fecbuffer[4] = { 0xFF, 0x00, 0xAB, 0x00 };
57+
uint8_t buffer[4] = { 0, 0, 0, 0 };
58+
uint8_t buffer2[4] = { 0, 0, 0, 0 };
59+
uint8_t* output = buffer;
60+
uint8_t* input = buffer;
61+
62+
*output++ = ((fecbuffer[0] & 0x03)) | ((fecbuffer[1] & 0x03) << 2) | ((fecbuffer[2] & 0x03) << 4) | ((fecbuffer[3] & 0x03) << 6);
63+
*output++ = (((fecbuffer[0] >> 2) & 0x03)) | (((fecbuffer[1] >> 2) & 0x03) << 2) | (((fecbuffer[2] >> 2) & 0x03) << 4)
64+
| (((fecbuffer[3] >> 2) & 0x03) << 6);
65+
*output++ = (((fecbuffer[0] >> 4) & 0x03)) | (((fecbuffer[1] >> 4) & 0x03) << 2) | (((fecbuffer[2] >> 4) & 0x03) << 4)
66+
| (((fecbuffer[3] >> 4) & 0x03) << 6);
67+
*output++ = (((fecbuffer[0] >> 6) & 0x03)) | (((fecbuffer[1] >> 6) & 0x03) << 2) | (((fecbuffer[2] >> 6) & 0x03) << 4)
68+
| (((fecbuffer[3] >> 6) & 0x03) << 6);
69+
70+
printf("Input : ");
71+
print_array((uint8_t*)fecbuffer, 4, BINARY);
72+
printf("\n");
73+
printf("Interl: ");
74+
print_array((uint8_t*)buffer, 4, BINARY);
75+
printf("\n");
76+
77+
fecbuffer[0] = ((input[0] & 0x03)) | ((input[1] & 0x03) << 2) | ((input[2] & 0x03) << 4) | ((input[3] & 0x03) << 6);
78+
fecbuffer[1] = (((input[0] >> 2) & 0x03)) | (((input[1] >> 2) & 0x03) << 2) | (((input[2] >> 2) & 0x03) << 4) | (((input[3] >> 2) & 0x03) << 6);
79+
fecbuffer[2] = (((input[0] >> 4) & 0x03)) | (((input[1] >> 4) & 0x03) << 2) | (((input[2] >> 4) & 0x03) << 4) | (((input[3] >> 4) & 0x03) << 6);
80+
fecbuffer[3] = (((input[0] >> 6) & 0x03)) | (((input[1] >> 6) & 0x03) << 2) | (((input[2] >> 6) & 0x03) << 4) | (((input[3] >> 6) & 0x03) << 6);
81+
82+
printf("Deint : ");
83+
print_array((uint8_t*)fecbuffer, 4, BINARY);
84+
printf("\n");
10185
}
10286

103-
int main(int argc, char *argv[])
87+
int main(int argc, char* argv[])
10488
{
105-
//test_interleaver();
106-
uint8_t input[] = {0x19,0x00,0x80,0x00,0x0B,0x57,0x00,0x00,0x07,0x8C,0x63,0x20,0x00,0x0B,0x57,0x00,0x00,0x07,0x8F,0x52,0x41,0x07,0x00,0x00,0xD0,0x81};
107-
uint8_t input_length = sizeof(input);
108-
uint8_t encoded[255];
109-
uint8_t decoded[255];
110-
uint8_t errors[255];
111-
112-
memset(errors, 0, 255);
113-
114-
115-
printf("Input: %d ", input_length);
116-
print_array(input, input_length, BINARY);
117-
printf("\n");
118-
119-
memcpy(encoded, input, input_length);
120-
121-
uint16_t lenght_encoded = fec_encode(encoded, input_length);
122-
123-
printf("Encoded: %d ", lenght_encoded);
124-
print_array(encoded, lenght_encoded, BINARY);
125-
printf("\n");
126-
127-
memcpy(decoded, encoded, lenght_encoded);
128-
129-
130-
uint8_t length_decoded = fec_decode_packet(decoded, lenght_encoded, 255);
131-
132-
printf("Decoded: %d ", length_decoded);
133-
print_array(decoded, length_decoded, BINARY);
134-
printf("\n");
135-
136-
int nr_errors = 1;
137-
int notrecovered = 0;
138-
srand(time(NULL));
139-
140-
// while (notrecovered < 1)
141-
// {
142-
// int r = rand() % (lenght_encoded * 8);
143-
// //printf("Rand: %d\n", r);
144-
//
145-
// encoded[r/8] ^= 1 << r % 8;
146-
// errors[r/8] ^= 1 << r % 8;
147-
// printf("Errors %d - BER %d%%\n", nr_errors, (nr_errors * 100) / (lenght_encoded * 8));
148-
// printf("Error: ");
149-
// print_array(errors, lenght_encoded);
150-
// printf("\n");
151-
// printf("Enc. error: ");
152-
// print_array(encoded, lenght_encoded);
153-
// printf("\n");
154-
//
155-
// length_decoded = fec_decode_packet(encoded, lenght_encoded, decoded, 255);
156-
//
157-
// printf("Decoded: ");
158-
// print_array(decoded, length_decoded);
159-
// printf("\n");
160-
//
161-
// if (memcmp(input, decoded, input_length) == 0)
162-
// {
163-
// printf("ok\n");
164-
// }
165-
// else
166-
// {
167-
// printf("error\n");
168-
// notrecovered++;
169-
// }
170-
//
171-
// nr_errors++;
172-
// }
89+
// test_interleaver();
90+
uint8_t input[] = { 0x19, 0x00, 0x80, 0x00, 0x0B, 0x57, 0x00, 0x00, 0x07, 0x8C, 0x63, 0x20, 0x00,
91+
0x0B, 0x57, 0x00, 0x00, 0x07, 0x8F, 0x52, 0x41, 0x07, 0x00, 0x00, 0xD0, 0x81 };
92+
uint8_t input_length = sizeof(input);
93+
uint8_t encoded[255];
94+
uint8_t decoded[255];
95+
uint8_t errors[255];
96+
97+
memset(errors, 0, 255);
98+
99+
printf("Input: %d ", input_length);
100+
print_array(input, input_length, BINARY);
101+
printf("\n");
102+
103+
memcpy(encoded, input, input_length);
104+
105+
uint16_t lenght_encoded = fec_encode(encoded, input_length);
106+
107+
printf("Encoded: %d ", lenght_encoded);
108+
print_array(encoded, lenght_encoded, BINARY);
109+
printf("\n");
110+
111+
memcpy(decoded, encoded, lenght_encoded);
112+
113+
uint8_t length_decoded = fec_decode_packet(decoded, lenght_encoded, 255);
114+
115+
printf("Decoded: %d ", length_decoded);
116+
print_array(decoded, length_decoded, BINARY);
117+
printf("\n");
118+
119+
int nr_errors = 1;
120+
int notrecovered = 0;
121+
srand(time(NULL));
122+
123+
if(memcmp(input, decoded, input_length) == 0)
124+
{
125+
printf("Input was decoded successfully\n");
126+
}
127+
else
128+
{
129+
printf("error\n");
130+
// notrecovered++;
131+
}
173132

133+
// while (notrecovered < 1)
134+
// {
135+
// int r = rand() % (lenght_encoded * 8);
136+
// //printf("Rand: %d\n", r);
137+
//
138+
// encoded[r/8] ^= 1 << r % 8;
139+
// errors[r/8] ^= 1 << r % 8;
140+
// printf("Errors %d - BER %d%%\n", nr_errors, (nr_errors * 100) / (lenght_encoded * 8));
141+
// printf("Error: ");
142+
// print_array(errors, lenght_encoded);
143+
// printf("\n");
144+
// printf("Enc. error: ");
145+
// print_array(encoded, lenght_encoded);
146+
// printf("\n");
147+
//
148+
// length_decoded = fec_decode_packet(encoded, lenght_encoded, decoded, 255);
149+
//
150+
// printf("Decoded: ");
151+
// print_array(decoded, length_decoded);
152+
// printf("\n");
153+
//
154+
// if (memcmp(input, decoded, input_length) == 0)
155+
// {
156+
// printf("ok\n");
157+
// }
158+
// else
159+
// {
160+
// printf("error\n");
161+
// notrecovered++;
162+
// }
163+
//
164+
// nr_errors++;
165+
// }
174166

175167
return 0;
176168
}

0 commit comments

Comments
 (0)