diff options
author | Steven Moreland <smoreland@google.com> | 2019-09-17 17:41:02 -0700 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2019-09-20 11:35:09 -0700 |
commit | 2056cf3eee33bee6e75e0cffbeea931118cbb1e2 (patch) | |
tree | 787624c02ec834ed96ede78eda7075c44fcf871d /base | |
parent | 23c28f5e21a6749e4df8e11eaa3c70f12fa9c616 (diff) | |
download | libhidl-2056cf3eee33bee6e75e0cffbeea931118cbb1e2.tar.gz |
HIDL stuff on host.
The motivation of this is for quickly running unit tests of HAL
implementations on host. Before, you would have to abstract away
HIDL stuff, but now, you can just call a class that inherits from
HIDL stuff directly.
Currently, there is no binder or passthrough support on host though.
This is only for unit tests of C++ classes.
Bug: 124524556
Test: libhidl_test on host
Change-Id: I922060e48406ca196fbf864e549c05f5e1113d62
Diffstat (limited to 'base')
-rw-r--r-- | base/Android.bp | 3 | ||||
-rw-r--r-- | base/HidlInternal.cpp | 71 |
2 files changed, 37 insertions, 37 deletions
diff --git a/base/Android.bp b/base/Android.bp index 0bc3af0..ca4e259 100644 --- a/base/Android.bp +++ b/base/Android.bp @@ -28,8 +28,9 @@ cc_defaults { cc_library { name: "libhidlbase-impl-internal", - vendor_available: true, + host_supported: true, recovery_available: true, + vendor_available: true, defaults: [ "libhidlbase-impl-shared-libs", "libhidl-defaults" diff --git a/base/HidlInternal.cpp b/base/HidlInternal.cpp index 440b30f..956effd 100644 --- a/base/HidlInternal.cpp +++ b/base/HidlInternal.cpp @@ -21,7 +21,6 @@ #include <android-base/logging.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> -#include <cutils/properties.h> #ifdef LIBHIDL_TARGET_DEBUGGABLE #include <dirent.h> @@ -56,7 +55,7 @@ std::string getVndkVersionStr() { // "0" means the vndkVersion must be initialized with the property value. // Otherwise, return the value. if (vndkVersion == "0") { - vndkVersion = android::base::GetProperty("ro.vndk.version", ""); + vndkVersion = base::GetProperty("ro.vndk.version", ""); if (vndkVersion != "" && vndkVersion != "current") { vndkVersion = "-" + vndkVersion; } else { @@ -76,44 +75,44 @@ HidlInstrumentor::HidlInstrumentor(const std::string& package, const std::string configureInstrumentation(false); if (__sanitizer_cov_dump != nullptr) { ::android::add_sysprop_change_callback( - []() { - bool enableCoverage = property_get_bool(kSysPropHalCoverage, false); - if (enableCoverage) { - __sanitizer_cov_dump(); - } - }, - 0); + []() { + bool enableCoverage = base::GetBoolProperty(kSysPropHalCoverage, false); + if (enableCoverage) { + __sanitizer_cov_dump(); + } + }, + 0); } - if (property_get_bool("ro.vts.coverage", false)) { + if (base::GetBoolProperty("ro.vts.coverage", false)) { const char* prefixOverride = getenv(kGcovPrefixOverrideEnvVar); if (prefixOverride == nullptr || strcmp(prefixOverride, "true") != 0) { const std::string gcovPath = kGcovPrefixPath + std::to_string(getpid()); setenv(kGcovPrefixEnvVar, gcovPath.c_str(), true /* overwrite */); } ::android::add_sysprop_change_callback( - []() { - const bool enableCoverage = property_get_bool(kSysPropHalCoverage, false); - if (enableCoverage) { - dl_iterate_phdr( - [](struct dl_phdr_info* info, size_t /* size */, void* /* data */) { - if (strlen(info->dlpi_name) == 0) return 0; - - void* handle = dlopen(info->dlpi_name, RTLD_LAZY); - if (handle == nullptr) { - LOG(INFO) << "coverage dlopen failed: " << dlerror(); - return 0; - } - void (*flush)() = (void (*)())dlsym(handle, "__gcov_flush"); - if (flush == nullptr) { - return 0; - } - flush(); - return 0; - }, - nullptr /* data */); - } - }, - 0 /* priority */); + []() { + const bool enableCoverage = base::GetBoolProperty(kSysPropHalCoverage, false); + if (enableCoverage) { + dl_iterate_phdr( + [](struct dl_phdr_info* info, size_t /* size */, void* /* data */) { + if (strlen(info->dlpi_name) == 0) return 0; + + void* handle = dlopen(info->dlpi_name, RTLD_LAZY); + if (handle == nullptr) { + LOG(INFO) << "coverage dlopen failed: " << dlerror(); + return 0; + } + void (*flush)() = (void (*)())dlsym(handle, "__gcov_flush"); + if (flush == nullptr) { + return 0; + } + flush(); + return 0; + }, + nullptr /* data */); + } + }, + 0 /* priority */); } #endif } @@ -121,7 +120,7 @@ HidlInstrumentor::HidlInstrumentor(const std::string& package, const std::string HidlInstrumentor::~HidlInstrumentor() {} void HidlInstrumentor::configureInstrumentation(bool log) { - mEnableInstrumentation = property_get_bool("hal.instrumentation.enable", false); + mEnableInstrumentation = base::GetBoolProperty("hal.instrumentation.enable", false); if (mEnableInstrumentation) { if (log) { LOG(INFO) << "Enable instrumentation."; @@ -140,8 +139,8 @@ void HidlInstrumentor::registerInstrumentationCallbacks( std::vector<InstrumentationCallback> *instrumentationCallbacks) { #ifdef LIBHIDL_TARGET_DEBUGGABLE std::vector<std::string> instrumentationLibPaths; - char instrumentationLibPath[PROPERTY_VALUE_MAX]; - if (property_get(kSysPropInstrumentationPath, instrumentationLibPath, "") > 0) { + const std::string instrumentationLibPath = base::GetProperty(kSysPropInstrumentationPath, ""); + if (instrumentationLibPath.size() > 0) { instrumentationLibPaths.push_back(instrumentationLibPath); } else { static std::string halLibPathVndkSp = android::base::StringPrintf( |