diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-23 23:26:19 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-08-30 21:50:32 +0200 |
commit | 1fd93bbc6edbf1c297d71739242e8f35aa499787 (patch) | |
tree | 1b8dba2e07b15132b97f61a40220963aa0395f86 /tests | |
parent | 7723b4e9a3fd51cec28fb48423472479cd41d95e (diff) |
tests: e1inp_ipa_*_test: add signal handling for process termination
This patch adds signal handling to release memory in the exit
path of the tests. This is good to check what memory we are
leaking in the exist path of the tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/e1inp_ipa_bsc_test.c | 17 | ||||
-rw-r--r-- | tests/e1inp_ipa_bts_test.c | 16 |
2 files changed, 30 insertions, 3 deletions
diff --git a/tests/e1inp_ipa_bsc_test.c b/tests/e1inp_ipa_bsc_test.c index a0e5653..b447893 100644 --- a/tests/e1inp_ipa_bsc_test.c +++ b/tests/e1inp_ipa_bsc_test.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <signal.h> #include <osmocom/core/talloc.h> #include <osmocom/abis/abis.h> #include <osmocom/abis/e1_input.h> @@ -199,10 +200,16 @@ const struct log_info bsc_test_log_info = { .num_cat = ARRAY_SIZE(bsc_test_cat), }; -int main(void) +static struct e1inp_line *line; + +static void sighandler(int foo) { - struct e1inp_line *line; + e1inp_line_put(line); + exit(EXIT_SUCCESS); +} +int main(void) +{ tall_test = talloc_named_const(NULL, 1, "e1inp_test"); libosmo_abis_init(tall_test); @@ -220,6 +227,12 @@ int main(void) .sign_link = sign_link, }; + if (signal(SIGINT, sighandler) == SIG_ERR || + signal(SIGTERM, sighandler) == SIG_ERR) { + perror("Cannot set sighandler"); + exit(EXIT_FAILURE); + } + #define LINENR 0 line = e1inp_line_create(LINENR, "ipa"); diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c index 1b9a2db..f885c5c 100644 --- a/tests/e1inp_ipa_bts_test.c +++ b/tests/e1inp_ipa_bts_test.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <signal.h> #include <osmocom/core/talloc.h> #include <string.h> #include <unistd.h> @@ -236,6 +237,14 @@ static int test_bts_gsm_12_21_cb(struct osmo_fd *ofd, unsigned int what) return 0; } +static struct e1inp_line *line; + +static void sighandler(int foo) +{ + e1inp_line_put(line); + exit(EXIT_SUCCESS); +} + int main(void) { struct ipaccess_unit bts_dev_info = { @@ -250,7 +259,6 @@ int main(void) .location2 = "testBTS", .serno = "", }; - struct e1inp_line *line; tall_test = talloc_named_const(NULL, 1, "e1inp_test"); libosmo_abis_init(tall_test); @@ -272,6 +280,12 @@ int main(void) #define LINENR 0 + if (signal(SIGINT, sighandler) == SIG_ERR || + signal(SIGTERM, sighandler) == SIG_ERR) { + perror("Cannot set sighandler"); + exit(EXIT_FAILURE); + } + line = e1inp_line_create(LINENR, "ipa"); if (line == NULL) { LOGP(DBTSTEST, LOGL_ERROR, "problem enabling E1 line\n"); |