From f747b07db8a57971266e75c3d73fddb9b7ebca29 Mon Sep 17 00:00:00 2001 From: Martine Lenders <mlenders@inf.fu-berlin.de> Date: Sat, 25 Jul 2015 01:33:02 +0200 Subject: [PATCH] unittests: adapt ng_pktbuf tests for new API --- .../unittests/tests-ipv6_hdr/tests-ipv6_hdr.c | 11 +- tests/unittests/tests-pktbuf/tests-pktbuf.c | 490 +++++++++--------- 2 files changed, 261 insertions(+), 240 deletions(-) diff --git a/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c b/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c index 0aea586e89..c4dd482166 100644 --- a/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c +++ b/tests/unittests/tests-ipv6_hdr/tests-ipv6_hdr.c @@ -304,6 +304,7 @@ static void test_ipv6_hdr_build__wrong_src_len(void) ng_ipv6_addr_t src = DEFAULT_TEST_SRC; ng_ipv6_addr_t dst = DEFAULT_TEST_DST; + ng_pktbuf_init(); TEST_ASSERT_NULL(ng_ipv6_hdr_build(NULL, (uint8_t *)&src, sizeof(ng_ipv6_addr_t) + TEST_UINT8, (uint8_t *)&dst, @@ -316,6 +317,7 @@ static void test_ipv6_hdr_build__wrong_dst_len(void) ng_ipv6_addr_t src = DEFAULT_TEST_SRC; ng_ipv6_addr_t dst = DEFAULT_TEST_DST; + ng_pktbuf_init(); TEST_ASSERT_NULL(ng_ipv6_hdr_build(NULL, (uint8_t *)&src, sizeof(ng_ipv6_addr_t), (uint8_t *)&dst, @@ -329,7 +331,7 @@ static void test_ipv6_hdr_build__src_NULL(void) ng_pktsnip_t *pkt; ng_ipv6_hdr_t *hdr; - TEST_ASSERT(ng_pktbuf_is_empty()); + ng_pktbuf_init(); TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, NULL, 0, (uint8_t *)&dst, sizeof(ng_ipv6_addr_t)))); hdr = pkt->data; @@ -341,7 +343,6 @@ static void test_ipv6_hdr_build__src_NULL(void) TEST_ASSERT_EQUAL_INT(0, hdr->hl); TEST_ASSERT(ng_ipv6_addr_equal(&dst, &hdr->dst)); TEST_ASSERT(!ng_pktbuf_is_empty()); - ng_pktbuf_reset(); } static void test_ipv6_hdr_build__dst_NULL(void) @@ -350,7 +351,7 @@ static void test_ipv6_hdr_build__dst_NULL(void) ng_pktsnip_t *pkt; ng_ipv6_hdr_t *hdr; - TEST_ASSERT(ng_pktbuf_is_empty()); + ng_pktbuf_init(); TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, (uint8_t *)&src, sizeof(ng_ipv6_addr_t), NULL, 0))); @@ -363,7 +364,6 @@ static void test_ipv6_hdr_build__dst_NULL(void) TEST_ASSERT_EQUAL_INT(0, hdr->hl); TEST_ASSERT(ng_ipv6_addr_equal(&src, &hdr->src)); TEST_ASSERT(!ng_pktbuf_is_empty()); - ng_pktbuf_reset(); } static void test_ipv6_hdr_build__complete(void) @@ -373,7 +373,7 @@ static void test_ipv6_hdr_build__complete(void) ng_pktsnip_t *pkt; ng_ipv6_hdr_t *hdr; - TEST_ASSERT(ng_pktbuf_is_empty()); + ng_pktbuf_init(); TEST_ASSERT_NOT_NULL((pkt = ng_ipv6_hdr_build(NULL, (uint8_t *)&src, sizeof(ng_ipv6_addr_t), (uint8_t *)&dst, @@ -388,7 +388,6 @@ static void test_ipv6_hdr_build__complete(void) TEST_ASSERT(ng_ipv6_addr_equal(&src, &hdr->src)); TEST_ASSERT(ng_ipv6_addr_equal(&dst, &hdr->dst)); TEST_ASSERT(!ng_pktbuf_is_empty()); - ng_pktbuf_reset(); } Test *tests_ipv6_hdr_tests(void) diff --git a/tests/unittests/tests-pktbuf/tests-pktbuf.c b/tests/unittests/tests-pktbuf/tests-pktbuf.c index c54dfe897b..4abe42907a 100644 --- a/tests/unittests/tests-pktbuf/tests-pktbuf.c +++ b/tests/unittests/tests-pktbuf/tests-pktbuf.c @@ -32,96 +32,72 @@ typedef struct __attribute__((packed)) { int16_t s16; int32_t s32; int64_t s64; -} test_pktbuf_struct_t; +} +test_pktbuf_struct_t; -static void tear_down(void) +static void set_up(void) { - ng_pktbuf_reset(); + ng_pktbuf_init(); } -static void test_pktbuf_reset(void) +static void test_pktbuf_init(void) { TEST_ASSERT(ng_pktbuf_is_empty()); TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), - NG_NETTYPE_UNDEF)); + NG_NETTYPE_TEST)); TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, TEST_STRING8, sizeof(TEST_STRING8), - NG_NETTYPE_UNDEF)); + NG_NETTYPE_TEST)); TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), - NG_NETTYPE_UNDEF)); + NG_NETTYPE_TEST)); + TEST_ASSERT(ng_pktbuf_is_sane()); TEST_ASSERT(!ng_pktbuf_is_empty()); - ng_pktbuf_reset(); + ng_pktbuf_init(); TEST_ASSERT(ng_pktbuf_is_empty()); } static void test_pktbuf_add__pkt_NULL__data_NULL__size_0(void) { - ng_pktsnip_t *pkt; - - TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(NULL, NULL, 0, NG_NETTYPE_UNDEF))); - - TEST_ASSERT_NULL(pkt->next); - TEST_ASSERT_NULL(pkt->data); - TEST_ASSERT_EQUAL_INT(0, pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); - - TEST_ASSERT(!ng_pktbuf_is_empty()); + TEST_ASSERT_NULL(ng_pktbuf_add(NULL, NULL, 0, NG_NETTYPE_TEST)); + TEST_ASSERT(ng_pktbuf_is_empty()); } static void test_pktbuf_add__pkt_NOT_NULL__data_NULL__size_0(void) { - ng_pktsnip_t *pkt, *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), - NG_NETTYPE_UNDEF); + ng_pktsnip_t *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), + NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(next); - TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(next, NULL, 0, NG_NETTYPE_UNDEF))); - - TEST_ASSERT(pkt->next == next); - TEST_ASSERT_NULL(pkt->data); - TEST_ASSERT_EQUAL_INT(0, pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); - + TEST_ASSERT_NULL(ng_pktbuf_add(next, NULL, 0, NG_NETTYPE_TEST)); TEST_ASSERT_NULL(next->next); TEST_ASSERT_EQUAL_STRING(TEST_STRING4, next->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), next->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); - + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, next->type); + TEST_ASSERT(ng_pktbuf_is_sane()); TEST_ASSERT(!ng_pktbuf_is_empty()); } static void test_pktbuf_add__pkt_NULL__data_NOT_NULL__size_0(void) { - ng_pktsnip_t *pkt; - - TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(NULL, TEST_STRING8, 0, NG_NETTYPE_UNDEF))); - - TEST_ASSERT_NULL(pkt->next); - TEST_ASSERT_NOT_NULL(pkt->data); - TEST_ASSERT_EQUAL_INT(0, pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); - - TEST_ASSERT(!ng_pktbuf_is_empty()); + TEST_ASSERT_NULL(ng_pktbuf_add(NULL, TEST_STRING8, 0, NG_NETTYPE_TEST)); + TEST_ASSERT(ng_pktbuf_is_empty()); } static void test_pktbuf_add__pkt_NOT_NULL__data_NOT_NULL__size_0(void) { - ng_pktsnip_t *pkt, *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), - NG_NETTYPE_UNDEF); + ng_pktsnip_t *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), + NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(next); - TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(next, TEST_STRING8, 0, NG_NETTYPE_UNDEF))); - - TEST_ASSERT(pkt->next == next); - TEST_ASSERT_NOT_NULL(pkt->data); - TEST_ASSERT_EQUAL_INT(0, pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_NULL(ng_pktbuf_add(next, TEST_STRING8, 0, NG_NETTYPE_TEST)); TEST_ASSERT_NULL(next->next); TEST_ASSERT_EQUAL_STRING(TEST_STRING4, next->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), next->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, next->type); + TEST_ASSERT(ng_pktbuf_is_sane()); TEST_ASSERT(!ng_pktbuf_is_empty()); } @@ -130,34 +106,35 @@ static void test_pktbuf_add__pkt_NULL__data_NULL__size_not_0(void) ng_pktsnip_t *pkt; TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), - NG_NETTYPE_UNDEF))); + NG_NETTYPE_TEST))); TEST_ASSERT_NULL(pkt->next); TEST_ASSERT_NOT_NULL(pkt->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_EQUAL_INT(1, pkt->users); + TEST_ASSERT(ng_pktbuf_is_sane()); TEST_ASSERT(!ng_pktbuf_is_empty()); } static void test_pktbuf_add__pkt_NOT_NULL__data_NULL__size_not_0(void) { ng_pktsnip_t *pkt, *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), - NG_NETTYPE_UNDEF); + NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(next); - TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(next, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF))); + TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(next, NULL, sizeof(TEST_STRING8), NG_NETTYPE_TEST))); TEST_ASSERT(pkt->next == next); TEST_ASSERT_NOT_NULL(pkt->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_NULL(next->next); TEST_ASSERT_EQUAL_STRING(TEST_STRING4, next->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), next->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT(!ng_pktbuf_is_empty()); } @@ -165,84 +142,50 @@ static void test_pktbuf_add__pkt_NOT_NULL__data_NULL__size_not_0(void) static void test_pktbuf_add__pkt_NOT_NULL__data_NOT_NULL__size_not_0(void) { ng_pktsnip_t *pkt, *next = ng_pktbuf_add(NULL, TEST_STRING4, sizeof(TEST_STRING4), - NG_NETTYPE_UNDEF); + NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(next); TEST_ASSERT_NOT_NULL((pkt = ng_pktbuf_add(next, TEST_STRING8, sizeof(TEST_STRING8), - NG_NETTYPE_UNDEF))); + NG_NETTYPE_TEST))); TEST_ASSERT(pkt->next == next); TEST_ASSERT_EQUAL_STRING(TEST_STRING8, pkt->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_NULL(next->next); TEST_ASSERT_EQUAL_STRING(TEST_STRING4, next->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING4), next->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); + TEST_ASSERT(ng_pktbuf_is_sane()); TEST_ASSERT(!ng_pktbuf_is_empty()); } -static void test_pktbuf_add__in_place(void) -{ - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), - NG_NETTYPE_UNDEF); - ng_pktsnip_t *header; - - TEST_ASSERT_NOT_NULL((header = ng_pktbuf_add(pkt, pkt->data, 4, NG_NETTYPE_UNDEF))); - TEST_ASSERT(header == pkt->next); - TEST_ASSERT_EQUAL_STRING(TEST_STRING16, header->data); /* there is no 0 byte */ - TEST_ASSERT_EQUAL_INT(4, header->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, header->type); - TEST_ASSERT_EQUAL_INT(1, header->users); - TEST_ASSERT_EQUAL_STRING(TEST_STRING16 + 4, pkt->data); - TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 4, pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); - TEST_ASSERT_EQUAL_INT(1, pkt->users); - ng_pktbuf_release(header); - ng_pktbuf_release(pkt); - TEST_ASSERT(ng_pktbuf_is_empty()); -} - -#if NG_PKTBUF_SIZE > 0 static void test_pktbuf_add__memfull(void) { - TEST_ASSERT_NULL(ng_pktbuf_add(NULL, NULL, NG_PKTBUF_SIZE + 1, NG_NETTYPE_UNDEF)); - TEST_ASSERT(ng_pktbuf_is_empty()); -} - -static void test_pktbuf_add__memfull2(void) -{ - TEST_ASSERT_NULL(ng_pktbuf_add(NULL, NULL, NG_PKTBUF_SIZE - sizeof(ng_pktsnip_t), - NG_NETTYPE_UNDEF)); - TEST_ASSERT(ng_pktbuf_is_empty()); -} - -static void test_pktbuf_add__memfull3(void) -{ - for (int i = 0; i < 9; i++) { - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, (NG_PKTBUF_SIZE / 10) + 4, NG_NETTYPE_UNDEF)); - /* Why 4? Because: http://xkcd.com/221/, thats why ;-) */ + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, 1, NG_NETTYPE_TEST); + while (pkt) { + pkt = ng_pktbuf_add(NULL, NULL, 1, NG_NETTYPE_TEST); } - TEST_ASSERT_NULL(ng_pktbuf_add(NULL, NULL, (NG_PKTBUF_SIZE / 10) + 4, NG_NETTYPE_UNDEF)); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT(!ng_pktbuf_is_empty()); } -#endif static void test_pktbuf_add__success(void) { ng_pktsnip_t *pkt, *pkt_prev = NULL; for (int i = 0; i < 9; i++) { - pkt = ng_pktbuf_add(NULL, NULL, (NG_PKTBUF_SIZE / 10) + 4, NG_NETTYPE_UNDEF); + pkt = ng_pktbuf_add(NULL, NULL, (NG_PKTBUF_SIZE / 10) + 4, NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt); TEST_ASSERT_NULL(pkt->next); TEST_ASSERT_NOT_NULL(pkt->data); TEST_ASSERT_EQUAL_INT((NG_PKTBUF_SIZE / 10) + 4, pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_EQUAL_INT(1, pkt->users); if (pkt_prev != NULL) { @@ -252,6 +195,7 @@ static void test_pktbuf_add__success(void) pkt_prev = pkt; } + TEST_ASSERT(ng_pktbuf_is_sane()); } static void test_pktbuf_add__packed_struct(void) @@ -260,7 +204,7 @@ static void test_pktbuf_add__packed_struct(void) 34, -4469, 149699748, -46590430597 }; test_pktbuf_struct_t *data_cpy; - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, &data, sizeof(test_pktbuf_struct_t), NG_NETTYPE_UNDEF); + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, &data, sizeof(test_pktbuf_struct_t), NG_NETTYPE_TEST); data_cpy = (test_pktbuf_struct_t *)pkt->data; TEST_ASSERT_EQUAL_INT(data.u8, data_cpy->u8); @@ -275,14 +219,14 @@ static void test_pktbuf_add__packed_struct(void) static void test_pktbuf_add__unaligned_in_aligned_hole(void) { - ng_pktsnip_t *pkt1 = ng_pktbuf_add(NULL, NULL, 8, NG_NETTYPE_UNDEF); - ng_pktsnip_t *pkt2 = ng_pktbuf_add(NULL, NULL, 8, NG_NETTYPE_UNDEF); - ng_pktsnip_t *pkt3 = ng_pktbuf_add(NULL, NULL, 8, NG_NETTYPE_UNDEF); + ng_pktsnip_t *pkt1 = ng_pktbuf_add(NULL, NULL, 8, NG_NETTYPE_TEST); + ng_pktsnip_t *pkt2 = ng_pktbuf_add(NULL, NULL, 8, NG_NETTYPE_TEST); + ng_pktsnip_t *pkt3 = ng_pktbuf_add(NULL, NULL, 8, NG_NETTYPE_TEST); ng_pktsnip_t *pkt4; void *tmp_data2 = pkt2->data; ng_pktbuf_release(pkt2); - pkt4 = ng_pktbuf_add(NULL, TEST_STRING12, 9, NG_NETTYPE_UNDEF); + pkt4 = ng_pktbuf_add(NULL, TEST_STRING12, 9, NG_NETTYPE_TEST); TEST_ASSERT(tmp_data2 != pkt4->data); @@ -292,171 +236,287 @@ static void test_pktbuf_add__unaligned_in_aligned_hole(void) TEST_ASSERT(ng_pktbuf_is_empty()); } -static void test_pktbuf_realloc_data__pkt_NULL(void) +static void test_pktbuf_mark__pkt_NULL__size_0(void) { - TEST_ASSERT_EQUAL_INT(ENOENT, ng_pktbuf_realloc_data(NULL, 0)); - TEST_ASSERT(ng_pktbuf_is_empty()); + TEST_ASSERT_NULL(ng_pktbuf_mark(NULL, 0, NG_NETTYPE_TEST)); } -static void test_pktbuf_realloc_data__pkt_wrong(void) +static void test_pktbuf_mark__pkt_NULL__size_not_0(void) { - ng_pktsnip_t pkt = { 1, NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF }; - - TEST_ASSERT_EQUAL_INT(ENOENT, ng_pktbuf_realloc_data(&pkt, 0)); - TEST_ASSERT(ng_pktbuf_is_empty()); + TEST_ASSERT_NULL(ng_pktbuf_mark(NULL, sizeof(TEST_STRING4), NG_NETTYPE_TEST)); } -static void test_pktbuf_realloc_data__pkt_data_wrong(void) +static void test_pktbuf_mark__pkt_NOT_NULL__size_0(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); - void *orig_data = pkt->data; - pkt->data = TEST_STRING8; + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), + NG_NETTYPE_TEST); - TEST_ASSERT_EQUAL_INT(ENOENT, ng_pktbuf_realloc_data(pkt, 0)); - pkt->data = orig_data; - ng_pktbuf_release(pkt); - TEST_ASSERT(ng_pktbuf_is_empty()); + TEST_ASSERT_NOT_NULL(pkt); + TEST_ASSERT_NULL(ng_pktbuf_mark(pkt, 0, NG_NETTYPE_TEST)); + TEST_ASSERT_NULL(pkt->next); + TEST_ASSERT_NOT_NULL(pkt->data); + TEST_ASSERT_EQUAL_STRING(TEST_STRING16, pkt->data); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16), pkt->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); + TEST_ASSERT_EQUAL_INT(1, pkt->users); } -static void test_pktbuf_realloc_data__pkt_users_gt_1(void) +static void test_pktbuf_mark__pkt_NOT_NULL__size_greater_than_pkt_size(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); - ng_pktbuf_hold(pkt, 1); + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), + NG_NETTYPE_TEST); - TEST_ASSERT_EQUAL_INT(EINVAL, ng_pktbuf_realloc_data(pkt, sizeof(TEST_STRING8) - 1)); - ng_pktbuf_release(pkt); - ng_pktbuf_release(pkt); - TEST_ASSERT(ng_pktbuf_is_empty()); + TEST_ASSERT_NOT_NULL(pkt); + TEST_ASSERT_NULL(ng_pktbuf_mark(pkt, sizeof(TEST_STRING16) + 8, + NG_NETTYPE_TEST)); + TEST_ASSERT_NULL(pkt->next); + TEST_ASSERT_NOT_NULL(pkt->data); + TEST_ASSERT_EQUAL_STRING(TEST_STRING16, pkt->data); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16), pkt->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); + TEST_ASSERT_EQUAL_INT(1, pkt->users); } -static void test_pktbuf_realloc_data__pkt_next_neq_NULL(void) +static void test_pktbuf_mark__pkt_NOT_NULL__pkt_data_NULL(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); + ng_pktsnip_t pkt = { 1, NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_TEST }; - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(pkt, pkt->data, sizeof(TEST_STRING4), NG_NETTYPE_UNDEF)); - TEST_ASSERT_EQUAL_INT(EINVAL, ng_pktbuf_realloc_data(pkt, sizeof(TEST_STRING8) - 1)); - ng_pktbuf_release(pkt); - TEST_ASSERT(ng_pktbuf_is_empty()); + TEST_ASSERT_NULL(ng_pktbuf_mark(&pkt, sizeof(TEST_STRING16) - 1, + NG_NETTYPE_TEST)); + TEST_ASSERT_NULL(pkt.next); + TEST_ASSERT_NULL(pkt.data); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16), pkt.size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt.type); + TEST_ASSERT_EQUAL_INT(1, pkt.users); } -static void test_pktbuf_realloc_data__size_0(void) +static void test_pktbuf_mark__success_large(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); + uint8_t *data = (uint8_t *)(TEST_STRING16); + ng_pktsnip_t *pkt1 = ng_pktbuf_add(NULL, data, sizeof(TEST_STRING16), + NG_NETTYPE_TEST); + ng_pktsnip_t *pkt2; + uint8_t exp_data1[sizeof(TEST_STRING16) - sizeof(TEST_STRING8)]; + uint8_t exp_data2[sizeof(TEST_STRING8)]; - TEST_ASSERT_EQUAL_INT(ENOMEM, ng_pktbuf_realloc_data(pkt, 0)); - ng_pktbuf_release(pkt); + memcpy(exp_data1, data + sizeof(exp_data2), sizeof(exp_data1)); + memcpy(exp_data2, data, sizeof(exp_data2)); + + TEST_ASSERT_NOT_NULL(pkt1); + TEST_ASSERT_NOT_NULL((pkt2 = ng_pktbuf_mark(pkt1, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF))); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT(pkt1->next == pkt2); + TEST_ASSERT_NOT_NULL(pkt1->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data1, pkt1->data, pkt1->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - sizeof(TEST_STRING8), + pkt1->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); + TEST_ASSERT_EQUAL_INT(1, pkt1->users); + TEST_ASSERT_NULL(pkt2->next); + TEST_ASSERT_NOT_NULL(pkt2->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data2, pkt2->data, pkt2->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt2->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt2->type); + TEST_ASSERT_EQUAL_INT(1, pkt2->users); + + /* check if slightly larger packet would override data */ + ng_pktbuf_remove_snip(pkt1, pkt2); + pkt2 = ng_pktbuf_add(NULL, TEST_STRING12, 12, NG_NETTYPE_TEST); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT_NOT_NULL(pkt1->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data1, pkt1->data, pkt1->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - sizeof(TEST_STRING8), + pkt1->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); + TEST_ASSERT_EQUAL_INT(1, pkt1->users); + + /* check if everything can be cleaned up */ + ng_pktbuf_release(pkt1); + ng_pktbuf_release(pkt2); TEST_ASSERT(ng_pktbuf_is_empty()); } -#if NG_PKTBUF_SIZE > 0 -static void test_pktbuf_realloc_data__memfull(void) +static void test_pktbuf_mark__success_aligned(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); + uint8_t *data = (uint8_t *)(TEST_STRING16); + ng_pktsnip_t *pkt1 = ng_pktbuf_add(NULL, data, sizeof(TEST_STRING16), + NG_NETTYPE_TEST); + ng_pktsnip_t *pkt2; + uint8_t exp_data1[sizeof(TEST_STRING16) - 8]; + uint8_t exp_data2[8]; - TEST_ASSERT_EQUAL_INT(ENOMEM, ng_pktbuf_realloc_data(pkt, NG_PKTBUF_SIZE + 1)); - ng_pktbuf_release(pkt); + memcpy(exp_data1, data + sizeof(exp_data2), sizeof(exp_data1)); + memcpy(exp_data2, data, sizeof(exp_data2)); + + TEST_ASSERT_NOT_NULL(pkt1); + TEST_ASSERT_NOT_NULL((pkt2 = ng_pktbuf_mark(pkt1, 8, NG_NETTYPE_UNDEF))); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT(pkt1->next == pkt2); + TEST_ASSERT_NOT_NULL(pkt1->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data1, pkt1->data, pkt1->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 8, + pkt1->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); + TEST_ASSERT_EQUAL_INT(1, pkt1->users); + TEST_ASSERT_NULL(pkt2->next); + TEST_ASSERT_NOT_NULL(pkt2->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data2, pkt2->data, pkt2->size)); + TEST_ASSERT_EQUAL_INT(8, pkt2->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt2->type); + TEST_ASSERT_EQUAL_INT(1, pkt2->users); + + /* check if slightly larger packet would override data */ + ng_pktbuf_remove_snip(pkt1, pkt2); + pkt2 = ng_pktbuf_add(NULL, TEST_STRING12, 12, NG_NETTYPE_TEST); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT_NOT_NULL(pkt1->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data1, pkt1->data, pkt1->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 8, + pkt1->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); + TEST_ASSERT_EQUAL_INT(1, pkt1->users); + + /* check if everything can be cleaned up */ + ng_pktbuf_release(pkt1); + ng_pktbuf_release(pkt2); TEST_ASSERT(ng_pktbuf_is_empty()); } -static void test_pktbuf_realloc_data__memfull2(void) +static void test_pktbuf_mark__success_small(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); + uint8_t *data = (uint8_t *)(TEST_STRING16); + ng_pktsnip_t *pkt1 = ng_pktbuf_add(NULL, data, sizeof(TEST_STRING16), + NG_NETTYPE_TEST); + ng_pktsnip_t *pkt2; + uint8_t exp_data1[sizeof(TEST_STRING16) - 1]; + uint8_t exp_data2[1]; - TEST_ASSERT_NOT_NULL(pkt); - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF)); - TEST_ASSERT_EQUAL_INT(ENOMEM, ng_pktbuf_realloc_data(pkt, NG_PKTBUF_SIZE - sizeof(TEST_STRING8))); + memcpy(exp_data1, data + sizeof(exp_data2), sizeof(exp_data1)); + memcpy(exp_data2, data, sizeof(exp_data2)); + + TEST_ASSERT_NOT_NULL(pkt1); + TEST_ASSERT_NOT_NULL((pkt2 = ng_pktbuf_mark(pkt1, 1, NG_NETTYPE_UNDEF))); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT(pkt1->next == pkt2); + TEST_ASSERT_NOT_NULL(pkt1->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data1, pkt1->data, pkt1->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 1, pkt1->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); + TEST_ASSERT_EQUAL_INT(1, pkt1->users); + TEST_ASSERT_NULL(pkt2->next); + TEST_ASSERT_NOT_NULL(pkt2->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data2, pkt2->data, pkt2->size)); + TEST_ASSERT_EQUAL_INT(1, pkt2->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt2->type); + TEST_ASSERT_EQUAL_INT(1, pkt2->users); + + /* check if slightly larger packet would override data */ + ng_pktbuf_remove_snip(pkt1, pkt2); + pkt2 = ng_pktbuf_add(NULL, TEST_STRING12, 3, NG_NETTYPE_TEST); + TEST_ASSERT(ng_pktbuf_is_sane()); + TEST_ASSERT_NOT_NULL(pkt1->data); + TEST_ASSERT_EQUAL_INT(0, memcmp(exp_data1, pkt1->data, pkt1->size)); + TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 1, pkt1->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); + TEST_ASSERT_EQUAL_INT(1, pkt1->users); + + /* check if everything can be cleaned up */ + ng_pktbuf_release(pkt1); + ng_pktbuf_release(pkt2); + TEST_ASSERT(ng_pktbuf_is_empty()); } -static void test_pktbuf_realloc_data__memfull3(void) +static void test_pktbuf_realloc_data__size_0(void) { - ng_pktsnip_t *pkt; + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_TEST); - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF)); + TEST_ASSERT_EQUAL_INT(ENOMEM, ng_pktbuf_realloc_data(pkt, 0)); + ng_pktbuf_release(pkt); + TEST_ASSERT(ng_pktbuf_is_empty()); +} - pkt = ng_pktbuf_add(NULL, NULL, TEST_UINT8, NG_NETTYPE_UNDEF); +static void test_pktbuf_realloc_data__memfull(void) +{ + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_TEST); - TEST_ASSERT_NOT_NULL(pkt); - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF)); - TEST_ASSERT_EQUAL_INT(ENOMEM, ng_pktbuf_realloc_data(pkt, NG_PKTBUF_SIZE - TEST_UINT8)); + TEST_ASSERT_EQUAL_INT(ENOMEM, ng_pktbuf_realloc_data(pkt, NG_PKTBUF_SIZE + 1)); + ng_pktbuf_release(pkt); + TEST_ASSERT(ng_pktbuf_is_empty()); } -/* dynamic malloc is a little more unpredictable ;-) */ static void test_pktbuf_realloc_data__shrink(void) { ng_pktsnip_t *pkt; void *exp_data; - pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); + pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_TEST); exp_data = pkt->data; TEST_ASSERT_NOT_NULL(pkt); - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, 4, NG_NETTYPE_UNDEF)); + TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, 4, NG_NETTYPE_TEST)); - TEST_ASSERT_EQUAL_INT(0, ng_pktbuf_realloc_data(pkt, sizeof(TEST_STRING8))); + TEST_ASSERT_EQUAL_INT(0, ng_pktbuf_realloc_data(pkt, 8)); TEST_ASSERT(exp_data == pkt->data); TEST_ASSERT_NULL(pkt->next); - TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(8, pkt->size); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_EQUAL_INT(1, pkt->users); } static void test_pktbuf_realloc_data__memenough(void) { ng_pktsnip_t *pkt; - void *exp_data; - pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); - exp_data = pkt->data; + pkt = ng_pktbuf_add(NULL, NULL, sizeof(TEST_STRING16), NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt); TEST_ASSERT_EQUAL_INT(0, ng_pktbuf_realloc_data(pkt, sizeof(TEST_STRING8))); - TEST_ASSERT(exp_data == pkt->data); TEST_ASSERT_NULL(pkt->next); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_EQUAL_INT(1, pkt->users); } static void test_pktbuf_realloc_data__nomemenough(void) { ng_pktsnip_t *pkt1, *pkt2; - void *exp_data; - pkt1 = ng_pktbuf_add(NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); - exp_data = pkt1->data; + pkt1 = ng_pktbuf_add(NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt1); - pkt2 = ng_pktbuf_add(NULL, NULL, 1, NG_NETTYPE_UNDEF); + pkt2 = ng_pktbuf_add(NULL, NULL, 1, NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt2); - TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, 4, NG_NETTYPE_UNDEF)); + TEST_ASSERT_NOT_NULL(ng_pktbuf_add(NULL, NULL, 4, NG_NETTYPE_TEST)); ng_pktbuf_release(pkt2); TEST_ASSERT_EQUAL_INT(0, ng_pktbuf_realloc_data(pkt1, 200)); - TEST_ASSERT(exp_data != pkt1->data); TEST_ASSERT_NULL(pkt1->next); TEST_ASSERT_EQUAL_INT(200, pkt1->size); TEST_ASSERT_EQUAL_STRING(TEST_STRING8, pkt1->data); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt1->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt1->type); TEST_ASSERT_EQUAL_INT(1, pkt1->users); } -#endif static void test_pktbuf_realloc_data__success(void) { + char exp_data[] = TEST_STRING16; ng_pktsnip_t *pkt; - pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); + pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt); TEST_ASSERT_EQUAL_INT(0, ng_pktbuf_realloc_data(pkt, sizeof(TEST_STRING8))); TEST_ASSERT_NULL(pkt->next); - TEST_ASSERT_EQUAL_STRING(TEST_STRING16, pkt->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING8), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + for (unsigned int i = 0; i < pkt->size; i++) { + uint8_t *data = pkt->data; + TEST_ASSERT_EQUAL_INT(exp_data[i], data[i]); + } + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_EQUAL_INT(1, pkt->users); } @@ -464,7 +524,7 @@ static void test_pktbuf_realloc_data__success2(void) { ng_pktsnip_t *pkt; - pkt = ng_pktbuf_add(NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF); + pkt = ng_pktbuf_add(NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt); @@ -472,41 +532,10 @@ static void test_pktbuf_realloc_data__success2(void) TEST_ASSERT_NULL(pkt->next); TEST_ASSERT_EQUAL_STRING(TEST_STRING8, pkt->data); TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16), pkt->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, pkt->type); + TEST_ASSERT_EQUAL_INT(NG_NETTYPE_TEST, pkt->type); TEST_ASSERT_EQUAL_INT(1, pkt->users); } -static void test_pktbuf_realloc_data__further_down_the_line(void) -{ - ng_pktsnip_t *pkt1, *pkt2, *header; - void *exp_data; - - pkt1 = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); - exp_data = pkt1->data; - - TEST_ASSERT_NOT_NULL(pkt1); - - header = ng_pktbuf_add(pkt1, pkt1->data, 4, NG_NETTYPE_UNDEF); - pkt2 = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); - - TEST_ASSERT_NOT_NULL(header); - TEST_ASSERT(header == pkt1->next); - TEST_ASSERT_EQUAL_INT(4, header->size); - TEST_ASSERT(((uint8_t *)pkt1->data) == (((uint8_t *)header->data) + 4)); - TEST_ASSERT_EQUAL_INT(sizeof(TEST_STRING16) - 4, pkt1->size); - - TEST_ASSERT_EQUAL_INT(0, ng_pktbuf_realloc_data(header, 40)); - TEST_ASSERT(exp_data != header->data); - TEST_ASSERT_NULL(header->next); - TEST_ASSERT_EQUAL_STRING(TEST_STRING16, header->data); - TEST_ASSERT_EQUAL_INT(40, header->size); - TEST_ASSERT_EQUAL_INT(NG_NETTYPE_UNDEF, header->type); - TEST_ASSERT_EQUAL_INT(1, header->users); - ng_pktbuf_release(pkt1); - ng_pktbuf_release(pkt2); - TEST_ASSERT(ng_pktbuf_is_empty()); -} - static void test_pktbuf_hold__pkt_null(void) { ng_pktbuf_hold(NULL, 1); @@ -515,7 +544,7 @@ static void test_pktbuf_hold__pkt_null(void) static void test_pktbuf_hold__pkt_external(void) { - ng_pktsnip_t pkt = { 1, NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF }; + ng_pktsnip_t pkt = { 1, NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_TEST }; ng_pktbuf_hold(&pkt, 1); TEST_ASSERT(ng_pktbuf_is_empty()); @@ -523,7 +552,7 @@ static void test_pktbuf_hold__pkt_external(void) static void test_pktbuf_hold__success(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_TEST); for (uint8_t i = 0; i < TEST_UINT8; i++) { uint8_t prev_users = pkt->users; @@ -534,7 +563,7 @@ static void test_pktbuf_hold__success(void) static void test_pktbuf_hold__success2(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_TEST); ng_pktbuf_hold(pkt, TEST_UINT8); @@ -549,7 +578,7 @@ static void test_pktbuf_release__pkt_null(void) static void test_pktbuf_release__pkt_external(void) { - ng_pktsnip_t pkt = { 1, NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_UNDEF }; + ng_pktsnip_t pkt = { 1, NULL, TEST_STRING8, sizeof(TEST_STRING8), NG_NETTYPE_TEST }; ng_pktbuf_release(&pkt); TEST_ASSERT(ng_pktbuf_is_empty()); @@ -557,7 +586,7 @@ static void test_pktbuf_release__pkt_external(void) static void test_pktbuf_release__success(void) { - ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_UNDEF); + ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), NG_NETTYPE_TEST); for (uint8_t i = 0; i < TEST_UINT8; i++) { uint8_t prev_users = pkt->users; @@ -587,7 +616,7 @@ static void test_pktbuf_start_write__NULL(void) static void test_pktbuf_start_write__pkt_users_1(void) { ng_pktsnip_t *pkt_copy, *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), - NG_NETTYPE_UNDEF); + NG_NETTYPE_TEST); TEST_ASSERT_NOT_NULL((pkt_copy = ng_pktbuf_start_write(pkt))); TEST_ASSERT(pkt == pkt_copy); @@ -598,7 +627,7 @@ static void test_pktbuf_start_write__pkt_users_1(void) static void test_pktbuf_start_write__pkt_users_2(void) { ng_pktsnip_t *pkt_copy, *pkt = ng_pktbuf_add(NULL, TEST_STRING16, sizeof(TEST_STRING16), - NG_NETTYPE_UNDEF); + NG_NETTYPE_TEST); ng_pktbuf_hold(pkt, 1); TEST_ASSERT_NOT_NULL((pkt_copy = ng_pktbuf_start_write(pkt))); @@ -618,7 +647,7 @@ static void test_pktbuf_start_write__pkt_users_2(void) Test *tests_pktbuf_tests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { - new_TestFixture(test_pktbuf_reset), + new_TestFixture(test_pktbuf_init), new_TestFixture(test_pktbuf_add__pkt_NULL__data_NULL__size_0), new_TestFixture(test_pktbuf_add__pkt_NOT_NULL__data_NULL__size_0), new_TestFixture(test_pktbuf_add__pkt_NULL__data_NOT_NULL__size_0), @@ -626,32 +655,25 @@ Test *tests_pktbuf_tests(void) new_TestFixture(test_pktbuf_add__pkt_NULL__data_NULL__size_not_0), new_TestFixture(test_pktbuf_add__pkt_NOT_NULL__data_NULL__size_not_0), new_TestFixture(test_pktbuf_add__pkt_NOT_NULL__data_NOT_NULL__size_not_0), - new_TestFixture(test_pktbuf_add__in_place), -#if NG_PKTBUF_SIZE > 0 new_TestFixture(test_pktbuf_add__memfull), - new_TestFixture(test_pktbuf_add__memfull2), - new_TestFixture(test_pktbuf_add__memfull3), -#endif new_TestFixture(test_pktbuf_add__success), new_TestFixture(test_pktbuf_add__packed_struct), new_TestFixture(test_pktbuf_add__unaligned_in_aligned_hole), - new_TestFixture(test_pktbuf_realloc_data__pkt_NULL), - new_TestFixture(test_pktbuf_realloc_data__pkt_wrong), - new_TestFixture(test_pktbuf_realloc_data__pkt_data_wrong), - new_TestFixture(test_pktbuf_realloc_data__pkt_users_gt_1), - new_TestFixture(test_pktbuf_realloc_data__pkt_next_neq_NULL), + new_TestFixture(test_pktbuf_mark__pkt_NULL__size_0), + new_TestFixture(test_pktbuf_mark__pkt_NULL__size_not_0), + new_TestFixture(test_pktbuf_mark__pkt_NOT_NULL__size_0), + new_TestFixture(test_pktbuf_mark__pkt_NOT_NULL__size_greater_than_pkt_size), + new_TestFixture(test_pktbuf_mark__pkt_NOT_NULL__pkt_data_NULL), + new_TestFixture(test_pktbuf_mark__success_large), + new_TestFixture(test_pktbuf_mark__success_aligned), + new_TestFixture(test_pktbuf_mark__success_small), new_TestFixture(test_pktbuf_realloc_data__size_0), -#if NG_PKTBUF_SIZE > 0 new_TestFixture(test_pktbuf_realloc_data__memfull), - new_TestFixture(test_pktbuf_realloc_data__memfull2), - new_TestFixture(test_pktbuf_realloc_data__memfull3), new_TestFixture(test_pktbuf_realloc_data__nomemenough), new_TestFixture(test_pktbuf_realloc_data__shrink), new_TestFixture(test_pktbuf_realloc_data__memenough), -#endif new_TestFixture(test_pktbuf_realloc_data__success), new_TestFixture(test_pktbuf_realloc_data__success2), - new_TestFixture(test_pktbuf_realloc_data__further_down_the_line), new_TestFixture(test_pktbuf_hold__pkt_null), new_TestFixture(test_pktbuf_hold__pkt_external), new_TestFixture(test_pktbuf_hold__success), @@ -664,7 +686,7 @@ Test *tests_pktbuf_tests(void) new_TestFixture(test_pktbuf_start_write__pkt_users_2), }; - EMB_UNIT_TESTCALLER(ng_pktbuf_tests, NULL, tear_down, fixtures); + EMB_UNIT_TESTCALLER(ng_pktbuf_tests, set_up, NULL, fixtures); return (Test *)&ng_pktbuf_tests; } -- GitLab