-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathmain.cpp
94 lines (75 loc) · 2.26 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "test_core.h"
#include "swoole_proxy.h"
using namespace swoole;
using namespace std;
static string root_path;
static void init_root_path(const char *);
int main(int argc, char **argv) {
swoole_init();
init_root_path(argv[0]);
if (getenv("DISPLAY_BACKTRACE") != nullptr) {
sw_logger()->display_backtrace();
}
::testing::InitGoogleTest(&argc, argv);
int retval = RUN_ALL_TESTS();
swoole_clean();
return retval;
}
static void init_root_path(const char *_exec_file) {
char buf[PATH_MAX];
string file;
if (_exec_file[0] == '/') {
file = _exec_file;
} else {
char *dir = getcwd(buf, sizeof(buf));
file = string(dir) + "/" + _exec_file;
}
string relative_root_path = file.substr(0, file.rfind('/')) + "/../../";
char *_realpath = realpath(relative_root_path.c_str(), buf);
if (_realpath == nullptr) {
root_path = relative_root_path;
} else {
root_path = string(_realpath);
}
}
namespace swoole {
namespace test {
const string &get_root_path() {
return root_path;
}
string get_ssl_dir() {
return get_root_path() + "/tests/include/ssl_certs";
}
string get_jpg_file() {
return root_path + TEST_JPG_FILE;
}
bool is_github_ci() {
return getenv("GITHUB_ACTIONS") != nullptr;
}
Socks5Proxy *create_socks5_proxy() {
auto socks5_proxy = new Socks5Proxy();
socks5_proxy->host = std::string(TEST_SOCKS5_PROXY_HOST);
socks5_proxy->port = TEST_SOCKS5_PROXY_PORT;
socks5_proxy->dns_tunnel = 1;
if (is_github_ci()) {
socks5_proxy->method = SW_SOCKS5_METHOD_AUTH;
socks5_proxy->username = std::string(TEST_SOCKS5_PROXY_USER);
socks5_proxy->password = std::string(TEST_SOCKS5_PROXY_PASSWORD);
}
return socks5_proxy;
}
HttpProxy *create_http_proxy() {
auto http_proxy = new HttpProxy();
http_proxy->proxy_host = std::string(TEST_HTTP_PROXY_HOST);
http_proxy->proxy_port = TEST_HTTP_PROXY_PORT;
if (is_github_ci()) {
http_proxy->username = std::string(TEST_HTTP_PROXY_USER);
http_proxy->password = std::string(TEST_HTTP_PROXY_PASSWORD);
}
return http_proxy;
}
int get_random_port() {
return TEST_PORT + swoole_system_random(1, 10000);
}
} // namespace test
} // namespace swoole