Message ID | 1447753069-17466-5-git-send-email-jerlbeck@sysmocom.de |
---|---|
State | Superseded |
Headers | show |
On Tue, Nov 17, 2015 at 10:37:48AM +0100, Jacob Erlbeck wrote: > diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c > index 412e8bb..08d9857 100644 > --- a/tests/msgb/msgb_test.c > +++ b/tests/msgb/msgb_test.c > @@ -87,6 +87,7 @@ static void test_msgb_api() > msg->l3h = msg->head - 1; > printf("Buffer: %s\n", msgb_hexdump(msg)); > > + > #if 0 > extern void msgb_reset(struct msgb *m); > #define msgb_l1(m) ((void *)(MSGB_CHECK2(m)->l1h)) > @@ -97,15 +98,61 @@ static inline unsigned int msgb_l1len(const struct msgb *msgb) > static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len) > static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len) > static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len) > - > + > static inline unsigned char *msgb_pull_to_l3(struct msgb *msg) > static inline int msgb_trim(struct msgb *msg, int len) > static inline int msgb_l3trim(struct msgb *msg, int l3len) > uint8_t *msgb_data(const struct msgb *msg); > - return; > +return; > #endif > } ^ seems like those whitespace changes came in by accident... ~Neels
On 23.11.2015 10:43, Neels Hofmeyr wrote: > On Tue, Nov 17, 2015 at 10:37:48AM +0100, Jacob Erlbeck wrote: >> diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c >> index 412e8bb..08d9857 100644 >> --- a/tests/msgb/msgb_test.c >> +++ b/tests/msgb/msgb_test.c >> @@ -87,6 +87,7 @@ static void test_msgb_api() >> msg->l3h = msg->head - 1; >> printf("Buffer: %s\n", msgb_hexdump(msg)); >> >> + >> #if 0 >> extern void msgb_reset(struct msgb *m); >> #define msgb_l1(m) ((void *)(MSGB_CHECK2(m)->l1h)) >> @@ -97,15 +98,61 @@ static inline unsigned int msgb_l1len(const struct msgb *msgb) >> static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len) >> static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len) >> static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len) >> - >> + >> static inline unsigned char *msgb_pull_to_l3(struct msgb *msg) >> static inline int msgb_trim(struct msgb *msg, int len) >> static inline int msgb_l3trim(struct msgb *msg, int l3len) >> uint8_t *msgb_data(const struct msgb *msg); >> - return; >> +return; >> #endif >> } > > ^ seems like those whitespace changes came in by accident... Yes, thanks for noticing. I will remove the complete commentary block. Jacob
diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c index 412e8bb..08d9857 100644 --- a/tests/msgb/msgb_test.c +++ b/tests/msgb/msgb_test.c @@ -87,6 +87,7 @@ static void test_msgb_api() msg->l3h = msg->head - 1; printf("Buffer: %s\n", msgb_hexdump(msg)); + #if 0 extern void msgb_reset(struct msgb *m); #define msgb_l1(m) ((void *)(MSGB_CHECK2(m)->l1h)) @@ -97,15 +98,61 @@ static inline unsigned int msgb_l1len(const struct msgb *msgb) static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len) static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len) static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len) - + static inline unsigned char *msgb_pull_to_l3(struct msgb *msg) static inline int msgb_trim(struct msgb *msg, int len) static inline int msgb_l3trim(struct msgb *msg, int l3len) uint8_t *msgb_data(const struct msgb *msg); - return; +return; #endif } +static void test_msgb_copy() +{ + struct msgb *msg = msgb_alloc_headroom(4096, 128, "data"); + struct msgb *msg2; + + printf("Testing msgb_copy\n"); + + msg->l1h = msgb_put(msg, 20); + msg->l2h = msgb_put(msg, 20); + msg->l3h = msgb_put(msg, 20); + msg->l4h = msgb_put(msg, 20); + + msg2 = msgb_copy(msg, "copy"); + + OSMO_ASSERT(msgb_length(msg) == msgb_length(msg2)); + OSMO_ASSERT(msgb_l1len(msg) == msgb_l1len(msg2)); + OSMO_ASSERT(msgb_l2len(msg) == msgb_l2len(msg2)); + OSMO_ASSERT(msgb_l3len(msg) == msgb_l3len(msg2)); + OSMO_ASSERT(msg->tail - msg->l4h == msg2->tail - msg2->l4h); +} + +static void test_msgb_resize_area() +{ + struct msgb *msg = msgb_alloc_headroom(4096, 128, "data"); + int rc; + + printf("Testing msgb_resize_area\n"); + + msg->l1h = msgb_put(msg, 20); + msg->l2h = msgb_put(msg, 20); + msg->l3h = msgb_put(msg, 20); + msg->l4h = msgb_put(msg, 20); + + rc = msgb_resize_area(msg, msg->l2h, 20, 20 + 30); + + OSMO_ASSERT(rc >= 0); + OSMO_ASSERT(msgb_length(msg) == 80 + 30); + OSMO_ASSERT(msgb_l1len(msg) == 80 + 30); + OSMO_ASSERT(msgb_l2len(msg) == 60 + 30); + OSMO_ASSERT(msgb_l3len(msg) == 40); + OSMO_ASSERT(msg->tail - msg->l4h == 20); + + rc = msgb_resize_area(msg, msg->l2h, 50, 8000); + OSMO_ASSERT(rc == -1); +} + static struct log_info info = {}; int main(int argc, char **argv) @@ -113,6 +160,8 @@ int main(int argc, char **argv) osmo_init_logging(&info); test_msgb_api(); + test_msgb_copy(); + test_msgb_resize_area(); printf("Success.\n"); diff --git a/tests/msgb/msgb_test.ok b/tests/msgb/msgb_test.ok index f8de0cd..3ace5be 100644 --- a/tests/msgb/msgb_test.ok +++ b/tests/msgb/msgb_test.ok @@ -18,4 +18,6 @@ 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 msgb_copy +Testing msgb_resize_area Success.