Skip to content

Commit 5eb974d

Browse files
pfalconioannisg
authored andcommitted
samples: net: sockets: Allow to build and test with POSIX subsys
With CONFIG_POSIX_API enabled, these samples now build under Zephyr with exactly the same source as e.g. Linux (or in general, other POSIX systems). However, building without CONFIG_POSIX_API (i.e. with CONFIG_NET_SOCKETS_POSIX_NAMES aux option) is retained for now. Add testcase definitions to build these samples with CONFIG_POSIX_API in CI. Fixes: #17353 Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent a358248 commit 5eb974d

File tree

9 files changed

+60
-23
lines changed

9 files changed

+60
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
sample:
22
description: BSD Sockets big HTTP download example
33
name: big_http_download
4+
common:
5+
filter: TOOLCHAIN_HAS_NEWLIB == 1
6+
harness: net
7+
min_ram: 32
8+
min_flash: 128
9+
tags: net socket
410
tests:
511
sample.net.sockets.big_http_download:
6-
filter: TOOLCHAIN_HAS_NEWLIB == 1
7-
harness: net
8-
min_ram: 32
9-
min_flash: 128
10-
tags: net socket
12+
extra_configs:
13+
- CONFIG_NET_SOCKETS_POSIX_NAMES=y
14+
sample.net.sockets.big_http_download.posix:
15+
filter: and not CONFIG_NET_SOCKETS_OFFLOAD
16+
extra_configs:
17+
- CONFIG_NET_SOCKETS_POSIX_NAMES=n
18+
- CONFIG_POSIX_API=y

samples/net/sockets/big_http_download/src/big_http_download.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "mbedtls/md.h"
1313

14-
#ifndef __ZEPHYR__
14+
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
1515

1616
#include <netinet/in.h>
1717
#include <sys/socket.h>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
sample:
22
description: BSD Sockets API dumb HTTP server example
33
name: socket_dumb_http_server
4+
common:
5+
filter: TOOLCHAIN_HAS_NEWLIB == 1
6+
harness: net
7+
min_ram: 32
8+
min_flash: 96
9+
tags: net socket
410
tests:
511
sample.net.sockets.dumb_http_server:
6-
filter: TOOLCHAIN_HAS_NEWLIB == 1
7-
harness: net
8-
min_ram: 32
9-
min_flash: 96
10-
tags: net socket
12+
extra_configs:
13+
- CONFIG_NET_SOCKETS_POSIX_NAMES=y
14+
sample.net.sockets.dumb_http_server.posix:
15+
filter: and not CONFIG_NET_SOCKETS_OFFLOAD
16+
extra_configs:
17+
- CONFIG_NET_SOCKETS_POSIX_NAMES=n
18+
- CONFIG_POSIX_API=y

samples/net/sockets/dumb_http_server/src/socket_dumb_http.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <stdlib.h>
99
#include <errno.h>
1010

11-
#ifndef __ZEPHYR__
11+
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
1212

1313
#include <netinet/in.h>
1414
#include <sys/socket.h>

samples/net/sockets/echo_async/sample.yaml

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ sample:
22
description: BSD Sockets API TCP echo server sample
33
using non-blocking sockets
44
name: socket_echo_async
5+
common:
6+
filter: TOOLCHAIN_HAS_NEWLIB == 1
7+
harness: net
8+
platform_whitelist: qemu_x86
9+
tags: net socket
510
tests:
611
sample.net.sockets.echo_async:
7-
harness: net
8-
platform_whitelist: qemu_x86
9-
tags: net socket
12+
extra_configs:
13+
- CONFIG_NET_SOCKETS_POSIX_NAMES=y
14+
sample.net.sockets.echo_async.posix:
15+
filter: and not CONFIG_NET_SOCKETS_OFFLOAD
16+
extra_configs:
17+
- CONFIG_NET_SOCKETS_POSIX_NAMES=n
18+
- CONFIG_POSIX_API=y

samples/net/sockets/echo_async/src/socket_echo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <errno.h>
1010
#include <stdlib.h>
1111

12-
#ifndef __ZEPHYR__
12+
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
1313

1414
#include <netinet/in.h>
1515
#include <sys/socket.h>

samples/net/sockets/echo_async_select/src/socket_echo_select.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#include <errno.h>
1010
#include <stdlib.h>
1111

12-
#ifndef __ZEPHYR__
12+
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
1313

1414
#include <netinet/in.h>
1515
#include <sys/socket.h>
16+
#include <sys/select.h>
1617
#include <arpa/inet.h>
1718
#include <unistd.h>
1819
#include <fcntl.h>
+16-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
sample:
22
description: BSD Sockets API HTTP GET example
33
name: socket_http_get
4+
common:
5+
filter: TOOLCHAIN_HAS_NEWLIB == 1
6+
harness: net
7+
min_ram: 32
8+
min_flash: 80
9+
tags: net socket
410
tests:
511
sample.net.sockets.http_get:
6-
filter: TOOLCHAIN_HAS_NEWLIB == 1
7-
harness: net
8-
min_ram: 32
9-
min_flash: 80
10-
tags: net socket
12+
extra_configs:
13+
- CONFIG_NET_SOCKETS_POSIX_NAMES=y
14+
# Forcibly defines CONFIG_POSIX_API, which is incompatible with
15+
# CONFIG_NET_SOCKETS_POSIX_NAMES.
16+
platform_exclude: cc3220sf_launchxl
17+
sample.net.sockets.http_get.posix:
18+
filter: and not CONFIG_NET_SOCKETS_OFFLOAD
19+
extra_configs:
20+
- CONFIG_NET_SOCKETS_POSIX_NAMES=n
21+
- CONFIG_POSIX_API=y

samples/net/sockets/http_get/src/http_get.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <stdio.h>
88
#include <stdlib.h>
99

10-
#ifndef __ZEPHYR__
10+
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
1111

1212
#include <netinet/in.h>
1313
#include <sys/socket.h>

0 commit comments

Comments
 (0)