Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lwip-tests: create port enabling run of lwip tests #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ fi

[ "${PORTS_FS_MARK}" = "y" ] && ./phoenix-rtos-ports/fs_mark/build.sh

[ "${PORTS_CHECK}" = "y" ] && ./phoenix-rtos-ports/check/build.sh

[ "${PORTS_LWIP_TESTS}" = "y" ] && ./phoenix-rtos-ports/lwip-tests/build.sh

exit 0
47 changes: 47 additions & 0 deletions check/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -e

CHECK_VER="0.10.0"
CHECK="check-$CHECK_VER"
CHECK_PKG_URL="https://github.com/libcheck/check/archive/refs/tags/${CHECK_VER}.tar.gz"
CHECK_PKG_MIRROR_URL="https://files.phoesys.com/ports/${CHECK}.tar.gz"

PREFIX_CHECK="${PREFIX_PROJECT}/phoenix-rtos-ports/check"
PREFIX_CHECK_SRC="${PREFIX_BUILD}/check"

b_log "Building check test framework"

#
# Download and unpack
#
if [ ! -f "${PREFIX_CHECK}/${CHECK}.tar.gz" ]; then
if ! wget "$CHECK_PKG_URL" -O "${PREFIX_CHECK}/${CHECK}.tar.gz" --no-check-certificate; then
wget "$CHECK_PKG_MIRROR_URL" -P "$PREFIX_CHECK" --no-check-certificate
fi
fi

if [ ! -d "$PREFIX_CHECK_SRC" ]; then
tar xzf "${PREFIX_CHECK}/${CHECK}.tar.gz" -C "$PREFIX_BUILD" && \
mv "${PREFIX_BUILD}/${CHECK}" "$PREFIX_CHECK_SRC"
fi

#
# Configure
#
mkdir -p "${PREFIX_CHECK_SRC}/include"
if [ ! -f "${PREFIX_CHECK_SRC}/config.h" ]; then
CHECK_CFLAGS="-std=gnu99 -I${PREFIX_CHECK_SRC}/include"
(cd "$PREFIX_CHECK_SRC" && autoreconf -i -v -f && \
PKG_CONFIG="" ./configure CC="$CC" LD="$LD" AR="$AR" STRIP="${CROSS}strip" CFLAGS="$CFLAGS $CHECK_CFLAGS" \
LDFLAGS="$LDFLAGS" --host="${HOST}" --build="x86_64-linux-gnu" --disable-subunit \
--disable-shared --disable-doc --enable-static --libdir="$PREFIX_A" \
--includedir="${PREFIX_CHECK_SRC}/include")
fi

#
# Make
#
SUBDIRS="lib src . tests" # Run makefiles from this directories
make -C "$PREFIX_CHECK_SRC"
make SUBDIRS="$SUBDIRS" doc_DATA="" m4data_DATA="" -C "$PREFIX_CHECK_SRC" install
56 changes: 56 additions & 0 deletions lwip-tests/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

set -e

b_log "Building lwip-test"

LWIP_CONTRIB_TAG="STABLE-2_1_0_RELEASE"
LWIP_CONTRIB_PKG_URL="https://git.savannah.nongnu.org/cgit/lwip/lwip-contrib.git/snapshot/lwip-contrib-${LWIP_CONTRIB_TAG}.tar.gz"
LWIP_CONTRIB_PKG_MIRROR_URL="https://files.phoesys.com/ports/lwip-contrib.tar.gz"

PREFIX_LWIP_TEST="${PREFIX_PROJECT}/phoenix-rtos-ports/lwip-tests"
PREFIX_LWIP_TEST_BUILD="${PREFIX_BUILD}/lwip-test"
PREFIX_LWIP_CONTRIB="${PREFIX_LWIP_TEST_BUILD}/contrib-lwip"
PREFIX_LWIP_CHECK="${PREFIX_LWIP_CONTRIB}/ports/unix/check"
PREFIX_LWIP_TEST_MARKERS="${PREFIX_LWIP_TEST_BUILD}/markers"

# Set variables used by Makefile
CHECK_H_PATH="${PREFIX_BUILD}/check/include"
CONTRIBDIR="${PREFIX_BUILD}/lwip-test/contrib-lwip"
MBEDTLSDIR="${PREFIX_BUILD}/mbedtls/mbedtls-2.28.0"
LWIPDIR="${PREFIX_PROJECT}/phoenix-rtos-lwip/lib-lwip/src"

export CHECK_H_PATH CONTRIBDIR MBEDTLSDIR LWIPDIR

#
# Download and unpack lwip-contrib
#
if [ ! -f "${PREFIX_LWIP_TEST}/lwip-contrib.tar.gz" ]; then
if ! wget "$LWIP_CONTRIB_PKG_URL" -O "${PREFIX_LWIP_TEST}/lwip-contrib.tar.gz" --no-check-certificate; then
wget "$LWIP_CONTRIB_PKG_MIRROR_URL" -P "$PREFIX_LWIP_TEST" --no-check-certificate
fi
fi

mkdir -p "$PREFIX_LWIP_TEST_BUILD"
if [ ! -d "$PREFIX_LWIP_CONTRIB" ]; then
tar xzf "${PREFIX_LWIP_TEST}/lwip-contrib.tar.gz" -C "$PREFIX_LWIP_TEST_BUILD" && \
mv "${PREFIX_LWIP_TEST_BUILD}/lwip-contrib-$LWIP_CONTRIB_TAG" "${PREFIX_LWIP_TEST_BUILD}/contrib-lwip"
fi

#
# Apply patches
#
mkdir -p "$PREFIX_LWIP_TEST_MARKERS"
for patchfile in "$PREFIX_LWIP_TEST"/patch/*; do
if [ ! -f "${PREFIX_LWIP_TEST_MARKERS}/$(basename "$patchfile").applied" ]; then
echo "applying patch: $patchfile"
patch -d "${PREFIX_LWIP_CONTRIB}/" -p1 < "$patchfile"
touch "${PREFIX_LWIP_TEST_MARKERS}/$(basename "$patchfile").applied"
fi
done

make check -C "$PREFIX_LWIP_CHECK"
"${CROSS}strip" -s "${PREFIX_LWIP_CHECK}/lwip_unittests" -o "${PREFIX_PROG_STRIPPED}/lwip_unittests"
cp -a "${PREFIX_LWIP_CHECK}/lwip_unittests" "${PREFIX_PROG}/lwip_unittests"

b_install "${PREFIX_PROG_STRIPPED}/lwip_unittests" /bin
24 changes: 24 additions & 0 deletions lwip-tests/patch/Common-allports.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- contrib_orginal/ports/Common.allports.mk 2024-01-09 16:16:39.398560526 +0100
+++ contrib/ports/Common.allports.mk 2024-01-15 15:32:10.693335127 +0100
@@ -29,11 +29,9 @@
# Author: Adam Dunkels <adam@sics.se>
#

-#CC=gcc
-#CC=clang
CCDEP?=$(CC)

-CFLAGS+=-g -DLWIP_DEBUG -Wall -pedantic -Werror \
+CFLAGS+=-g -DLWIP_DEBUG -Wall -pedantic \
-Wparentheses -Wsequence-point -Wswitch-default \
-Wextra -Wundef -Wshadow -Wpointer-arith -Wcast-qual \
-Wc++-compat -Wwrite-strings -Wold-style-definition -Wcast-align \
@@ -48,7 +46,7 @@
#CFLAGS:=$(CFLAGS) -fsanitize=address -fstack-protector -fstack-check -fsanitize=undefined -fno-sanitize=alignment
else
# we cannot sanitize alignment on x86-64 targets because clang wants 64 bit alignment
-CFLAGS+= -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -Wdocumentation -Wno-documentation-deprecated-sync
+# CFLAGS+= -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -Wdocumentation -Wno-documentation-deprecated-sync
endif

CONTRIBDIR?=../../..
17 changes: 17 additions & 0 deletions lwip-tests/patch/Common.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- contrib_orginal/ports/unix/Common.mk 2024-01-09 16:16:39.402560579 +0100
+++ contrib/ports/unix/Common.mk 2024-01-10 20:01:40.592109932 +0100
@@ -42,10 +42,12 @@
UNIX_COMMON_MK_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
include $(UNIX_COMMON_MK_DIR)../Common.allports.mk

-LDFLAGS+=-lutil
+# Util lib not necessary
+# LDFLAGS+=-lutil

UNAME_S:= $(shell uname -s)
ifneq ($(UNAME_S),Darwin)
# Darwin doesn't have pthreads or POSIX real-time extensions libs
-LDFLAGS+=-pthread -lrt
+# Phoenix do not need real-time extensions libs and -pthread linker flag
+# LDFLAGS+=-pthread -lrt
endif
41 changes: 41 additions & 0 deletions lwip-tests/patch/Makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--- contrib_orginal/ports/unix/check/Makefile 2024-01-09 16:16:39.402560579 +0100
+++ contrib/ports/unix/check/Makefile 2024-01-15 17:00:03.544552858 +0100
@@ -33,7 +33,7 @@
.PHONY: all clean check

# The include path to sys_arch.h and lwipopts.h must be first, so this must be before Common.mk
-CFLAGS=-DLWIP_NOASSERT_ON_ERROR -I/usr/include/check -I$(LWIPDIR)/../test/unit
+CFLAGS+=-DLWIP_NOASSERT_ON_ERROR -I$(LWIPDIR)/../../include/arch -I$(LWIPDIR)/../../include/default-opts/testsuite -I$(CHECK_H_PATH)

# Ignore 'too many arguments for format' warnings which happen with GCCs
# from check 0.15.2 on fail_if/fail_unless macros with text.
@@ -46,18 +46,21 @@
endif

# Prevent compiling sys_arch.c of unix port because unit test provide their own port
-SYSARCH?=
+PORTDIR = $(LWIPDIR)/../../port
+SYSARCH?=$(wildcard $(PORTDIR)/*.c)
include ../Common.mk

-LDFLAGS:=-lcheck -lm $(LDFLAGS)
+LDFLAGS+= -lcheck --static

ifneq ($(UNAME_S),Darwin)
# check installed via brew on Darwin doesn't have a separate subunit library (must be statically linked)
-LDFLAGS+=-lsubunit
+# Subunit not ported, tests can work without it
+# LDFLAGS+=-lsubunit
endif

TESTDIR=$(LWIPDIR)/../test/unit
include $(TESTDIR)/Filelists.mk
+include $(LWIPDIR)/../test/unit/Filelists.mk
TESTOBJS=$(notdir $(TESTFILES:.c=.o))

clean:
@@ -83,4 +86,3 @@
endif

check: lwip_unittests
- @./lwip_unittests
6 changes: 6 additions & 0 deletions lwip-tests/patch/config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--- contrib_orginal/ports/unix/check/config.h 2024-01-09 16:16:39.402560579 +0100
+++ contrib/ports/unix/check/config.h 2024-01-11 12:56:06.185539301 +0100
@@ -1,2 +1,2 @@
/* Enable this to simplify debugging */
-/* #define LWIP_UNITTESTS_NOFORK */
+#define LWIP_UNITTESTS_NOFORK
53 changes: 53 additions & 0 deletions lwip-tests/patch/sio.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--- contrib_orginal/ports/unix/port/netif/sio.c 2024-01-09 16:16:39.406560629 +0100
+++ contrib/ports/unix/port/netif/sio.c 2024-01-11 13:57:17.473232246 +0100
@@ -44,7 +44,7 @@
#include <fcntl.h>
#include <signal.h>
#include <string.h>
-#include <sys/signal.h>
+#include <signal.h>
#include <sys/types.h>

#ifndef LWIP_HAVE_SLIPIF
@@ -161,11 +161,20 @@
}
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
- if ( fcntl( fd, F_SETFL, FASYNC ) != 0)
+
+
+/*
+ * FASYNC is not standardized by OPEN GROUP and not supported by Phoenix-RTOS
+ * Comment out this code to make it compile, this code is excluded anyway since PPP_SUPPORT is defined
+ */
+
+/*
+ if ( fcntl( fd, F_SETFL, FASYNC ) != 0)
{
perror( device );
exit( -1 );
}
+*/
#else
if ( fcntl( fd, F_SETFL, 0 ) != 0)
{
@@ -175,6 +184,19 @@

#endif /* ! (PPP_SUPPORT || LWIP_HAVE_SLIPIF) */

+
+/*
+ * Phoenix-RTOS patch
+ *
+ * CRTSCTS termios cflag is BSD specific,
+ * This compilation is for Phoenix-RTOS which does not support this flag.
+ * This macro has a chance to be forward compatible if Phoenix-RTOS will support it in the future.
+ */
+#ifndef CRTSCTS
+#define CRTSCTS 0
+#endif
+
+
tcgetattr( fd,&oldtio ); /* save current port settings */
/* set new port settings */
/* see 'man termios' for further settings */
Loading