aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-07-03 05:53:28 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-07-03 06:07:09 +0700
commit1a077cb0caf3d6b49f9085de7136667a2a515c16 (patch)
tree342294200183b158b3d2fda9e6f72c9cd34062f6
parent8f577fbb5c2815975ebd52596187f24ce1f1af19 (diff)
gsm0408_test: do not return early in test_bearer_cap()
Currently, if one of the testcases fails, test_bearer_cap() would abort and skip the remaining testcases. Also, a msgb would not be free()ed making the LeakSanitizer unhappy. Instead of returning early, jump to the end of loop to ensure that: * the verdict ('passed' or 'failed') is always printed, * all remaining testcases are still executed, * the msgb is free()ed. Change-Id: I39ac801e59ba56dfe3bcd4603b48f6fbf7cfb21c
-rw-r--r--tests/gsm0408/gsm0408_test.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 2aceefa0..16bc8e82 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -84,6 +84,7 @@ static int test_bearer_cap()
for (i = 0; i < ARRAY_SIZE(bcap_tests); i++) {
struct msgb *msg = msgb_alloc(100, "test");
+ bool pass = false;
int lv_len;
memset(&bc, 0, sizeof(bc));
@@ -93,7 +94,7 @@ static int test_bearer_cap()
if (rc < 0) {
fprintf(stderr, "Error decoding %s\n",
bcap_tests[i].name);
- return rc;
+ goto verdict;
}
if (memcmp(&bc, bcap_tests[i].bc, sizeof(bc))) {
fprintf(stderr, "Incorrect decoded result of %s:\n",
@@ -102,7 +103,7 @@ static int test_bearer_cap()
osmo_hexdump((uint8_t *) bcap_tests[i].bc, sizeof(bc)));
fprintf(stderr, " is: %s\n",
osmo_hexdump((uint8_t *) &bc, sizeof(bc)));
- return -1;
+ goto verdict;
}
/* also test re-encode? */
@@ -110,7 +111,7 @@ static int test_bearer_cap()
if (rc < 0) {
fprintf(stderr, "Error encoding %s\n",
bcap_tests[i].name);
- return rc;
+ goto verdict;
}
lv_len = bcap_tests[i].lv[0]+1;
if (memcmp(msg->data, bcap_tests[i].lv, lv_len)) {
@@ -120,10 +121,14 @@ static int test_bearer_cap()
osmo_hexdump(bcap_tests[i].lv, lv_len));
fprintf(stderr, " is: %s\n",
osmo_hexdump(msg->data, msg->len));
- return -1;
+ goto verdict;
}
- printf("Test `%s' passed\n", bcap_tests[i].name);
+ /* all checks passed */
+ pass = true;
+
+verdict:
+ printf("Test `%s' %sed\n", bcap_tests[i].name, pass ? "pass" : "fail");
msgb_free(msg);
}