Skip to content

Commit

Permalink
tests: Add unit test for libmptcpwrap.so. (multipath-tcp#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ossama Othman authored Oct 14, 2021
1 parent 591b3b1 commit 9951807
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tests/test-commands
tests/test-configuration
tests/test-cxx-build
tests/test-id-manager
tests/mptcpwrap-tester
tests/*.log
tests/*.trs
tests/test-suite.log
Expand Down
2 changes: 1 addition & 1 deletion src/mptcpwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int __attribute__((visibility("default"))) socket(int family, int type, int prot
(type & 0xff) != SOCK_STREAM)
goto do_socket;

// socket(AF_INET, SOCK_STREM, 0) maps to TCP, too
// socket(AF_INET, SOCK_STREAM, 0) maps to TCP, too
if (protocol != 0 && protocol != IPPROTO_TCP)
goto do_socket;

Expand Down
8 changes: 7 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ check_PROGRAMS = \
test-configuration \
test-id-manager

noinst_PROGRAMS = mptcpwrap-tester

dist_check_SCRIPTS = \
test-bad-log-empty \
test-bad-log-long \
test-bad-log-short \
test-bad-option \
test-bad-path-manager \
test-bad-plugin-dir \
test-start-stop
test-start-stop \
test-mptcpwrap

test_plugin_SOURCES = test-plugin.c
test_plugin_CPPFLAGS = \
Expand Down Expand Up @@ -94,6 +97,9 @@ test_id_manager_LDADD = \
$(ELL_LIBS) \
$(CODE_COVERAGE_LIBS)

mptcpwrap_tester_SOURCES = mptcpwrap-tester.c
mptcpwrap_tester_LDADD = $(CODE_COVERAGE_LIBS)

if HAVE_CXX
check_PROGRAMS += test-cxx-build
test_cxx_build_SOURCES = test-cxx-build.cpp
Expand Down
54 changes: 54 additions & 0 deletions tests/mptcpwrap-tester.c
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:
*/
10 changes: 10 additions & 0 deletions tests/test-mptcpwrap
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

0 comments on commit 9951807

Please sign in to comment.