Skip to content

Commit b1b2007

Browse files
committed
Make CI workflow.
1 parent cfd8224 commit b1b2007

9 files changed

Lines changed: 183 additions & 13 deletions

File tree

.github/workflows/main.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
posix:
10+
name: ${{ matrix.name }}
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- name: Ubuntu 22.04 GCC
18+
os: ubuntu-22.04
19+
cc: gcc
20+
cxx: g++
21+
packages: build-essential
22+
cc_flags: -march=native
23+
24+
- name: Ubuntu 22.04 Clang
25+
os: ubuntu-22.04
26+
cc: clang
27+
cxx: clang++
28+
packages: clang
29+
cc_flags: -march=native
30+
31+
- name: Ubuntu 24.04 GCC
32+
os: ubuntu-24.04
33+
cc: gcc
34+
cxx: g++
35+
packages: build-essential
36+
cc_flags: -march=native
37+
38+
- name: Ubuntu 24.04 Clang
39+
os: ubuntu-24.04
40+
cc: clang
41+
cxx: clang++
42+
packages: clang
43+
cc_flags: -march=native
44+
45+
env:
46+
CC: ${{ matrix.cc }}
47+
CXX: ${{ matrix.cxx }}
48+
CC_FLAGS: ${{ matrix.cc_flags }}
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
- name: Install dependencies
55+
run: |
56+
sudo apt-get update
57+
sudo apt-get install -y cmake expect netcat-openbsd ${{ matrix.packages }}
58+
59+
- name: Show tool versions
60+
run: |
61+
cmake --version
62+
"${CC}" --version
63+
64+
- name: Configure
65+
run: |
66+
cmake \
67+
-DCMAKE_C_FLAGS="-Werror ${CC_FLAGS}" \
68+
-S platforms/posix \
69+
-B platforms/posix/build
70+
71+
- name: Build
72+
run: cmake --build platforms/posix/build
73+
74+
- name: Test
75+
working-directory: platforms/posix/build
76+
run: ctest -V

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.com/sobomax/microsippy.svg?branch=master)](https://travis-ci.com/sobomax/microsippy)
1+
[![CI](https://github.com/sobomax/microsippy/actions/workflows/main.yml/badge.svg)](https://github.com/sobomax/microsippy/actions/workflows/main.yml)
22

33
# microsippy
44
Extremely fast and lean, yet fully functional, SIP (RFC3261) and RTP (RFC3550)

platforms/posix/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ ENDIF (IS_BIG_ENDIAN)
9393

9494
enable_testing()
9595

96-
add_test(basic ${CMAKE_SOURCE_DIR}/../../scripts/do-test.sh ${CMAKE_SOURCE_DIR})
96+
add_test(NAME basic COMMAND
97+
${CMAKE_COMMAND} -E env BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}
98+
${CMAKE_SOURCE_DIR}/../../scripts/do-test.sh ${CMAKE_SOURCE_DIR}
99+
)
97100
add_test(NAME usipy_test_uac COMMAND usipy_test_uac)
98101
add_test(NAME usipy_test_ua COMMAND usipy_test_ua)
99102

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
${BUILDDIR}/usipy_test 2>&1 | tee "${MLOG}" &
1+
MON_PIDFILE="${BUILDDIR}/usipy_test.pid"
2+
rm -f "${MON_PIDFILE}"
3+
(
4+
"${BUILDDIR}/usipy_test" 2>&1 &
5+
echo ${!} > "${MON_PIDFILE}"
6+
wait ${!}
7+
) | tee "${MLOG}" &
8+
MON_PIPE_PID=${!}

platforms/posix/usipy_test_ua.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <sys/socket.h>
2+
#include <arpa/inet.h>
23
#include <netinet/in.h>
34
#include <unistd.h>
45

@@ -41,9 +42,12 @@ bind_loopback_udp(void)
4142
sock = socket(AF_INET, SOCK_DGRAM, 0);
4243
assert(sock >= 0);
4344
sin.sin_family = AF_INET;
44-
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
45+
assert(inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr) == 1);
4546
sin.sin_port = 0;
46-
assert(bind(sock, (struct sockaddr *)&sin, sizeof(sin)) == 0);
47+
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) != 0) {
48+
perror("bind_loopback_udp bind");
49+
assert(0);
50+
}
4751
return (sock);
4852
}
4953

platforms/posix/usipy_test_uac.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <sys/socket.h>
2+
#include <arpa/inet.h>
23
#include <netinet/in.h>
34
#include <unistd.h>
45

@@ -317,8 +318,11 @@ bind_loopback_udp(void)
317318
memset(&sin, '\0', sizeof(sin));
318319
sin.sin_family = AF_INET;
319320
sin.sin_port = htons(0);
320-
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
321-
assert(bind(sock, (const struct sockaddr *)&sin, sizeof(sin)) == 0);
321+
assert(inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr) == 1);
322+
if (bind(sock, (const struct sockaddr *)&sin, sizeof(sin)) != 0) {
323+
perror("bind_loopback_udp bind");
324+
assert(0);
325+
}
322326
return (sock);
323327
}
324328

scripts/do-test.sh

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,62 @@ TOOLSDIR=`dirname ${TOOLSPATH}`
1010

1111
MLOG="${BUILDDIR}/monitor.log"
1212
TESTS="empty foobar 100trying ACK OPTIONS INVITE CANCEL 200OK"
13+
MON_PID=
14+
MON_PIPE_PID=
15+
16+
cleanup()
17+
{
18+
if [ ! -z "${MON_PID}" ]
19+
then
20+
kill -TERM "${MON_PID}" 2>/dev/null || true
21+
wait "${MON_PID}" 2>/dev/null || true
22+
fi
23+
if [ ! -z "${MON_PIPE_PID}" ]
24+
then
25+
wait "${MON_PIPE_PID}" 2>/dev/null || true
26+
fi
27+
}
28+
29+
dump_failure_logs()
30+
{
31+
echo "==== basic test failure diagnostics ===="
32+
echo "SRCDIR=${SRCDIR}"
33+
echo "BUILDDIR=${BUILDDIR}"
34+
echo "BRD_IP=${BRD_IP}"
35+
echo "MON_PID=${MON_PID}"
36+
echo "MON_PIPE_PID=${MON_PIPE_PID}"
37+
echo "---- loopback diagnostics ----"
38+
cat /etc/hosts 2>/dev/null || true
39+
getent hosts localhost 2>/dev/null || true
40+
getent hosts 127.0.0.1 2>/dev/null || true
41+
ip addr show lo 2>/dev/null || true
42+
ip route get 127.0.0.1 2>/dev/null || true
43+
ifconfig lo 2>/dev/null || true
44+
ss -lunp 2>/dev/null || netstat -anu 2>/dev/null || true
45+
python3 -c 'import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.bind(("127.0.0.1", 0)); print("python bind 127.0.0.1:0 ok", s.getsockname())' 2>&1 || true
46+
echo "---- generated files ----"
47+
ls -l "${BUILDDIR}"/*.req "${BUILDDIR}"/*.res "${BUILDDIR}"/*.res.pp 2>/dev/null || true
48+
if [ -e "${MLOG}" ]
49+
then
50+
echo "---- ${MLOG} ----"
51+
cat "${MLOG}"
52+
else
53+
echo "monitor log not found: ${MLOG}"
54+
fi
55+
}
56+
57+
finish()
58+
{
59+
rc=${?}
60+
set +e
61+
if [ ${rc} -ne 0 ]
62+
then
63+
dump_failure_logs
64+
fi
65+
cleanup
66+
exit ${rc}
67+
}
68+
trap finish EXIT
1369

1470
if [ -e "${MLOG}" ]
1571
then
@@ -18,7 +74,17 @@ fi
1874

1975
. "${SRCDIR}/scripts/test_start.sub"
2076
MON_RC=${?}
21-
MON_PID=${!}
77+
i=0
78+
while [ ${i} -lt 10 ] && [ ! -s "${MON_PIDFILE}" ]
79+
do
80+
sleep 1
81+
i=$((${i} + 1))
82+
done
83+
if [ ! -s "${MON_PIDFILE}" ]
84+
then
85+
exit 1
86+
fi
87+
MON_PID=`cat "${MON_PIDFILE}"`
2288

2389
. "${SRCDIR}/scripts/test_waitready.sub"
2490

@@ -36,8 +102,6 @@ then
36102
done
37103
sleep 3
38104
fi
39-
kill -TERM ${MON_PID}
40-
wait ${MON_PID} || true
41105
if [ -z "${BRD_IP}" ]
42106
then
43107
exit 1

scripts/test.common.sub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ then
1717
. "${SRCDIR}/scripts/test.common.sub"
1818
fi
1919

20-
BUILDDIR="${SRCDIR}/build"
20+
BUILDDIR="${BUILDDIR:-${SRCDIR}/build}"
2121
DIFF="diff -u"

src/usipy_sip_udp_task.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626

2727
#define MAX_UDP_SIZE 1472 /* MTU 1500, no fragmentation */
2828

29+
static uint16_t
30+
usipy_sip_udp_task_hton16(uint16_t hp)
31+
{
32+
33+
#if USIPY_BIGENDIAN
34+
return (hp);
35+
#else
36+
return ((uint16_t)((hp << 8) | (hp >> 8)));
37+
#endif
38+
}
39+
2940
#define TIME_HDR_PARSE(hm, to) do { \
3041
timer_opbegin(&ods); \
3142
rval = usipy_sip_msg_parse_hdrs(msg, hm, to); \
@@ -58,15 +69,15 @@ usipy_sip_udp_task(void *pvParameters)
5869
if (cfp->sip_af == AF_INET) {
5970
destAddr.v4.sin_addr.s_addr = htonl(INADDR_ANY);
6071
destAddr.v4.sin_family = AF_INET;
61-
destAddr.v4.sin_port = htons(cfp->sip_port);
72+
destAddr.v4.sin_port = usipy_sip_udp_task_hton16(cfp->sip_port);
6273
addr_family = AF_INET;
6374
ip_protocol = IPPROTO_IP;
6475
inet_ntop(AF_INET, &destAddr.v4.sin_addr, addr_str, sizeof(addr_str) - 1);
6576
} else {
6677
#ifdef IPPROTO_IPV6
6778
bzero(&destAddr.v6.sin6_addr, sizeof(destAddr.v6.sin6_addr));
6879
destAddr.v6.sin6_family = AF_INET6;
69-
destAddr.v6.sin6_port = htons(cfp->sip_port);
80+
destAddr.v6.sin6_port = usipy_sip_udp_task_hton16(cfp->sip_port);
7081
addr_family = AF_INET6;
7182
ip_protocol = IPPROTO_IPV6;
7283
inet_ntop(AF_INET6, &destAddr.v6.sin6_addr, addr_str, sizeof(addr_str) - 1);
@@ -82,6 +93,7 @@ usipy_sip_udp_task(void *pvParameters)
8293
break;
8394
}
8495
USIPY_LOGI(cfp->log_tag, "Socket created");
96+
USIPY_LOGI(cfp->log_tag, "Binding UDP port %u", cfp->sip_port);
8597

8698
int err;
8799
if (cfp->sip_af == AF_INET) {

0 commit comments

Comments
 (0)