Interface for configureRpcThreadpool tests am: 16a0437ab3
am: d19838d2c4
am: 6c0b3bee3c
Change-Id: I94d513c5052cdd7b59a8a675fa401da21765f39d
This commit is contained in:
commit
3bbf0c19d2
7 changed files with 305 additions and 0 deletions
|
@ -20,6 +20,8 @@ subdirs = [
|
|||
"memory/1.0/default",
|
||||
"msgq/1.0",
|
||||
"msgq/1.0/default",
|
||||
"multithread/1.0",
|
||||
"multithread/1.0/default",
|
||||
"pointer/1.0",
|
||||
"pointer/1.0/default",
|
||||
"pointer/1.0/default/lib",
|
||||
|
|
59
tests/multithread/1.0/Android.bp
Normal file
59
tests/multithread/1.0/Android.bp
Normal file
|
@ -0,0 +1,59 @@
|
|||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
filegroup {
|
||||
name: "android.hardware.tests.multithread@1.0_hal",
|
||||
srcs: [
|
||||
"IMultithread.hal",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.tests.multithread@1.0_genc++",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tests.multithread@1.0",
|
||||
srcs: [
|
||||
":android.hardware.tests.multithread@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/tests/multithread/1.0/MultithreadAll.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.tests.multithread@1.0_genc++_headers",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tests.multithread@1.0",
|
||||
srcs: [
|
||||
":android.hardware.tests.multithread@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/tests/multithread/1.0/IMultithread.h",
|
||||
"android/hardware/tests/multithread/1.0/IHwMultithread.h",
|
||||
"android/hardware/tests/multithread/1.0/BnHwMultithread.h",
|
||||
"android/hardware/tests/multithread/1.0/BpHwMultithread.h",
|
||||
"android/hardware/tests/multithread/1.0/BsMultithread.h",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "android.hardware.tests.multithread@1.0",
|
||||
defaults: ["hidl-module-defaults"],
|
||||
generated_sources: ["android.hardware.tests.multithread@1.0_genc++"],
|
||||
generated_headers: ["android.hardware.tests.multithread@1.0_genc++_headers"],
|
||||
export_generated_headers: ["android.hardware.tests.multithread@1.0_genc++_headers"],
|
||||
vendor_available: true,
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
],
|
||||
export_shared_lib_headers: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
],
|
||||
}
|
76
tests/multithread/1.0/Android.mk
Normal file
76
tests/multithread/1.0/Android.mk
Normal file
|
@ -0,0 +1,76 @@
|
|||
# This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.tests.multithread-V1.0-java
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java \
|
||||
|
||||
|
||||
#
|
||||
# Build IMultithread.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tests/multithread/V1_0/IMultithread.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IMultithread.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tests.multithread@1.0::IMultithread
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/IMultithread.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.tests.multithread-V1.0-java-static
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java-static \
|
||||
|
||||
|
||||
#
|
||||
# Build IMultithread.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tests/multithread/V1_0/IMultithread.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IMultithread.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tests.multithread@1.0::IMultithread
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/IMultithread.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
40
tests/multithread/1.0/IMultithread.hal
Normal file
40
tests/multithread/1.0/IMultithread.hal
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.tests.multithread@1.0;
|
||||
|
||||
/**
|
||||
* IMultithread tests configureRpcThreadpool
|
||||
*
|
||||
* Makes calls finish only when specific number of them are running in parallel
|
||||
*/
|
||||
interface IMultithread {
|
||||
/**
|
||||
* Sets up controller
|
||||
* Must be called for each test
|
||||
* @param maxThreads arg passed to configureRpcThreadpool
|
||||
* Could not be decremented by future calls
|
||||
* @param numThreads number of calls in parallel to finish
|
||||
*/
|
||||
setNumThreads(int32_t maxThreads, int32_t numThreads);
|
||||
|
||||
/**
|
||||
* Makes a new call
|
||||
* @return noTimeout numThreads appeared in parallel before timeout
|
||||
* Shall return the same value for one setNumThreads call
|
||||
*/
|
||||
runNewThread() generates (bool noTimeout);
|
||||
};
|
17
tests/multithread/1.0/default/Android.bp
Normal file
17
tests/multithread/1.0/default/Android.bp
Normal file
|
@ -0,0 +1,17 @@
|
|||
cc_library_shared {
|
||||
name: "android.hardware.tests.multithread@1.0-impl",
|
||||
defaults: ["hidl_defaults"],
|
||||
relative_install_path: "hw",
|
||||
proprietary: true,
|
||||
srcs: [
|
||||
"Multithread.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"android.hardware.tests.multithread@1.0",
|
||||
],
|
||||
}
|
63
tests/multithread/1.0/default/Multithread.cpp
Normal file
63
tests/multithread/1.0/default/Multithread.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#define LOG_TAG "hidl_test"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include "Multithread.h"
|
||||
#include <inttypes.h>
|
||||
#include <thread>
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tests {
|
||||
namespace multithread {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
// Methods from ::android::hardware::tests::multithread::V1_0::IMultithread follow.
|
||||
Return<void> Multithread::setNumThreads(int32_t maxThreads, int32_t numThreads) {
|
||||
LOG(INFO) << "SERVER(Multithread) setNumThreads("
|
||||
<< maxThreads << ", " << numThreads << ")";
|
||||
|
||||
LOG(INFO) << "SERVER(Multithread) call configureRpcThreadpool("
|
||||
<< maxThreads << ")";
|
||||
::android::hardware::configureRpcThreadpool(maxThreads, /*willjoin*/ false);
|
||||
|
||||
mNumThreads = numThreads;
|
||||
mNoTimeout = true;
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<bool> Multithread::runNewThread() {
|
||||
LOG(INFO) << "SERVER(Multithread) runNewThread()";
|
||||
|
||||
std::unique_lock<std::mutex> lk(mCvMutex);
|
||||
--mNumThreads;
|
||||
|
||||
LOG(INFO) << "SERVER(Multithread) runNewThread()";
|
||||
LOG(INFO) << mNumThreads << "threads left";
|
||||
|
||||
mCv.notify_all();
|
||||
bool noTimeout = mCv.wait_for(lk, kTimeoutDuration,
|
||||
[&] { return mNumThreads <= 0 || !mNoTimeout; });
|
||||
|
||||
if (!noTimeout) {
|
||||
mNoTimeout = false;
|
||||
mCv.notify_all();
|
||||
}
|
||||
return mNoTimeout;
|
||||
}
|
||||
|
||||
IMultithread* HIDL_FETCH_IMultithread(const char* /* name */) {
|
||||
return new Multithread();
|
||||
}
|
||||
|
||||
decltype(Multithread::kTimeoutDuration) Multithread::kTimeoutDuration;
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace multithread
|
||||
} // namespace tests
|
||||
} // namespace hardware
|
||||
} // namespace android
|
48
tests/multithread/1.0/default/Multithread.h
Normal file
48
tests/multithread/1.0/default/Multithread.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef ANDROID_HARDWARE_TESTS_MULTITHREAD_V1_0_MULTITHREAD_H
|
||||
#define ANDROID_HARDWARE_TESTS_MULTITHREAD_V1_0_MULTITHREAD_H
|
||||
|
||||
#include <android/hardware/tests/multithread/1.0/IMultithread.h>
|
||||
#include <hidl/Status.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tests {
|
||||
namespace multithread {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::tests::multithread::V1_0::IMultithread;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
struct Multithread : public IMultithread {
|
||||
// Methods from ::android::hardware::tests::multithread::V1_0::IMultithread follow.
|
||||
virtual Return<void> setNumThreads(int32_t maxThreads, int32_t numThreads) override;
|
||||
virtual Return<bool> runNewThread() override;
|
||||
|
||||
private:
|
||||
int32_t mNumThreads;
|
||||
bool mNoTimeout;
|
||||
|
||||
std::condition_variable mCv;
|
||||
std::mutex mCvMutex;
|
||||
|
||||
static constexpr auto kTimeoutDuration = 100ms;
|
||||
};
|
||||
|
||||
extern "C" IMultithread* HIDL_FETCH_IMultithread(const char* name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace multithread
|
||||
} // namespace tests
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_TESTS_MULTITHREAD_V1_0_MULTITHREAD_H
|
Loading…
Reference in a new issue