Skip to content

Commit

Permalink
framing/autotest: using consistent internal callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Mar 18, 2024
1 parent a39faff commit 966c26b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 121 deletions.
18 changes: 17 additions & 1 deletion autotest/autotest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2022 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -362,3 +362,19 @@ int liquid_autotest_validate_psd_iirfilt_rrrf(iirfilt_rrrf _q, unsigned int _nff
return liquid_autotest_validate_spectrum(psd,_nfft,_regions,num_regions,debug_filename);
}

// callback function to simplify testing for framing objects
int framing_autotest_callback(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _context)
{
printf("*** callback invoked (%s) ***\n", _payload_valid ? "pass" : "FAIL");
unsigned int * secret = (unsigned int*) _context;
*secret = FRAMING_AUTOTEST_SECRET;
return 0;
}

13 changes: 12 additions & 1 deletion autotest/autotest.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2022 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -316,5 +316,16 @@ int liquid_autotest_validate_psd_firfilt_cccf(firfilt_cccf _q, unsigned int _nff
int liquid_autotest_validate_psd_iirfilt_rrrf(iirfilt_rrrf _q, unsigned int _nfft,
autotest_psd_s * _regions, unsigned int num_regions, const char * debug_filename);

// callback function to simplify testing for framing objects
#define FRAMING_AUTOTEST_SECRET 0x01234567
int framing_autotest_callback(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _context);

#endif // __LIQUID_AUTOTEST_H__

18 changes: 1 addition & 17 deletions src/framing/tests/dsssframe64_autotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@
#include "autotest/autotest.h"
#include "liquid.h"

// static callback function
static int framing_autotest_callback(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _context)
{
printf("*** callback invoked (%s) ***\n", _payload_valid ? "pass" : "FAIL");
unsigned int * secret = (unsigned int*) _context;
*secret = 0x01234567;
return 0;
}

void autotest_dsssframe64sync()
{
// create objects
Expand All @@ -64,7 +48,7 @@ void autotest_dsssframe64sync()
dsssframe64sync_execute(fs, frame, frame_len);

// ensure callback was invoked
CONTEND_EQUALITY(context, 0x01234567);
CONTEND_EQUALITY(context, FRAMING_AUTOTEST_SECRET);

// parse statistics
framedatastats_s stats = dsssframe64sync_get_framedatastats(fs);
Expand Down
27 changes: 4 additions & 23 deletions src/framing/tests/dsssframesync_autotest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2022 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,25 +26,6 @@
#include "autotest/autotest.h"
#include "liquid.h"

static int callback_dsssframe(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _userdata)
{
printf("*** dsssframe callback invoked ***\n");
framesyncstats_print(&_stats);
if (_payload_valid)
*((int*)_userdata) = 1; // success
return 0;
}

//
// AUTOTEST : test simple recovery of frame in noise
//
void autotest_dsssframesync()
{
unsigned int _payload_len = 400;
Expand All @@ -60,8 +41,8 @@ void autotest_dsssframesync()
dsssframegen_assemble(fg, NULL, NULL, _payload_len);

// create dsssframesync object
int success = 0;
dsssframesync fs = dsssframesync_create(callback_dsssframe,(void*)&success);
unsigned int context = 0;
dsssframesync fs = dsssframesync_create(framing_autotest_callback, (void*)&context);

// generate the frame
int frame_complete = 0;
Expand All @@ -87,7 +68,7 @@ void autotest_dsssframesync()
CONTEND_EQUALITY( stats.num_payloads_valid, 1 );
CONTEND_EQUALITY( stats.num_bytes_received, _payload_len );
#endif
CONTEND_EQUALITY( success, 1 );
CONTEND_EQUALITY(context, FRAMING_AUTOTEST_SECRET);

// destroy objects
dsssframegen_destroy(fg);
Expand Down
8 changes: 6 additions & 2 deletions src/framing/tests/flexframesync_autotest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2023 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -49,7 +49,8 @@ void autotest_flexframesync()
flexframegen fg = flexframegen_create(&fgprops);

// create flexframesync object
flexframesync fs = flexframesync_create(NULL,NULL);
unsigned int context = 0;
flexframesync fs = flexframesync_create(framing_autotest_callback, (void*)&context);

// initialize header and payload
unsigned char header[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
Expand Down Expand Up @@ -78,6 +79,9 @@ void autotest_flexframesync()
if (liquid_autotest_verbose)
flexframesync_print(fs);

// ensure callback was invoked
CONTEND_EQUALITY(context, FRAMING_AUTOTEST_SECRET);

// check to see that frame was recovered
CONTEND_EQUALITY( stats.num_frames_detected, 1 );
CONTEND_EQUALITY( stats.num_headers_valid, 1 );
Expand Down
43 changes: 13 additions & 30 deletions src/framing/tests/framesync64_autotest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2022 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -27,30 +27,15 @@
#include "autotest/autotest.h"
#include "liquid.h"

static int callback_framesync64_autotest(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _userdata)
{
//printf("callback invoked, payload valid: %s\n", _payload_valid ? "yes" : "no");
*((int*)(_userdata)) += _header_valid && _payload_valid ? 1 : 0;
return 0;
}

// AUTOTEST : test simple recovery of frame in noise
void autotest_framesync64()
{
unsigned int i;
int frames_recovered = 0;

// create objects
unsigned int context = 0;
framegen64 fg = framegen64_create();
framesync64 fs = framesync64_create(callback_framesync64_autotest,
(void*)&frames_recovered);
framesync64 fs = framesync64_create(framing_autotest_callback, (void*)&context);

// generate the frame
float complex frame[LIQUID_FRAME64_LEN];
Expand All @@ -63,8 +48,8 @@ void autotest_framesync64()
// try to receive the frame
framesync64_execute(fs, frame, LIQUID_FRAME64_LEN);

// check to see that exactly one frame was recovered
CONTEND_EQUALITY( frames_recovered, 1 );
// ensure callback was actually invoked
CONTEND_EQUALITY(context, FRAMING_AUTOTEST_SECRET);

// parse statistics
framedatastats_s stats = framesync64_get_framedatastats(fs);
Expand Down Expand Up @@ -97,13 +82,12 @@ void autotest_framegen64_copy()
void autotest_framesync64_copy()
{
unsigned int i;
int frames_recovered_0 = 0;
int frames_recovered_1 = 0;
int context_0 = 0;
int context_1 = 0;

// create objects
framegen64 fg = framegen64_create();
framesync64 fs0 = framesync64_create(callback_framesync64_autotest,
(void*)&frames_recovered_0);
framesync64 fs0 = framesync64_create(framing_autotest_callback, (void*)&context_0);

// feed random samples into synchronizer
float complex buf[LIQUID_FRAME64_LEN];
Expand All @@ -120,7 +104,7 @@ void autotest_framesync64_copy()

// copy object, but set different context
framesync64 fs1 = framesync64_copy(fs0);
framesync64_set_userdata(fs1, (void*)&frames_recovered_1);
framesync64_set_userdata(fs1, (void*)&context_1);
framesync64_print(fs0);
framesync64_print(fs1);

Expand All @@ -131,12 +115,12 @@ void autotest_framesync64_copy()
framesync64_execute(fs1, buf+i, 1);

// ensure that the frames are recovered at exactly the same time
CONTEND_EQUALITY( frames_recovered_0, frames_recovered_1 );
CONTEND_EQUALITY( context_0, context_1 );
}

// check that frame was actually recovered by each object
CONTEND_EQUALITY( frames_recovered_0, 1 );
CONTEND_EQUALITY( frames_recovered_1, 1 );
CONTEND_EQUALITY( context_0, 0x01234567 );
CONTEND_EQUALITY( context_1, 0x01234567 );

// parse statistics
framedatastats_s stats_0 = framesync64_get_framedatastats(fs0);
Expand Down Expand Up @@ -174,13 +158,12 @@ void autotest_framesync64_config()
framesync64 q = framesync64_create(NULL, NULL);

CONTEND_EQUALITY(LIQUID_OK, framesync64_print(q))
CONTEND_EQUALITY(LIQUID_OK, framesync64_set_callback(q,callback_framesync64_autotest))
CONTEND_EQUALITY(LIQUID_OK, framesync64_set_callback(q,NULL))
CONTEND_EQUALITY(LIQUID_OK, framesync64_set_userdata(q,NULL))

CONTEND_EQUALITY(LIQUID_OK, framesync64_set_threshold(q,0.654321f))
CONTEND_EQUALITY(0.654321f, framesync64_get_threshold(q))


framesync64_destroy(q);
}

Expand Down
25 changes: 5 additions & 20 deletions src/framing/tests/fskframesync_autotest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2023 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -27,20 +27,6 @@
#include "autotest/autotest.h"
#include "liquid.h"

static int callback_fskframesync_autotest(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _userdata)
{
//printf("callback invoked, payload valid: %s\n", _payload_valid ? "yes" : "no");
*((int*)(_userdata)) += _header_valid && _payload_valid ? 1 : 0;
return 0;
}

// AUTOTEST : test simple recovery of frame in noise
void autotest_fskframesync()
{
Expand All @@ -60,12 +46,11 @@ void autotest_fskframesync()
float gamma = powf(10.0f, (SNRdB+noise_floor)/20.0f); // channel gain

unsigned int i;
int frames_recovered = 0;
unsigned int context = 0;

// create objects
fskframegen fg = fskframegen_create();
fskframesync fs = fskframesync_create(callback_fskframesync_autotest,
(void*)&frames_recovered);
fskframesync fs = fskframesync_create(framing_autotest_callback, (void*)&context);

// assemble the frame
unsigned char header [ 8];
Expand Down Expand Up @@ -94,8 +79,8 @@ void autotest_fskframesync()
fskframesync_execute_block(fs, buf_rx, buf_len);
}

// check to see that exactly one frame was recovered
CONTEND_EQUALITY( frames_recovered, 1 );
// check to see that callback was invoked
CONTEND_EQUALITY(context, FRAMING_AUTOTEST_SECRET);

#if 0
// parse statistics
Expand Down
29 changes: 4 additions & 25 deletions src/framing/tests/gmskframe_autotest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 - 2022 Joseph Gaeddert
* Copyright (c) 2007 - 2024 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,26 +26,6 @@
#include "autotest/autotest.h"
#include "liquid.h"

static int gmskframesync_autotest_callback(
unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _userdata)
{
// check data
unsigned int * secret = (unsigned int*) _userdata;
unsigned int i, num_errors = 0;
for (i=0; i<8; i++)
num_errors += _header[i] != i;
for (i=0; i<_payload_len; i++)
num_errors += _payload[i] != (i & 0xff);
*secret = num_errors == 0 ? 0x01234567 : 0;
return 0;
}

// test simple recovery of GMSK frame
void autotest_gmskframesync_process()
{
Expand All @@ -54,14 +34,13 @@ void autotest_gmskframesync_process()
crc_scheme crc = LIQUID_CRC_32;
fec_scheme fec0 = LIQUID_FEC_NONE;
fec_scheme fec1 = LIQUID_FEC_NONE;
unsigned int secret = 0; // placeholder for secret return value
unsigned int context = 0;

// create objects
gmskframegen fg = gmskframegen_create();

// create frame synchronizer
gmskframesync fs = gmskframesync_create(
gmskframesync_autotest_callback,(void*)&secret);
gmskframesync fs = gmskframesync_create(framing_autotest_callback, (void*)&context);

if (liquid_autotest_verbose) {
gmskframegen_print(fg);
Expand Down Expand Up @@ -91,7 +70,7 @@ void autotest_gmskframesync_process()
CONTEND_EQUALITY( gmskframesync_is_frame_open(fs), 0 );

// check to see that frame was recovered
CONTEND_EQUALITY( secret, 0x01234567 );
CONTEND_EQUALITY( context, FRAMING_AUTOTEST_SECRET );

// parse statistics
framedatastats_s stats = gmskframesync_get_framedatastats(fs);
Expand Down
Loading

0 comments on commit 966c26b

Please sign in to comment.