Skip to content

Commit c73b8ed

Browse files
cfriedtcarlescufi
authored andcommitted
tests: net: socketpair: put common includes in one header
This serves to increase SNR in the test sources (i.e. to make test sources easier to read). Signed-off-by: Chris Friedt <[email protected]>
1 parent 7502995 commit c73b8ed

File tree

9 files changed

+30
-179
lines changed

9 files changed

+30
-179
lines changed

tests/net/socket/socketpair/src/_main.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,28 @@
77
#ifndef TEST_SOCKETPAIR_THREAD_H_
88
#define TEST_SOCKETPAIR_THREAD_H_
99

10-
#include <zephyr/kernel.h>
10+
#include <errno.h>
11+
#include <string.h>
12+
13+
#include <zephyr/logging/log.h>
14+
#include <zephyr/net/socket.h>
15+
#include <zephyr/sys/util.h>
16+
#include <zephyr/ztest.h>
17+
18+
#ifdef CONFIG_ARCH_POSIX
19+
#include <fcntl.h>
20+
#else
21+
#include <zephyr/posix/fcntl.h>
22+
#include <zephyr/posix/unistd.h>
23+
#endif
24+
25+
#undef read
26+
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
27+
28+
#undef write
29+
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
30+
31+
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
1132

1233
extern struct k_work_q test_socketpair_work_q;
1334

tests/net/socket/socketpair/src/block.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <string.h>
14-
15-
#include <zephyr/logging/log.h>
16-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
17-
18-
#include <zephyr/net/socket.h>
19-
#include <zephyr/sys/util.h>
20-
#include <zephyr/posix/unistd.h>
21-
22-
#include <zephyr/ztest_assert.h>
23-
24-
#include "test_socketpair_thread.h"
25-
26-
#undef read
27-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
28-
29-
#undef write
30-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
318

329
struct ctx {
3310
/* true if test is write_block(), false if test is read_block() */

tests/net/socket/socketpair/src/closed_ends.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,8 @@
22
*
33
* Copyright (c) 2020 Friedt Professional Engineering Services, Inc
44
*/
5-
#ifdef CONFIG_ARCH_POSIX
6-
#include <fcntl.h>
7-
#else
8-
#include <zephyr/posix/fcntl.h>
9-
#endif
105

11-
#include <zephyr/logging/log.h>
12-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
13-
14-
#include <stdio.h>
15-
#include <string.h>
16-
#include <zephyr/net/socket.h>
17-
#include <zephyr/sys/util.h>
18-
#include <zephyr/posix/unistd.h>
19-
20-
#include <zephyr/ztest_assert.h>
21-
22-
#undef read
23-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
24-
25-
#undef write
26-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
6+
#include "_main.h"
277

288
ZTEST_USER(net_socketpair, close_one_end_and_write_to_the_other)
299
{

tests/net/socket/socketpair/src/expected_failures.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <zephyr/logging/log.h>
14-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
15-
16-
#include <stdio.h>
17-
#include <string.h>
18-
#include <zephyr/net/socket.h>
19-
#include <zephyr/sys/util.h>
20-
#include <zephyr/posix/unistd.h>
21-
22-
#include <zephyr/ztest_assert.h>
23-
24-
#undef read
25-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
26-
27-
#undef write
28-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
298

309
ZTEST_USER(net_socketpair, expected_failures)
3110
{

tests/net/socket/socketpair/src/fcntl.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <zephyr/logging/log.h>
14-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
15-
16-
#include <stdio.h>
17-
#include <string.h>
18-
#include <zephyr/net/socket.h>
19-
#include <zephyr/sys/util.h>
20-
#include <zephyr/posix/unistd.h>
21-
22-
#include <zephyr/ztest_assert.h>
23-
24-
#undef read
25-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
26-
27-
#undef write
28-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
298

309
ZTEST_USER(net_socketpair, fcntl)
3110
{

tests/net/socket/socketpair/src/happy_path.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <zephyr/logging/log.h>
14-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
15-
16-
#include <string.h>
17-
#include <zephyr/net/socket.h>
18-
#include <zephyr/sys/util.h>
19-
#include <zephyr/posix/unistd.h>
20-
21-
#include <zephyr/ztest_assert.h>
22-
23-
#undef read
24-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
25-
26-
#undef write
27-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
288

299
static void happy_path(
3010
const int family, const char *family_s,

tests/net/socket/socketpair/src/nonblock.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <zephyr/logging/log.h>
14-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
15-
16-
#include <stdio.h>
17-
#include <string.h>
18-
#include <zephyr/net/socket.h>
19-
#include <zephyr/sys/util.h>
20-
#include <zephyr/posix/unistd.h>
21-
22-
#include <zephyr/ztest_assert.h>
23-
24-
#undef read
25-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
26-
27-
#undef write
28-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
298

309
ZTEST_USER(net_socketpair, write_nonblock)
3110
{

tests/net/socket/socketpair/src/poll.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <string.h>
14-
15-
#include <zephyr/logging/log.h>
16-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
17-
18-
#include <zephyr/net/socket.h>
19-
#include <zephyr/posix/unistd.h>
20-
#include <zephyr/sys/util.h>
21-
22-
#include <zephyr/ztest_assert.h>
23-
24-
#include "test_socketpair_thread.h"
25-
26-
#undef read
27-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
28-
29-
#undef write
30-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
318

329
struct ctx {
3310
bool should_write;

tests/net/socket/socketpair/src/unsupported_calls.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_ARCH_POSIX
8-
#include <fcntl.h>
9-
#else
10-
#include <zephyr/posix/fcntl.h>
11-
#endif
12-
13-
#include <zephyr/logging/log.h>
14-
LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
15-
16-
#include <stdio.h>
17-
#include <string.h>
18-
#include <zephyr/net/socket.h>
19-
#include <zephyr/sys/util.h>
20-
#include <zephyr/posix/unistd.h>
21-
22-
#include <zephyr/ztest_assert.h>
23-
24-
#undef read
25-
#define read(fd, buf, len) zsock_recv(fd, buf, len, 0)
26-
27-
#undef write
28-
#define write(fd, buf, len) zsock_send(fd, buf, len, 0)
7+
#include "_main.h"
298

309
ZTEST_USER(net_socketpair, unsupported_calls)
3110
{

0 commit comments

Comments
 (0)