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
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 @@
// "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 @@
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;
+ []() {
+ 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 */);
+ 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() {}
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 @@
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(