diff --git a/BUILD.gn b/BUILD.gn index 230e680b746b466a304cd9d6bb809ea27870f6dd..d2b9bf009147fc72d7b13671860ff801ed66e258 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -181,6 +181,9 @@ if (defined(ohos_lite)) { cflags += [ "-Wno-frame-address" ] # for use of __builtin_return_address } + if (is_ohos) { + defines += [ "UV_OHOS" ] + } } else if (is_mingw || is_win) { cflags += [ "-Wno-missing-braces", diff --git a/test/run-tests.c b/test/run-tests.c index 467f2d56b870073bacf8cb2c14d3eda4d162b50c..94955175706875064e23feac953cc5c309ee0925 100644 --- a/test/run-tests.c +++ b/test/run-tests.c @@ -65,6 +65,14 @@ typedef BOOL (WINAPI *sCompareObjectHandles)(_In_ HANDLE, _In_ HANDLE); int main(int argc, char **argv) { + #ifndef UV_OHOS + #ifndef _WIN32 + if (0 == geteuid() && NULL == getenv("UV_RUN_AS_ROOT")) { + fprintf(stderr, "The libuv test suite cannot be run as root.\n"); + return EXIT_FAILURE; + } + #endif + #endif platform_init(argc, argv); argv = uv_setup_args(argc, argv); diff --git a/test/runner-unix.c b/test/runner-unix.c index 60f111868d268ee0344a9a50ed7d5aa14635787e..c9ad6b2a837bb7940d669d0e6f04bc1c13027d6f 100644 --- a/test/runner-unix.c +++ b/test/runner-unix.c @@ -107,9 +107,13 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { args[n++] = name; args[n++] = part; args[n++] = NULL; - + #ifdef UV_OHOS stdout_file = fopen("/data/local/tmp/test.txt", "w+"); stdout_fd = fileno(stdout_file); + #else + stdout_file = tmpfile(); + stdout_fd = fileno(stdout_file); + #endif if (!stdout_file) { perror("tmpfile"); return -1; @@ -142,6 +146,10 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { /* child */ if (is_helper) closefd(pipefd[0]); + #ifndef UV_OHOS + dup2(stdout_fd, STDOUT_FILENO); + dup2(stdout_fd, STDERR_FILENO); + #endif execve(args[0], args, environ); perror("execve()"); _exit(127); diff --git a/test/test-close-fd.c b/test/test-close-fd.c index 6940eccc0630c0c7b2289aa43661a0c5452a2fe7..7cd8378f7ff637b2344e7b4e4fcf6a0a22b8cbbf 100644 --- a/test/test-close-fd.c +++ b/test/test-close-fd.c @@ -44,7 +44,11 @@ static void read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { uv_close((uv_handle_t *) handle, NULL); break; default: + #ifdef UV_OHOS ASSERT(!(read_cb_called > 2)); + #else + ASSERT(!"read_cb_called > 2"); + #endif } } diff --git a/test/test-dlerror.c b/test/test-dlerror.c index dd3f2c46bd7970474b2190fd0382089e1499bbe9..3a01d87b8e7532ceec2cb286484e297498bd7991 100644 --- a/test/test-dlerror.c +++ b/test/test-dlerror.c @@ -38,8 +38,25 @@ TEST_IMPL(dlerror) { ASSERT_NOT_NULL(strstr(msg, dlerror_no_error)); r = uv_dlopen(path, &lib); - ASSERT(r == 0); + #ifndef UV_OHOS + ASSERT(r == -1); + msg = uv_dlerror(&lib); + ASSERT_NOT_NULL(msg); + #if !defined(__OpenBSD__) && !defined(__QNX__) + ASSERT_NOT_NULL(strstr(msg, path)); + #endif + ASSERT_NULL(strstr(msg, dlerror_no_error)); + /* Should return the same error twice in a row. */ + msg = uv_dlerror(&lib); + ASSERT_NOT_NULL(msg); + #if !defined(__OpenBSD__) && !defined(__QNX__) + ASSERT_NOT_NULL(strstr(msg, path)); + #endif + ASSERT_NULL(strstr(msg, dlerror_no_error)); + #else + ASSERT(r == 0); + #endif uv_dlclose(&lib); return 0; diff --git a/test/test-idna.c b/test/test-idna.c index 77af3a9da0341c53c05a06920dd909324c00d8d9..40f65781e0d252bbbb08dd7d6b1c4c3f7a08cbfb 100644 --- a/test/test-idna.c +++ b/test/test-idna.c @@ -20,7 +20,11 @@ */ #include "task.h" +#ifdef UV_OHOS #include "../src/idna.h" +#else +#include "../src/idna.c" +#endif #include TEST_IMPL(utf8_decode1) { @@ -103,13 +107,21 @@ TEST_IMPL(utf8_decode1_overrun) { /* Single byte. */ p = b; b[0] = 0x7F; + #ifdef UV_OHOS ASSERT((unsigned int)0x7F == uv__utf8_decode1(&p, b + 1)); + #else + ASSERT_EQ(0x7F, uv__utf8_decode1(&p, b + 1)); + #endif ASSERT_EQ(p, b + 1); /* Multi-byte. */ p = b; b[0] = 0xC0; + #ifdef UV_OHOS ASSERT_EQ((unsigned int) -1, uv__utf8_decode1(&p, b + 1)); + #else + ASSERT_EQ((unsigned int) -1, uv__utf8_decode1(&p, b + 1)); + #endif ASSERT_EQ(p, b + 1); return 0; diff --git a/test/test-strscpy.c b/test/test-strscpy.c index 993f7a13be78bb2f75fb741118d821b245c3ecf1..5bc7144980ef24627bd27e8b1b37c4bfd5934fe9 100644 --- a/test/test-strscpy.c +++ b/test/test-strscpy.c @@ -24,6 +24,9 @@ #include #include "../src/strscpy.h" +#ifndef UV_OHOS +#include "../src/strscpy.c" +#endif TEST_IMPL(strscpy) { char d[4];