Skip to content

Commit 559ee6d

Browse files
authored
Increase more core tests, refactor and optimize core code, and raise test coverage to 84% (#5785)
1 parent 04b3f82 commit 559ee6d

Some content is hidden

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

69 files changed

+2266
-850
lines changed

.github/workflows/core.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jobs:
2929
PROXY_USER: user
3030
PROXY_PASSWORD: password
3131
PROXY_SERVER: 0.0.0.0:1080
32+
socks5-no-auth:
33+
image: "xkuma/socks5"
34+
ports:
35+
- 8081:1080
36+
env:
37+
PROXY_SERVER: 0.0.0.0:1080
3238

3339
steps:
3440
- uses: actions/checkout@v4
@@ -41,7 +47,12 @@ jobs:
4147

4248
- name: make
4349
run: |
44-
cmake . -D CODE_COVERAGE=ON -D enable_thread=1
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
55+
4556
make VERBOSE=1 -j $(nproc) lib-swoole
4657
4758
- name: make test

core-tests/include/test_core.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <fstream>
1818

1919
#define TEST_HOST "127.0.0.1"
20+
#define TEST_HOST6 "::1"
2021
#define TEST_PORT 9501
2122
#define TEST_TMP_FILE "/tmp/swoole_core_test_file"
2223
#define TEST_TMP_DIR "/tmp/swoole_core_test_dir"
@@ -30,6 +31,7 @@
3031

3132
#define TEST_SOCKS5_PROXY_HOST "127.0.0.1"
3233
#define TEST_SOCKS5_PROXY_PORT 8080
34+
#define TEST_SOCKS5_PROXY_NO_AUTH_PORT 8081
3335
#define TEST_SOCKS5_PROXY_USER "user"
3436
#define TEST_SOCKS5_PROXY_PASSWORD "password"
3537

@@ -63,7 +65,7 @@
6365
#define TIMER_PARAMS swoole::Timer *timer, swoole::TimerNode *tnode
6466

6567
#ifdef SW_VERBOSE
66-
#define DEBUG() std::cout
68+
#define DEBUG() swoole::test::debug_output.get()
6769
#else
6870
#define DEBUG() swoole::test::null_stream
6971
#endif
@@ -72,26 +74,23 @@ namespace swoole {
7274
struct HttpProxy;
7375
struct Socks5Proxy;
7476
namespace test {
75-
class NullStream {
77+
class NullStream : public std::ostream {
7678
public:
77-
template <typename T>
78-
NullStream &operator<<(const T &) {
79-
return *this;
80-
}
81-
82-
NullStream &operator<<(std::ostream &(*) (std::ostream &) ) {
83-
return *this;
84-
}
79+
NullStream() : std::ostream(nullptr) {}
8580
};
8681

8782
extern NullStream null_stream;
83+
extern std::reference_wrapper<std::ostream> debug_output;
8884
const std::string &get_root_path();
8985
std::string get_ssl_dir();
9086
std::string get_jpg_file();
9187
bool is_github_ci();
9288
int exec_js_script(const std::string &file, const std::string &args);
9389
std::string http_get_request(const std::string &domain, const std::string &path);
9490
int get_random_port();
91+
int has_threads();
92+
int has_child_processes();
93+
int wait_all_child_processes(bool verbose = false);
9594

9695
pid_t spawn_exec(const std::function<void(void)> &fn);
9796
int spawn_exec_and_wait(const std::function<void(void)> &fn);

core-tests/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ __SWOOLE_DIR__=$(cd "$(dirname "${__DIR__}")" || exit;pwd)
44
CMAKE_ARGS="-D swoole_dir=${__SWOOLE_DIR__} -D enable_thread=1"
55

66
if [ "${SWOOLE_ENABLE_ASAN}" = 1 ]; then
7+
export ASAN_OPTIONS=detect_leaks=0
8+
echo 0 > /proc/sys/kernel/randomize_va_space
79
CMAKE_ARGS="${CMAKE_ARGS} -D enable_asan=1"
810
fi
911

0 commit comments

Comments
 (0)