From 0a7732593275c5443bc4c6d685685af9d34029f4 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 3 Aug 2022 19:53:33 +0200 Subject: [PATCH 01/60] async: add new tests (#107) --- CMakeLists.txt | 1 + src/async.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ src/test.c | 1 + src/test.h | 1 + 4 files changed, 112 insertions(+) create mode 100644 src/async.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 33747d32..dd910f94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,7 @@ set(SRCS src/aubuf.c src/aulevel.c src/auresamp.c + src/async.c src/av1.c src/base64.c src/bfcp.c diff --git a/src/async.c b/src/async.c new file mode 100644 index 00000000..581a764d --- /dev/null +++ b/src/async.c @@ -0,0 +1,109 @@ +/** + * @file async.c Testcode for re async + * + * Copyright (C) 2022 Sebastian Reimers + */ +#define _BSD_SOURCE 1 +#define _DEFAULT_SOURCE 1 + +#ifndef WIN32 +#include +#endif + +#include +#include +#include "test.h" + +#define DEBUG_MODULE "async" +#define DEBUG_LEVEL 5 +#include + +static int test_add; +static int test_complete; + +static struct test { + char domain[128]; + struct sa sa; + int err; + int err_expected; +} testv[] = { + {"localhost", {.len = 0}, -1, 0}, + {"test.notfound", {.len = 0}, -1, EADDRNOTAVAIL} +}; + + +static int blocking_getaddr(void *arg) +{ + int err; + struct test *test = arg; + struct addrinfo *res = NULL; + struct addrinfo hints; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; + + + /* Blocking */ + err = getaddrinfo(test->domain, NULL, &hints, &res); + if (err) + return EADDRNOTAVAIL; + + sa_set_sa(&test->sa, res->ai_addr); + freeaddrinfo(res); + + return 0; +} + + +static void completed(int err, void *arg) +{ + struct test *test = arg; + struct sa sa; + + if (err) + goto out; + + err = re_thread_check(); + TEST_ERR(err); + + sa_set_str(&sa, "127.0.0.1", 0); + if (!sa_cmp(&sa, &test->sa, SA_ADDR)) + err = EINVAL; + + TEST_ERR(err); + +out: + test->err = err; + if (++test_complete >= test_add) + re_cancel(); +} + + +int test_async(void) +{ + int err; + + test_add = 0; + test_complete = 0; + + err = re_thread_async_init(4); + TEST_ERR(err); + + for (size_t i = 0; i < ARRAY_SIZE(testv); i++) { + err = re_thread_async(blocking_getaddr, completed, &testv[i]); + TEST_ERR(err); + ++test_add; + } + + err = re_main_timeout(100); + TEST_ERR(err); + + for (size_t i = 0; i < ARRAY_SIZE(testv); i++) { + TEST_EQUALS(testv[i].err_expected, testv[i].err); + } + +out: + re_thread_async_close(); + return err; +} diff --git a/src/test.c b/src/test.c index 8126daf6..ecd587e8 100644 --- a/src/test.c +++ b/src/test.c @@ -43,6 +43,7 @@ static const struct test tests[] = { TEST(test_aubuf), TEST(test_aulevel), TEST(test_auresamp), + TEST(test_async), TEST(test_av1), TEST(test_base64), TEST(test_bfcp), diff --git a/src/test.h b/src/test.h index 43cfed4a..eecff565 100644 --- a/src/test.h +++ b/src/test.h @@ -163,6 +163,7 @@ int test_aes_gcm(void); int test_aubuf(void); int test_aulevel(void); int test_auresamp(void); +int test_async(void); int test_av1(void); int test_base64(void); int test_bfcp(void); From 84015c804f4f563b15163e345a7ffb102690c9ff Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 13 Aug 2022 19:12:34 +0200 Subject: [PATCH 02/60] cmake: add path to windows build --- cmake/FindRE.cmake | 3 ++- cmake/FindREM.cmake | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/FindRE.cmake b/cmake/FindRE.cmake index 2ddc5ff5..2e36c90a 100644 --- a/cmake/FindRE.cmake +++ b/cmake/FindRE.cmake @@ -5,7 +5,8 @@ find_path(RE_INCLUDE_DIR re.h HINTS ../re/include ${PC_LIBRE_INCLUDEDIR} ${PC_LIBRE_INCLUDE_DIRS}) find_library(RE_LIBRARY NAMES re libre re-static - HINTS ../re ../re/build ${PC_LIBRE_LIBDIR} ${PC_LIBRE_LIBRARY_DIRS}) + HINTS ../re ../re/build ../re/build/Debug + ${PC_LIBRE_LIBDIR} ${PC_LIBRE_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(RE DEFAULT_MSG RE_LIBRARY RE_INCLUDE_DIR) diff --git a/cmake/FindREM.cmake b/cmake/FindREM.cmake index 4a3502b0..3df2e620 100644 --- a/cmake/FindREM.cmake +++ b/cmake/FindREM.cmake @@ -5,7 +5,8 @@ find_path(REM_INCLUDE_DIR rem.h HINTS ../rem/include ${PC_LIBREM_INCLUDEDIR} ${PC_LIBREM_INCLUDE_DIRS}) find_library(REM_LIBRARY NAMES rem librem - HINTS ../rem ../rem/build ${PC_LIBREM_LIBDIR} ${PC_LIBREM_LIBRARY_DIRS}) + HINTS ../rem ../rem/build ../rem/build/Debug + ${PC_LIBREM_LIBDIR} ${PC_LIBREM_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(REM DEFAULT_MSG REM_LIBRARY REM_INCLUDE_DIR) From 9db06a4c6ff28faf30135a863b617c3e269e91c2 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 13 Aug 2022 19:14:03 +0200 Subject: [PATCH 03/60] mock: fix warning --- src/mock/turnsrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mock/turnsrv.c b/src/mock/turnsrv.c index 014c1b5b..e15fad30 100644 --- a/src/mock/turnsrv.c +++ b/src/mock/turnsrv.c @@ -94,7 +94,7 @@ static void relay_udp_recv(const struct sa *src, struct mbuf *mb, void *arg) chan = find_channel_peer(turn, src); if (chan) { - uint16_t len = mbuf_get_left(mb); + uint16_t len = (uint16_t)mbuf_get_left(mb); size_t start; if (mb->pos < 4) { From 11b66e3de7290fc0252ee99224a1d28320c1a02c Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 14 Aug 2022 08:43:59 +0200 Subject: [PATCH 04/60] dns/client: add async getaddrinfo usage (#112) * dns: refactor IP checks and add system test * use dnsc_getaddrinfo --- src/dns.c | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/dns.c b/src/dns.c index f9f09895..a5916dbe 100644 --- a/src/dns.c +++ b/src/dns.c @@ -13,7 +13,14 @@ #include -enum {NUM_TESTS = 32}; +enum { + NUM_TESTS = 32, + IP_127_0_0_1 = 0x7f000001, + IP_127_0_0_2 = 0x7f000002, + IP_127_0_0_3 = 0x7f000003, + IP_127_0_0_4 = 0x7f000004, + IP_127_0_0_5 = 0x7f000005, +}; static int mkstr(char **strp) @@ -371,57 +378,63 @@ int test_dns_integration(void) err = dns_server_alloc(&srv, false); TEST_ERR(err); - err = dns_server_add_a(srv, "test1.example.net", 0x7f000001, 1); + err = dns_server_add_a(srv, "test1.example.net", IP_127_0_0_1, 1); TEST_ERR(err); err = dnsc_alloc(&data.dnsc, NULL, &srv->addr, 1); TEST_ERR(err); - err = check_dns(&data, "test1.example.net", 0x7f000001, true); + /* Test system getaddrinfo */ + dnsc_getaddrinfo(data.dnsc, true); + err = check_dns(&data, "localhost", IP_127_0_0_1, true); + TEST_ERR(err); + dnsc_getaddrinfo(data.dnsc, false); + + err = check_dns(&data, "test1.example.net", IP_127_0_0_1, true); TEST_ERR(err); /* Test does not exist */ - err = check_dns(&data, "test2.example.net", 0x7f000001, true); + err = check_dns(&data, "test2.example.net", IP_127_0_0_1, true); TEST_EQUALS(ENODATA, err); dns_server_flush(srv); - err = dns_server_add_a(srv, "test1.example.net", 0x7f000002, 1); + err = dns_server_add_a(srv, "test1.example.net", IP_127_0_0_2, 1); TEST_ERR(err); - err = dns_server_add_a(srv, "test2.example.net", 0x7f000003, 1); + err = dns_server_add_a(srv, "test2.example.net", IP_127_0_0_3, 1); TEST_ERR(err); - err = dns_server_add_a(srv, "test3.example.net", 0x7f000004, 1); + err = dns_server_add_a(srv, "test3.example.net", IP_127_0_0_4, 1); TEST_ERR(err); /* --- Test DNS Cache --- */ - err = check_dns(&data, "test1.example.net", 0x7f000001, true); + err = check_dns(&data, "test1.example.net", IP_127_0_0_1, true); TEST_ERR(err); - err = check_dns(&data, "test2.example.net", 0x7f000003, true); + err = check_dns(&data, "test2.example.net", IP_127_0_0_3, true); TEST_ERR(err); - err = check_dns(&data, "test2.example.net", 0x7f000003, true); + err = check_dns(&data, "test2.example.net", IP_127_0_0_3, true); TEST_ERR(err); /* Check another resource record afterwards */ - err = check_dns(&data, "test3.example.net", 0x7f000004, true); + err = check_dns(&data, "test3.example.net", IP_127_0_0_4, true); TEST_ERR(err); sys_msleep(100); /* wait until TTL timer expires */ re_main_timeout(1); /* execute tmr callbacks */ /* --- Check expired TTL --- */ - err = check_dns(&data, "test1.example.net", 0x7f000002, true); + err = check_dns(&data, "test1.example.net", IP_127_0_0_2, true); TEST_ERR(err); /* --- Test explicit DNS cache flush --- */ dns_server_flush(srv); - err = dns_server_add_a(srv, "test1.example.net", 0x7f000005, 1); + err = dns_server_add_a(srv, "test1.example.net", IP_127_0_0_5, 1); TEST_ERR(err); dnsc_cache_flush(data.dnsc); - err = check_dns(&data, "test1.example.net", 0x7f000005, true); + err = check_dns(&data, "test1.example.net", IP_127_0_0_5, true); TEST_ERR(err); /* --- Test early query cancellation --- */ @@ -430,7 +443,7 @@ int test_dns_integration(void) TEST_ERR(err); mem_deref(q); - err = check_dns(&data, "test1.example.net", 0x7f000005, true); + err = check_dns(&data, "test1.example.net", IP_127_0_0_5, true); TEST_ERR(err); /* --- Leave query open for cleanup test --- */ From 31bc53c04e96af44b2b0b863c4c3436150940c93 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 10:04:27 +0200 Subject: [PATCH 05/60] fmt: workaround for windows compiler --- src/fmt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fmt.c b/src/fmt.c index 56ab035e..e1ddc076 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -133,7 +133,7 @@ int test_fmt_pl_i32(void) {PL(""), 0}, {{NULL, 2}, 0}, {{"fo", 0}, 0}, - {PL("2147483648"), -2147483648}, + {PL("2147483648"), -2147483647 - 1}, {PL("9223372036854775808"), 0}, /* Working cases */ @@ -147,7 +147,7 @@ int test_fmt_pl_i32(void) {PL("-5467"), -5467}, {PL("2147483647"), 2147483647}, {PL("+2147483647"), 2147483647}, - {PL("-2147483648"), -2147483648}, + {PL("-2147483648"), -2147483647 - 1}, }; uint32_t i; int err = 0; @@ -192,7 +192,7 @@ int test_fmt_pl_i64(void) {PL("-5467"), -5467}, {PL("2147483647"), 2147483647}, {PL("2147483648"), 2147483648L}, - {PL("-2147483648"), -2147483648L}, + {PL("-2147483648"), -2147483647L - 1L}, {PL("9223372036854775807"), 9223372036854775807L}, {PL("+9223372036854775807"), 9223372036854775807L}, {PL("-9223372036854775808"), -9223372036854775807L - 1L}, From bf826125617da9736bab39c0ea01feece779845b Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 10:11:13 +0200 Subject: [PATCH 06/60] sys: fix unlink and WIN32 --- src/sys.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sys.c b/src/sys.c index 07661daf..fc9a0fee 100644 --- a/src/sys.c +++ b/src/sys.c @@ -213,7 +213,12 @@ int test_sys_fs_fopen(void) err = fclose(file); TEST_ERR(err); +#ifdef WIN32 + (void)_unlink("retest_fs_fopen"); +#else (void)unlink("retest_fs_fopen"); +#endif + out: return err; } From ee3c35a902c34acb402110c69bda18c5b027113b Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 10:15:25 +0200 Subject: [PATCH 07/60] test: cast values to fix WIN32 warnings --- src/test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test.c b/src/test.c index ecd587e8..5be758fb 100644 --- a/src/test.c +++ b/src/test.c @@ -535,7 +535,7 @@ static int testcase_perf(const struct test *test, double *usec_avgp) usec_avg = 1.0 * (usec_stop - usec_start) / (double)i; - n = usec_avg ? (REPEATS_USEC / usec_avg) : 0; + n = usec_avg ? (size_t)(REPEATS_USEC / usec_avg) : 0; n = min(REPEATS_MAX, max(n, REPEATS_MIN)); /* now for the real measurement */ @@ -647,7 +647,7 @@ int test_perf(const char *name, bool verbose) return err; } - tim->nsec_avg = 1000.0 * usec_avg; + tim->nsec_avg = (uint64_t)(1000.0 * usec_avg); } /* sort the timing table by average time */ From 65e5a32e8cb1badd427a3f7fde766c16715d1dfc Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 10:17:34 +0200 Subject: [PATCH 08/60] trace: fix unlink and WIN32 --- src/trace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/trace.c b/src/trace.c index 4ffceda3..be85c828 100644 --- a/src/trace.c +++ b/src/trace.c @@ -60,7 +60,11 @@ int test_trace(void) /* Test TRACE after close - should do nothing */ RE_TRACE_BEGIN("test", "test after close"); +#ifdef WIN32 + (void)_unlink("test_trace.json"); +#else (void)unlink("test_trace.json"); +#endif out: return err; From 569c976b0d37a0ded87a54d30fa54c42e644cd5c Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 10:23:21 +0200 Subject: [PATCH 09/60] main: only run regular tests if GETOPT is missing --- src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.c b/src/main.c index f31cd8f5..c346e040 100644 --- a/src/main.c +++ b/src/main.c @@ -174,6 +174,8 @@ int main(int argc, char *argv[]) do_oom = true; do_int = true; do_perf = true; + do_all = false; + verbose = true; #endif /* Initialise debugging */ From 6de493e111882e58cdfcd66f4ce7394f5c513806 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 10:35:22 +0200 Subject: [PATCH 10/60] test: various fixes for WIN32 --- src/test.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/test.c b/src/test.c index 5be758fb..969ef496 100644 --- a/src/test.c +++ b/src/test.c @@ -27,6 +27,14 @@ #include +#ifdef WIN32 +#define open _open +#define read _read +#define write _write +#define close _close +#endif + + typedef int (test_exec_h)(void); struct test { @@ -296,8 +304,13 @@ static void restore_output(int err) (void)fclose(f); out: +#ifdef WIN32 + (void)_unlink("stdout.out"); + (void)_unlink("stderr.out"); +#else (void)unlink("stdout.out"); (void)unlink("stderr.out"); +#endif } @@ -970,17 +983,17 @@ int test_write_file(struct mbuf *mb, const char *filename) for (;;) { uint8_t buf[1024]; - ssize_t n; + size_t count; - n = min(sizeof(buf), mbuf_get_left(mb)); - if (n == 0) + count = min(sizeof(buf), mbuf_get_left(mb)); + if (count == 0) break; - err = mbuf_read_mem(mb, buf, n); + err = mbuf_read_mem(mb, buf, count); if (err) break; - n = write(fd, (void *)buf, n); + ssize_t n = write(fd, (void *)buf, (unsigned int)count); if (n < 0) { err = errno; break; From e44fa24702c7f9d9ab0d8bf5db88b0b117904939 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 14 Aug 2022 11:33:34 +0200 Subject: [PATCH 11/60] async: fix multithreading tests (#115) --- src/async.c | 30 +++++++++++++++++------------- src/main.c | 2 ++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/async.c b/src/async.c index 581a764d..8ee99687 100644 --- a/src/async.c +++ b/src/async.c @@ -18,20 +18,19 @@ #define DEBUG_LEVEL 5 #include -static int test_add; -static int test_complete; +struct test_cnt { + int tests; + int done; +}; -static struct test { +struct test { char domain[128]; struct sa sa; int err; int err_expected; -} testv[] = { - {"localhost", {.len = 0}, -1, 0}, - {"test.notfound", {.len = 0}, -1, EADDRNOTAVAIL} + struct test_cnt *cnt; }; - static int blocking_getaddr(void *arg) { int err; @@ -75,7 +74,7 @@ static void completed(int err, void *arg) out: test->err = err; - if (++test_complete >= test_add) + if (++test->cnt->done >= test->cnt->tests) re_cancel(); } @@ -84,19 +83,24 @@ int test_async(void) { int err; - test_add = 0; - test_complete = 0; + struct test_cnt cnt = {0, 0}; + + struct test testv[] = { + {"localhost", {.len = 0}, -1, 0, &cnt}, + {"test.notfound", {.len = 0}, -1, EADDRNOTAVAIL, &cnt} + }; + + cnt.tests = ARRAY_SIZE(testv); - err = re_thread_async_init(4); + err = re_thread_async_init(2); TEST_ERR(err); for (size_t i = 0; i < ARRAY_SIZE(testv); i++) { err = re_thread_async(blocking_getaddr, completed, &testv[i]); TEST_ERR(err); - ++test_add; } - err = re_main_timeout(100); + err = re_main_timeout(200); TEST_ERR(err); for (size_t i = 0; i < ARRAY_SIZE(testv); i++) { diff --git a/src/main.c b/src/main.c index c346e040..c4b7a3b7 100644 --- a/src/main.c +++ b/src/main.c @@ -255,6 +255,8 @@ int main(int argc, char *argv[]) } out: + re_thread_async_close(); + /* Check for open timers */ tmr_debug(); From 7fded3adf6f35abfb4a23fcf4ec2b84197a6f83a Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 11:38:46 +0200 Subject: [PATCH 12/60] main: if GETOPT is missing run regular tests --- src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index c4b7a3b7..f8ffe8dc 100644 --- a/src/main.c +++ b/src/main.c @@ -171,9 +171,9 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; do_reg = true; - do_oom = true; - do_int = true; - do_perf = true; + do_oom = false; + do_int = false; + do_perf = false; do_all = false; verbose = true; #endif From 95acc18e2fabb76681cd60c5edd39bf6262eba70 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 11:40:34 +0200 Subject: [PATCH 13/60] cmake: add LINKLIBS variable --- CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd910f94..70cccf52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,10 +242,16 @@ endif() # Main target object # +set(LINKLIBS ${REM_LIBRARIES} ${RE_LIBRARIES} ${OPENSSL_LIBRARIES}) +if(WIN32) + list(APPEND LINKLIBS qwave iphlpapi wsock32 ws2_32) +else() + list(APPEND LINKLIBS -lz -lpthread -lm) +endif() + add_executable(${PROJECT_NAME} ${SRCS}) set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS 1) -target_link_libraries(${PROJECT_NAME} - PRIVATE ${REM_LIBRARIES} ${RE_LIBRARIES} ${OPENSSL_LIBRARIES} - -lz -lpthread -lm) +target_link_libraries(${PROJECT_NAME} PRIVATE ${LINKLIBS}) + target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR}) From 0bbb3771b7b60a3ee12396e8d7284ecfe02fad6a Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 14 Aug 2022 12:36:12 +0200 Subject: [PATCH 14/60] test cmake on Windows (#114) * test cmake on Windows * You have an error in your yaml syntax on line 14 * fix yaml syntax error * try to find re * try to find rem * mock: fix win32 warning * fix unlink warnings * fix warnings * fix write * fix size_t * write needs unsigned int * link to win32 libs * add qwave * execute retest.exe in build/debug * set verbose * set verbose * disable all * update flags * ci: fix compiler list and choco * LINKLIBS and flags --- .github/workflows/build.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3424f93a..db109c91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,10 +17,12 @@ jobs: strategy: matrix: compiler: [gcc, clang] - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] exclude: - os: macos-latest compiler: gcc + - os: windows-latest + compiler: clang env: CC: ${{ matrix.compiler }} @@ -32,6 +34,11 @@ jobs: run: | echo "OPENSSL_ROOT_DIR=/usr/local/opt/openssl" >> $GITHUB_ENV + - name: install packages + if: ${{ runner.os == 'Windows' }} + run: | + choco install --no-progress openssl + - uses: sreimers/pr-dependency-action@v0.5 with: name: re @@ -45,6 +52,7 @@ jobs: secret: ${{ secrets.GITHUB_TOKEN }} - name: make re/rem + shell: bash run: | for p in re rem; do cmake -S $p -B $p/build @@ -69,3 +77,10 @@ jobs: run: | OPENSSL_ROOT_DIR=/usr/local/opt/openssl cmake -DCMAKE_C_FLAGS="-Werror" . && make ./retest -r + + - name: retest + if: ${{ runner.os == 'Windows' }} + run: | + cmake -B build -DCMAKE_C_FLAGS="/WX" + cmake --build build + build\Debug\retest.exe -v -r From b5514527c4e849604a5a9096410f754853bf2fb0 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 14 Aug 2022 12:49:39 +0200 Subject: [PATCH 15/60] test: fix c11 err handling --- src/test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test.c b/src/test.c index 969ef496..ca1f1119 100644 --- a/src/test.c +++ b/src/test.c @@ -776,9 +776,10 @@ int test_multithread(void) threadv[i].test = &tests[ti]; threadv[i].err = -1; /* error not set */ - err = thrd_create(&threadv[i].tid, - thread_handler, (void *)&threadv[i]); - if (err != thrd_success) { + err = thrd_success != thrd_create(&threadv[i].tid, + thread_handler, + (void *)&threadv[i]); + if (err) { err = EAGAIN; DEBUG_WARNING("thread_create failed (%m)\n", err); break; From f17625e981ce1c9011e12cff7184bcd4b484365a Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 3 Sep 2022 14:00:49 +0200 Subject: [PATCH 16/60] cmake: use re config (#118) --- CMakeLists.txt | 83 ++------------------------------------------------ 1 file changed, 2 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70cccf52..877173f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,21 +21,14 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) # Module/Package Includes # -include(CheckIncludeFile) -include(CheckFunctionExists) -include(CheckSymbolExists) find_package(RE REQUIRED) find_package(REM REQUIRED) -find_package(Threads REQUIRED) -find_package(OpenSSL) - ############################################################################## # # Compile options/definitions # -option(USE_OPENSSL "Enable OpenSSL" ${OPENSSL_FOUND}) option(USE_SANITIZER "Sanitizers like: address, thread, undefined, memory") include(sanitizer) @@ -66,86 +59,13 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options(-Wshorten-64-to-32) endif() -check_include_file(unistd.h HAVE_UNISTD_H) -if(HAVE_UNISTD_H) - add_definitions(-DHAVE_UNISTD_H) -endif() - -check_function_exists(thrd_create HAVE_THREADS) -if(HAVE_THREADS) - add_definitions(-DHAVE_THREADS) -endif() - -if(CMAKE_USE_PTHREADS_INIT) - add_definitions(-DHAVE_PTHREAD) - set(HAVE_PTHREAD ON) -endif() - -check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM) -if(HAVE_ARC4RANDOM) - add_definitions(-DHAVE_ARC4RANDOM) -endif() - - include_directories( src - ../re/include - ../rem/include ${RE_INCLUDE_DIRS} ${REM_INCLUDE_DIRS} ) -add_definitions( - -DHAVE_ATOMIC - -DHAVE_INET6 - -DHAVE_SELECT - ) - -if(UNIX) - add_definitions( - -DHAVE_GETOPT - -DHAVE_POLL - -DHAVE_PWD_H - -DHAVE_ROUTE_LIST - -DHAVE_SETRLIMIT - -DHAVE_STRERROR_R - -DHAVE_STRINGS_H - -DHAVE_SYS_TIME_H - -DHAVE_UNAME - -DHAVE_SELECT_H - -DHAVE_SIGNAL - ) - if(NOT ANDROID) - add_definitions(-DHAVE_GETIFADDRS) - endif() -endif() - - -if(MSVC) - add_definitions( - -DHAVE_IO_H - -D_CRT_SECURE_NO_WARNINGS - ) -endif() - -if(WIN32) - add_definitions( - -DWIN32 -D_WIN32_WINNT=0x0600 - ) -endif() - -if(USE_OPENSSL) - add_definitions( - -DUSE_DTLS - -DUSE_OPENSSL - -DUSE_OPENSSL_AES - -DUSE_OPENSSL_DTLS - -DUSE_OPENSSL_HMAC - -DUSE_OPENSSL_SRTP - -DUSE_TLS - ) -endif() - +find_package(re CONFIG REQUIRED HINTS ../re/cmake) ############################################################################## # @@ -253,5 +173,6 @@ add_executable(${PROJECT_NAME} ${SRCS}) set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS 1) target_link_libraries(${PROJECT_NAME} PRIVATE ${LINKLIBS}) +target_compile_definitions(${PROJECT_NAME} PRIVATE ${RE_DEFINITIONS}) target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR}) From ef997453dc594a468f430761799ec64e56938baa Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 3 Sep 2022 14:01:03 +0200 Subject: [PATCH 17/60] base64: Encoding/Decoding with URL and Filename Safe Alphabet (#113) --- src/base64.c | 99 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 21 deletions(-) diff --git a/src/base64.c b/src/base64.c index ee0e829a..f1cdbb15 100644 --- a/src/base64.c +++ b/src/base64.c @@ -18,72 +18,129 @@ int test_base64(void) const struct { struct pl pl; struct pl b64; + struct pl b64url; } testv[] = { - {PL(""), PL("") }, - {PL("f"), PL("Zg==")}, - {PL("fo"), PL("Zm8=")}, - {PL("foo"), PL("Zm9v")}, - {PL("foob"), PL("Zm9vYg==")}, - {PL("fooba"), PL("Zm9vYmE=")}, - {PL("foobar"), PL("Zm9vYmFy")}, + {PL(""), PL(""), PL("")}, + {PL("f"), PL("Zg=="), PL("Zg")}, + {PL("fo"), PL("Zm8="), PL("Zm8")}, + {PL("foo"), PL("Zm9v"), PL("Zm9v")}, + {PL("foob"), PL("Zm9vYg=="), PL("Zm9vYg")}, + {PL("fooba"), PL("Zm9vYmE="), PL("Zm9vYmE")}, + {PL("foobar"), PL("Zm9vYmFy"), PL("Zm9vYmFy")}, + {PL("\xff\x01\xfe\x02"), PL("/wH+Ag=="), PL("_wH-Ag")}, {PL("asdlkjqopinzidfj84r77fsgljsdf9823r"), - PL("YXNkbGtqcW9waW56aWRmajg0cjc3ZnNnbGpzZGY5ODIzcg==")}, + PL("YXNkbGtqcW9waW56aWRmajg0cjc3ZnNnbGpzZGY5ODIzcg=="), + PL("YXNkbGtqcW9waW56aWRmajg0cjc3ZnNnbGpzZGY5ODIzcg")}, {PL("918nvbakishdl8317237dlakskdkaldj"), - PL("OTE4bnZiYWtpc2hkbDgzMTcyMzdkbGFrc2tka2FsZGo=")}, + PL("OTE4bnZiYWtpc2hkbDgzMTcyMzdkbGFrc2tka2FsZGo="), + PL("OTE4bnZiYWtpc2hkbDgzMTcyMzdkbGFrc2tka2FsZGo")}, {PL("very10long..testxyzstring/.,-=-3029===7823#'];'#';]#'"), PL("dmVyeTEwbG9uZy4udGVzdHh5enN0cmluZy8uLC0" - "9LTMwMjk9PT03ODIzIyddOycjJztdIyc=")} + "9LTMwMjk9PT03ODIzIyddOycjJztdIyc="), + PL("dmVyeTEwbG9uZy4udGVzdHh5enN0cmluZy8uLC0" + "9LTMwMjk9PT03ODIzIyddOycjJztdIyc")}, }; uint32_t i; int err = 0; + uint8_t b64_buf[128]; + size_t olen; for (i=0; ip, pl->l, buf, &olen); - if (err) - break; + TEST_ERR(err); if (olen != testv[i].b64.l) { DEBUG_WARNING("b64_encode %u failed: l=%u olen=%u\n", i, testv[i].b64.l, olen); err = EINVAL; - break; + TEST_ERR(err); } if (0 != memcmp(testv[i].b64.p, buf, olen)) { DEBUG_WARNING("b64_encode %u failed: ref=%r, enc=%b\n", i, &testv[i].b64, buf, olen); err = EINVAL; - break; + TEST_ERR(err); + } + + /* Encode URL */ + olen = sizeof(buf); + err = base64url_encode((uint8_t *)pl->p, pl->l, buf, &olen); + TEST_ERR(err); + + if (olen != testv[i].b64url.l) { + DEBUG_WARNING("b64_encode %u failed: l=%u olen=%u\n", + i, testv[i].b64url.l, olen); + err = EINVAL; + TEST_ERR(err); + } + if (0 != memcmp(testv[i].b64url.p, buf, olen)) { + DEBUG_WARNING("b64_encode %u failed: ref=%r, enc=%b\n", + i, &testv[i].b64url, buf, olen); + err = EINVAL; + TEST_ERR(err); } /* Decode */ b = &testv[i].b64; olen = sizeof(b64_buf); err = base64_decode(b->p, b->l, b64_buf, &olen); - if (err) - break; + TEST_ERR(err); if (olen != testv[i].pl.l) { DEBUG_WARNING("b64_decode %u failed: l=%u olen=%u\n", i, testv[i].pl.l, olen); err = EINVAL; - break; + TEST_ERR(err); } if (0 != memcmp(testv[i].pl.p, b64_buf, olen)) { DEBUG_WARNING("b64_decode %u failed: ref=%r, enc=%b\n", i, &testv[i].pl, b64_buf, olen); err = EINVAL; - break; + TEST_ERR(err); + } + + /* Decode Url */ + b = &testv[i].b64url; + olen = sizeof(b64_buf); + err = base64_decode(b->p, b->l, b64_buf, &olen); + TEST_ERR(err); + + if (olen != testv[i].pl.l) { + DEBUG_WARNING( + "b64_decode url %u failed: l=%u olen=%u\n", i, + testv[i].pl.l, olen); + err = EINVAL; + TEST_ERR(err); + } + if (0 != memcmp(testv[i].pl.p, b64_buf, olen)) { + DEBUG_WARNING( + "b64_decode url %u failed: ref=%r, enc=%b\n", + i, &testv[i].pl, b64_buf, olen); + err = EINVAL; + TEST_ERR(err); } } + /* Invalid checks */ + char c = 'A'; + olen = sizeof(b64_buf); + err = base64_decode(&c, sizeof(c), b64_buf, &olen); + TEST_ERR(err); + + struct pl inv; + pl_set_str(&inv, "Zm8="); + olen = 1; + err = base64_decode(inv.p, inv.l, b64_buf, &olen); + TEST_EQUALS(EOVERFLOW, err); + + err = 0; +out: return err; } From 511e5fe95b5e48227e4fa96f3ec96554db323b95 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 3 Sep 2022 15:40:56 +0200 Subject: [PATCH 18/60] cmake: bump minimum to 3.10 (#119) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 877173f9..780a69a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ # Versioning # -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.10) project(retest C) From 69824a66d84063630bf0ac92d8440a062f98371d Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Sun, 4 Sep 2022 14:12:07 +0300 Subject: [PATCH 19/60] Don't fail on compilation when there no OpenSSL on target platform (#120) --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 780a69a4..748c3950 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,4 +175,6 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS 1) target_link_libraries(${PROJECT_NAME} PRIVATE ${LINKLIBS}) target_compile_definitions(${PROJECT_NAME} PRIVATE ${RE_DEFINITIONS}) -target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR}) +if(USE_OPENSSL) + target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR}) +endif() From 6b793c90ebc3d65231db9c1fc5e6046415c94070 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 4 Sep 2022 18:12:10 +0200 Subject: [PATCH 20/60] trice: fix win32 with explicit error tests (#121) --- src/trice.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/trice.c b/src/trice.c index a74ed78b..8ba3fdca 100644 --- a/src/trice.c +++ b/src/trice.c @@ -303,14 +303,15 @@ static int fixture_init(struct fixture *f) err = trice_alloc(&f->icem, &conf, f->controlling ? ICE_ROLE_CONTROLLING : ICE_ROLE_CONTROLLED, f->lufrag, f->lpwd); - if (err) - goto out; + TEST_ERR(err); + TEST_ASSERT(f->icem != NULL); - err |= trice_set_remote_ufrag(f->icem, f->rufrag); - err |= trice_set_remote_pwd(f->icem, f->rpwd); - if (err) - goto out; + err = trice_set_remote_ufrag(f->icem, f->rufrag); + TEST_ERR(err); + + err = trice_set_remote_pwd(f->icem, f->rpwd); + TEST_ERR(err); err = sa_set_str(&f->laddr, "127.0.0.1", 0); TEST_ERR(err); @@ -1142,10 +1143,18 @@ int test_trice_loop(void) { int err = 0; - err |= checklist_udp_loop(0, 0); - err |= checklist_udp_loop(0, 1); - err |= checklist_udp_loop(1, 0); - err |= checklist_udp_loop(1, 1); + err = checklist_udp_loop(0, 0); + TEST_ERR(err); + + err = checklist_udp_loop(0, 1); + TEST_ERR(err); + + err = checklist_udp_loop(1, 0); + TEST_ERR(err); + + err = checklist_udp_loop(1, 1); + TEST_ERR(err); +out: return err; } From e6c34ed0a9fb686ca2279d2cc5e905ee8d7b3805 Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Thu, 4 Aug 2022 11:36:33 +0200 Subject: [PATCH 21/60] http: test http/https requests with large body --- src/http.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++------- src/test.c | 2 + src/test.h | 2 + 3 files changed, 181 insertions(+), 27 deletions(-) diff --git a/src/http.c b/src/http.c index 98690422..4b0ddb86 100644 --- a/src/http.c +++ b/src/http.c @@ -12,6 +12,12 @@ #define DEBUG_LEVEL 5 #include +enum large_body_test { + REQ_BODY_CHUNK_SIZE = 26 * 42, + REQ_BODY_SIZE = REQ_BODY_CHUNK_SIZE * 480 - 26, + REQ_HTTP_REQUESTS = 2 +}; + static int test_http_response_no_reasonphrase(void) { @@ -122,6 +128,7 @@ struct test { size_t clen; uint32_t n_request; uint32_t n_response; + size_t i_req_body; bool secure; int err; }; @@ -201,6 +208,85 @@ static void http_req_handler(struct http_conn *conn, } +static void http_put_req_handler(struct http_conn *conn, + const struct http_msg *msg, void *arg) +{ + struct test *t = arg; + struct mbuf *mb_body = mbuf_alloc(1024); + int err = 0; + size_t l = 0; + size_t cmp_len; + + if (!mb_body) { + err = ENOMEM; + goto out; + } + + ++t->n_request; + + if (t->secure) { + TEST_ASSERT(http_conn_tls(conn) != NULL); + } + else { + TEST_ASSERT(http_conn_tls(conn) == NULL); + } + + /* verify HTTP request */ + TEST_STRCMP("1.1", 3, msg->ver.p, msg->ver.l); + TEST_STRCMP("PUT", 3, msg->met.p, msg->met.l); + TEST_STRCMP("/index.html", 11, msg->path.p, msg->path.l); + TEST_STRCMP("", 0, msg->prm.p, msg->prm.l); + TEST_EQUALS(t->clen, msg->clen); + + l = mbuf_get_left(msg->mb); + + while (l > 0) { + cmp_len = min(l, 26); + TEST_STRCMP("abcdefghijklmnopqrstuvwxyz", cmp_len, + mbuf_buf(msg->mb), cmp_len); + mbuf_advance(msg->mb, cmp_len); + l -= cmp_len; + } + + /* Create a chunked response body */ + err = mbuf_write_str(mb_body, + "2\r\n" + "ab\r\n" + + "4\r\n" + "cdef\r\n" + + "8\r\n" + "ghijklmn\r\n" + + "c\r\n" + "opqrstuvwxyz\r\n" + + "0\r\n" + "\r\n" + ); + if (err) + goto out; + + t->clen = mb_body->end; + + err = http_reply(conn, 200, "OK", + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: %zu\r\n" + "\r\n" + "%b", + mb_body->end, + mb_body->buf, mb_body->end + ); + + out: + mem_deref(mb_body); + if (err) + abort_test(t, err); +} + + static void http_resp_handler(int err, const struct http_msg *msg, void *arg) { struct test *t = arg; @@ -249,18 +335,43 @@ static int http_data_handler(const uint8_t *buf, size_t size, struct test *t = arg; (void)msg; - if (!t->mb_body) { - + if (!t->mb_body) t->mb_body = mbuf_alloc(256); - if (!t->mb_body) - return ENOMEM; - } + if (!t->mb_body) + return 0; return mbuf_write_mem(t->mb_body, buf, size); } -static int test_http_loop_base(bool secure) +static size_t http_req_body_handler(struct mbuf *mb, void *arg) +{ + struct test *t = arg; + size_t l = 0; + size_t wlen; + + /* Create a chunked response body */ + while ( l < REQ_BODY_CHUNK_SIZE && t->i_req_body < t->clen) { + wlen = min(min(26, REQ_BODY_CHUNK_SIZE - l), + t->clen - t->i_req_body); + if (wlen <= 0) + return l; + + if (mbuf_write_mem(mb, + (const uint8_t*) "abcdefghijklmnopqrstuvwxyz", + wlen)) { + mbuf_reset(mb); + return 0; + } + l += wlen; + t->i_req_body += (uint32_t)wlen; + } + + return l; +} + + +static int test_http_loop_base(bool secure, const char *met) { struct http_sock *sock = NULL; struct http_cli *cli = NULL; @@ -271,6 +382,11 @@ static int test_http_loop_base(bool secure) char url[256]; char path[256]; int err = 0; + unsigned int i; + bool put = false; + + if (!strcmp(met, "PUT")) + put = true; memset(&t, 0, sizeof(t)); @@ -287,10 +403,11 @@ static int test_http_loop_base(bool secure) test_datapath()); err = https_listen(&sock, &srv, path, - http_req_handler, &t); + put ? http_put_req_handler : http_req_handler, &t); } else { - err = http_listen(&sock, &srv, http_req_handler, &t); + err = http_listen(&sock, &srv, + put ? http_put_req_handler : http_req_handler, &t); } if (err) goto out; @@ -307,6 +424,9 @@ static int test_http_loop_base(bool secure) if (err) goto out; + if (put) + http_client_set_bufsize_max(cli, REQ_BODY_CHUNK_SIZE + 128); + #ifdef USE_TLS if (secure) { err = http_client_add_ca(cli, path); @@ -318,27 +438,43 @@ static int test_http_loop_base(bool secure) (void)re_snprintf(url, sizeof(url), "http%s://127.0.0.1:%u/index.html", secure ? "s" : "", sa_port(&srv)); - err = http_request(&req, cli, "GET", url, - http_resp_handler, http_data_handler, &t, - NULL); - if (err) - goto out; - err = re_main_timeout(secure ? 1800 : 900); - if (err) - goto out; + if (put) + t.clen = REQ_BODY_SIZE; + + for (i = 1; i <= REQ_HTTP_REQUESTS; i++) { + t.i_req_body = 0; + err = http_request(&req, cli, met, url, + http_resp_handler, http_data_handler, + put ? http_req_body_handler : NULL, + &t, + put ? "Content-Length: %llu\r\n%s\r\n" : NULL, + t.clen, + t.clen > REQ_BODY_CHUNK_SIZE ? + "Expect: 100-continue\r\n" : ""); + if (err) + goto out; - if (t.err) { - err = t.err; - goto out; - } + err = re_main_timeout(secure ? 1800 : 900); + if (err) + goto out; + + if (t.err) { + err = t.err; + goto out; + } + + /* verify results after HTTP traffic */ + TEST_EQUALS(i, t.n_request); + TEST_EQUALS(i, t.n_response); - /* verify results after HTTP traffic */ - TEST_EQUALS(1, t.n_request); - TEST_EQUALS(1, t.n_response); + if (t.mb_body) + TEST_STRCMP("abcdefghijklmnopqrstuvwxyz", 26, + t.mb_body->buf, t.mb_body->end); - TEST_STRCMP("abcdefghijklmnopqrstuvwxyz", 26, - t.mb_body->buf, t.mb_body->end); + t.mb_body = mem_deref(t.mb_body); + req = mem_deref(req); + } out: mem_deref(t.mb_body); @@ -418,13 +554,27 @@ int test_http_client_set_tls(void) int test_http_loop(void) { - return test_http_loop_base(false); + return test_http_loop_base(false, "GET"); } #ifdef USE_TLS int test_https_loop(void) { - return test_http_loop_base(true); + return test_http_loop_base(true, "GET"); +} +#endif + + +int test_http_large_body(void) +{ + return test_http_loop_base(false, "PUT"); +} + + +#ifdef USE_TLS +int test_https_large_body(void) +{ + return test_http_loop_base(true, "PUT"); } #endif diff --git a/src/test.c b/src/test.c index ca1f1119..c383b340 100644 --- a/src/test.c +++ b/src/test.c @@ -101,9 +101,11 @@ static const struct test tests[] = { TEST(test_hmac_sha256), TEST(test_http), TEST(test_http_loop), + TEST(test_http_large_body), #ifdef USE_TLS TEST(test_https_loop), TEST(test_http_client_set_tls), + TEST(test_https_large_body), #endif TEST(test_httpauth_chall), TEST(test_httpauth_resp), diff --git a/src/test.h b/src/test.h index eecff565..8400142e 100644 --- a/src/test.h +++ b/src/test.h @@ -210,9 +210,11 @@ int test_hmac_sha1(void); int test_hmac_sha256(void); int test_http(void); int test_http_loop(void); +int test_http_large_body(void); #ifdef USE_TLS int test_https_loop(void); int test_http_client_set_tls(void); +int test_https_large_body(void); #endif int test_httpauth_chall(void); int test_httpauth_resp(void); From b24577a52b4a69aad1158179146790a36cfeb507 Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Wed, 31 Aug 2022 09:54:23 +0200 Subject: [PATCH 22/60] http: validate body of http requests for get method --- src/http.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/http.c b/src/http.c index 4b0ddb86..249e4cfc 100644 --- a/src/http.c +++ b/src/http.c @@ -167,7 +167,9 @@ static void http_req_handler(struct http_conn *conn, TEST_STRCMP("GET", 3, msg->met.p, msg->met.l); TEST_STRCMP("/index.html", 11, msg->path.p, msg->path.l); TEST_STRCMP("", 0, msg->prm.p, msg->prm.l); - TEST_EQUALS(0, msg->clen); + TEST_EQUALS(t->clen, msg->clen); + TEST_STRCMP("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52, + mbuf_buf(msg->mb), mbuf_get_left(msg->mb)); /* Create a chunked response body */ err = mbuf_write_str(mb_body, @@ -345,6 +347,25 @@ static int http_data_handler(const uint8_t *buf, size_t size, static size_t http_req_body_handler(struct mbuf *mb, void *arg) +{ + struct test *t = arg; + + if (t->i_req_body >= t->clen) + return 0; + + if (mbuf_write_mem(mb, + (const uint8_t*) "abcdefghijklmnopqrstuvwxyz", + strlen("abcdefghijklmnopqrstuvwxyz"))) { + mbuf_reset(mb); + return 0; + } + + t->i_req_body += strlen("abcdefghijklmnopqrstuvwxyz"); + return strlen("abcdefghijklmnopqrstuvwxyz"); +} + + +static size_t http_req_long_body_handler(struct mbuf *mb, void *arg) { struct test *t = arg; size_t l = 0; @@ -439,19 +460,22 @@ static int test_http_loop_base(bool secure, const char *met) "http%s://127.0.0.1:%u/index.html", secure ? "s" : "", sa_port(&srv)); - if (put) - t.clen = REQ_BODY_SIZE; - for (i = 1; i <= REQ_HTTP_REQUESTS; i++) { t.i_req_body = 0; + + t.clen = put ? REQ_BODY_SIZE : + 2 * strlen("abcdefghijklmnopqrstuvwxyz"); + err = http_request(&req, cli, met, url, - http_resp_handler, http_data_handler, - put ? http_req_body_handler : NULL, - &t, - put ? "Content-Length: %llu\r\n%s\r\n" : NULL, - t.clen, - t.clen > REQ_BODY_CHUNK_SIZE ? - "Expect: 100-continue\r\n" : ""); + http_resp_handler, http_data_handler, + put ? http_req_long_body_handler : + http_req_body_handler, + &t, + "Content-Length: %llu\r\n%s\r\n%s", + t.clen, + t.clen > REQ_BODY_CHUNK_SIZE ? + "Expect: 100-continue\r\n" : "", + "abcdefghijklmnopqrstuvwxyz"); if (err) goto out; From 65424e8897d03c302662563513adb9454dd3137b Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Wed, 31 Aug 2022 13:06:45 +0200 Subject: [PATCH 23/60] http: add test for http conn requests --- src/http.c | 89 +++++++++++++++++++++++++++++++++++++++++++++--------- src/test.c | 2 ++ src/test.h | 2 ++ 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/http.c b/src/http.c index 249e4cfc..597730e5 100644 --- a/src/http.c +++ b/src/http.c @@ -392,11 +392,12 @@ static size_t http_req_long_body_handler(struct mbuf *mb, void *arg) } -static int test_http_loop_base(bool secure, const char *met) +static int test_http_loop_base(bool secure, const char *met, bool http_conn) { struct http_sock *sock = NULL; struct http_cli *cli = NULL; struct http_req *req = NULL; + struct http_reqconn *conn = NULL; struct dnsc *dnsc = NULL; struct sa srv, dns; struct test t; @@ -405,6 +406,8 @@ static int test_http_loop_base(bool secure, const char *met) int err = 0; unsigned int i; bool put = false; + struct mbuf *mb_body = NULL; + struct pl pl; if (!strcmp(met, "PUT")) put = true; @@ -466,16 +469,58 @@ static int test_http_loop_base(bool secure, const char *met) t.clen = put ? REQ_BODY_SIZE : 2 * strlen("abcdefghijklmnopqrstuvwxyz"); - err = http_request(&req, cli, met, url, - http_resp_handler, http_data_handler, - put ? http_req_long_body_handler : - http_req_body_handler, - &t, - "Content-Length: %llu\r\n%s\r\n%s", - t.clen, - t.clen > REQ_BODY_CHUNK_SIZE ? - "Expect: 100-continue\r\n" : "", - "abcdefghijklmnopqrstuvwxyz"); + + if (http_conn) { + err = http_reqconn_alloc(&conn, cli, + http_resp_handler, http_data_handler, &t); + if (err) + goto out; + + if (put) { + err = http_reqconn_set_req_bodyh(conn, + put ? http_req_long_body_handler : + http_req_body_handler, + t.clen); + if (err) + goto out; + + pl_set_str(&pl, "PUT"); + err = http_reqconn_set_method(conn, &pl); + if (err) + goto out; + } + else { + mb_body = mbuf_alloc(t.clen); + if (!mb_body) + goto out; + + if (mbuf_write_str(mb_body, + "abcdefghijklmnopqrstuvwxyz"\ + "abcdefghijklmnopqrstuvwxyz")) + goto out; + + err = http_reqconn_set_body(conn, mb_body); + mb_body = mem_deref(mb_body); + if (err) + goto out; + } + + pl_set_str(&pl, url); + err = http_reqconn_send(conn, &pl); + } + else { + err = http_request(&req, cli, met, url, + http_resp_handler, http_data_handler, + put ? http_req_long_body_handler : + http_req_body_handler, + &t, + "Content-Length: %llu\r\n%s\r\n%s", + t.clen, + t.clen > REQ_BODY_CHUNK_SIZE ? + "Expect: 100-continue\r\n" : "", + "abcdefghijklmnopqrstuvwxyz"); + } + if (err) goto out; @@ -498,11 +543,13 @@ static int test_http_loop_base(bool secure, const char *met) t.mb_body = mem_deref(t.mb_body); req = mem_deref(req); + conn = mem_deref(conn); } out: mem_deref(t.mb_body); mem_deref(req); + mem_deref(conn); mem_deref(cli); mem_deref(dnsc); mem_deref(sock); @@ -578,27 +625,39 @@ int test_http_client_set_tls(void) int test_http_loop(void) { - return test_http_loop_base(false, "GET"); + return test_http_loop_base(false, "GET", false); } #ifdef USE_TLS int test_https_loop(void) { - return test_http_loop_base(true, "GET"); + return test_http_loop_base(true, "GET", false); } #endif int test_http_large_body(void) { - return test_http_loop_base(false, "PUT"); + return test_http_loop_base(false, "PUT", false); } #ifdef USE_TLS int test_https_large_body(void) { - return test_http_loop_base(true, "PUT"); + return test_http_loop_base(true, "PUT", false); } #endif + + +int test_http_conn(void) +{ + return test_http_loop_base(false, "GET", true); +} + + +int test_http_conn_large_body(void) +{ + return test_http_loop_base(false, "PUT", true); +} diff --git a/src/test.c b/src/test.c index c383b340..d08a4152 100644 --- a/src/test.c +++ b/src/test.c @@ -102,6 +102,8 @@ static const struct test tests[] = { TEST(test_http), TEST(test_http_loop), TEST(test_http_large_body), + TEST(test_http_conn), + TEST(test_http_conn_large_body), #ifdef USE_TLS TEST(test_https_loop), TEST(test_http_client_set_tls), diff --git a/src/test.h b/src/test.h index 8400142e..edb90f39 100644 --- a/src/test.h +++ b/src/test.h @@ -211,6 +211,8 @@ int test_hmac_sha256(void); int test_http(void); int test_http_loop(void); int test_http_large_body(void); +int test_http_conn(void); +int test_http_conn_large_body(void); #ifdef USE_TLS int test_https_loop(void); int test_http_client_set_tls(void); From 00188614a9027b5ebbe0d11532acd39f51cad60c Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Wed, 14 Sep 2022 09:54:02 +0200 Subject: [PATCH 24/60] dns: test dnsc_getaddrinfo_enabled --- src/dns.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dns.c b/src/dns.c index a5916dbe..6ebf87b0 100644 --- a/src/dns.c +++ b/src/dns.c @@ -387,8 +387,10 @@ int test_dns_integration(void) /* Test system getaddrinfo */ dnsc_getaddrinfo(data.dnsc, true); err = check_dns(&data, "localhost", IP_127_0_0_1, true); + TEST_EQUALS(dnsc_getaddrinfo_enabled(data.dnsc), true); TEST_ERR(err); dnsc_getaddrinfo(data.dnsc, false); + TEST_EQUALS(dnsc_getaddrinfo_enabled(data.dnsc), false); err = check_dns(&data, "test1.example.net", IP_127_0_0_1, true); TEST_ERR(err); From 3dda29917a150cb268135ccf6ad19b3f9c732475 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 9 Jul 2022 22:06:56 +0300 Subject: [PATCH 25/60] rtp: Update tests for the changed rtp_send signature. This updates RTP tests for compatibility with this PR: https://github.com/baresip/re/pull/418 --- src/rtp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rtp.c b/src/rtp.c index bcd73b8a..c5312b80 100644 --- a/src/rtp.c +++ b/src/rtp.c @@ -520,7 +520,8 @@ static int test_rtp_listen_priv(bool clear) mbuf_write_u8(test.mb, 0); test.mb->pos = pos; sa_set_str(&sa, "127.0.0.1", sa_port(rtp_local(test.rtp))); - err = rtp_send(test.rtp, &sa, false, true, 0, 160, test.mb); + err = rtp_send(test.rtp, &sa, false, true, 0, 160, + tmr_jiffies_rt_usec(), test.mb); TEST_ERR(err); pos = test.mb->end + RTP_HEADER_SIZE; @@ -528,7 +529,8 @@ static int test_rtp_listen_priv(bool clear) mbuf_write_str(test.mb, "bcde"); mbuf_write_u8(test.mb, 0); test.mb->pos = pos; - err = rtp_send(test.rtp, &sa, false, false, 0, 320, test.mb); + err = rtp_send(test.rtp, &sa, false, false, 0, 320, + tmr_jiffies_rt_usec(), test.mb); TEST_ERR(err); if (clear) { From 1dc96d5d771c45590cba782df2f73ac760ba5405 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 16 Sep 2022 14:06:27 +0200 Subject: [PATCH 26/60] crc32: add re wrapper --- src/crc32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crc32.c b/src/crc32.c index 27592fc8..755d227d 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -28,8 +28,8 @@ int test_crc32(void) for (i=0; i Date: Sun, 18 Sep 2022 09:41:45 +0200 Subject: [PATCH 27/60] sipreg: use TEST_ERR and remove static port test Tests should run without interfere with each other. Looks like on Github Actions runners share the same port range sometimes? So for tests we have to use dynamic ports. --- src/sipreg.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/sipreg.c b/src/sipreg.c index d599b4ea..d3c397cb 100644 --- a/src/sipreg.c +++ b/src/sipreg.c @@ -157,13 +157,12 @@ static int reg_test(enum sip_transp tp, bool deprecated, uint16_t srcport) if (err) goto out; - err = re_main_timeout(800); - if (err) - goto out; + err = re_main_timeout(1000); + TEST_ERR(err); if (test.err) { err = test.err; - goto out; + TEST_ERR(err); } TEST_ASSERT(srv->n_register_req > 0); @@ -197,7 +196,6 @@ int test_sipreg_tcp(void) err = reg_test(SIP_TRANSP_TCP, true, 0); err |= reg_test(SIP_TRANSP_TCP, false, 0); - err |= reg_test(SIP_TRANSP_TCP, false, 56060); return err; } @@ -209,7 +207,6 @@ int test_sipreg_tls(void) err = reg_test(SIP_TRANSP_TLS, true, 0); err |= reg_test(SIP_TRANSP_TLS, false, 0); - err |= reg_test(SIP_TRANSP_TLS, false, 56060); return err; } #endif From 3b807328b94a5f7a27469aaf99976499a6ff9ac9 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 22 Sep 2022 08:19:26 +0200 Subject: [PATCH 28/60] cmake: no need to link to libz --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 748c3950..d98f3177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,7 +166,7 @@ set(LINKLIBS ${REM_LIBRARIES} ${RE_LIBRARIES} ${OPENSSL_LIBRARIES}) if(WIN32) list(APPEND LINKLIBS qwave iphlpapi wsock32 ws2_32) else() - list(APPEND LINKLIBS -lz -lpthread -lm) + list(APPEND LINKLIBS -lpthread -lm) endif() add_executable(${PROJECT_NAME} ${SRCS}) From f64a1d084bf3d8d7d19e48b5510bfecebb8f14cc Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 23 Sep 2022 09:50:10 +0200 Subject: [PATCH 29/60] sa: init err --- src/sa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sa.c b/src/sa.c index 416e995a..5bae68e2 100644 --- a/src/sa.c +++ b/src/sa.c @@ -205,7 +205,7 @@ int test_sa_class(void) #endif }; uint32_t i; - int err; + int err = 0; for (i=0; i Date: Fri, 23 Sep 2022 13:55:15 +0200 Subject: [PATCH 30/60] cmake: add optional zlib linking --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d98f3177..86bc9a5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,10 @@ else() list(APPEND LINKLIBS -lpthread -lm) endif() +if(ZLIB_FOUND) + list(APPEND LINKLIBS ZLIB::ZLIB) +endif() + add_executable(${PROJECT_NAME} ${SRCS}) set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS 1) From afed483304b31c0aab2ce0a4cf2110d82655539c Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Fri, 23 Sep 2022 17:30:13 +0200 Subject: [PATCH 31/60] cmake/FindREM: add rem-static target name --- cmake/FindREM.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindREM.cmake b/cmake/FindREM.cmake index 3df2e620..45b99b2e 100644 --- a/cmake/FindREM.cmake +++ b/cmake/FindREM.cmake @@ -4,7 +4,7 @@ pkg_check_modules(PC_LIBREM QUIET librem) find_path(REM_INCLUDE_DIR rem.h HINTS ../rem/include ${PC_LIBREM_INCLUDEDIR} ${PC_LIBREM_INCLUDE_DIRS}) -find_library(REM_LIBRARY NAMES rem librem +find_library(REM_LIBRARY NAMES rem librem rem-static HINTS ../rem ../rem/build ../rem/build/Debug ${PC_LIBREM_LIBDIR} ${PC_LIBREM_LIBRARY_DIRS}) From dbb6b81312ab2c602aca982e577ea56b869f8e3f Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 25 Sep 2022 17:15:42 +0200 Subject: [PATCH 32/60] sys: remove old sys div test (#130) --- src/sys.c | 25 ------------------------- src/test.c | 1 - src/test.h | 1 - 3 files changed, 27 deletions(-) diff --git a/src/sys.c b/src/sys.c index fc9a0fee..0b9112b6 100644 --- a/src/sys.c +++ b/src/sys.c @@ -17,31 +17,6 @@ #include -int test_sys_div(void) -{ - static const struct { - uint64_t a, b, res; - } testv[] = { - {15, 5, 3}, - {0x100000000ULL, 0x10000UL, 0x10000}, - {846744073709551616ULL, 8474407795116ULL, 99917}, - {1446744073709551615ULL, 2, 723372036854775807ULL} - }; - uint32_t i; - int err = 0; - - for (i=0; i Date: Tue, 27 Sep 2022 08:25:31 +0200 Subject: [PATCH 33/60] aubuf: refactor aubuf_auframe test (#70) --- src/aubuf.c | 176 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 101 insertions(+), 75 deletions(-) diff --git a/src/aubuf.c b/src/aubuf.c index 90065590..096ed65f 100644 --- a/src/aubuf.c +++ b/src/aubuf.c @@ -15,17 +15,21 @@ #define AUDIO_TIMEBASE 1000000U +enum { + FRAMES = 80, +}; + static int test_aubuf_raw(void) { struct aubuf *ab = NULL; - int16_t sampv_in[160]; - int16_t sampv_out[160]; + int16_t sampv_in[2 * FRAMES]; + int16_t sampv_out[2 * FRAMES]; struct mbuf *mb; unsigned i; int err; - mb = mbuf_alloc(80 * sizeof(int16_t)); + mb = mbuf_alloc(FRAMES * sizeof(int16_t)); if (!mb) return ENOMEM; @@ -33,24 +37,24 @@ static int test_aubuf_raw(void) sampv_in[i] = i; memset(sampv_out, 0, sizeof(sampv_out)); - err = aubuf_alloc(&ab, 320, 0); + err = aubuf_alloc(&ab, 4 * FRAMES, 0); TEST_ERR(err); TEST_EQUALS(0, aubuf_cur_size(ab)); - err = aubuf_write(ab, (uint8_t *)sampv_in, 80 * sizeof(int16_t)); + err = aubuf_write(ab, (uint8_t *)sampv_in, FRAMES * sizeof(int16_t)); TEST_ERR(err); - TEST_EQUALS(160, aubuf_cur_size(ab)); + TEST_EQUALS(2 * FRAMES, aubuf_cur_size(ab)); - (void)mbuf_write_mem(mb, (uint8_t *)&sampv_in[80], - 80 * sizeof(int16_t)); + (void)mbuf_write_mem(mb, (uint8_t *)&sampv_in[FRAMES], + FRAMES * sizeof(int16_t)); mb->pos = 0; err = aubuf_append(ab, mb); TEST_ERR(err); - TEST_EQUALS(320, aubuf_cur_size(ab)); + TEST_EQUALS(4 * FRAMES, aubuf_cur_size(ab)); memset(sampv_out, 0, sizeof(sampv_out)); - aubuf_read(ab, (uint8_t *)sampv_out, 160 * sizeof(int16_t)); + aubuf_read(ab, (uint8_t *)sampv_out, 2 * FRAMES * sizeof(int16_t)); TEST_MEMCMP(sampv_in, sizeof(sampv_in), sampv_out, sizeof(sampv_out)); TEST_EQUALS(0, aubuf_cur_size(ab)); @@ -64,8 +68,8 @@ static int test_aubuf_raw(void) static int test_aubuf_samp(void) { struct aubuf *ab = NULL; - int16_t sampv_in[160]; - int16_t sampv_out[160]; + int16_t sampv_in[2 * FRAMES]; + int16_t sampv_out[2 * FRAMES]; unsigned i; int err; @@ -73,16 +77,16 @@ static int test_aubuf_samp(void) sampv_in[i] = i; memset(sampv_out, 0, sizeof(sampv_out)); - err = aubuf_alloc(&ab, 320, 0); + err = aubuf_alloc(&ab, 4 * FRAMES, 0); TEST_ERR(err); TEST_EQUALS(0, aubuf_cur_size(ab)); - err |= aubuf_write_samp(ab, sampv_in, 80); - err |= aubuf_write_samp(ab, &sampv_in[80], 80); + err |= aubuf_write_samp(ab, sampv_in, FRAMES); + err |= aubuf_write_samp(ab, &sampv_in[FRAMES], FRAMES); TEST_ERR(err); - TEST_EQUALS(320, aubuf_cur_size(ab)); + TEST_EQUALS(4 * FRAMES, aubuf_cur_size(ab)); aubuf_read_samp(ab, sampv_out, ARRAY_SIZE(sampv_out)); TEST_MEMCMP(sampv_in, sizeof(sampv_in), sampv_out, sizeof(sampv_out)); @@ -97,74 +101,96 @@ static int test_aubuf_samp(void) static int test_aubuf_auframe(void) { struct aubuf *ab = NULL; - float sampv_in[160]; - float sampv_out[160]; + float sampv_in[3 * FRAMES + (FRAMES / 2)]; + float sampv_out[3 * FRAMES + (FRAMES / 2)]; uint64_t dt; struct auframe af_in; struct auframe af_out; - unsigned i; int err; - for (i=0; i Date: Thu, 29 Sep 2022 22:07:09 +0200 Subject: [PATCH 34/60] rtcp: use udp_send() (#132) * rtcp: use udp_send() * rtcp: add workaround for OOM test --- src/rtcp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rtcp.c b/src/rtcp.c index 38ee8381..bd7cc559 100644 --- a/src/rtcp.c +++ b/src/rtcp.c @@ -32,7 +32,8 @@ struct fixture { }; -static int send_rtp_packet(const struct sa *dst, uint16_t seq, uint32_t ssrc) +static int send_rtp_packet(struct udp_sock *us, const struct sa *dst, + uint16_t seq, uint32_t ssrc) { struct rtp_header hdr; struct mbuf *mb = mbuf_alloc(256); @@ -53,7 +54,7 @@ static int send_rtp_packet(const struct sa *dst, uint16_t seq, uint32_t ssrc) mbuf_fill(mb, 160, 0x00); mb->pos = 0; - err = udp_send_anon(dst, mb); + err = udp_send(us, dst, mb); if (err) goto out; @@ -132,7 +133,8 @@ static int test_loss(const uint16_t *seqv, size_t seqc, for (i=0; irtp_addr, seq, ssrc); + err = send_rtp_packet(rtp_sock(f->rtp), &f->rtp_addr, + seq, ssrc); if (err) goto out; } @@ -141,7 +143,11 @@ static int test_loss(const uint16_t *seqv, size_t seqc, TEST_ERR(err); err = rtcp_stats(f->rtp, ssrc, &stats); - TEST_ERR(err); + if (err) { + if (err == ENOENT) + err = ENOMEM; + goto out; + } /* in OOM-test, detect if member/sender was not allocated */ if (stats.rx.sent == 0 && From 51b438b92bc3b62dbd43ac38d26a208c07ccc704 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Tue, 4 Oct 2022 14:00:48 +0200 Subject: [PATCH 35/60] leb128: remove debug --- src/av1.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/av1.c b/src/av1.c index d9e4c7e9..dd613642 100644 --- a/src/av1.c +++ b/src/av1.c @@ -49,8 +49,6 @@ static int test_leb128(void) if (err) goto out; - re_printf("leb128 value: [ %w ]\n", mb->buf, mb->end); - mb->pos = 0; err = av1_leb128_decode(mb, &val_dec); From 0b53f39b25c66efc2c75b37f53d2c6dac64af6d5 Mon Sep 17 00:00:00 2001 From: Franz <48635806+fAuernigg@users.noreply.github.com> Date: Tue, 4 Oct 2022 20:55:31 +0200 Subject: [PATCH 36/60] http: fix http content length format (#136) --- src/http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http.c b/src/http.c index 597730e5..45d14b0e 100644 --- a/src/http.c +++ b/src/http.c @@ -514,7 +514,7 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn) put ? http_req_long_body_handler : http_req_body_handler, &t, - "Content-Length: %llu\r\n%s\r\n%s", + "Content-Length: %zu\r\n%s\r\n%s", t.clen, t.clen > REQ_BODY_CHUNK_SIZE ? "Expect: 100-continue\r\n" : "", From 5e20771487e9d2871d5c30cf527cd7d0966bb2a9 Mon Sep 17 00:00:00 2001 From: Franz <48635806+fAuernigg@users.noreply.github.com> Date: Wed, 5 Oct 2022 08:36:49 +0200 Subject: [PATCH 37/60] Support run specific integration test and add http with local dnssrv (#135) * support run specific integration test * http: add integration test for http using local dns server --- src/http.c | 46 ++++++++++++++++++++++++++++++++++------------ src/test.c | 36 ++++++++++++++++++++++++++++++++++++ src/test.h | 1 + 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/src/http.c b/src/http.c index 45d14b0e..c7e65d1d 100644 --- a/src/http.c +++ b/src/http.c @@ -18,6 +18,9 @@ enum large_body_test { REQ_HTTP_REQUESTS = 2 }; +enum { + IP_127_0_0_1 = 0x7f000001, +}; static int test_http_response_no_reasonphrase(void) { @@ -392,13 +395,15 @@ static size_t http_req_long_body_handler(struct mbuf *mb, void *arg) } -static int test_http_loop_base(bool secure, const char *met, bool http_conn) +static int test_http_loop_base(bool secure, const char *met, bool http_conn, + bool dns_srv_query) { struct http_sock *sock = NULL; struct http_cli *cli = NULL; struct http_req *req = NULL; struct http_reqconn *conn = NULL; struct dnsc *dnsc = NULL; + struct dns_server *dns_srv = NULL; struct sa srv, dns; struct test t; char url[256]; @@ -416,10 +421,18 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn) t.secure = secure; + if (dns_srv_query) { + /* Setup Mocking DNS Server */ + err = dns_server_alloc(&dns_srv, false); + TEST_ERR(err); + + err = dns_server_add_a(dns_srv, "test1.example.net", + IP_127_0_0_1, 1); + TEST_ERR(err); + } + err |= sa_set_str(&srv, "127.0.0.1", 0); err |= sa_set_str(&dns, "127.0.0.1", 53); /* note: unused */ - if (err) - goto out; if (secure) { @@ -440,7 +453,7 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn) if (err) goto out; - err = dnsc_alloc(&dnsc, NULL, &dns, 1); + err = dnsc_alloc(&dnsc, NULL, dns_srv ? &dns_srv->addr : &dns, 1); if (err) goto out; @@ -460,8 +473,10 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn) #endif (void)re_snprintf(url, sizeof(url), - "http%s://127.0.0.1:%u/index.html", - secure ? "s" : "", sa_port(&srv)); + "http%s://%s:%u/index.html", + secure ? "s" : "", + dns_srv_query ? "test1.example.net" : "127.0.0.1", + sa_port(&srv)); for (i = 1; i <= REQ_HTTP_REQUESTS; i++) { t.i_req_body = 0; @@ -553,6 +568,7 @@ static int test_http_loop_base(bool secure, const char *met, bool http_conn) mem_deref(cli); mem_deref(dnsc); mem_deref(sock); + mem_deref(dns_srv); return err; } @@ -625,39 +641,45 @@ int test_http_client_set_tls(void) int test_http_loop(void) { - return test_http_loop_base(false, "GET", false); + return test_http_loop_base(false, "GET", false, false); } #ifdef USE_TLS int test_https_loop(void) { - return test_http_loop_base(true, "GET", false); + return test_http_loop_base(true, "GET", false, false); } #endif int test_http_large_body(void) { - return test_http_loop_base(false, "PUT", false); + return test_http_loop_base(false, "PUT", false, false); } #ifdef USE_TLS int test_https_large_body(void) { - return test_http_loop_base(true, "PUT", false); + return test_http_loop_base(true, "PUT", false, false); } #endif int test_http_conn(void) { - return test_http_loop_base(false, "GET", true); + return test_http_loop_base(false, "GET", true, false); } int test_http_conn_large_body(void) { - return test_http_loop_base(false, "PUT", true); + return test_http_loop_base(false, "PUT", true, false); +} + + +int test_dns_http_integration(void) +{ + return test_http_loop_base(false, "GET", true, true); } diff --git a/src/test.c b/src/test.c index c801075c..17225e1c 100644 --- a/src/test.c +++ b/src/test.c @@ -244,6 +244,7 @@ static const struct test tests_integration[] = { TEST(test_tmr_jiffies), TEST(test_tmr_jiffies_usec), TEST(test_dns_integration), + TEST(test_dns_http_integration), }; @@ -331,6 +332,18 @@ static const struct test *find_test(const char *name) } +static const struct test *find_test_int(const char *name) +{ + for (size_t i=0; iname) + return EINVAL; + + (void)re_fprintf(stderr, " %-24s: ", test->name); + + if (test->exec) + err = test->exec(); + + if (err) + DEBUG_WARNING(" %-24s: NOK: %m\n", test->name, err); + else + (void)re_fprintf(stderr, "\x1b[32mOK\x1b[;m\n"); + + return err; + } + for (i=0; i Date: Wed, 5 Oct 2022 08:39:41 +0200 Subject: [PATCH 38/60] odict: check return value of compare() --- src/odict.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/odict.c b/src/odict.c index 6e1a708f..5146e113 100644 --- a/src/odict.c +++ b/src/odict.c @@ -151,7 +151,9 @@ int test_odict(void) /* verify that entry exist after adding */ entry = odict_lookup(dict, test->key); TEST_ASSERT(entry != NULL); - compare(test, entry); + + err = compare(test, entry); + TEST_ERR(err); } /* verify size of dictionary, after adding all entries */ From 06434e35d6eac9cb04768dda78dd89ccac0ae0a9 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 5 Oct 2022 09:54:07 +0200 Subject: [PATCH 39/60] odict: use correct union field (boolean) (#137) Fixes a bug on Alpine/S390x which is 64-bit Big Endian architecture --- src/odict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/odict.c b/src/odict.c index 5146e113..4b68f853 100644 --- a/src/odict.c +++ b/src/odict.c @@ -43,7 +43,7 @@ static int compare(const struct dtest *test, const struct odict_entry *entry) break; case ODICT_BOOL: - TEST_EQUALS(test->u.i, odict_entry_boolean(entry)); + TEST_EQUALS(test->u.b, odict_entry_boolean(entry)); break; case ODICT_DOUBLE: From 62b420df42c6c34a6a44dfd3d13ef39a1372ae44 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 5 Oct 2022 10:21:59 +0200 Subject: [PATCH 40/60] test: use fs_stdio_restore() (#138) --- src/test.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/test.c b/src/test.c index 17225e1c..dfd132f8 100644 --- a/src/test.c +++ b/src/test.c @@ -276,13 +276,7 @@ static void restore_output(int err) fflush(stderr); /* Restore stdout/stderr */ -#ifdef WIN32 - freopen("CON", "w", stdout); - freopen("CON", "w", stderr); -#else - freopen("/dev/tty", "w", stdout); - freopen("/dev/tty", "w", stderr); -#endif + fs_stdio_restore(); if (!err) goto out; From 16dc2407c253cbf824aa476d47f9104702182702 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 5 Oct 2022 11:23:46 +0200 Subject: [PATCH 41/60] oom: align testcase names --- src/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test.c b/src/test.c index dfd132f8..5c43510d 100644 --- a/src/test.c +++ b/src/test.c @@ -362,7 +362,7 @@ static int testcase_oom(const struct test *test, int levels, bool verbose) int err = 0; if (verbose) - (void)re_fprintf(stderr, " %-24s: ", test->name); + (void)re_fprintf(stderr, " %-26s: ", test->name); /* All memory levels */ for (i=0; i Date: Wed, 5 Oct 2022 11:28:26 +0200 Subject: [PATCH 42/60] align testcase names --- src/test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test.c b/src/test.c index 5c43510d..b7c62291 100644 --- a/src/test.c +++ b/src/test.c @@ -688,7 +688,7 @@ int test_perf(const char *name, bool verbose) if (!tim->test) continue; - re_fprintf(stderr, "%-32s: %10.2f usec\n", + re_fprintf(stderr, "%-34s: %10.2f usec\n", tim->test->name, usec_avg); } re_fprintf(stderr, "\n"); @@ -1070,7 +1070,7 @@ int test_integration(const char *name, bool verbose) if (str_isset(name) && test->name) continue; - (void)re_fprintf(stderr, " %-24s: ", test->name); + (void)re_fprintf(stderr, " %-28s: ", test->name); if (test->exec) err = test->exec(); From af2c1a7a43692e877598b27692d3572f81cd3fa7 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 5 Oct 2022 12:27:41 +0200 Subject: [PATCH 43/60] tmr: increase upper bound --- src/tmr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tmr.c b/src/tmr.c index adc04dfa..06cc66b8 100644 --- a/src/tmr.c +++ b/src/tmr.c @@ -43,7 +43,7 @@ int test_tmr_jiffies_usec(void) diff = tmr_jiffies_usec() - tmr_start; TEST_ASSERT(diff >= 1); - TEST_ASSERT(diff < 100); + TEST_ASSERT(diff < 1000); out: return err; From d3867f40bc6e93128a7a80d983ffe2985bd39421 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 5 Oct 2022 14:06:44 +0200 Subject: [PATCH 44/60] remove leb128 printf --- src/av1.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/av1.c b/src/av1.c index dd613642..6f3c3605 100644 --- a/src/av1.c +++ b/src/av1.c @@ -54,9 +54,6 @@ static int test_leb128(void) err = av1_leb128_decode(mb, &val_dec); ASSERT_EQ(0, err); - printf("decoded: %" PRIu64 " / %" PRIx64 "\n", - val_dec, val_dec); - ASSERT_EQ(val, val_dec); mb = mem_deref(mb); From aa787a12b379e0546fa5b5934fbdcf025969567c Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Wed, 5 Oct 2022 14:50:12 +0200 Subject: [PATCH 45/60] sys: add todo --- src/sys.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sys.c b/src/sys.c index 0b9112b6..9bb1d583 100644 --- a/src/sys.c +++ b/src/sys.c @@ -174,6 +174,9 @@ int test_sys_fs_fopen(void) FILE *file; int err; + /* TODO: add a unique filename to avoid clash when running + * multiple instances of test + */ err = fs_fopen(&file, "retest_fs_fopen", "w+"); TEST_ERR(err); TEST_EQUALS(true, fs_isfile("retest_fs_fopen")); From 01d95455e40d6b36250913302a5eaa2fd3e2dcc6 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 6 Oct 2022 10:10:10 +0200 Subject: [PATCH 46/60] net: add ipv6_supported() --- src/net.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/net.c b/src/net.c index b43b2b01..e2ec28ec 100644 --- a/src/net.c +++ b/src/net.c @@ -10,6 +10,30 @@ #include +static bool ipv6_handler(const char *ifname, const struct sa *sa, void *arg) +{ + bool *supp = arg; + (void)ifname; + + if (AF_INET6 == sa_af(sa)) { + *supp = true; + return true; + } + + return false; +} + + +static bool ipv6_supported(void) +{ + bool supp = false; + + net_if_apply(ipv6_handler, &supp); + + return supp; +} + + int test_net_dst_source_addr_get(void) { struct sa dst; @@ -27,15 +51,23 @@ int test_net_dst_source_addr_get(void) TEST_ASSERT(sa_is_loopback(&ip)); - sa_init(&dst, AF_INET6); - sa_init(&ip, AF_UNSPEC); - sa_set_str(&dst, "::1", 53); + if (ipv6_supported()) { - err = net_dst_source_addr_get(&dst, &ip); - if (err) - return err; + DEBUG_NOTICE("ipv6 enabled\n"); - TEST_ASSERT(sa_is_loopback(&ip)); + sa_init(&dst, AF_INET6); + sa_init(&ip, AF_UNSPEC); + sa_set_str(&dst, "::1", 53); + + err = net_dst_source_addr_get(&dst, &ip); + if (err) + return err; + + TEST_ASSERT(sa_is_loopback(&ip)); + } + else { + DEBUG_NOTICE("ipv6 disabled\n"); + } out: return err; From f8017ea865b2a1690e7deea4e36e7f339e0014e7 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 6 Oct 2022 15:52:08 +0200 Subject: [PATCH 47/60] sys: unique filename in test_sys_fs_fopen (#142) --- src/sys.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/sys.c b/src/sys.c index 9bb1d583..ab1bafa6 100644 --- a/src/sys.c +++ b/src/sys.c @@ -171,30 +171,34 @@ int test_sys_fs_isfile(void) int test_sys_fs_fopen(void) { + char filename[256]; FILE *file; int err; - /* TODO: add a unique filename to avoid clash when running - * multiple instances of test + /* Use a unique filename to avoid clash when running + * multiple instances of test */ - err = fs_fopen(&file, "retest_fs_fopen", "w+"); + re_snprintf(filename, sizeof(filename), + "retest_fs_fopen-%llu", rand_u64()); + + err = fs_fopen(&file, filename, "w+"); TEST_ERR(err); - TEST_EQUALS(true, fs_isfile("retest_fs_fopen")); + TEST_EQUALS(true, fs_isfile(filename)); err = fclose(file); TEST_ERR(err); /* Try reopen */ - err = fs_fopen(&file, "retest_fs_fopen", "w+"); + err = fs_fopen(&file, filename, "w+"); TEST_ERR(err); err = fclose(file); TEST_ERR(err); #ifdef WIN32 - (void)_unlink("retest_fs_fopen"); + (void)_unlink(filename); #else - (void)unlink("retest_fs_fopen"); + (void)unlink(filename); #endif out: From 082640eb71058c05822c730975de40f017f3cae2 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 7 Oct 2022 10:14:49 +0200 Subject: [PATCH 48/60] net: remove logging --- src/net.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/net.c b/src/net.c index e2ec28ec..6ece560f 100644 --- a/src/net.c +++ b/src/net.c @@ -53,8 +53,6 @@ int test_net_dst_source_addr_get(void) if (ipv6_supported()) { - DEBUG_NOTICE("ipv6 enabled\n"); - sa_init(&dst, AF_INET6); sa_init(&ip, AF_UNSPEC); sa_set_str(&dst, "::1", 53); From 25f06cca1dce9621cb12c95ac6d31c896c85f911 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 7 Oct 2022 10:18:40 +0200 Subject: [PATCH 49/60] Enable valgrind for Linux build (#140) --- .github/workflows/build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db109c91..8b019e56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,11 @@ jobs: steps: - uses: actions/checkout@v2 + - name: install packages linux + if: ${{ runner.os == 'Linux' }} + run: | + sudo apt-get update -q -y && sudo apt-get install -q -y libssl-dev valgrind + - name: openssl path macos if: ${{ runner.os == 'macOS' }} run: | @@ -70,7 +75,7 @@ jobs: if: ${{ runner.os == 'Linux' }} run: | cmake -DCMAKE_C_FLAGS="-Werror" . && make - ./retest -r + valgrind --leak-check=full --show-reachable=yes --error-exitcode=42 ./retest -v -r - name: retest if: ${{ runner.os == 'macOS' }} From 985b200a3b0f79b43fb1878acb726a014fa300df Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 7 Oct 2022 10:40:59 +0200 Subject: [PATCH 50/60] integration: make IPv6 tests optional --- src/sip.c | 12 +++++++----- src/sipevent.c | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/sip.c b/src/sip.c index 885c8751..55a6092f 100644 --- a/src/sip.c +++ b/src/sip.c @@ -760,14 +760,16 @@ int test_sip_drequestf(void) int test_sip_drequestf_network(void) { - int err; struct sa laddr; + int err = 0; - err = net_if_getlinklocal(NULL, AF_INET6, &laddr); - TEST_ERR(err); + sa_init(&laddr, AF_INET6); - err = do_sip_drequestf(&laddr); - TEST_ERR(err); + if (0 == net_if_getlinklocal(NULL, AF_INET6, &laddr)) { + + err = do_sip_drequestf(&laddr); + TEST_ERR(err); + } out: return err; diff --git a/src/sipevent.c b/src/sipevent.c index 3b774a17..2ee2d1fa 100644 --- a/src/sipevent.c +++ b/src/sipevent.c @@ -425,13 +425,15 @@ int test_sipevent(void) int test_sipevent_network(void) { - int err; struct sa laddr; + int err = 0; - err = net_if_getlinklocal(NULL, AF_INET6, &laddr); - TEST_ERR(err); + sa_init(&laddr, AF_INET6); + + if (0 == net_if_getlinklocal(NULL, AF_INET6, &laddr)) { + + err = do_sipevent(&laddr); + } - err = do_sipevent(&laddr); -out: return err; } From d8674bc86488b0785f6f87b69256e250125ccd67 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 7 Oct 2022 11:00:59 +0200 Subject: [PATCH 51/60] bfcp: check for handler errors after re_main --- src/bfcp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bfcp.c b/src/bfcp.c index ea3b17e9..90103df9 100644 --- a/src/bfcp.c +++ b/src/bfcp.c @@ -441,6 +441,18 @@ int test_bfcp_tcp(void) err = re_main_timeout(100); TEST_ERR(err); + if (cli->handler_err) { + DEBUG_WARNING("client error: %m\n", cli->handler_err); + err = cli->handler_err; + goto out; + } + + if (srv->handler_err) { + DEBUG_WARNING("server error: %m\n", srv->handler_err); + err = srv->handler_err; + goto out; + } + TEST_EQUALS((estab_handler_called | resp_handler_called), cli->flags); TEST_EQUALS((conn_handler_called | estab_handler_called | recv_handler_called), srv->flags); From 4c58d7464916fc2cd93dfa708c89d75a351d528b Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Fri, 7 Oct 2022 14:23:21 +0200 Subject: [PATCH 52/60] fmt: add test_fmt_str_itoa (#143) --- src/fmt.c | 32 ++++++++++++++++++++++++++++++++ src/test.c | 1 + src/test.h | 1 + 3 files changed, 34 insertions(+) diff --git a/src/fmt.c b/src/fmt.c index e1ddc076..045d20fd 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -1056,3 +1056,35 @@ int test_fmt_str_bool(void) return err; } + + +int test_fmt_str_itoa(void) +{ + char buf[ITOA_BUFSZ]; + char *s; + int err = 0; + + s = str_itoa(0, buf, 10); + TEST_ASSERT(!str_casecmp(s, "0")); + + s = str_itoa(42, buf, 10); + TEST_ASSERT(!str_casecmp(s, "42")); + + s = str_itoa(UINT32_MAX, buf, 10); + TEST_ASSERT(!str_casecmp(s, "4294967295")); + + s = str_itoa(UINT32_MAX, buf, 16); + TEST_ASSERT(!str_casecmp(s, "FFFFFFFF")); + + s = str_itoa(23, buf, 2); + TEST_ASSERT(!str_casecmp(s, "10111")); + + s = str_itoa(UINT32_MAX, buf, 2); + TEST_ASSERT(!str_casecmp(s, "11111111111111111111111111111111")); + +out: + if (err) + DEBUG_WARNING("err itoa string: %s\n", s); + + return err; +} diff --git a/src/test.c b/src/test.c index b7c62291..d3dca49c 100644 --- a/src/test.c +++ b/src/test.c @@ -87,6 +87,7 @@ static const struct test tests[] = { TEST(test_fmt_str), TEST(test_fmt_str_bool), TEST(test_fmt_str_error), + TEST(test_fmt_str_itoa), TEST(test_fmt_unicode), TEST(test_fmt_unicode_decode), TEST(test_g711_alaw), diff --git a/src/test.h b/src/test.h index a6fd1e36..18866c44 100644 --- a/src/test.h +++ b/src/test.h @@ -196,6 +196,7 @@ int test_fmt_snprintf(void); int test_fmt_str(void); int test_fmt_str_bool(void); int test_fmt_str_error(void); +int test_fmt_str_itoa(void); int test_fmt_unicode(void); int test_fmt_unicode_decode(void); int test_g711_alaw(void); From 49f1adfab7d7ef844def42a84374db27444ac57e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 8 Oct 2022 12:03:37 +0200 Subject: [PATCH 53/60] git: ignore cmake generated files --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 064a29d3..01581350 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,8 @@ tags # Vim swp files *.swp + +# cmake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake From 2398b44c82a4346e3d46f44949aca7a52c55e48f Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 8 Oct 2022 13:31:22 +0200 Subject: [PATCH 54/60] workflows: add run-on-arch action (#134) --- .github/workflows/run-on-arch.yml | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .github/workflows/run-on-arch.yml diff --git a/.github/workflows/run-on-arch.yml b/.github/workflows/run-on-arch.yml new file mode 100644 index 00000000..cf960f9e --- /dev/null +++ b/.github/workflows/run-on-arch.yml @@ -0,0 +1,91 @@ +on: [push, pull_request] + +jobs: + build_job: + # The host should always be linux + runs-on: ubuntu-18.04 + name: Build on ${{ matrix.distro }} ${{ matrix.arch }} + + # Run steps on a matrix of 3 arch/distro combinations + strategy: + matrix: + include: + - arch: armv7 + distro: alpine_latest + - arch: aarch64 + distro: bullseye + - arch: s390x + distro: fedora_latest + + steps: + - uses: actions/checkout@v2.1.0 + + - uses: sreimers/pr-dependency-action@v0.5 + with: + name: re + repo: https://github.com/baresip/re + secret: ${{ secrets.GITHUB_TOKEN }} + + - uses: sreimers/pr-dependency-action@v0.5 + with: + name: rem + repo: https://github.com/baresip/rem + secret: ${{ secrets.GITHUB_TOKEN }} + + - uses: uraimo/run-on-arch-action@v2 + name: Build artifact + id: build + with: + arch: ${{ matrix.arch }} + distro: ${{ matrix.distro }} + + # Not required, but speeds up builds + githubToken: ${{ github.token }} + + # Create an artifacts directory + setup: | + mkdir -p "${PWD}/artifacts" + + # The shell to run commands with in the container + shell: /bin/sh + + # Install some dependencies in the container. This speeds up builds if + # you are also using githubToken. Any dependencies installed here will + # be part of the container image that gets cached, so subsequent + # builds don't have to re-install them. The image layer is cached + # publicly in your project's package repository, so it is vital that + # no secrets are present in the container state or logs. + install: | + case "${{ matrix.distro }}" in + ubuntu*|jessie|stretch|buster|bullseye) + apt-get update -q -y + apt-get install -q -y cmake gcc git make libssl-dev + ;; + fedora*) + dnf -y update + dnf -y install cmake gcc git make openssl-devel + ;; + alpine*) + apk update + apk add cmake gcc git linux-headers make musl-dev openssl-dev + ;; + esac + + # Produce a binary artifact and place it in the mounted volume + run: | + for p in re rem; do + cmake -S $p -B $p/build -DCMAKE_C_FLAGS="-Werror" + cmake --build $p/build -j + done + for p in re rem; do + mv $p ../. + done + cmake -B build -DCMAKE_C_FLAGS="-Werror" + cmake --build build -j + ./build/retest -v -r + + - name: Show the artifact + # Items placed in /artifacts in the container will be in + # ${PWD}/artifacts on the host. + run: | + ls -al "${PWD}/artifacts" From 751eda4c6e6f22f609e7f651ca62a5bb3ccffca5 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 9 Oct 2022 11:38:26 +0200 Subject: [PATCH 55/60] test_multithread: increase timeout to 15 seconds --- src/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test.c b/src/test.c index d3dca49c..d54b150f 100644 --- a/src/test.c +++ b/src/test.c @@ -772,7 +772,7 @@ int test_multithread(void) test_mode = TEST_THREAD; - timeout_override = 10000; + timeout_override = 15000; memset(threadv, 0, sizeof(threadv)); From 6b331e76f7555e1befc0d1cb54aef54578c8160e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 9 Oct 2022 14:54:11 +0200 Subject: [PATCH 56/60] tls: remove some warnings (#144) --- src/tls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tls.c b/src/tls.c index 2ece7c6e..58239064 100644 --- a/src/tls.c +++ b/src/tls.c @@ -524,8 +524,8 @@ int test_tls_cli_conn_change_cert(void) (void)re_snprintf(clientcert, sizeof(clientcert), "%s/not_a_file.pem", test_datapath()); - err = tls_conn_change_cert(tt.sc_cli, clientcert); - TEST_EQUALS(EINVAL, err); + int ret = tls_conn_change_cert(tt.sc_cli, clientcert); + ASSERT_TRUE(ret==EINVAL || ret==ENOENT); memset(clientcert, 0, sizeof(clientcert)); (void)re_snprintf(clientcert, sizeof(clientcert), From 57691b276b534be3fc072b98bd5e527331cb0a5a Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 9 Oct 2022 15:15:45 +0200 Subject: [PATCH 57/60] ci/run-on-arch: add prepare (needed for dependency) (#145) --- .github/workflows/run-on-arch.yml | 39 +++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/run-on-arch.yml b/.github/workflows/run-on-arch.yml index cf960f9e..aebe4a67 100644 --- a/.github/workflows/run-on-arch.yml +++ b/.github/workflows/run-on-arch.yml @@ -1,10 +1,36 @@ on: [push, pull_request] jobs: + prepare: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: sreimers/pr-dependency-action@v0.5 + with: + name: re + repo: https://github.com/baresip/re + secret: ${{ secrets.GITHUB_TOKEN }} + + - uses: sreimers/pr-dependency-action@v0.5 + with: + name: rem + repo: https://github.com/baresip/rem + secret: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/upload-artifact@v3 + with: + name: prepare + path: | + re + rem + build_job: # The host should always be linux runs-on: ubuntu-18.04 name: Build on ${{ matrix.distro }} ${{ matrix.arch }} + needs: prepare # Run steps on a matrix of 3 arch/distro combinations strategy: @@ -20,17 +46,10 @@ jobs: steps: - uses: actions/checkout@v2.1.0 - - uses: sreimers/pr-dependency-action@v0.5 - with: - name: re - repo: https://github.com/baresip/re - secret: ${{ secrets.GITHUB_TOKEN }} - - - uses: sreimers/pr-dependency-action@v0.5 + - name: Download re/rem + uses: actions/download-artifact@v3 with: - name: rem - repo: https://github.com/baresip/rem - secret: ${{ secrets.GITHUB_TOKEN }} + name: prepare - uses: uraimo/run-on-arch-action@v2 name: Build artifact From bc85c16b12308d109bff9bfa0801a06d6da9d8bd Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 15 Oct 2022 22:59:24 +0200 Subject: [PATCH 58/60] ci: use actions/checkout@v3 (#148) --- .github/workflows/all.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/ccheck.yml | 2 +- .github/workflows/fedora.yml | 4 ++-- .github/workflows/run-on-arch.yml | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 9e379306..e0683f50 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -22,7 +22,7 @@ jobs: # os: [ubuntu-latest, macos-latest] # @todo: macOS need fixes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: sreimers/pr-dependency-action@v0.5 with: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b019e56..b223eb4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: CC: ${{ matrix.compiler }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: install packages linux if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/ccheck.yml b/.github/workflows/ccheck.yml index 050fdc0c..17836868 100644 --- a/.github/workflows/ccheck.yml +++ b/.github/workflows/ccheck.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: ccheck run: | wget "https://raw.githubusercontent.com/baresip/baresip/main/test/ccheck.py" diff --git a/.github/workflows/fedora.yml b/.github/workflows/fedora.yml index 48684d93..a39050fb 100644 --- a/.github/workflows/fedora.yml +++ b/.github/workflows/fedora.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: sreimers/pr-dependency-action@v0.5 with: @@ -50,7 +50,7 @@ jobs: CC: ${{ matrix.compiler }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: install devel tools run: | yum -y install git gcc clang cmake openssl-devel pkgconfig zlib-devel net-tools diff --git a/.github/workflows/run-on-arch.yml b/.github/workflows/run-on-arch.yml index aebe4a67..4b068a80 100644 --- a/.github/workflows/run-on-arch.yml +++ b/.github/workflows/run-on-arch.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: sreimers/pr-dependency-action@v0.5 with: @@ -44,7 +44,7 @@ jobs: distro: fedora_latest steps: - - uses: actions/checkout@v2.1.0 + - uses: actions/checkout@v3 - name: Download re/rem uses: actions/download-artifact@v3 From 4e9dd394f81be3d1466a31410457e6c9077de3c2 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 29 Oct 2022 07:52:36 +0200 Subject: [PATCH 59/60] list: add test_list_flush (#151) --- src/list.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/test.c | 1 + src/test.h | 1 + 3 files changed, 49 insertions(+) diff --git a/src/list.c b/src/list.c index 1b1eb086..6b6d19a4 100644 --- a/src/list.c +++ b/src/list.c @@ -4,6 +4,7 @@ * Copyright (C) 2010 Creytiv.com */ #include +#include #include #include "test.h" @@ -190,3 +191,49 @@ int test_list_sort(void) out: return err; } + + +static struct list flushl = LIST_INIT; + +struct flush_data { + struct le le; +}; + + +static void data_destroy(void *arg) +{ + (void)arg; + struct le *le; + + LIST_FOREACH(&flushl, le) + { + assert(list_count(&flushl)); + } +} + + +int test_list_flush(void) +{ + struct flush_data *data[2]; + int err = 0; + + data[0] = mem_zalloc(sizeof(struct flush_data), data_destroy); + if (!data[0]) + return ENOMEM; + + data[1] = mem_zalloc(sizeof(struct flush_data), data_destroy); + if (!data[1]) { + mem_deref(data[0]); + return ENOMEM; + } + + list_append(&flushl, &data[0]->le, data[0]); + list_append(&flushl, &data[1]->le, data[1]); + + list_flush(&flushl); + + TEST_EQUALS(0, list_count(&flushl)); + +out: + return err; +} diff --git a/src/test.c b/src/test.c index d54b150f..0b603c69 100644 --- a/src/test.c +++ b/src/test.c @@ -122,6 +122,7 @@ static const struct test tests[] = { TEST(test_json_bad), TEST(test_json_array), TEST(test_list), + TEST(test_list_flush), TEST(test_list_ref), TEST(test_list_sort), TEST(test_mbuf), diff --git a/src/test.h b/src/test.h index 18866c44..bee5b06c 100644 --- a/src/test.h +++ b/src/test.h @@ -232,6 +232,7 @@ int test_json_file(void); int test_json_unicode(void); int test_json_array(void); int test_list(void); +int test_list_flush(void); int test_list_ref(void); int test_list_sort(void); int test_mbuf(void); From 613b830239c487a7383d0f2d4c6b02627c8c9bf5 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 29 Oct 2022 21:47:48 +0200 Subject: [PATCH 60/60] list: fix flushl global (#152) --- src/list.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/list.c b/src/list.c index 6b6d19a4..f5d030af 100644 --- a/src/list.c +++ b/src/list.c @@ -193,21 +193,20 @@ int test_list_sort(void) } -static struct list flushl = LIST_INIT; - struct flush_data { struct le le; + struct list *flushl; }; static void data_destroy(void *arg) { - (void)arg; + struct flush_data *data = arg; struct le *le; - LIST_FOREACH(&flushl, le) + LIST_FOREACH(data->flushl, le) { - assert(list_count(&flushl)); + assert(list_count(data->flushl)); } } @@ -215,6 +214,7 @@ static void data_destroy(void *arg) int test_list_flush(void) { struct flush_data *data[2]; + struct list flushl = LIST_INIT; int err = 0; data[0] = mem_zalloc(sizeof(struct flush_data), data_destroy); @@ -227,6 +227,9 @@ int test_list_flush(void) return ENOMEM; } + data[0]->flushl = &flushl; + data[1]->flushl = &flushl; + list_append(&flushl, &data[0]->le, data[0]); list_append(&flushl, &data[1]->le, data[1]);