diff options
author | Victor Chang <vichang@google.com> | 2021-01-19 10:18:07 +0000 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2022-11-14 15:45:44 +0000 |
commit | 3058671135052511dc9a74fd785776ff5f259731 (patch) | |
tree | 0c711af3bc0081821bbe50e4c5e837adec2bda0b /icu4c | |
parent | 7821c47a7249a35eb124244b8251cb499cb59053 (diff) | |
download | icu-3058671135052511dc9a74fd785776ff5f259731.tar.gz |
Android patch: Android support for ICU4C tests.
On Android, the source tree is not available as the tests are cross
compiled. The ICU data itself is installed to a known system path, and
additional test data is found at paths relative to the test binary.
The upstream request is tracked at
https://unicode-org.atlassian.net/browse/ICU-13849.
Bug: 120776993
Test: treehugger
Change-Id: I3548a66b32b5e36856eac52dbfd29c2352bcd554
Diffstat (limited to 'icu4c')
-rw-r--r-- | icu4c/source/tools/ctestfw/ctest.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/icu4c/source/tools/ctestfw/ctest.c b/icu4c/source/tools/ctestfw/ctest.c index 06857d87f..b3189f9d5 100644 --- a/icu4c/source/tools/ctestfw/ctest.c +++ b/icu4c/source/tools/ctestfw/ctest.c @@ -16,6 +16,12 @@ #include <stdlib.h> #include <string.h> +#if defined(__ANDROID__) +#include <errno.h> +#include <libgen.h> +#include <unistd.h> +#endif + #if defined(__linux__) #include <features.h> #endif @@ -1354,7 +1360,23 @@ static const char* ctest_icuSrcDir(void) { return srcDir; } -#if defined(U_TOPSRCDIR) +#if defined(__ANDROID__) + /* + * On Android, the source tree is not available as the tests are cross + * compiled. Test data is found at paths relative to the test binary. + */ + char exePath[PATH_MAX]; + ssize_t len = readlink("/proc/self/exe", exePath, sizeof(exePath)); + if (len == -1) { + fprintf(stderr, "Failed to read /proc/self/exe: %s\n", strerror(errno)); + abort(); + } + exePath[len] = '\0'; + + static char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/", dirname(exePath)); + srcDir = path; +#elif defined(U_TOPSRCDIR) /* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and * intltst to point to the top of the build hierarchy, which may or may not * be the same as the source directory, depending on the configure options @@ -1439,10 +1461,17 @@ ctest_dataOutDir(void) { return path; } +#if defined(__ANDROID__) + // Android has the ICU data installed to a known location on the device. Use + // that if ICU_DATA is not set. + snprintf(path, sizeof(path), "/system/usr/icu/"); + return path; +#else // But fallback to the source directory if needed. snprintf(path, sizeof(path), "%sout%s", ctest_dataSrcDir(), U_FILE_SEP_STRING); return path; +#endif } const char* T_CTEST_EXPORT2 |