summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ulya Trofimovich <skvadrik@google.com> 2024-10-03 08:15:33 +0000
committer Ulya Trofimovich <skvadrik@google.com> 2024-10-08 14:36:38 +0000
commit8d24de75151c74963c253b58173452b57d028d6a (patch)
tree9d9e7d9e1891d477cb8e644263ed6f8f949f8bb0
parentb0349f656a4b4f95db7e9f4bab53657436c0df98 (diff)
Skip gtest ImgDiagTest.ImageDiffPidSelf when running tests on VM.
We do skip this test on host, as it tries to access system files for which it does not have permissions. It's the same situation on VM. Test: checked that ImgDiagTest.ImageDiffPidSelf is skipped on VM: . ./build/envsetup.sh lunch riscv64-trunk_staging-eng export SOONG_ALLOW_MISSING_DEPENDENCIES=true art/tools/buildbot-build.sh --target -j72 export ART_TEST_SSH_USER=ubuntu export ART_TEST_SSH_HOST=localhost export ART_TEST_SSH_PORT=10001 export ART_TEST_ON_VM=true . art/tools/buildbot-utils.sh art/tools/buildbot-cleanup-device.sh art/tools/buildbot-setup-device.sh art/tools/buildbot-sync.sh art/tools/run-gtests.sh \ /apex/com.android.art/bin/art/riscv64/art_imgdiag_tests Change-Id: If183439b2e9269ab199450fa12a1a0e0ef2e8dee
-rw-r--r--imgdiag/imgdiag_test.cc3
-rw-r--r--libartbase/base/utils.cc6
-rw-r--r--libartbase/base/utils.h3
-rw-r--r--runtime/common_runtime_test.h5
-rwxr-xr-xtools/run-gtests.sh1
5 files changed, 18 insertions, 0 deletions
diff --git a/imgdiag/imgdiag_test.cc b/imgdiag/imgdiag_test.cc
index 9dd7953a24..e523022803 100644
--- a/imgdiag/imgdiag_test.cc
+++ b/imgdiag/imgdiag_test.cc
@@ -119,6 +119,9 @@ TEST_F(ImgDiagTest, DISABLED_ImageDiffPidSelf) {
// This should succeed because we have a runtime and so it should
// be able to map in the boot.art and do a diff for it.
+ // Not allowed to read /proc/kpagestats on VM (in the same way as on host).
+ TEST_DISABLED_ON_VM();
+
// Run imgdiag --image-diff-pid=$(self pid) and wait until it's done with a 0 exit code.
std::string error_msg;
ASSERT_TRUE(ExecDefaultBootImage(getpid(), &error_msg)) << "Failed to execute -- because: "
diff --git a/libartbase/base/utils.cc b/libartbase/base/utils.cc
index da53d0b99f..2c95986809 100644
--- a/libartbase/base/utils.cc
+++ b/libartbase/base/utils.cc
@@ -19,6 +19,7 @@
#include <dirent.h>
#include <inttypes.h>
#include <pthread.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -190,6 +191,11 @@ bool CacheOperationsMaySegFault() {
#endif
}
+bool RunningOnVM() {
+ const char* on_vm = getenv("ART_TEST_ON_VM");
+ return on_vm != nullptr && std::strcmp("true", on_vm) == 0;
+}
+
uint32_t GetTid() {
#if defined(__APPLE__)
uint64_t owner;
diff --git a/libartbase/base/utils.h b/libartbase/base/utils.h
index 32f8b87204..4b86651f95 100644
--- a/libartbase/base/utils.h
+++ b/libartbase/base/utils.h
@@ -129,6 +129,9 @@ bool IsKernelVersionAtLeast(int reqd_major, int reqd_minor);
// On some old kernels, a cache operation may segfault.
WARN_UNUSED bool CacheOperationsMaySegFault();
+// Is the execution environment on a virtual machine? See ART_TEST_ON_VM.
+WARN_UNUSED bool RunningOnVM();
+
template <typename Func, typename... Args>
static inline void CheckedCall(const Func& function, const char* what, Args... args) {
int rc = function(args...);
diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h
index f0f83eac83..5416cb493c 100644
--- a/runtime/common_runtime_test.h
+++ b/runtime/common_runtime_test.h
@@ -308,6 +308,11 @@ class CheckJniAbortCatcher {
GTEST_SKIP() << "WARNING: TEST DISABLED ON KERNEL THAT SEGFAULT ON CACHE OPERATIONS"; \
}
+#define TEST_DISABLED_ON_VM() \
+ if (RunningOnVM()) { \
+ GTEST_SKIP(); \
+ }
+
} // namespace art
#endif // ART_RUNTIME_COMMON_RUNTIME_TEST_H_
diff --git a/tools/run-gtests.sh b/tools/run-gtests.sh
index b98efa5f8a..acc5c8a2ed 100755
--- a/tools/run-gtests.sh
+++ b/tools/run-gtests.sh
@@ -101,6 +101,7 @@ for t in ${tests[@]}; do
env ANDROID_ART_ROOT="$android_art_root" \
ANDROID_I18N_ROOT="$android_i18n_root" \
ANDROID_TZDATA_ROOT="$android_tzdata_root" \
+ ART_TEST_ON_VM="$ART_TEST_ON_VM" \
$(maybe_get_fake_dex2oatbootclasspath) \
$t $options \
|| failing_tests+=("$t")