📄 test_sdb.c
字号:
/*************************************************************************** subsys_test.c - Testmodule for software radio subsystems ------------------- begin : 2002 authors : Linus Gasser emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 02-09-11 - ineiti - init 04/03/03 - ineiti - added a small description **************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/char desc[] ="Description:\n""Tries to allocate as many subsystems as possible, returning the\n""maximum possible once found. For the moment, this defaults to\n""1024 subsystems.\n\n";/** * Debugging priorities * * LVL 0 : Error messages only * LVL 1 : Important status messages * LVL 2 : Not too much traffic * LVL 3 : A bit more detailed * LVL 4 : S P A M - all we can do * * This way you can increase or decreas the level of debugging * messages depending on what you're doing. */#define DBG_LVL 1#include "system.h"#include "memory.h"#include "debugging.h"#include "cdb.h"#include "sdb.h"#define MAX_INST 16384swr_sdb_id *inst;int test_inst(void) { int i; swr_spc_id_t spm_id; spm_id = swr_cdb_get_id( "rrc" ); if ( spm_id < 0 ) { PR( "ERROR: couldn't get ID\n" ); return -1; } inst = swr_malloc( sizeof( swr_sdb_id ) * MAX_INST ); if ( !inst ) { PR( "ERROR: couldn't allocate %i bytes\n", sizeof( swr_sdb_id ) * MAX_INST ); return -1; } for ( i=0; i<MAX_INST; i++ ) { inst[i] = swr_sdb_instantiate_id( spm_id ); if ( inst[i] < 0 ) { break; } } if ( i < MAX_INST ) { PR( "%i maximal instances found\n", i ); } else { PR( "%i or more instances possible\n", MAX_INST ); } return i;}int test_destroy( int count ) { int i, err; if ( count > MAX_INST ) { PR( "ERROR: count too high: %i > %i\n", count, MAX_INST ); } for ( i=0; i<count; i++ ) { if ( ( err = swr_sdb_destroy( inst[i] ) < 0 ) ) { PR( "ERROR: while freeing %i, error %i occured\n", i, err ); swr_free( inst ); return -1; } } swr_free( inst ); PR( "OK\n" ); return 0;}void *test_it( void *arg ) { int i; PR_CL( desc ); PR( "Testing instances...\n" ); if ( ( i = test_inst() ) < 0 ) { return 0; } PR( "Testing deletion...\n" ); if ( test_destroy( i ) < 0 ) { return 0; } return 0;}pthread_t thread;int initialize(void) { if ( pthread_create( &thread, 0, test_it, 0) < 0 ) { PR( "Failed to create test_it thread\n"); return 1; } return 0;}void finalize(void) { pthread_join( thread, NULL ); pthread_cancel( thread ); swr_memory_show(); PR( "Thread joined, finishing\n" );}module_init(initialize);module_exit(finalize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -