Skip to content

Commit adcaac1

Browse files
authored
Add tests, optimize code, refactor, Improve test coverage to 86% (#5790)
1 parent c0a21c4 commit adcaac1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1606
-1367
lines changed

.github/workflows/core.yml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,14 @@ jobs:
4545
- name: configure
4646
run: phpize && ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-iouring
4747

48-
- name: make
48+
- name: build
4949
run: |
50-
if [[ "$GITHUB_COMMIT_MESSAGE" == *"--asan"* ]]; then
51-
cmake . -D CODE_COVERAGE=ON -D enable_thread=1 -D enable_asan=1
52-
else
53-
cmake . -D CODE_COVERAGE=ON -D enable_thread=1
54-
fi
50+
cmake . -D CODE_COVERAGE=ON -D enable_thread=1 -D verbose=1 || exit 1
51+
make VERBOSE=1 -j $(nproc) core-tests || exit 1
5552
56-
make VERBOSE=1 -j $(nproc) lib-swoole
57-
58-
- name: make test
53+
- name: run tests
5954
run: |
60-
export GITHUB_COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
61-
if [[ "$GITHUB_COMMIT_MESSAGE" == *"--valgrind"* ]]; then
62-
export SWOOLE_VALGRIND=1
63-
fi
64-
if [[ "$GITHUB_COMMIT_MESSAGE" == *"--asan"* ]]; then
65-
export SWOOLE_ENABLE_ASAN=1
66-
fi
67-
if [[ "$GITHUB_COMMIT_MESSAGE" == *"--strace"* ]]; then
68-
export SWOOLE_ENABLE_STRACE=1
69-
fi
70-
if [[ "$GITHUB_COMMIT_MESSAGE" == *"--verbose"* ]]; then
71-
export SWOOLE_ENABLE_VERBOSE=1
72-
fi
73-
echo "SWOOLE_VALGRIND=${SWOOLE_VALGRIND}"
74-
echo "SWOOLE_ENABLE_ASAN=${SWOOLE_ENABLE_ASAN}"
75-
echo "SWOOLE_ENABLE_STRACE=${SWOOLE_ENABLE_STRACE}"
76-
echo "SWOOLE_ENABLE_VERBOSE=${SWOOLE_ENABLE_VERBOSE}"
77-
cd core-tests && ./run.sh
55+
./run-core-tests.sh
7856
7957
- name: run coverage
8058
shell: bash

CMakeLists.txt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ enable_language(ASM)
55
set(SWOOLE_VERSION 6.1.0-dev)
66

77
set(CMAKE_CXX_STANDARD 17)
8-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -g")
9-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g")
10+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
1011

1112
file(READ ./config.h SWOOLE_CONFIG_FILE)
1213

@@ -21,6 +22,8 @@ else()
2122
list(APPEND SWOOLE_LINK_LIBRARIES rt crypt)
2223
endif()
2324

25+
find_package(PkgConfig REQUIRED)
26+
2427
if (UNIX AND NOT APPLE)
2528
find_library(URING_LIBRARIES uring)
2629
if (URING_LIBRARIES)
@@ -31,7 +34,9 @@ if (UNIX AND NOT APPLE)
3134
endif()
3235
endif()
3336

34-
SET(CMAKE_BUILD_TYPE Debug)
37+
if (NOT CMAKE_BUILD_TYPE)
38+
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
39+
endif ()
3540

3641
# Code Coverage Configuration
3742
add_library(coverage_config INTERFACE)
@@ -67,8 +72,8 @@ file(GLOB_RECURSE SRC_LIST FOLLOW_SYMLINKS src/*.c src/*.cc
6772
file(GLOB_RECURSE HEAD_FILES FOLLOW_SYMLINKS include/*.h)
6873
file(GLOB_RECURSE HEAD_WAPPER_FILES FOLLOW_SYMLINKS include/wrapper/*.hpp)
6974

70-
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
71-
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
75+
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
76+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
7277

7378
#message(STATUS "source=${SRC_LIST}")
7479
#message(STATUS "header=${HEAD_FILES}")
@@ -78,7 +83,6 @@ add_definitions(-DHAVE_CONFIG_H)
7883
#add_definitions(-DSW_USE_THREAD_CONTEXT)
7984

8085
include_directories(BEFORE ./include ./include/wrapper ext-src/ thirdparty/ ./)
81-
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
8286

8387
# find OpenSSL
8488
if (DEFINED openssl_dir)
@@ -116,6 +120,14 @@ if (DEFINED enable_asan)
116120
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
117121
endif()
118122

123+
if (DEFINED enable_thread)
124+
add_definitions(-DSW_THREAD)
125+
endif()
126+
127+
if (DEFINED verbose)
128+
add_definitions(-DSW_VERBOSE)
129+
endif()
130+
119131
if (DEFINED php_dir)
120132
set(PHP_CONFIG "${php_dir}/bin/php-config")
121133
else ()
@@ -213,15 +225,10 @@ add_dependencies(core-tests lib-swoole)
213225
include_directories(BEFORE core-tests/include thirdparty thirdparty/hiredis core-tests/deps/llhttp/include ${GTEST_INCLUDE_DIRS} ${NGHTTP2_INCLUDE_DIR})
214226
target_link_libraries(core-tests swoole pthread ssl crypto ${GTEST_BOTH_LIBRARIES} ${NGHTTP2_LIBRARIES})
215227

216-
if (DEFINED enable_thread)
217-
add_definitions(-DSW_THREAD)
218-
endif()
219-
220228
# find libpq
221229
if (DEFINED libpq_dir)
222230
target_include_directories(ext-swoole BEFORE ${LIBPQ_INCLUDE_DIRS})
223231
else()
224-
find_package(PkgConfig REQUIRED)
225232
pkg_check_modules(LIBPQ REQUIRED libpq)
226233
target_include_directories(ext-swoole PRIVATE ${LIBPQ_INCLUDE_DIRS})
227234
endif()

core-tests/CMakeLists.txt

Lines changed: 0 additions & 95 deletions
This file was deleted.

core-tests/README-CN.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

core-tests/README.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

core-tests/docker-compose.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ services:
66
tinyproxy:
77
container_name: "tinyproxy"
88
image: "vimagick/tinyproxy"
9+
ports:
10+
- 8888:8888
911
socks5:
1012
container_name: "socks5"
1113
image: "xkuma/socks5"
@@ -15,4 +17,9 @@ services:
1517
- PROXY_USER=user
1618
- PROXY_PASSWORD=password
1719
- PROXY_SERVER=0.0.0.0:1080
18-
20+
socks5-no-auth:
21+
image: "xkuma/socks5"
22+
ports:
23+
- 8081:1080
24+
environment:
25+
PROXY_SERVER: 0.0.0.0:1080

core-tests/run.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)