fix the testcode bug

Previously, test code could be executed although HSS-MME is not
connected.
As such, I've fixed test code is executed right after HSS-MME is connected
This commit is contained in:
Sukchan Lee 2017-08-02 19:15:30 +09:00
parent 432626628c
commit bcbb08acf5
9 changed files with 85 additions and 22 deletions

View file

@ -8,7 +8,7 @@ libs6a_la_SOURCES = \
s6a_lib.h
nodist_libs6a_la_SOURCES = \
s6a_init.c s6a_fd.c s6a_config.c s6a_debug.c s6a_dict.c
s6a_init.c s6a_fd.c s6a_config.c s6a_hook.c s6a_dict.c
libs6a_la_DEPENDENCIES = \
$(top_srcdir)/lib/base/libbase.la \

View file

@ -1,4 +1,4 @@
#define TRACE_MODULE _s6a
#define TRACE_MODULE _s6a_fd
#include "core_debug.h"
#include "core_param.h"
@ -11,8 +11,6 @@ static void s6a_gnutls_log_func(int level, const char *str);
static void s6a_fd_logger(int printlevel, const char *format, va_list ap);
extern status_t s6a_config_apply();
extern int s6a_debug_init();
extern void s6a_debug_final();
int s6a_fd_init(const char *conffile)
{
@ -46,7 +44,7 @@ int s6a_fd_init(const char *conffile)
}
/* register debug hook */
CHECK_FCT_DO( s6a_debug_init(), goto error );
CHECK_FCT_DO( s6a_hook_init(), goto error );
/* Start the servers */
CHECK_FCT_DO( fd_core_start(), goto error );
@ -63,7 +61,7 @@ error:
void s6a_fd_final()
{
s6a_debug_final();
s6a_hook_final();
CHECK_FCT_DO( fd_core_shutdown(), d_error("fd_core_shutdown() failed") );
CHECK_FCT_DO( fd_core_wait_shutdown_complete(),

View file

@ -1,20 +1,27 @@
#define TRACE_MODULE _s6a_debug
#define TRACE_MODULE _s6a_hook
#include "core_debug.h"
#include "s6a_lib.h"
static struct fd_hook_hdl *md_hdl = NULL;
static struct fd_hook_hdl *s6a_hook_hdl = NULL;
static char * buf = NULL;
static size_t len;
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static s6a_hook_user_handler s6a_hook_user_handler_instance = NULL;
/* The callback called when messages are received and sent */
static void md_hook_cb_tree(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata)
static void s6a_hook_cb_tree(enum fd_hook_type type, struct msg * msg,
struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd,
void * regdata)
{
char * peer_name = peer ? peer->info.pi_diamid : "<unknown peer>";
CHECK_POSIX_DO( pthread_mutex_lock(&mtx), );
if (s6a_hook_user_handler_instance)
s6a_hook_user_handler_instance(type, msg, peer, other, pmd, regdata);
if (msg) {
CHECK_MALLOC_DO( fd_msg_dump_treeview(&buf, &len, NULL, msg, fd_g_config->cnf_dict, (type == HOOK_MESSAGE_PARSING_ERROR) ? 0 : 1, 1),
@ -102,7 +109,7 @@ static void md_hook_cb_tree(enum fd_hook_type type, struct msg * msg, struct pee
CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), );
}
int s6a_debug_init()
int s6a_hook_init()
{
uint32_t mask_errors, mask_sndrcv, mask_routing, mask_peers;
uint32_t mask_tree;
@ -121,12 +128,22 @@ int s6a_debug_init()
mask_tree |= mask_peers;
CHECK_FCT( fd_hook_register(
mask_tree, md_hook_cb_tree, NULL, NULL, &md_hdl) );
mask_tree, s6a_hook_cb_tree, NULL, NULL, &s6a_hook_hdl) );
return 0;
}
void s6a_debug_final()
void s6a_hook_final()
{
if (md_hdl) { CHECK_FCT_DO( fd_hook_unregister( md_hdl ), ); }
if (s6a_hook_hdl) { CHECK_FCT_DO( fd_hook_unregister( s6a_hook_hdl ), ); }
}
void s6a_hook_register(s6a_hook_user_handler instance)
{
s6a_hook_user_handler_instance = instance;
}
void s6a_hook_unregister(void)
{
s6a_hook_user_handler_instance = NULL;
}

View file

@ -164,6 +164,16 @@ CORE_DECLARE(void) s6a_final(void);
CORE_DECLARE(int) s6a_config_init(void);
CORE_DECLARE(int) s6a_hook_init();
CORE_DECLARE(void) s6a_hook_final();
typedef void (*s6a_hook_user_handler)(
enum fd_hook_type type, struct msg *msg, struct peer_hdr *peer,
void *other, struct fd_hook_permsgdata *pmd, void *regdata);
CORE_DECLARE(void) s6a_hook_register(s6a_hook_user_handler instance);
CORE_DECLARE(void) s6a_hook_unregister();
#ifdef __cplusplus
}
#endif /* __cplusplus */

4
main.c
View file

@ -4,6 +4,7 @@
/* Core library */
#define TRACE_MODULE _main_
#include "core_general.h"
#include "core_debug.h"
#include "core_signal.h"
@ -116,10 +117,12 @@ int main(int argc, char *argv[])
show_version();
d_print("\n");
core_initialize();
if (app_initialize(config_path, log_path) != CORE_OK)
{
d_fatal("NextEPC initialization failed. Aborted");
app_terminate();
core_terminate();
return EXIT_FAILURE;
}
@ -130,6 +133,7 @@ int main(int argc, char *argv[])
d_info("NextEPC daemon terminating...");
app_terminate();
core_terminate();
return EXIT_SUCCESS;
}

View file

@ -289,12 +289,12 @@ status_t hss_context_setup_trace_module()
{
extern int _hss_s6a_handler;
d_trace_level(&_hss_s6a_handler, s6a);
extern int _s6a;
d_trace_level(&_s6a, s6a);
extern int _s6a_fd;
d_trace_level(&_s6a_fd, s6a);
extern int _s6a_init;
d_trace_level(&_s6a_init, s6a);
extern int _s6a_debug;
d_trace_level(&_s6a_debug, s6a);
extern int _s6a_hook;
d_trace_level(&_s6a_hook, s6a);
}
if (others)

View file

@ -1,6 +1,5 @@
#define TRACE_MODULE _app
#include "core_general.h"
#include "core_debug.h"
#include "core_thread.h"
#include "core_net.h"
@ -20,7 +19,9 @@ status_t app_will_initialize(char *config_path, char *log_path)
{
status_t rv;
#if 0
core_initialize();
#endif
context_init();
rv = context_read_file(config_path);
@ -68,7 +69,9 @@ void app_will_terminate(void)
void app_did_terminate(void)
{
context_final();
#if 0
core_terminate();
#endif
}
void *THREAD_FUNC net_main(thread_id id, void *data)

View file

@ -828,12 +828,12 @@ status_t mme_context_setup_trace_module()
{
extern int _mme_s6a_handler;
d_trace_level(&_mme_s6a_handler, s6a);
extern int _s6a;
d_trace_level(&_s6a, s6a);
extern int _s6a_fd;
d_trace_level(&_s6a_fd, s6a);
extern int _s6a_init;
d_trace_level(&_s6a_init, s6a);
extern int _s6a_debug;
d_trace_level(&_s6a_debug, s6a);
extern int _s6a_hook;
d_trace_level(&_s6a_hook, s6a);
}
if (gtp)

View file

@ -14,13 +14,17 @@
* limitations under the License.
*/
#include "core_general.h"
#include "core_debug.h"
#include "core_semaphore.h"
#include "s6a_lib.h"
#include "app.h"
#include "mme_context.h"
#include "abts.h"
#include "testutil.h"
#if 0
void core_assert_ok(abts_case* tc, const char* context, status_t rv,
int lineno)
{
@ -35,16 +39,43 @@ void core_assert_ok(abts_case* tc, const char* context, status_t rv,
abts_fail(tc, buf, lineno);
}
}
#endif
static semaphore_id test_sem;
static void test_s6a_hook_handler(enum fd_hook_type type, struct msg * msg,
struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd,
void * regdata)
{
if (type == HOOK_PEER_CONNECT_SUCCESS)
{
d_assert(semaphore_post(test_sem) == CORE_OK,,
"semaphore_post() failed");
}
}
void test_terminate(void)
{
app_terminate();
core_terminate();
}
void test_initialize(void)
{
s6a_hook_register(test_s6a_hook_handler);
core_initialize();
d_assert(semaphore_create(&test_sem, 0) == CORE_OK,
return, "semaphore_create() failed");
app_initialize(NULL, NULL);
d_assert(semaphore_wait(test_sem) == CORE_OK, return,
"semaphore_wait() failed");
d_assert(semaphore_wait(test_sem) == CORE_OK, return,
"semaphore_wait() failed");
d_assert(semaphore_delete(test_sem) == CORE_OK, return,
"semaphore_delete() failed");
atexit(test_terminate);
}