Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
c935a075
Commit
c935a075
authored
7 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys/net/gnrc/pkt: match pktsnip struct start with iolist_t
parent
ff6b8aa4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/net/gnrc/pkt.h
+8
-3
8 additions, 3 deletions
sys/include/net/gnrc/pkt.h
tests/unittests/tests-pkt/tests-pkt.c
+45
-4
45 additions, 4 deletions
tests/unittests/tests-pkt/tests-pkt.c
with
53 additions
and
7 deletions
sys/include/net/gnrc/pkt.h
+
8
−
3
View file @
c935a075
...
@@ -96,20 +96,25 @@ extern "C" {
...
@@ -96,20 +96,25 @@ extern "C" {
* | * L2 header 3
* | * L2 header 3
* * L2 header 4
* * L2 header 4
*
*
* The first three fields (next, data, size) match iolist_t (named iol_next,
* iol_base and iol_len there). That means that any pktsnip can be casted to
* iolist_t for direct passing to e.g., netdev send() functions.
*
* @note This type has no initializer on purpose. Please use @ref net_gnrc_pktbuf
* @note This type has no initializer on purpose. Please use @ref net_gnrc_pktbuf
* as factory.
* as factory.
*/
*/
/* packed to be aligned correctly in the static packet buffer */
/* packed to be aligned correctly in the static packet buffer */
typedef
struct
gnrc_pktsnip
{
typedef
struct
gnrc_pktsnip
{
/* the first three fields *MUST* match iolist_t! */
struct
gnrc_pktsnip
*
next
;
/**< next snip in the packet */
void
*
data
;
/**< pointer to the data of the snip */
size_t
size
;
/**< the length of the snip in byte */
/**
/**
* @brief Counter of threads currently having control over this packet.
* @brief Counter of threads currently having control over this packet.
*
*
* @internal
* @internal
*/
*/
unsigned
int
users
;
unsigned
int
users
;
struct
gnrc_pktsnip
*
next
;
/**< next snip in the packet */
void
*
data
;
/**< pointer to the data of the snip */
size_t
size
;
/**< the length of the snip in byte */
gnrc_nettype_t
type
;
/**< protocol of the packet snip */
gnrc_nettype_t
type
;
/**< protocol of the packet snip */
#ifdef MODULE_GNRC_NETERR
#ifdef MODULE_GNRC_NETERR
kernel_pid_t
err_sub
;
/**< subscriber to errors related to this
kernel_pid_t
err_sub
;
/**< subscriber to errors related to this
...
...
This diff is collapsed.
Click to expand it.
tests/unittests/tests-pkt/tests-pkt.c
+
45
−
4
View file @
c935a075
...
@@ -13,21 +13,27 @@
...
@@ -13,21 +13,27 @@
* @file
* @file
*/
*/
#include
<errno.h>
#include
<errno.h>
#include
<stddef.h>
#include
<stdint.h>
#include
<stdint.h>
#include
<string.h>
#include
"embUnit/embUnit.h"
#include
"embUnit/embUnit.h"
#include
"net/gnrc/pkt.h"
#include
"net/gnrc/pkt.h"
#include
"net/gnrc/nettype.h"
#include
"net/gnrc/nettype.h"
#include
"iolist.h"
#include
"unittests-constants.h"
#include
"unittests-constants.h"
#include
"tests-pkt.h"
#include
"tests-pkt.h"
#define _INIT_ELEM(len, data, next) \
#define _INIT_ELEM(len, _data, _next) \
{ 1, (next), (data), (len), GNRC_NETTYPE_UNDEF }
{ .users = 1, .next = (_next), .data = (_data), \
.size = (len), .type = GNRC_NETTYPE_UNDEF \
}
#define _INIT_ELEM_STATIC_DATA(data, next) _INIT_ELEM(sizeof(data), data, next)
#define _INIT_ELEM_STATIC_DATA(data, next) _INIT_ELEM(sizeof(data), data, next)
#define _INIT_ELEM_STATIC_TYPE(type, next) \
#define _INIT_ELEM_STATIC_TYPE(
_
type,
_
next) \
{
1, (next), NULL, 0, (
type) }
{
.users = 1, .next = (_next), .data = NULL, .size = 0, .type = (_
type) }
static
void
test_pkt_len__NULL
(
void
)
static
void
test_pkt_len__NULL
(
void
)
{
{
...
@@ -129,6 +135,40 @@ static void test_pktsnip_search_type(void)
...
@@ -129,6 +135,40 @@ static void test_pktsnip_search_type(void)
TEST_ASSERT_NULL
(
gnrc_pktsnip_search_type
(
&
snip3
,
GNRC_NETTYPE_NUMOF
));
TEST_ASSERT_NULL
(
gnrc_pktsnip_search_type
(
&
snip3
,
GNRC_NETTYPE_NUMOF
));
}
}
static
void
test_pkt_equals_iolist
(
void
)
{
iolist_t
iol
;
gnrc_pktsnip_t
pkt
;
memset
(
&
iol
,
'\0'
,
sizeof
(
iol
));
memset
(
&
pkt
,
'\0'
,
sizeof
(
pkt
));
/* compare empty structs */
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
&
iol
,
&
pkt
,
sizeof
(
iol
)));
/* check next pointer position */
iol
.
iol_next
=
(
void
*
)
0xAAAAAAAA
;
pkt
.
next
=
(
void
*
)
0xAAAAAAAA
;
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
&
iol
,
&
pkt
,
sizeof
(
iol
)));
/* check data pointer position */
iol
.
iol_base
=
&
iol
;
pkt
.
data
=
&
iol
;
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
&
iol
,
&
pkt
,
sizeof
(
iol
)));
/* check size position */
iol
.
iol_len
=
0x12345678
;
pkt
.
size
=
0x12345678
;
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
&
iol
,
&
pkt
,
sizeof
(
iol
)));
TEST_ASSERT_EQUAL_INT
(
offsetof
(
iolist_t
,
iol_next
),
offsetof
(
gnrc_pktsnip_t
,
next
));
TEST_ASSERT_EQUAL_INT
(
offsetof
(
iolist_t
,
iol_base
),
offsetof
(
gnrc_pktsnip_t
,
data
));
TEST_ASSERT_EQUAL_INT
(
offsetof
(
iolist_t
,
iol_len
),
offsetof
(
gnrc_pktsnip_t
,
size
));
}
Test
*
tests_pkt_tests
(
void
)
Test
*
tests_pkt_tests
(
void
)
{
{
EMB_UNIT_TESTFIXTURES
(
fixtures
)
{
EMB_UNIT_TESTFIXTURES
(
fixtures
)
{
...
@@ -143,6 +183,7 @@ Test *tests_pkt_tests(void)
...
@@ -143,6 +183,7 @@ Test *tests_pkt_tests(void)
new_TestFixture
(
test_pkt_count__5_elem
),
new_TestFixture
(
test_pkt_count__5_elem
),
new_TestFixture
(
test_pkt_count__null
),
new_TestFixture
(
test_pkt_count__null
),
new_TestFixture
(
test_pktsnip_search_type
),
new_TestFixture
(
test_pktsnip_search_type
),
new_TestFixture
(
test_pkt_equals_iolist
),
};
};
EMB_UNIT_TESTCALLER
(
pkt_tests
,
NULL
,
NULL
,
fixtures
);
EMB_UNIT_TESTCALLER
(
pkt_tests
,
NULL
,
NULL
,
fixtures
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment