Add test for uc_mbuf-copy_data
This commit is contained in:
@@ -43,7 +43,7 @@ struct MBuf *uc_mbuf_new_inline_hr(uint32_t len, uint32_t headroom);
|
|||||||
#define uc_mbuf_new_inline(len) uc_mbuf_new_inline_hr((len), 0)
|
#define uc_mbuf_new_inline(len) uc_mbuf_new_inline_hr((len), 0)
|
||||||
|
|
||||||
void uc_mbuf_free(struct MBuf *mbuf);
|
void uc_mbuf_free(struct MBuf *mbuf);
|
||||||
struct MBuf *uc_mbuf_copy(struct MBuf *mbuf);
|
struct MBuf *uc_mbuf_copy_data(struct MBuf *mbuf);
|
||||||
|
|
||||||
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags);
|
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags);
|
||||||
void uc_mbuf_zero(struct MBuf *mbuf);
|
void uc_mbuf_zero(struct MBuf *mbuf);
|
||||||
@@ -70,9 +70,6 @@ uint8_t *uc_mbuf_push(struct MBuf *mbuf, uint32_t size);
|
|||||||
|
|
||||||
uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size);
|
uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size);
|
||||||
|
|
||||||
struct MBuf *uc_uc_mbuf_new_hr(uint32_t len, uint32_t headroom);
|
|
||||||
struct MBuf *uc_uc_mbuf_new_inline_hr(uint32_t len, uint32_t headroom);
|
|
||||||
|
|
||||||
#undef UC_INLINE
|
#undef UC_INLINE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+21
-1
@@ -5,6 +5,7 @@
|
|||||||
uint8_t *uc_mbuf_put(struct MBuf *mbuf, uint32_t size)
|
uint8_t *uc_mbuf_put(struct MBuf *mbuf, uint32_t size)
|
||||||
{
|
{
|
||||||
uint8_t *data = mbuf->tail;
|
uint8_t *data = mbuf->tail;
|
||||||
|
|
||||||
if (uc_mbuf_tailroom(mbuf) < size) {
|
if (uc_mbuf_tailroom(mbuf) < size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -28,6 +29,7 @@ uint8_t *uc_mbuf_push(struct MBuf *mbuf, uint32_t size)
|
|||||||
uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size)
|
uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size)
|
||||||
{
|
{
|
||||||
uint8_t *data = mbuf->head;
|
uint8_t *data = mbuf->head;
|
||||||
|
|
||||||
if (uc_mbuf_len(mbuf) < size) {
|
if (uc_mbuf_len(mbuf) < size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -37,7 +39,6 @@ uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags)
|
void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags)
|
||||||
{
|
{
|
||||||
mbuf->bufstart = buf;
|
mbuf->bufstart = buf;
|
||||||
@@ -97,5 +98,24 @@ void uc_mbuf_zero(struct MBuf *mbuf)
|
|||||||
memset(mbuf->bufstart, 0, mbuf->allocated);
|
memset(mbuf->bufstart, 0, mbuf->allocated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MBuf *uc_mbuf_copy_data(struct MBuf *mbuf)
|
||||||
|
{
|
||||||
|
uint32_t len;
|
||||||
|
struct MBuf *copy;
|
||||||
|
uint8_t *data;
|
||||||
|
|
||||||
|
len = uc_mbuf_len(mbuf);
|
||||||
|
|
||||||
|
copy = uc_mbuf_new_hr(len, uc_mbuf_headroom(mbuf));
|
||||||
|
if (copy == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = uc_mbuf_put(copy, len);
|
||||||
|
memcpy(data, mbuf->head, len);
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
#undef UC_INLINE
|
#undef UC_INLINE
|
||||||
|
|
||||||
|
|||||||
@@ -174,6 +174,30 @@ START_TEST (test_mbuf_pull_fail)
|
|||||||
|
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_mbuf_copy)
|
||||||
|
struct MBuf *mbuf;
|
||||||
|
uint8_t *data1;
|
||||||
|
struct MBuf *copy;
|
||||||
|
|
||||||
|
mbuf = uc_mbuf_new_inline_hr(10,5);
|
||||||
|
fail_if(mbuf == NULL);
|
||||||
|
|
||||||
|
data1 = uc_mbuf_put(mbuf, 10);
|
||||||
|
fail_if(data1 == NULL);
|
||||||
|
|
||||||
|
strcpy((char*)data1, "123456789");
|
||||||
|
|
||||||
|
copy = uc_mbuf_copy_data(mbuf);
|
||||||
|
fail_if(copy == NULL);
|
||||||
|
fail_if(uc_mbuf_len(copy) != 10);
|
||||||
|
fail_if(uc_mbuf_headroom(copy) != 5);
|
||||||
|
fail_if(memcmp(mbuf->head, copy->head, 10) != 0);
|
||||||
|
|
||||||
|
uc_mbuf_free(mbuf);
|
||||||
|
uc_mbuf_free(copy);
|
||||||
|
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Suite *mbuf_suite(void)
|
Suite *mbuf_suite(void)
|
||||||
@@ -189,6 +213,7 @@ Suite *mbuf_suite(void)
|
|||||||
tcase_add_test(tc, test_mbuf_push_fail);
|
tcase_add_test(tc, test_mbuf_push_fail);
|
||||||
tcase_add_test(tc, test_mbuf_pull);
|
tcase_add_test(tc, test_mbuf_pull);
|
||||||
tcase_add_test(tc, test_mbuf_pull_fail);
|
tcase_add_test(tc, test_mbuf_pull_fail);
|
||||||
|
tcase_add_test(tc, test_mbuf_copy);
|
||||||
|
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user