Skip to content

Commit 509f97b

Browse files
committed
Fix compilation errors of core tests on the Android platform
1 parent 18f8228 commit 509f97b

File tree

9 files changed

+17
-9
lines changed

9 files changed

+17
-9
lines changed

‎core-tests/include/test_core.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
#define debug_info(...)
7272
#endif
7373

74+
#ifdef __ANDROID__
75+
#define sysv_signal signal
76+
#endif
77+
7478
namespace swoole {
7579
struct HttpProxy;
7680
struct Socks5Proxy;

‎core-tests/src/core/base.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ TEST(base, set_task_tmpdir) {
208208
ASSERT_FALSE(swoole_set_task_tmpdir("aaa"));
209209

210210
size_t length = SW_TASK_TMP_PATH_SIZE + 1;
211-
char too_long_dir[length + 1] = {};
211+
char too_long_dir[SW_TASK_TMP_PATH_SIZE + 2] = {};
212212
swoole_random_string(too_long_dir + 1, length - 1);
213213
too_long_dir[0] = '/';
214214
ASSERT_FALSE(swoole_set_task_tmpdir(too_long_dir));

‎core-tests/src/coroutine/socket.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ TEST(coroutine_socket, sendmsg_and_recvmsg) {
13411341
socketpair(AF_UNIX, SOCK_STREAM, 0, pairs);
13421342

13431343
std::string text = "Hello World";
1344-
size_t length = text.length();
1344+
const size_t length = text.length();
13451345

13461346
Coroutine::create([&](void *) {
13471347
Socket sock(pairs[0], SW_SOCK_UNIX_STREAM);

‎core-tests/src/coroutine/system.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TEST(coroutine_system, flock) {
7979
}
8080

8181
TEST(coroutine_system, flock_nb) {
82-
coroutine::run([&](void *arg) {
82+
swoole::coroutine::run([&](void *arg) {
8383
DEBUG() << "[thread-1] open" << std::endl;
8484
int fd = swoole_coroutine_open(test_file, File::WRITE | File::CREATE, 0666);
8585
DEBUG() << "[thread-1] LOCK_EX | LOCK_NB" << std::endl;

‎core-tests/src/main.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "swoole_memory.h"
33

44
#include <dirent.h>
5+
#include <system_error>
56

67
using namespace swoole;
78
using namespace std;
@@ -352,7 +353,7 @@ int recursive_rmdir(const char *path) {
352353
pid_t spawn_exec(const std::function<void(void)> &fn) {
353354
pid_t child_pid = fork();
354355
if (child_pid == -1) {
355-
throw std::system_error();
356+
throw std::system_error{errno, std::generic_category()};
356357
} else if (child_pid == 0) {
357358
fn();
358359
exit(0);

‎core-tests/src/memory/buffer.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ TEST(buffer, append_iov) {
2828
Buffer buf(1024);
2929
Buffer buf_for_offset(1024);
3030

31-
int iovcnt = 4;
32-
iovec v[iovcnt];
31+
constexpr int N = 4;
32+
int iovcnt = N;
33+
iovec v[N];
3334
size_t total_len = 0;
3435

3536
SW_LOOP_N(iovcnt) {

‎core-tests/src/network/client.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ TEST(client, sleep_2) {
401401
swoole_timer_after(10, [cli, server_pid](auto _1, auto _2) {
402402
cli->sleep();
403403
DEBUG() << "Client is sleeping...\n";
404-
swoole_timer_after(15, [cli, server_pid](auto _1, auto _2) {
404+
swoole_timer_after(15, [cli](auto _1, auto _2) {
405405
cli->wakeup();
406406
DEBUG() << "Client woke up, closing connection...\n";
407407
});
@@ -988,7 +988,7 @@ TEST(client, ssl) {
988988
iovec wr_iov[2];
989989
wr_iov[0].iov_base = (void *) req.c_str();
990990
wr_iov[0].iov_len = offset1;
991-
wr_iov[1].iov_base = (void *) req.c_str() + offset1;
991+
wr_iov[1].iov_base = (char *) req.c_str() + offset1;
992992
wr_iov[1].iov_len = req.length() - offset1;
993993

994994
swoole::network::IOVector wr_vec(wr_iov, 2);

‎core-tests/src/os/process_pool.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ TEST(process_pool, tcp_raw) {
126126
pool.destroy();
127127
}
128128

129+
#ifdef HAVE_MSGQUEUE
129130
TEST(process_pool, msgqueue) {
130131
ProcessPool pool{};
131132
ASSERT_EQ(pool.create(1, 0x9501, SW_IPC_MSGQUEUE), SW_OK);
@@ -145,6 +146,7 @@ TEST(process_pool, msgqueue_2) {
145146
ASSERT_ERREQ(EACCES);
146147
});
147148
}
149+
#endif
148150

149151
TEST(process_pool, message_protocol) {
150152
ProcessPool pool{};

‎core-tests/src/server/server.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ TEST(server, task_sync_multi_task) {
20162016
std::vector<std::string> tasks;
20172017
std::vector<std::string> results;
20182018
int n_task = 16;
2019-
size_t len_task = SW_IPC_MAX_SIZE * 2;
2019+
constexpr size_t len_task = SW_IPC_MAX_SIZE * 2;
20202020
SW_LOOP_N(n_task) {
20212021
char data[len_task] = {};
20222022
swoole_random_string(data, len_task - 1);

0 commit comments

Comments
 (0)