[PATCH 11/13] tests: e1inp_ipa_*_test: add signal handling for process termination

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

pablo at gnumonks.org pablo at gnumonks.org
Thu Aug 23 22:45:00 UTC 2012


From: Pablo Neira Ayuso <pablo at gnumonks.org>

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.
---
 tests/e1inp_ipa_bsc_test.c |   17 +++++++++++++++--
 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");
-- 
1.7.10.4





More information about the OpenBSC mailing list