1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pktqueue: adapt to change in pkt.h

This commit is contained in:
Martine Lenders 2015-01-30 15:41:14 +01:00 committed by Martine Lenders
parent 7317097db2
commit cb74094edd
2 changed files with 73 additions and 73 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
* Copyright (C) 2014, 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for
@ -7,24 +7,24 @@
*/
/**
* @defgroup pktqueue Packet Queue
* @defgroup ng_pktqueue Packet Queue
* @brief Packet wrapper for the Priority Queue
* @ingroup net
* @{
*
* @file pktqueue.h
* @brief `pkt_t`-centric wrapper for @ref priority_queue_t
* @file
* @brief `ng_pktsnip_t`-centric wrapper for @ref priority_queue_t
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef __PKTQUEUE_H_
#define __PKTQUEUE_H_
#ifndef NG_PKTQUEUE_H_
#define NG_PKTQUEUE_H_
#include <stdint.h>
#include <stdlib.h>
#include "pkt.h"
#include "net/ng_pkt.h"
#include "priority_queue.h"
#ifdef __cplusplus
@ -36,11 +36,11 @@ extern "C" {
*
* @extends priority_queue_node_t
*/
typedef struct pktqueue_node_t {
struct pktqueue_node_t *next; /**< next node in queue */
typedef struct ng_pktqueue_node {
struct ng_pktqueue_node *next; /**< next node in queue */
uint32_t priority; /**< priority of the node */
pkt_t *data; /**< pointer to the data */
} pktqueue_node_t;
ng_pktsnip_t *data; /**< pointer to the data */
} ng_pktqueue_node_t;
/**
* @brief data type for packet queues
@ -48,39 +48,39 @@ typedef struct pktqueue_node_t {
* @extends priority_queue_t
*/
typedef struct {
pktqueue_node_t *first; /**< first node in the queue */
} pktqueue_t;
ng_pktqueue_node_t *first; /**< first node in the queue */
} ng_pktqueue_t;
/**
* @brief Static initializer for pktqueue_node_t
* @brief Static initializer for ng_pktqueue_node_t
*/
#define PKTQUEUE_NODE_INIT { NULL, NULL, 0 }
#define NG_PKTQUEUE_NODE_INIT { NULL, NULL, 0 }
/**
* @brief Initializes a packet queue node.
* @details For initialization of variables use PKTQUEUE_NODE_INIT instead.
* @details For initialization of variables use NG_PKTQUEUE_NODE_INIT instead.
* Only use this function for dynamically allocated packet queue nodes.
*
* @param[out] node pre-allocated pktqueue_node_t object. must not be NULL.
* @param[out] node pre-allocated ng_pktqueue_node_t object. must not be NULL.
*/
static inline void pktqueue_node_init(pktqueue_node_t *node)
static inline void ng_pktqueue_node_init(ng_pktqueue_node_t *node)
{
priority_queue_node_init((priority_queue_node_t *)node);
}
/**
* @brief Static initializer for pktqueue_t.
* @brief Static initializer for ng_pktqueue_t.
*/
#define PKTQUEUE_INIT PRIORITY_QUEUE_INIT
#define NG_PKTQUEUE_INIT PRIORITY_QUEUE_INIT
/**
* @brief Initialize a packet queue object.
* @details For initialization of variables use PKTQUEUE_INIT
* @details For initialization of variables use NG_PKTQUEUE_INIT
* instead. Only use this function for dynamically allocated
* packet queues.
* @param[out] queue pre-allocated pktqueue_t object, must not be NULL.
* @param[out] queue pre-allocated ng_pktqueue_t object, must not be NULL.
*/
static inline void pktqueue_init(pktqueue_t *queue)
static inline void ng_pktqueue_init(ng_pktqueue_t *queue)
{
priority_queue_init((priority_queue_t *)queue);
}
@ -92,7 +92,7 @@ static inline void pktqueue_init(pktqueue_t *queue)
*
* @return the head
*/
static inline pktqueue_node_t *pktqueue_get_head(pktqueue_t *queue)
static inline ng_pktqueue_node_t *ng_pktqueue_get_head(ng_pktqueue_t *queue)
{
return queue->first;
}
@ -104,9 +104,9 @@ static inline pktqueue_node_t *pktqueue_get_head(pktqueue_t *queue)
*
* @return the old head
*/
static inline pktqueue_node_t *pktqueue_remove_head(pktqueue_t *queue)
static inline ng_pktqueue_node_t *ng_pktqueue_remove_head(ng_pktqueue_t *queue)
{
return (pktqueue_node_t *)priority_queue_remove_head((priority_queue_t *)queue);
return (ng_pktqueue_node_t *)priority_queue_remove_head((priority_queue_t *)queue);
}
/**
@ -118,7 +118,7 @@ static inline pktqueue_node_t *pktqueue_remove_head(pktqueue_t *queue)
* @param[in] queue the queue
* @param[in] node the node to add
*/
static inline void pktqueue_add(pktqueue_t *queue, pktqueue_node_t *node)
static inline void ng_pktqueue_add(ng_pktqueue_t *queue, ng_pktqueue_node_t *node)
{
priority_queue_add((priority_queue_t *)queue, (priority_queue_node_t *) node);
}
@ -129,7 +129,7 @@ static inline void pktqueue_add(pktqueue_t *queue, pktqueue_node_t *node)
* @param[in] queue the queue
* @param[in] node the node to remove
*/
static inline void pktqueue_remove(pktqueue_t *queue, pktqueue_node_t *node)
static inline void ng_pktqueue_remove(ng_pktqueue_t *queue, ng_pktqueue_node_t *node)
{
priority_queue_remove((priority_queue_t *)queue, (priority_queue_node_t *) node);
}
@ -138,7 +138,7 @@ static inline void pktqueue_remove(pktqueue_t *queue, pktqueue_node_t *node)
}
#endif
#endif /* __PKTQUEUE_H_ */
#endif /* NG_PKTQUEUE_H_ */
/**
* @}
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
* Copyright (C) 2014, 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
@ -15,66 +15,66 @@
#include "embUnit.h"
#include "pkt.h"
#include "pktqueue.h"
#include "net/ng_pkt.h"
#include "net/ng_pktqueue.h"
#include "tests-pktqueue.h"
#define Q_LEN (4)
static pktqueue_t q = PKTQUEUE_INIT;
static pktqueue_node_t qe[Q_LEN];
static ng_pktqueue_t q = NG_PKTQUEUE_INIT;
static ng_pktqueue_node_t qe[Q_LEN];
static void set_up(void)
{
pktqueue_init(&q);
ng_pktqueue_init(&q);
for (unsigned i = 0; i < Q_LEN; ++i) {
pktqueue_node_init(&(qe[i]));
ng_pktqueue_node_init(&(qe[i]));
}
}
static void test_pktqueue_remove_head_empty(void)
{
pktqueue_t *root = &q;
pktqueue_node_t *res;
ng_pktqueue_t *root = &q;
ng_pktqueue_node_t *res;
res = pktqueue_remove_head(root);
res = ng_pktqueue_remove_head(root);
TEST_ASSERT_NULL(res);
}
static void test_pktqueue_remove_head_one(void)
{
pktqueue_t *root = &q;
pktqueue_node_t *elem = &(qe[1]), *res;
ng_pktqueue_t *root = &q;
ng_pktqueue_node_t *elem = &(qe[1]), *res;
elem->data = (pkt_t *)62801;
elem->data = (ng_pktsnip_t *)62801;
pktqueue_add(root, elem);
ng_pktqueue_add(root, elem);
res = pktqueue_remove_head(root);
res = ng_pktqueue_remove_head(root);
TEST_ASSERT(res == elem);
TEST_ASSERT(((pkt_t *)62801) == res->data);
TEST_ASSERT(((ng_pktsnip_t *)62801) == res->data);
res = pktqueue_remove_head(root);
res = ng_pktqueue_remove_head(root);
TEST_ASSERT_NULL(res);
}
static void test_pktqueue_add_one(void)
{
pktqueue_t *root = &q;
pktqueue_node_t *elem = &(qe[1]);
ng_pktqueue_t *root = &q;
ng_pktqueue_node_t *elem = &(qe[1]);
elem->data = (pkt_t *)7317;
elem->data = (ng_pktsnip_t *)7317;
elem->priority = 713643658;
pktqueue_add(root, elem);
ng_pktqueue_add(root, elem);
TEST_ASSERT(root->first == elem);
TEST_ASSERT(((pkt_t *)7317) == root->first->data);
TEST_ASSERT(((ng_pktsnip_t *)7317) == root->first->data);
TEST_ASSERT_EQUAL_INT(713643658, root->first->priority);
TEST_ASSERT_NULL(root->first->next);
@ -82,24 +82,24 @@ static void test_pktqueue_add_one(void)
static void test_pktqueue_add_two_equal(void)
{
pktqueue_t *root = &q;
pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
ng_pktqueue_t *root = &q;
ng_pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
elem1->data = (pkt_t *)27088;
elem1->data = (ng_pktsnip_t *)27088;
elem1->priority = 14202;
elem2->data = (pkt_t *)4356;
elem2->data = (ng_pktsnip_t *)4356;
elem2->priority = 14202;
pktqueue_add(root, elem1);
pktqueue_add(root, elem2);
ng_pktqueue_add(root, elem1);
ng_pktqueue_add(root, elem2);
TEST_ASSERT(root->first == elem1);
TEST_ASSERT(((pkt_t *)27088) == root->first->data);
TEST_ASSERT(((ng_pktsnip_t *)27088) == root->first->data);
TEST_ASSERT_EQUAL_INT(14202, root->first->priority);
TEST_ASSERT(root->first->next == elem2);
TEST_ASSERT(((pkt_t *)4356) == root->first->next->data);
TEST_ASSERT(((ng_pktsnip_t *)4356) == root->first->next->data);
TEST_ASSERT_EQUAL_INT(14202, root->first->next->priority);
TEST_ASSERT_NULL(root->first->next->next);
@ -107,24 +107,24 @@ static void test_pktqueue_add_two_equal(void)
static void test_pktqueue_add_two_distinct(void)
{
pktqueue_t *root = &q;
pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
ng_pktqueue_t *root = &q;
ng_pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
elem1->data = (pkt_t *)46421;
elem1->data = (ng_pktsnip_t *)46421;
elem1->priority = 4567;
elem2->data = (pkt_t *)43088;
elem2->data = (ng_pktsnip_t *)43088;
elem2->priority = 1234;
pktqueue_add(root, elem1);
pktqueue_add(root, elem2);
ng_pktqueue_add(root, elem1);
ng_pktqueue_add(root, elem2);
TEST_ASSERT(root->first == elem2);
TEST_ASSERT(((pkt_t *)43088) == root->first->data);
TEST_ASSERT(((ng_pktsnip_t *)43088) == root->first->data);
TEST_ASSERT_EQUAL_INT(1234, root->first->priority);
TEST_ASSERT(root->first->next == elem1);
TEST_ASSERT(((pkt_t *)46421) == root->first->next->data);
TEST_ASSERT(((ng_pktsnip_t *)46421) == root->first->next->data);
TEST_ASSERT_EQUAL_INT(4567, root->first->next->priority);
TEST_ASSERT_NULL(root->first->next->next);
@ -132,13 +132,13 @@ static void test_pktqueue_add_two_distinct(void)
static void test_pktqueue_remove_one(void)
{
pktqueue_t *root = &q;
pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]), *elem3 = &(qe[3]);
ng_pktqueue_t *root = &q;
ng_pktqueue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]), *elem3 = &(qe[3]);
pktqueue_add(root, elem1);
pktqueue_add(root, elem2);
pktqueue_add(root, elem3);
pktqueue_remove(root, elem2);
ng_pktqueue_add(root, elem1);
ng_pktqueue_add(root, elem2);
ng_pktqueue_add(root, elem3);
ng_pktqueue_remove(root, elem2);
TEST_ASSERT(root->first == elem1);
TEST_ASSERT(root->first->next == elem3);