summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/test/pbproc/src/test_pbproc.c
blob: 06f164639ceef737e4dd25fede22367c10c984e2 (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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/test_pbproc.c
 * \brief   PBProc test.
 * \ingroup test
 */
#include "common/std.h"

#include "lib/trace.h"

#include "inc/test_pbproc.h"

#include "lib/scenario/scenario.h"

#include "hal/phy/inc/context.h"

#include <string.h>

void
prep_mpdu_test_suite (test_t t);

void
tx_data_test_suite (test_t t);

void
tx_sound_test_suite (test_t t);

void
tx_rts_cts_test_suite (test_t t);

void
rx_data_test_suite (test_t t);

void
rx_sound_test_suite (test_t t);

void
rx_rts_cts_test_suite (test_t t);

void
test_pbproc_rx_cb (void *user, pbproc_rx_desc_t *rx_desc)
{
    dbg_assert_ptr (user);
    test_pbproc_t *ctx = user;
    dbg_assert_ptr (rx_desc);
    pbproc_rx_t *rx = rx_desc->rx;
    if (rx->pb_nb)
    {
        dbg_assert_ptr (rx->pb_first);
        dbg_assert_ptr (rx->pb_last);
    }
    else
        dbg_assert (rx->pb_first == NULL && rx->pb_last == NULL);
    if (rx->chandata_nb)
        dbg_assert_ptr (rx->chandata_first);
    else
        dbg_assert (rx->chandata_first == NULL);
    scenario_event (pbproc_rx_cb, params, globals);
    test_fail_unless (rx->pb_nb == params->pb_nb);
    if (rx->pb_nb)
        blk_release_desc_range (&rx->pb_first->blk, &rx->pb_last->blk);
    test_fail_unless (rx->chandata_nb == params->chandata_nb);
    if (rx->chandata_nb)
        blk_release_desc_range_nb (&rx->chandata_first->blk, rx->chandata_nb);
    /* TODO: more verifications. */
    test_fail_unless (rx->params.beacon_period_start_ntb
                      == params->beacon_period_start_date
                      + ctx->config.ntb_offset_tck);
    test_fail_unless (rx->params.fl_tck == params->fl_tck);
    test_fail_unless (rx->params.pb_size == params->pb_size);
    test_fail_unless (rx->params.mpdu_cnt == params->mpdu_cnt);
    test_fail_unless (rx->params.mfs_cmd_data == params->mfs_cmd_data);
    test_fail_unless (rx->params.mfs_cmd_mme == params->mfs_cmd_mme);
    /* This took time. */
    globals->tp->pbproc->phy->current_date += params->duration_tck;
    /* Done. */
    blk_release_desc (&rx_desc->blk);
}

void
test_pbproc_rx_beacon_cb (void *user, pb_beacon_t *pb,
                          pbproc_rx_beacon_params_t *params)
{
    dbg_assert_ptr (user);
    dbg_assert_ptr (pb);
    dbg_assert (params == (void *) (pb->data + MAC_PB136_BYTES));
    scenario_event (pbproc_rx_beacon_cb, event_params, globals);
    /* TODO: more verifications. */
    /* This took time. */
    globals->tp->pbproc->phy->current_date += event_params->duration_tck;
    /* Done. */
    blk_release_desc (&pb->blk);
}

void
test_pbproc_init (test_pbproc_t *ctx)
{
    dbg_assert (ctx);
    lib_rnd_init (ctx->rnd, 1234);
    mac_config_init (&ctx->config);
    mac_ntb_init (&ctx->config);
    ctx->config.ntb_offset_tck = TEST_PBPROC_NTB_OFFSET_TCK;
    ctx->config.tei = 1;
    ctx->snid = 1;
    ctx->config.seed = 42;
    ctx->store = mac_store_init ();
    ctx->pbproc = pbproc_init (&ctx->config, ctx->store);
    pbproc_init_cb (ctx->pbproc, ctx, test_pbproc_rx_cb,
                    test_pbproc_rx_beacon_cb);
    pbproc_get_phy (ctx->pbproc);
    ctx->ca = pbproc_get_ca (ctx->pbproc);
    ctx->pbproc->activated = true;
    test_pbproc_alloc (ctx, false, 0);
    test_pbproc_check_stats_reset (ctx);
}

void
test_pbproc_alloc (test_pbproc_t *ctx, bool hybrid,
                   u32 beacon_period_start_date)
{
    dbg_assert (ctx);
    ctx->pbproc->alloc.coexistence_mode = hybrid
        ? MAC_COEXISTENCE_FULL_HYBRID_MODE : MAC_COEXISTENCE_AV_ONLY_MODE;
    ctx->pbproc->alloc.hybrid = hybrid;
    ctx->pbproc->alloc.merge = false;
    ctx->pbproc->times = ctx->pbproc->times_array[PBPROC_TIMES_ARRAY_INDEX (
        hybrid, ctx->pbproc->alloc.coexistence_mode)];
    ctx->pbproc->alloc.end_date = TEST_PBPROC_ALLOC_END_DATE;
    ctx->pbproc->alloc.aifs_date = TEST_PBPROC_ALLOC_END_DATE;
    ctx->pbproc->alloc.beacon_period_start_date = beacon_period_start_date;
}

void
test_pbproc_check_stats_ (test_t t, test_pbproc_t *ctx,
                          const pbproc_stat_t *stats)
{
    test_within (t);
    dbg_assert (ctx);
    dbg_assert (stats);
#define TEST_PBPROC_CHECK_STAT(stat) \
    test_fail_unless (ctx->pbproc->stats.stat == ctx->recorded_stats.stat \
                      + stats->stat, #stat ": %d", \
                      ctx->pbproc->stats.stat - ctx->recorded_stats.stat)
    TEST_PBPROC_CHECK_STAT(rts_fail);
    TEST_PBPROC_CHECK_STAT(prp_lost);
    TEST_PBPROC_CHECK_STAT(cw_lost);
    TEST_PBPROC_CHECK_STAT(aifs);
    TEST_PBPROC_CHECK_STAT(rx_out_of_alloc);
    TEST_PBPROC_CHECK_STAT(rx_pool_shortage);
    TEST_PBPROC_CHECK_STAT(rx_handle_fc);
    TEST_PBPROC_CHECK_STAT(rx_beacon);
    TEST_PBPROC_CHECK_STAT(rx_data);
    TEST_PBPROC_CHECK_STAT(rx_data_wack);
    TEST_PBPROC_CHECK_STAT(rx_data_woack);
    TEST_PBPROC_CHECK_STAT(rx_data_burst_stop);
    TEST_PBPROC_CHECK_STAT(rx_data_error);
    TEST_PBPROC_CHECK_STAT(rx_data_empty);
    TEST_PBPROC_CHECK_STAT(rx_data_bad_symb_nb);
    TEST_PBPROC_CHECK_STAT(rx_sound);
    TEST_PBPROC_CHECK_STAT(rx_sound_complete);
    TEST_PBPROC_CHECK_STAT(rx_sound_drop);
    TEST_PBPROC_CHECK_STAT(rx_nfu);
    TEST_PBPROC_CHECK_STAT(rx_fc_unknown);
    TEST_PBPROC_CHECK_STAT(rx_crc_error);
    TEST_PBPROC_CHECK_STAT(tx_invalid);
    TEST_PBPROC_CHECK_STAT(tx_late);
    TEST_PBPROC_CHECK_STAT(tx_data);
    TEST_PBPROC_CHECK_STAT(tx_data_cancel);
    TEST_PBPROC_CHECK_STAT(tx_data_burst);
    TEST_PBPROC_CHECK_STAT(tx_data_burst_interrupted);
    TEST_PBPROC_CHECK_STAT(tx_data_wack);
    TEST_PBPROC_CHECK_STAT(tx_data_woack);
    TEST_PBPROC_CHECK_STAT(tx_data_beacon);
    TEST_PBPROC_CHECK_STAT(tx_data_wack_ack);
    TEST_PBPROC_CHECK_STAT(tx_data_wack_noack);
    TEST_PBPROC_CHECK_STAT(tx_data_re_sync);
    TEST_PBPROC_CHECK_STAT(tx_sound);
    TEST_PBPROC_CHECK_STAT(tx_sound_ack);
    TEST_PBPROC_CHECK_STAT(tx_sound_noack);
}

void
test_pbproc_check_stats_reset (test_pbproc_t *ctx)
{
    dbg_assert (ctx);
    ctx->recorded_stats = ctx->pbproc->stats;
}

void
test_pbproc_uninit (test_pbproc_t *ctx)
{
    dbg_assert (ctx);
    ctx->ca = NULL;
    pbproc_uninit (ctx->pbproc);
    ctx->pbproc = NULL;
    mac_store_uninit (ctx->store);
    ctx->store = NULL;
}

static void
test_pbproc_aifs (test_t t, bool from_merge, bool to_merge)
{
    test_within (t);
    test_pbproc_t ctx;
    test_pbproc_init (&ctx);
    ctx.pbproc->alloc.merge = from_merge;
    ca_access_param_t access_param = {
        .access_date = 0, .cw_start_date = 0, .aifs = true,
    };
    ctx.pbproc->detect.hp10_detected = true;
    ctx.pbproc->detect.hp10_detect_date =
        phy_date () - MAC_MS_TO_TCK (1900);
    ctx.pbproc->detect.hp11_detected = true;
    ctx.pbproc->detect.hp11_detect_date =
        phy_date () - MAC_MS_TO_TCK (2900);
    scenario_entry_t entries[] = {
        SCENARIO_ACTION (phy_access, .mfs = NULL,
                         .access_param = &access_param,
                         .prp_won = true, .slot_count = 64),
        SCENARIO_EVENT_COND (!from_merge, phy_rx_activate, .now = true,
                             .pre_detection = false),
        SCENARIO_EVENT_COND (!from_merge, ca_backoff_cancel),
        SCENARIO_EVENT (ca_access_aifs,
                        .coexistence_mode =
                        MAC_COEXISTENCE_FULL_HYBRID_MODE,
                        .snid = ctx.snid, .hybrid = true, .merge = to_merge,
                        .nek_switch = 0),
        SCENARIO_EVENT_COND (!to_merge, phy_rx_param,
                             .fc_mode = PHY_FC_MODE (true, 1)),
        SCENARIO_END
    };
    scenario_globals_t globals = {
        .tp = &ctx,
    };
    scenario_run (t, entries, &globals);
    test_fail_unless (ctx.pbproc->fsm.current_state
                      == PBPROC_FSM_STATE_IDLE);
    if (!to_merge)
        test_fail_unless (memcmp (&ctx.pbproc->times,
                                  &ctx.pbproc->times_array[true],
                                  sizeof (pbproc_times_t)) == 0);
    test_fail_unless (ctx.pbproc->detect.hp10_detected == true);
    test_fail_unless (ctx.pbproc->detect.hp11_detected == false);
    ctx.pbproc->detect.hp10_detected = false;
    ctx.pbproc->detect.hp11_detected = false;
    test_pbproc_check_stats (t, &ctx, .aifs = 1);
    test_pbproc_uninit (&ctx);
}

void
test_pbproc_init_suite (test_t t)
{
    test_suite_begin (t, "init");
    test_case_begin (t, "basic");
    test_pbproc_t ctx;
    test_begin (t, "init uninit")
    {
        test_pbproc_init (&ctx);
        test_pbproc_uninit (&ctx);
        test_pbproc_init (&ctx);
        test_pbproc_uninit (&ctx);
    } test_end;
    test_begin (t, "rx segment refill")
    {
        test_pbproc_init (&ctx);
        blk_t *first, *last;
        first = blk_alloc_desc_range (10, &last);
        pbproc_rx_segment_refill (ctx.pbproc, PB_FROM_BLK (first),
                                  PB_FROM_BLK (last), 10);
        first = blk_alloc_desc_range (10, &last);
        pbproc_rx_segment_refill (ctx.pbproc, PB_FROM_BLK (first),
                                  PB_FROM_BLK (last), 10);
        test_pbproc_uninit (&ctx);
    } test_end;
    test_begin (t, "activate deactivate")
    {
        test_pbproc_init (&ctx);
        ctx.pbproc->activated = false;
        scenario_entry_t entries[] = {
            SCENARIO_ACTION (pbproc_activate, .flag = true),
            SCENARIO_EVENT (ca_access_activate, .date = 0,
                            .coexistence_mode = MAC_COEXISTENCE_AV_ONLY_MODE,
                            .snid = ctx.snid, .hybrid = false, .merge = false,
                            .nek_switch = 0),
            SCENARIO_EVENT (phy_rx_param, .fc_mode = PHY_FC_MODE (false, 1)),
            SCENARIO_EVENT (phy_rx_activate, .now = true,
                            .pre_detection = true),
            SCENARIO_ACTION (pbproc_activate, .flag = false),
            SCENARIO_EVENT (phy_rx_activate, .now = true,
                            .pre_detection = false),
            SCENARIO_EVENT (ca_access_deactivate),
            SCENARIO_END
        };
        scenario_globals_t globals = {
           .tp = &ctx,
        };
        scenario_run (t, entries, &globals);
        test_fail_unless (memcmp (&ctx.pbproc->times,
                                  &ctx.pbproc->times_array[false],
                                  sizeof (pbproc_times_t)) == 0);
        test_pbproc_uninit (&ctx);
    } test_end;
    test_begin (t, "activate hybrid")
    {
        test_pbproc_init (&ctx);
        ctx.pbproc->activated = false;
        scenario_entry_t entries[] = {
            SCENARIO_ACTION (pbproc_activate, .flag = true),
            SCENARIO_EVENT (ca_access_activate, .date = 0,
                            .coexistence_mode =
                            MAC_COEXISTENCE_FULL_HYBRID_MODE,
                            .snid = ctx.snid, .hybrid = true, .merge = false,
                            .nek_switch = 0),
            SCENARIO_EVENT (phy_rx_param, .fc_mode = PHY_FC_MODE (true, 1)),
            SCENARIO_EVENT (phy_rx_activate, .now = true,
                            .pre_detection = true),
            SCENARIO_END
        };
        scenario_globals_t globals = {
           .tp = &ctx,
        };
        scenario_run (t, entries, &globals);
        test_fail_unless (memcmp (&ctx.pbproc->times,
                                  &ctx.pbproc->times_array[true],
                                  sizeof (pbproc_times_t)) == 0);
        test_pbproc_uninit (&ctx);
    } test_end;
    test_begin (t, "aifs")
    {
        test_pbproc_aifs (t, false, false);
    } test_end;
    test_begin (t, "aifs merged")
    {
        test_pbproc_aifs (t, true, true);
    } test_end;
    test_begin (t, "aifs to merged")
    {
        test_pbproc_aifs (t, false, true);
    } test_end;
    test_begin (t, "aifs from merged")
    {
        test_pbproc_aifs (t, true, false);
    } test_end;
    test_case_begin (t, "memory");
    test_begin (t, "memory")
    {
        test_fail_unless (blk_check_memory ());
    } test_end;
}

struct test_pbproc_trace_dump_t
{
    char text[2048];
    uint size;
};
typedef struct test_pbproc_trace_dump_t test_pbproc_trace_dump_t;

static int
test_pbproc_trace_dump_callback (void *user, const char *text,
                                 uint text_size)
{
    test_pbproc_trace_dump_t *ctx = user;
    dbg_assert (ctx);
    if (text_size + ctx->size >= COUNT (ctx->text))
        return 0;
    memcpy (ctx->text, text, text_size);
    ctx->size += text_size;
    ctx->text[ctx->size] = '\0';
    return text_size;
}

void
test_pbproc_unexpected_event_suite (test_t t)
{
    test_suite_begin (t, "unexpected event");
    test_case_begin (t, "debug");
    test_pbproc_t ctx;
    test_pbproc_init (&ctx);
    test_begin (t, "pbdma in idle")
    {
        ctx.pbproc->phy->expected_event_mask = 0;
        ctx.pbproc->phy->unexpected_event = 0;
        dbg_fatal_try_begin
        {
            ctx.pbproc->phy->pbdma_cb (ctx.pbproc, 0);
        }
        dbg_fatal_try_catch (const char *fatal_message)
        {
            (void) fatal_message;
        }
        dbg_fatal_try_end;
        test_fail_unless (ctx.pbproc->phy->expected_event_mask
                          == (PHY_EVENT_ACCESS | PHY_EVENT_RX_FC));
        test_fail_unless (ctx.pbproc->phy->unexpected_event
                          == PHY_EVENT_PBDMA);
    } test_end;
    test_pbproc_uninit (&ctx);
}

void
test_pbproc_trace_suite (test_t t)
{
    test_suite_begin (t, "trace");
    test_case_begin (t, "fc");
    test_pbproc_t tp;
    test_pbproc_init (&tp);
    pbproc_t *ctx = tp.pbproc;
    test_begin (t, "rx fc")
    {
        char ref[2048], *refp = ref;
        const char *s;
        s = "---trace-begin[pbproc]---\n"
            "[.] init\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        s = "[0x00000000] fsm RX FC pre_date=0x00000000"
            " BEACON snid=A1 bts=0x12345678 bto=42330,42331,42332,42333\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 0, 0,
                      0x34567818, 0x5ba55a12, 0x5da55ca5, 0xdeaddea5);
        s = "[0x00000001] fsm RX FC pre_date=0x00000001"
            " SOF snid=2 stei=0x12 dtei=0x34 lid=0x56 mcf cfs hp10df eks=10"
            " ppb=0x78 ble=0xab pb136 num_sym=1 tmi=23 fl_av=3333 mpdu_cnt=2"
            " bbf mrtfl=0x3 rsr mfs=mINIT,IN_SYNC,mACK,NACK sacki=0x5\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 1, 1,
                      0x56341221, 0xbbab78a5, 0x21472d05, 0xdeadde54);
        s = "[0x00000002] fsm RX FC pre_date=0x00000002"
            " SOF snid=A13 stei=0xed dtei=0xcb lid=0xa9 mnbf bdf hp11df eks=5"
            " ppb=0x87 ble=0x54 num_sym=2 tmi=8 fl_av=762 burst_cnt=2"
            " dcppcf clst mfs=mNOP,RELEASE,mHOLD,FAIL sacki=0xa\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 2, 2,
                      0xa9cbedd9, 0x4454875a, 0x72b882fa, 0xdeaddeab);
        s = "[0x00000003] fsm RX FC pre_date=0x00000003"
            " SACK snid=3 dtei=0x12 cfs svn=1 mfs=ACK,mNACK sackt=m,mc,nr,u"
            " sacki=0x01234567,0x89abcdef,0x01\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 3, 3,
                      0xe4451232, 0x01234567, 0x89abcdef, 0xdeadde01);
        s = "[0x00000004] fsm RX FC pre_date=0x00000004"
            " SACK snid=A12 dtei=0xed bdf rrtf mfs=HOLD,mFAIL sackt=u,nr,mc,m"
            " sacki=0xfedcba98,0x76543210,0xfe\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 4, 4,
                      0x1bbaedca, 0xfedcba98, 0x76543210, 0xdeaddefe);
        s = "[0x00000005] fsm RX FC pre_date=0x00000005"
            " CTS snid=4 stei=0x23 dtei=0x45 lid=0x67 mcf cfs hp10df igf"
            " dur=11111\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 5, 5,
                      0x67452343, 0x002b67a5, 0x00000000, 0xdeadde00);
        s = "[0x00000006] fsm RX FC pre_date=0x00000006"
            " RTS snid=A11 stei=0xdc dtei=0xba lid=0x98 mnbf bdf hp11df"
            " dur=5272\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 6, 6,
                      0x98badcbb, 0x0014985a, 0x00000000, 0xdeadde00);
        s = "[0x00000007] fsm RX FC pre_date=0x00000007"
            " SOUND snid=5 stei=0x34 dtei=0x56 lid=0x78 cfs bdf scf req_tm=5"
            " fl_av=3333 ppb=0x9a src=0xbc\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 7, 7,
                      0x78563454, 0x9a0d05b5, 0x000000bc, 0xdeadde00);
        s = "[0x00000008] fsm RX FC pre_date=0x00000008"
            " SOUND snid=A10 stei=0xcb dtei=0xa9 lid=0x87 pb136 saf req_tm=2"
            " fl_av=762 mpdu_cnt=3 ppb=0x65 src=0x43\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 8, 8,
                      0x87a9cbac, 0x6532fa4a, 0x00000043, 0xdeadde00);
        s = "[0x00000009] fsm RX FC pre_date=0x00000009"
            " RSOF snid=6 dtei=0x12 cfs svn=1 mfs=mINIT,IN_SYNC,ACK,mNACK"
            " sackt=m,mc,nr,u sacki=0x01234567,0x89ab fl_av=1280 tmi=22 pb136"
            " num_sym=0\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 9, 9,
                      0xe4451265, 0x01234567, 0xdb8089ab, 0xdeadde20);
        s = "[0x0000000a] fsm RX FC pre_date=0x0000000a"
            " RSOF snid=A9 dtei=0xed bdf rrtf mfs=mNOP,RELEASE,HOLD,mFAIL"
            " sackt=u,nr,mc,m sacki=0xfedcba98,0x7654 fl_av=127 tmi=9"
            " num_sym=3\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        PBPROC_TRACE (FSM_RX_FC, 10, 10,
                      0x1bbaed9d, 0xfedcba98, 0x247f7654, 0xdeadde73);
        s = "---trace-end---\n";
        dbg_assert (refp + strlen (s) < ref + sizeof (ref));
        strcpy (refp, s); refp += strlen (s);
        test_pbproc_trace_dump_t dump;
        dump.size = 0;
        trace_buffer_dump (&ctx->trace, test_pbproc_trace_dump_callback,
                           &dump);
        test_fail_unless (strcmp (dump.text, ref) == 0);
    } test_end;
    test_pbproc_uninit (&tp);
}

void
test_pbproc_get_interval_group_suite (test_t t)
{
    test_suite_begin (t, "interval matching");
    test_case_begin (t, "basic");
    sta_t sta;
    tonemaps_t rx_tms;
    tonemap_intervals_t ti;
    int i;
    for (i = 0; i < 24; i++)
    {
        ti.interval[i].end_offset_atu = (i + 1) * 100;
        ti.interval[i].tmi = 4;
    }
    ti.group_intervals_nb = 6;
    /* Start without intervals. */
    ti.intervals_nb = 0;
    rx_tms.intervals = &ti;
    sta.rx_tonemaps = &rx_tms;
    test_begin (t, "no sta")
    {
        test_fail_unless (pbproc_get_interval_group (NULL,
                          MAC_ATU_TO_TCK (123), MAC_ATU_TO_TCK (45))
                          == PBPROC_NO_INT_MATCH);
    } test_end;
    test_begin (t, "no interval")
    {
        rx_tms.intervals->intervals_nb = 0;
        test_fail_unless (pbproc_get_interval_group (&sta,
                          MAC_ATU_TO_TCK (123), MAC_ATU_TO_TCK (45))
                          == PBPROC_NO_INT_MATCH);
    } test_end;
    test_begin (t, "sta and interval")
    {
        rx_tms.intervals->intervals_nb = 24;
        test_fail_unless (pbproc_get_interval_group (&sta,
                          MAC_ATU_TO_TCK (12), MAC_ATU_TO_TCK (34)) == 0);
        test_fail_unless (pbproc_get_interval_group (&sta,
                          MAC_ATU_TO_TCK (123), MAC_ATU_TO_TCK (45)) == 1);
        test_fail_unless (pbproc_get_interval_group (&sta,
                          MAC_ATU_TO_TCK (1234), MAC_ATU_TO_TCK (56)) == 0);
        test_fail_unless (pbproc_get_interval_group (&sta,
                          MAC_ATU_TO_TCK (12345), MAC_ATU_TO_TCK (67))
                          == PBPROC_NO_INT_MATCH);
    } test_end;
}

int
main (int argc, char **argv)
{
    test_t t;
    trace_init ();
    test_init (t, argc, argv);
    test_pbproc_init_suite (t);
    prep_mpdu_test_suite (t);
    tx_data_test_suite (t);
    tx_sound_test_suite (t);
    tx_rts_cts_test_suite (t);
    rx_data_test_suite (t);
    rx_sound_test_suite (t);
    rx_rts_cts_test_suite (t);
    test_pbproc_unexpected_event_suite (t);
    test_pbproc_trace_suite (t);
    test_pbproc_get_interval_group_suite (t);
    trace_uninit ();
    test_result (t);
    return test_nb_failed (t) == 0 ? 0 : 1;
}