blob: d804b3effb6af7023bddb0c8ab915ab308d0a3e9 [file] [log] [blame]
Harald Welte78861c02020-05-14 13:28:07 +02001
2#include <osmocom/core/application.h>
3#include <osmocom/core/logging.h>
4#include <osmocom/core/bits.h>
5
6#include <osmocom/trau/trau_sync.h>
7
8static void frame_out_cb(void *user_data, const ubit_t *bits, unsigned int num_bits)
9{
10 char *str = user_data;
11 printf("demux_bits_cb '%s': %s\n", str, osmo_ubit_dump(bits, num_bits));
12}
13
14static const uint8_t sync_pattern[] = {
15 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
16 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
17 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
18 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
19 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
20};
21
22#define ASSERT_STATE(fi, x) OSMO_ASSERT(!strcmp(osmo_fsm_inst_state_name(fi), x))
23
24static void test_body(void)
25{
26 struct osmo_fsm_inst *fi = osmo_trau_sync_alloc(NULL, "test", frame_out_cb, OSMO_TRAU_SYNCP_16_FR_EFR, "test");
27 OSMO_ASSERT(fi);
28
29 printf("\n==> %s\n", __func__);
30
31 ubit_t bits[40*8];
32
33 /* send some invalid data */
34 memset(bits, 0, sizeof(bits));
35 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
36 osmo_trau_sync_rx_ubits(fi, bits, 23);
37
38 /* first valid frame */
39 osmo_pbit2ubit(bits, sync_pattern, sizeof(sync_pattern)*8);
40 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
41 ASSERT_STATE(fi, "FRAME_ALIGNED");
42
43 /* second valid frame */
44 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
45 ASSERT_STATE(fi, "FRAME_ALIGNED");
46
47 /* send wrong frame */
48 memset(bits, 1, sizeof(bits));
49 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
50 ASSERT_STATE(fi, "FRAME_ALIGNED");
51
52 /* intersperse a valid frame */
53 osmo_pbit2ubit(bits, sync_pattern, sizeof(sync_pattern)*8);
54 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
55
56 /* second wrong frame - but not consecutive */
57 memset(bits, 1, sizeof(bits));
58 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
59 ASSERT_STATE(fi, "FRAME_ALIGNED");
60
61 /* third wrong frame - second consecutive */
62 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
63 ASSERT_STATE(fi, "FRAME_ALIGNED");
64
65 /* only from third consecutive invalid frame onwards we should loose alignment */
66 osmo_trau_sync_rx_ubits(fi, bits, sizeof(bits));
67 ASSERT_STATE(fi, "FRAME_ALIGNMENT_LOST");
68}
69
70
71static const struct log_info_cat default_categories[] = {
72};
73
74const struct log_info log_info = {
75 .cat = default_categories,
76 .num_cat = ARRAY_SIZE(default_categories),
77};
78
79int main(int argc, char **argv)
80{
81 osmo_init_logging2(NULL, NULL);
Pau Espin Pedrol7766e6d2020-09-09 15:52:03 +020082 log_set_use_color(osmo_stderr_target, 0);
Harald Welte78861c02020-05-14 13:28:07 +020083 osmo_fsm_log_addr(false);
84 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
85 test_body();
86}