diff options
Diffstat (limited to 'simpleperf/test_util.h')
-rw-r--r-- | simpleperf/test_util.h | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/simpleperf/test_util.h b/simpleperf/test_util.h index 5780b6c0..662c3b2f 100644 --- a/simpleperf/test_util.h +++ b/simpleperf/test_util.h @@ -24,8 +24,11 @@ #include "environment.h" #include "read_elf.h" +#include "utils.h" #include "workload.h" +using namespace simpleperf; + static const std::string SLEEP_SEC = "0.001"; void RunWorkloadFunction(); @@ -34,67 +37,81 @@ void CreateProcesses(size_t count, std::vector<std::unique_ptr<Workload>>* workl void ParseSymbol(const ElfFileSymbol& symbol, std::map<std::string, ElfFileSymbol>* symbols); void CheckElfFileSymbols(const std::map<std::string, ElfFileSymbol>& symbols); -bool IsRoot(); +#define TEST_IN_ROOT(TestStatement) \ + do { \ + if (IsRoot()) { \ + TestStatement; \ + } else { \ + GTEST_LOG_(INFO) << "Didn't test \"" << #TestStatement << "\" requires root privileges"; \ + } \ + } while (0) + +#define TEST_REQUIRE_ROOT() \ + do { \ + if (!IsRoot()) { \ + GTEST_LOG_(INFO) << "Skip this test as it needs root privileges."; \ + return; \ + } \ + } while (0) -#define TEST_IN_ROOT(TestStatement) \ - do { \ - if (IsRoot()) { \ - TestStatement; \ - } else { \ - GTEST_LOG_(INFO) << "Didn't test \"" << #TestStatement << "\" requires root privileges"; \ - } \ +#define TEST_REQUIRE_NON_ROOT() \ + do { \ + if (IsRoot()) { \ + GTEST_LOG_(INFO) << "Skip this test as it tests non-root behavior."; \ + return; \ + } \ } while (0) #if defined(__ANDROID__) #define TEST_REQUIRE_HOST_ROOT() #else -#define TEST_REQUIRE_HOST_ROOT() if (!IsRoot()) return +#define TEST_REQUIRE_HOST_ROOT() TEST_REQUIRE_ROOT() #endif bool IsInNativeAbi(); // Used to skip tests not supposed to run on non-native ABIs. -#define OMIT_TEST_ON_NON_NATIVE_ABIS() \ - do { \ - if (!IsInNativeAbi()) { \ +#define OMIT_TEST_ON_NON_NATIVE_ABIS() \ + do { \ + if (!IsInNativeAbi()) { \ GTEST_LOG_(INFO) << "Skip this test as it only runs on native ABIs."; \ - return; \ - } \ + return; \ + } \ } while (0) bool HasHardwareCounter(); -#define TEST_REQUIRE_HW_COUNTER() \ - do { \ - if (!HasHardwareCounter()) { \ +#define TEST_REQUIRE_HW_COUNTER() \ + do { \ + if (!HasHardwareCounter()) { \ GTEST_LOG_(INFO) << "Skip this test as the machine doesn't have hardware PMU counters."; \ - return; \ - } \ + return; \ + } \ } while (0) bool HasPmuCounter(); -#define TEST_REQUIRE_PMU_COUNTER() \ - do { \ - if (!HasPmuCounter()) { \ +#define TEST_REQUIRE_PMU_COUNTER() \ + do { \ + if (!HasPmuCounter()) { \ GTEST_LOG_(INFO) << "Skip this test as the machine doesn't have low-level PMU counters."; \ - return; \ - } \ + return; \ + } \ } while (0) bool HasTracepointEvents(); -#define TEST_REQUIRE_TRACEPOINT_EVENTS() \ - do { \ - if (!HasTracepointEvents()) { \ +#define TEST_REQUIRE_TRACEPOINT_EVENTS() \ + do { \ + if (!HasTracepointEvents()) { \ GTEST_LOG_(INFO) << "Skip this test as the machine doesn't support tracepoint events."; \ - return; \ - } \ + return; \ + } \ } while (0) #if defined(IN_CTS_TEST) #define TEST_REQUIRE_APPS() #else -#define TEST_REQUIRE_APPS() \ - do { \ +#define TEST_REQUIRE_APPS() \ + do { \ GTEST_LOG_(INFO) << "Skip this test as test apps aren't available."; \ - return; \ + return; \ } while (0) #endif @@ -172,7 +189,7 @@ class AppHelper { #elif defined(__arm__) return "armeabi-v7a"; #else - #error "unrecognized ABI" +#error "unrecognized ABI" #endif } |