Skip to content

Commit 6bf369f

Browse files
jukkarnashif
authored andcommitted
tests: net: pkt: Verify that net_pkt_write() writes correct data
Write the net_pkt using net_pkt_write() and then verify that the data is actually written into net_buf. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent b7c7591 commit 6bf369f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/net/net_pkt/src/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ static void test_net_pkt_allocate_with_buffer(void)
207207

208208
static void test_net_pkt_basics_of_rw(void)
209209
{
210+
struct net_pkt_cursor backup;
210211
struct net_pkt *pkt;
212+
u16_t value16;
211213
int ret;
212214

213215
pkt = net_pkt_alloc_with_buffer(eth_if, 512,
@@ -239,6 +241,31 @@ static void test_net_pkt_basics_of_rw(void)
239241
/* Length should be 3 now */
240242
zassert_true(net_pkt_get_len(pkt) == 3, "Pkt length mismatch");
241243

244+
/* Verify that the data is properly written to net_buf */
245+
net_pkt_cursor_backup(pkt, &backup);
246+
net_pkt_cursor_init(pkt);
247+
net_pkt_set_overwrite(pkt, true);
248+
net_pkt_skip(pkt, 1);
249+
net_pkt_read_be16(pkt, &value16);
250+
zassert_equal(value16, 0, "Invalid value %d read, expected %d",
251+
value16, 0);
252+
253+
/* Then write new value, overwriting the old one */
254+
net_pkt_cursor_init(pkt);
255+
net_pkt_skip(pkt, 1);
256+
ret = net_pkt_write_be16(pkt, 42);
257+
zassert_true(ret == 0, "Pkt write failed");
258+
259+
/* And re-read the value again */
260+
net_pkt_cursor_init(pkt);
261+
net_pkt_skip(pkt, 1);
262+
net_pkt_read_be16(pkt, &value16);
263+
zassert_equal(value16, 42, "Invalid value %d read, expected %d",
264+
value16, 42);
265+
266+
net_pkt_set_overwrite(pkt, false);
267+
net_pkt_cursor_restore(pkt, &backup);
268+
242269
ret = net_pkt_write_be32(pkt, 0);
243270
zassert_true(ret == 0, "Pkt write failed");
244271

0 commit comments

Comments
 (0)