Skip to content

Commit 3f21ca1

Browse files
Merge 3a871f9 into ec93b41
2 parents ec93b41 + 3a871f9 commit 3f21ca1

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

tests/lib/test-util.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#endif
1313

1414
#include <unistd.h>
15+
#include <stdlib.h>
1516

1617
#if defined(HAVE_LINUX_MPTCP_H_UPSTREAM) \
1718
|| defined(HAVE_LINUX_MPTCP_H_MPTCP_ORG)
@@ -22,6 +23,8 @@
2223
# include <mptcpd/private/mptcp_org.h>
2324
#endif
2425

26+
#include "../src/netlink_pm.h" // For MPTCP_SYSCTL_BASE
27+
2528
#include "test-util.h"
2629

2730

@@ -34,6 +37,30 @@ char const *tests_get_pm_family_name(void)
3437
#endif
3538
}
3639

40+
static bool is_mptcp_kernel(void)
41+
{
42+
// Kernel supports MPTCP if /proc/sys/net/mptcp exists.
43+
return access(MPTCP_SYSCTL_BASE, R_OK | X_OK) == 0;
44+
}
45+
46+
void tests_skip_if_no_mptcp(void)
47+
{
48+
/*
49+
An exit status of 77 causes the Automake test driver,
50+
i.e. the `test-driver' script, to consider the test result
51+
as SKIP rather than PASS or FAIL.
52+
53+
Tests that should be skipped under some conditions, such as
54+
when not running a MPTCP capable kernel, should exit the
55+
process with this value.
56+
*/
57+
static int const SKIP_EXIT_STATUS = 77;
58+
59+
if (!is_mptcp_kernel())
60+
exit(SKIP_EXIT_STATUS);
61+
}
62+
63+
3764

3865
/*
3966
Local Variables:

tests/lib/test-util.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
*
55
* @brief mptcpd test utilities library.
66
*
7-
* Copyright (c) 2020, Intel Corporation
7+
* Copyright (c) 2020, 2022, Intel Corporation
88
*/
99

1010
#ifndef MPTCP_TEST_UTIL_H
1111
#define MPTCP_TEST_UTIL_H
1212

1313

14+
/// Get MPTCP path management generic netlink API family name.
1415
char const *tests_get_pm_family_name(void);
1516

17+
/**
18+
* @brief Exit test process if the kernel does not support MPTCP.
19+
*
20+
* If the kernel does not support MPTCP exit the current test process
21+
* with an exit status suitable for making the Automake @c test-driver
22+
* script interpret the test result as @c SKIP instead of @c PASS or
23+
* @c FAIL. This is useful for tests that need MPTCP but are run on
24+
* platforms with a non-MPTCP capable kernel.
25+
*/
26+
void tests_skip_if_no_mptcp(void);
27+
1628

1729
#endif // MPTCP_TEST_UTIL_H

tests/test-commands.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ static void idle_callback(struct l_idle *idle, void *user_data)
570570

571571
int main(void)
572572
{
573+
// Skip this test if the kernel is not MPTCP capable.
574+
tests_skip_if_no_mptcp();
575+
573576
if (!l_main_init())
574577
return -1;
575578

tests/test-mptcpwrap

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
set -e
99

10+
# An exit status of 77 causes the Automake test driver to consider the
11+
# test as skipped.
12+
skip_exit_status=77
13+
1014
# Check if we're using the upstream kernel.
1115
#
12-
# upstream: net.mptcp.enabled
13-
# multipath-tcp.org: net.mptcp.mptcp_enabled
14-
key=`sysctl --names --pattern 'mptcp\.enabled' net.mptcp`
15-
if [ -z "$key" ]; then
16-
# Do not run the test if we're not using the upstream kernel.
16+
# upstream: /proc/sys/net/mptcp/enabled
17+
# multipath-tcp.org: /proc/sys/net/mptcp/mptcp_enabled
18+
if [ ! -f /proc/sys/net/mptcp/enabled ]; then
19+
# Skip the test if we're not using the upstream kernel.
1720
echo Not running upstream kernel. libmptcpwrap will not be tested.
18-
exit 0
21+
exit $skip_exit_status
1922
fi
2023

2124
LD_PRELOAD=../src/.libs/libmptcpwrap.so \

tests/test-path-manager.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ static void timeout_callback(struct l_timeout *timeout,
161161

162162
int main(void)
163163
{
164+
// Skip this test if the kernel is not MPTCP capable.
165+
tests_skip_if_no_mptcp();
166+
164167
if (!l_main_init())
165168
return -1;
166169

0 commit comments

Comments
 (0)