From 966c26be89c69ae52ab18257ad06e3207006f386 Mon Sep 17 00:00:00 2001 From: "Joseph D. Gaeddert" Date: Mon, 18 Mar 2024 17:58:41 -0400 Subject: [PATCH] framing/autotest: using consistent internal callback --- autotest/autotest.c | 18 ++++++++- autotest/autotest.h | 13 ++++++- src/framing/tests/dsssframe64_autotest.c | 18 +-------- src/framing/tests/dsssframesync_autotest.c | 27 ++------------ src/framing/tests/flexframesync_autotest.c | 8 +++- src/framing/tests/framesync64_autotest.c | 43 +++++++--------------- src/framing/tests/fskframesync_autotest.c | 25 +++---------- src/framing/tests/gmskframe_autotest.c | 29 ++------------- src/framing/tests/ofdmflexframe_autotest.c | 9 ++++- 9 files changed, 69 insertions(+), 121 deletions(-) diff --git a/autotest/autotest.c b/autotest/autotest.c index 78a62a529..ccd3cb785 100644 --- a/autotest/autotest.c +++ b/autotest/autotest.c @@ -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 @@ -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; +} + diff --git a/autotest/autotest.h b/autotest/autotest.h index 148a50311..5945ab5e2 100644 --- a/autotest/autotest.h +++ b/autotest/autotest.h @@ -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 @@ -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__ diff --git a/src/framing/tests/dsssframe64_autotest.c b/src/framing/tests/dsssframe64_autotest.c index 030e7abf1..f8b14490a 100644 --- a/src/framing/tests/dsssframe64_autotest.c +++ b/src/framing/tests/dsssframe64_autotest.c @@ -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 @@ -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); diff --git a/src/framing/tests/dsssframesync_autotest.c b/src/framing/tests/dsssframesync_autotest.c index bb8234c8c..1ef54d4d1 100644 --- a/src/framing/tests/dsssframesync_autotest.c +++ b/src/framing/tests/dsssframesync_autotest.c @@ -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 @@ -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; @@ -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; @@ -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); diff --git a/src/framing/tests/flexframesync_autotest.c b/src/framing/tests/flexframesync_autotest.c index f5e984ed4..a7546fed6 100644 --- a/src/framing/tests/flexframesync_autotest.c +++ b/src/framing/tests/flexframesync_autotest.c @@ -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 @@ -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}; @@ -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 ); diff --git a/src/framing/tests/framesync64_autotest.c b/src/framing/tests/framesync64_autotest.c index 7a1b78cc7..6393fe2c7 100644 --- a/src/framing/tests/framesync64_autotest.c +++ b/src/framing/tests/framesync64_autotest.c @@ -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 @@ -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]; @@ -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); @@ -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]; @@ -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); @@ -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); @@ -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); } diff --git a/src/framing/tests/fskframesync_autotest.c b/src/framing/tests/fskframesync_autotest.c index 9ffbef087..941e4d698 100644 --- a/src/framing/tests/fskframesync_autotest.c +++ b/src/framing/tests/fskframesync_autotest.c @@ -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 @@ -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() { @@ -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]; @@ -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 diff --git a/src/framing/tests/gmskframe_autotest.c b/src/framing/tests/gmskframe_autotest.c index aacc80182..41d9db5c4 100644 --- a/src/framing/tests/gmskframe_autotest.c +++ b/src/framing/tests/gmskframe_autotest.c @@ -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 @@ -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() { @@ -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); @@ -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); diff --git a/src/framing/tests/ofdmflexframe_autotest.c b/src/framing/tests/ofdmflexframe_autotest.c index 814ab0b29..ca243e437 100644 --- a/src/framing/tests/ofdmflexframe_autotest.c +++ b/src/framing/tests/ofdmflexframe_autotest.c @@ -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 @@ -34,6 +34,7 @@ void testbench_ofdmflexframe(unsigned int _M, modulation_scheme _ms) { // create frame generator/synchronizer + unsigned int context = 0; ofdmflexframegenprops_s fgprops; ofdmflexframegenprops_init_default(&fgprops); fgprops.check = LIQUID_CRC_32; @@ -41,7 +42,8 @@ void testbench_ofdmflexframe(unsigned int _M, fgprops.fec1 = LIQUID_FEC_NONE; fgprops.mod_scheme = _ms; ofdmflexframegen fg = ofdmflexframegen_create( _M, _cp_len, _taper_len, NULL, &fgprops); - ofdmflexframesync fs = ofdmflexframesync_create(_M, _cp_len, _taper_len, NULL, NULL, NULL); + ofdmflexframesync fs = ofdmflexframesync_create(_M, _cp_len, _taper_len, NULL, + framing_autotest_callback, (void*)&context); // initialize header and payload unsigned char header[8] = {0, 1, 2, 3, 4, 5, 6, 7}; @@ -66,6 +68,9 @@ void testbench_ofdmflexframe(unsigned int _M, if (liquid_autotest_verbose) ofdmflexframesync_print(fs); + // verify callback was invoked + CONTEND_EQUALITY( context, FRAMING_AUTOTEST_SECRET ); + // verify frame data statistics framedatastats_s stats = ofdmflexframesync_get_framedatastats(fs); CONTEND_EQUALITY( stats.num_frames_detected, 1 );