forked from multipath-tcp/mptcpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add unit test for libmptcpwrap.so. (multipath-tcp#160)
- Loading branch information
Ossama Othman
authored
Oct 14, 2021
1 parent
591b3b1
commit 9951807
Showing
5 changed files
with
73 additions
and
2 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,54 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/** | ||
* @file mptcpwrap-tester.c | ||
* | ||
* @brief Test wrapped socket() call for MPTCP protocol injection. | ||
* | ||
* Copyright (c) 2021, Intel Corporation | ||
*/ | ||
|
||
#undef NDEBUG | ||
#include <assert.h> | ||
|
||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <unistd.h> | ||
|
||
int main() | ||
{ | ||
/* | ||
libmptcpwrap.so should be preloaded when running this | ||
program, e.g.: | ||
LD_PRELOAD=libmptcpwrap.so ./mptcpwrap-tester | ||
*/ | ||
int const fd = socket(AF_INET, SOCK_STREAM, 0); | ||
assert(fd != -1); | ||
|
||
int protocol = 0; | ||
socklen_t len = sizeof(protocol); | ||
|
||
int const expected_protocol = IPPROTO_TCP + 256; // MPTCP-ized. | ||
|
||
int const ret = getsockopt(fd, | ||
SOL_SOCKET, | ||
SO_PROTOCOL, | ||
&protocol, | ||
&len); | ||
|
||
close(fd); | ||
|
||
assert(ret == 0 | ||
&& protocol == expected_protocol | ||
&& len == sizeof(protocol)); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
/* | ||
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,10 @@ | ||
#! /bin/sh | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
# Test that libmptcpwrap injects MPTCP into the socket() system call. | ||
# | ||
# Copyright (c) 2021, Intel Corporation | ||
|
||
set -e | ||
|
||
LD_PRELOAD=../src/.libs/libmptcpwrap.so ./mptcpwrap-tester |