-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add a unit test for sspi plugin.
A new unit test for the sspi plugin that simply exercises the the sspi plugin operations. Only blackbox testing is performed at this stage since it is not straightforward to perform whitebox testing of the sspi plugin internals.
- Loading branch information
1 parent
3aba4f6
commit 90fbb8e
Showing
6 changed files
with
429 additions
and
3 deletions.
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
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,102 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/** | ||
* @file tests/lib/interface.c | ||
* | ||
* @brief @c mptcpd_interface related utility functions. | ||
* | ||
* Copyright (c) 2022, Intel Corporation | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
# include <mptcpd/private/config.h> // For NDEBUG | ||
#endif | ||
|
||
#include <assert.h> | ||
|
||
#include <net/if_arp.h> | ||
#include <net/if.h> | ||
#include <netinet/in.h> | ||
|
||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wpedantic" | ||
#include <ell/util.h> | ||
#include <ell/queue.h> | ||
#pragma GCC diagnostic pop | ||
|
||
#include <mptcpd/network_monitor.h> | ||
|
||
#include "interface.h" | ||
|
||
|
||
static int | ||
addr_compare(void const *a, void const *b, void *user_data) | ||
{ | ||
(void) a; | ||
(void) b; | ||
(void) user_data; | ||
|
||
// No need to sort. | ||
return 1; | ||
} | ||
|
||
// ----------------------------------------------------------------------- | ||
|
||
struct mptcpd_interface *test_mptcpd_interface_create(void) | ||
{ | ||
struct mptcpd_interface *const i = | ||
l_new(struct mptcpd_interface, 1); | ||
|
||
// Bind test IP address to loopback interface. | ||
static char const loopback[] = "lo"; | ||
|
||
i->family = AF_UNSPEC; | ||
i->type = ARPHRD_LOOPBACK; | ||
i->flags = IFF_UP | IFF_LOOPBACK; | ||
|
||
i->index = if_nametoindex(loopback); | ||
assert(i->index != 0); | ||
|
||
l_strlcpy(i->name, loopback, L_ARRAY_SIZE(i->name)); | ||
|
||
i->addrs = l_queue_new(); | ||
|
||
return i; | ||
} | ||
|
||
bool test_mptcpd_interface_insert_addr(struct mptcpd_interface *i, | ||
struct sockaddr const *sa) | ||
{ | ||
assert(sa->sa_family == AF_INET || sa->sa_family == AF_INET6); | ||
|
||
struct sockaddr *addr = NULL; | ||
|
||
if (sa->sa_family == AF_INET) | ||
addr = l_memdup(sa, sizeof(struct sockaddr_in)); | ||
else | ||
addr = l_memdup(sa, sizeof(struct sockaddr_in6)); | ||
|
||
/* | ||
The mptcpd network monitor actually inserts an instance of | ||
the internal struct nm_addr_info into this list but it is | ||
actually expected for users to treat the list as a list of | ||
struct sockaddr const* objects. This works since the first | ||
member of struct nm_addr_info is a struct sockaddr_storage, | ||
meaning the latter will have the same address as the | ||
former. Just treat this list as list of struct sockaddr* | ||
for the purposes of the mptcpd unit test suite. | ||
*/ | ||
return l_queue_insert(i->addrs, addr, addr_compare, NULL); | ||
} | ||
|
||
void test_mptcpd_interface_destroy(struct mptcpd_interface *i) | ||
{ | ||
l_queue_destroy(i->addrs, l_free); | ||
l_free(i); | ||
} | ||
|
||
|
||
/* | ||
Local Variables: | ||
c-file-style: "linux" | ||
End: | ||
*/ |
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,40 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/** | ||
* @file tests/lib/interface.h | ||
* | ||
* @brief @c mptcpd_interface related utility functions. | ||
* | ||
* Copyright (c) 2022, Intel Corporation | ||
*/ | ||
|
||
#include <stdbool.h> | ||
|
||
|
||
struct mptcpd_interface; | ||
struct sockaddr; | ||
|
||
/// Create a @c struct @c mptcpd_interface for test purposes. | ||
struct mptcpd_interface *test_mptcpd_interface_create(void); | ||
|
||
/** | ||
* @brief Add an IP address to the address list in @a i. | ||
* | ||
* @param[in,out] i mptcpd interface information to which the IP | ||
* address @a sa will be added. | ||
* @param[in] sa IP address to be add to the address list in | ||
* @a i. | ||
* | ||
* @return @c true on success, @c false otherwise. | ||
*/ | ||
bool test_mptcpd_interface_insert_addr(struct mptcpd_interface *i, | ||
struct sockaddr const *sa); | ||
|
||
/// Destroy the @c struct @c mptcpd_interface instance @a i. | ||
void test_mptcpd_interface_destroy(struct mptcpd_interface *i); | ||
|
||
|
||
/* | ||
Local Variables: | ||
c-file-style: "linux" | ||
End: | ||
*/ |
Oops, something went wrong.