From 34fc4701c7681a4855534c20a6f59d12c4c81521 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Wed, 9 Oct 2013 11:27:04 +0200 Subject: tests/gb: Show invoked signals in test output Register an osmo signal handler to print a short notice about every SS_L_NS signal that is generated while processing the tests. Sponsored-by: On-Waves ehf --- include/osmocom/gprs/gprs_ns.h | 3 +++ src/gb/libosmogb.map | 1 + tests/gb/gprs_ns_test.c | 47 +++++++++++++++++++++++++++++++++++++++++- tests/gb/gprs_ns_test.ok | 7 +++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/include/osmocom/gprs/gprs_ns.h b/include/osmocom/gprs/gprs_ns.h index c709312a..d16068be 100644 --- a/include/osmocom/gprs/gprs_ns.h +++ b/include/osmocom/gprs/gprs_ns.h @@ -176,6 +176,9 @@ void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause); /* Add NS-specific VTY stuff */ int gprs_ns_vty_init(struct gprs_ns_inst *nsi); +/* Resturn peer info as string (NOTE: the buffer is allocated statically) */ +const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc); + #define NS_ALLOC_SIZE 2048 #define NS_ALLOC_HEADROOM 20 static inline struct msgb *gprs_ns_msgb_alloc(void) diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map index 7af085c5..0270db81 100644 --- a/src/gb/libosmogb.map +++ b/src/gb/libosmogb.map @@ -54,6 +54,7 @@ gprs_ns_tx_reset; gprs_ns_tx_status; gprs_ns_tx_unblock; gprs_ns_vty_init; +gprs_ns_format_peer; gprs_nsvc_create; gprs_nsvc_delete; diff --git a/tests/gb/gprs_ns_test.c b/tests/gb/gprs_ns_test.c index d07cc3de..c4fc228a 100644 --- a/tests/gb/gprs_ns_test.c +++ b/tests/gb/gprs_ns_test.c @@ -20,11 +20,11 @@ #include #include #include +#include #include #include #include - /* GPRS Network Service, PDU type: NS_RESET, * Cause: O&M intervention, NS VCI: 0x1122, NSEI 0x1122 */ @@ -121,6 +121,50 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, return len; } +/* Signal handler for signals from NS layer */ +static int test_signal(unsigned int subsys, unsigned int signal, + void *handler_data, void *signal_data) +{ + struct ns_signal_data *nssd = signal_data; + + if (subsys != SS_L_NS) + return 0; + + switch (signal) { + case S_NS_RESET: + printf("==> got signal NS_RESET, NS-VC 0x%04x/%s\n", + nssd->nsvc->nsvci, + gprs_ns_format_peer(nssd->nsvc)); + break; + + case S_NS_ALIVE_EXP: + printf("==> got signal NS_ALIVE_EXP, NS-VC 0x%04x/%s\n", + nssd->nsvc->nsvci, + gprs_ns_format_peer(nssd->nsvc)); + break; + + case S_NS_BLOCK: + printf("==> got signal NS_BLOCK, NS-VC 0x%04x/%s\n", + nssd->nsvc->nsvci, + gprs_ns_format_peer(nssd->nsvc)); + break; + + case S_NS_UNBLOCK: + printf("==> got signal NS_UNBLOCK, NS-VC 0x%04x/%s\n", + nssd->nsvc->nsvci, + gprs_ns_format_peer(nssd->nsvc)); + break; + + default: + printf("==> got signal %d, NS-VC 0x%04x/%s\n", signal, + nssd->nsvc->nsvci, + gprs_ns_format_peer(nssd->nsvc)); + break; + } + + return 0; +} + static int gprs_process_message(struct gprs_ns_inst *nsi, const char *text, struct sockaddr_in *peer, const unsigned char* data, size_t data_len) { struct msgb *msg; @@ -238,6 +282,7 @@ int main(int argc, char **argv) osmo_init_logging(&info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); + osmo_signal_register_handler(SS_L_NS, &test_signal, NULL); printf("===== NS protocol test START\n"); test_ns(); diff --git a/tests/gb/gprs_ns_test.ok b/tests/gb/gprs_ns_test.ok index 578b9054..01b1bc91 100644 --- a/tests/gb/gprs_ns_test.ok +++ b/tests/gb/gprs_ns_test.ok @@ -2,6 +2,7 @@ PROCESSING RESET from 0x01020304:1111 02 00 81 01 01 82 11 22 04 82 11 22 +==> got signal NS_RESET, NS-VC 0x1122/1.2.3.4:1111 RESPONSE, msg length 9 03 01 82 11 22 04 82 11 22 @@ -24,6 +25,7 @@ result (ALIVE) = 1 PROCESSING UNBLOCK from 0x01020304:1111 06 +==> got signal NS_UNBLOCK, NS-VC 0x1122/1.2.3.4:1111 RESPONSE, msg length 1 07 @@ -42,6 +44,7 @@ result (BSSGP RESET) = 0 PROCESSING RESET from 0x01020304:2222 02 00 81 01 01 82 11 22 04 82 11 22 +==> got signal NS_RESET, NS-VC 0x1122/1.2.3.4:2222 RESPONSE, msg length 9 03 01 82 11 22 04 82 11 22 @@ -58,6 +61,7 @@ Current NS-VCIs: PROCESSING RESET from 0x01020304:3333 02 00 81 01 01 82 33 44 04 82 11 22 +==> got signal NS_RESET, NS-VC 0x3344/1.2.3.4:3333 RESPONSE, msg length 9 03 01 82 33 44 04 82 11 22 @@ -75,6 +79,7 @@ Current NS-VCIs: PROCESSING RESET from 0x01020304:4444 02 00 81 01 01 82 11 22 04 82 33 44 +==> got signal NS_RESET, NS-VC 0x1122/1.2.3.4:4444 RESPONSE, msg length 9 03 01 82 11 22 04 82 33 44 @@ -92,6 +97,7 @@ Current NS-VCIs: PROCESSING RESET from 0x01020304:3333 02 00 81 01 01 82 11 22 04 82 11 22 +==> got signal NS_RESET, NS-VC 0x1122/1.2.3.4:3333 RESPONSE, msg length 9 03 01 82 11 22 04 82 11 22 @@ -109,6 +115,7 @@ Current NS-VCIs: PROCESSING RESET from 0x01020304:4444 02 00 81 01 01 82 11 22 04 82 11 22 +==> got signal NS_RESET, NS-VC 0x1122/1.2.3.4:4444 RESPONSE, msg length 9 03 01 82 11 22 04 82 11 22 -- cgit v1.2.3