From 17b3c3aca1290a3f2c20a0858d4d499a17752ced Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Fri, 27 Nov 2015 13:26:20 +0100 Subject: msgb/test: Add test case for error cases Include a test for msgb_trim. Sponsored-by: On-Waves ehf --- tests/msgb/msgb_test.c | 22 ++++++++++++++++++++++ tests/msgb/msgb_test.ok | 2 ++ 2 files changed, 24 insertions(+) diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c index e6cb33ec..8839a2ed 100644 --- a/tests/msgb/msgb_test.c +++ b/tests/msgb/msgb_test.c @@ -121,6 +121,27 @@ static void test_msgb_api() msgb_free(msg); } +static void test_msgb_api_errors() +{ + struct msgb *msg = msgb_alloc_headroom(4096, 128, "data"); + volatile int e = 0; + int rc; + + printf("Testing the msgb API error handling\n"); + + osmo_set_panic_handler(osmo_panic_raise); + + if (OSMO_PANIC_TRY(&e)) + msgb_trim(msg, -1); + OSMO_ASSERT(e != 0); + + rc = msgb_trim(msg, 4096 + 500); + OSMO_ASSERT(rc == -1); + + msgb_free(msg); + osmo_set_panic_handler(NULL); +} + static void test_msgb_copy() { struct msgb *msg = msgb_alloc_headroom(4096, 128, "data"); @@ -263,6 +284,7 @@ int main(int argc, char **argv) osmo_init_logging(&info); test_msgb_api(); + test_msgb_api_errors(); test_msgb_copy(); test_msgb_resize_area(); diff --git a/tests/msgb/msgb_test.ok b/tests/msgb/msgb_test.ok index 4cb76a98..6603fe71 100644 --- a/tests/msgb/msgb_test.ok +++ b/tests/msgb/msgb_test.ok @@ -18,6 +18,8 @@ Test msgb_hexdump Buffer: (L1=data-124) 00 00 00 00 00 00 00 00 [L2]> 00 00 00 00 [L3]> (L4=tail+4) Buffer: (L1=data-124) 00 00 00 00 00 00 00 00 [L2]> (L3+8) 00 00 00 00 (L4=tail+4) Buffer: (L1=data-124) 00 00 00 00 00 00 00 00 [L2]> 00 00 00 00 (L3 out of range) (L4=tail+4) +Testing the msgb API error handling +msgb(%p): Negative length is not allowed Testing msgb_copy Src: [L1]> 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 [L2]> 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 [L3]> 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b [L4]> 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f Dst: [L1]> 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 [L2]> 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 [L3]> 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b [L4]> 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f -- cgit v1.2.3