-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netdev: Provide test network device with netdev interface #1731
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright (C) 2014 Martin 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 more details. | ||
*/ | ||
|
||
/** | ||
* @addtogroup unittests | ||
* @{ | ||
* | ||
* @file netdev_dummy.h | ||
* @brief Provides a virtual device that understands the netdev_base API | ||
* for testing. | ||
* | ||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> | ||
*/ | ||
|
||
#ifndef __UNITTESTS_NETDEV_DUMMY_H_ | ||
#define __UNITTESTS_NETDEV_DUMMY_H_ | ||
|
||
#include <stdlib.h> | ||
|
||
#include "netdev/base.h" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef UNITTESTS_NETDEV_DUMMY_MAX_DEV | ||
/** | ||
* @brief Maximum number of devices you can initialize with this module | ||
*/ | ||
#define UNITTESTS_NETDEV_DUMMY_MAX_DEV (2) | ||
#endif /* UNITTESTS_NETDEV_DUMMY_MAX_DEV */ | ||
|
||
#ifndef UNITTESTS_NETDEV_DUMMY_MAX_PACKET | ||
/** | ||
* @brief Maximum packet length for the virtual test devices. | ||
*/ | ||
#define UNITTESTS_NETDEV_DUMMY_MAX_PACKET (12) | ||
#endif /* UNITTESTS_NETDEV_DUMMY_MAX_PACKET */ | ||
|
||
#ifndef UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN | ||
/** | ||
* @brief The maximum length of the addresses for the test devices | ||
*/ | ||
#define UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN (2) | ||
#endif /* UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN */ | ||
|
||
#ifndef UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN | ||
/** | ||
* @brief The maximum length of the addresses for the test devices | ||
*/ | ||
#define UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN (4) | ||
#endif /* UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN */ | ||
|
||
#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN | ||
#error "UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN < UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN!\n" | ||
#endif | ||
|
||
#if UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN > 64 | ||
#warning "UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN > 64 is not recommended" | ||
#endif | ||
|
||
#ifndef UNITTESTS_NETDEV_DUMMY_MAX_CB | ||
/** | ||
* @brief Maximum number of callbacks per device | ||
*/ | ||
#define UNITTESTS_NETDEV_DUMMY_MAX_CB (4) | ||
#endif /* UNITTESTS_NETDEV_DUMMY_MAX_CB */ | ||
|
||
/** | ||
* @brief Implementation of the driver for the virtual test device | ||
*/ | ||
extern const netdev_driver_t unittest_netdev_dummy_driver; | ||
|
||
/** | ||
* @brief Available devices | ||
*/ | ||
extern netdev_t unittest_netdev_dummy_devs[UNITTESTS_NETDEV_DUMMY_MAX_DEV]; | ||
|
||
/** | ||
* @brief Fires a receive event on a virtual test device | ||
* | ||
* @param[in] dev Device you want to fire the receive event on | ||
* @param[in] src Source address of the received packet | ||
* @param[in] src_len Length of *src* | ||
* @param[in] dest Destination address of the received packet | ||
* @param[in] dest_len Length of *dest* | ||
* @param[in] data Content of the received packet | ||
* @param[in] data_len Length of *data* | ||
* | ||
* @return 0 on success | ||
* @return -EAFNOSUPPORT, if src_len or dest_len are neither | ||
* UNITTESTS_NETDEV_DUMMY_MAX_LONG_ADDR_LEN nor | ||
* UNITTESTS_NETDEV_DUMMY_MAX_ADDR_LEN | ||
* @return -ECANCELED, receive event aborted since one of the registered | ||
* callbacks had an error. | ||
* @return -EINVAL, if *src* or *dest* are NULL or | ||
* *data* is NULL and *data_len* is not NULL | ||
* @return -EMSGSIZE, if *data_len* > UNITTESTS_NETDEV_DUMMY_MAX_PACKET | ||
* @return -ENODEV, if device was not initialized by | ||
* unittest_netdev_dummy_driver::init() | ||
*/ | ||
int unittest_netdev_dummy_fire_rcv_event(netdev_t *dev, void *src, | ||
size_t src_len, void *dest, size_t dest_len, void *data, | ||
size_t data_len); | ||
|
||
/** | ||
* @brief Checks if the data transmitted by | ||
* unittest_netdev_dummy_driver::send_data() is as expected. | ||
* | ||
* @param[in] dev Device you want to check the transmitted data for | ||
* @param[in] expected_dest The expected destination address. | ||
* @param[in] expected_dest_len The expected length of the destination address. | ||
* @param[in] expected_data The expected data | ||
* @param[in] expected_data_len The expected length of the data | ||
* | ||
* @note Please remember that the device prepends the *upper_layer_hdrs* | ||
* passed to unittest_netdev_dummy_driver::send_data() | ||
* | ||
* @return 0 on success and everything is as expected | ||
* @return 1 on success and something is not as expected | ||
* @return -ENODEV, if *dev* was not initialized by | ||
* unittest_netdev_dummy_driver::init() | ||
* @return -EINVAL, if *expected_data* is NULL and *expected_data_len is not 0 or | ||
* if | ||
*/ | ||
int unittest_netdev_dummy_check_transmitted(netdev_t *dev, | ||
void *expected_dest, | ||
size_t expected_dest_len, | ||
void *expected_data, | ||
size_t expected_data_len); | ||
|
||
/** | ||
* @brief Get last event notified by dev::driver::event | ||
* | ||
* @param[in] dev Device you want to get the last event from. | ||
* | ||
* @return The last event as given as parameter to dev::driver::event | ||
* @return ENODEV, if *dev* was not found | ||
*/ | ||
uint32_t unittest_netdev_dummy_get_last_event(netdev_t *dev); | ||
|
||
/** | ||
* @brief Resets all dummy devices to their initial state | ||
*/ | ||
void unittest_netdev_dummy_init(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __UNITTESTS_NETDEV_DUMMY_H_ */ | ||
|
||
/** | ||
* @} | ||
*/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
netdev_dummy
is a module that is only really useful or sensible in the context of unittests. So why not define it's dependencies in the Makefile of unittests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it has no advantage and deviates from standard practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But: I overlooked, that the interface is actually part of the
tests/unittests
structure, so I'm fine with it staying as it is.