hidl_test: Fix failing tests.
Test: The following succeeds. croot && cd hardware/interfaces mma croot && cd system/tools/hidl mma adb shell /data/nativetest64/hidl_test/hidl_test Bug: 31819198 Change-Id: I40c2338d09d5e80b9bad2d918b7b8c3f2709f434
This commit is contained in:
parent
d5b5b2ecea
commit
9517f9c871
2 changed files with 82 additions and 36 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
|
||||||
|
#define LOG_TAG "hidl_test"
|
||||||
|
|
||||||
#include "FooCallback.h"
|
#include "FooCallback.h"
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
@ -9,68 +12,111 @@ namespace foo {
|
||||||
namespace V1_0 {
|
namespace V1_0 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NOT_REPORTED = -1LL
|
||||||
|
};
|
||||||
|
|
||||||
|
FooCallback::FooCallback()
|
||||||
|
: mLock{}, mCond{} {
|
||||||
|
for (size_t i = 0; i < invokeInfo.size(); i++) {
|
||||||
|
invokeInfo[i].invoked = false;
|
||||||
|
invokeInfo[i].timeNs = NOT_REPORTED;
|
||||||
|
invokeInfo[i].callerBlockedNs = NOT_REPORTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Return<void> FooCallback::heyItsYou(
|
Return<void> FooCallback::heyItsYou(
|
||||||
const sp<IFooCallback> &_cb) {
|
const sp<IFooCallback> &_cb) {
|
||||||
nsecs_t start = systemTime();
|
nsecs_t start = systemTime();
|
||||||
ALOGI("SERVER(FooCallback) heyItsYou cb = %p", _cb.get());
|
ALOGI("SERVER(FooCallback) 1: heyItsYou cb = %p", _cb.get());
|
||||||
mLock.lock();
|
nsecs_t end = systemTime();
|
||||||
invokeInfo[0].invoked = true;
|
{
|
||||||
invokeInfo[0].timeNs = systemTime() - start;
|
Mutex::Autolock lock(mLock);
|
||||||
mCond.signal();
|
invokeInfo[0].invoked = true;
|
||||||
mLock.unlock();
|
invokeInfo[0].timeNs = end - start;
|
||||||
|
mCond.signal();
|
||||||
|
}
|
||||||
|
ALOGI("SERVER(FooCallback) 2: heyItsYou returned");
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<bool> FooCallback::heyItsYouIsntIt(const sp<IFooCallback> &_cb) {
|
Return<bool> FooCallback::heyItsYouIsntIt(const sp<IFooCallback> &_cb) {
|
||||||
nsecs_t start = systemTime();
|
nsecs_t start = systemTime();
|
||||||
ALOGI("SERVER(FooCallback) heyItsYouIsntIt cb = %p sleeping for %" PRId64 " seconds", _cb.get(), DELAY_S);
|
ALOGI("SERVER(FooCallback) 3: heyItsYouIsntIt cb = %p sleeping for %" PRId64 " seconds", _cb.get(), DELAY_S);
|
||||||
sleep(DELAY_S);
|
sleep(DELAY_S);
|
||||||
ALOGI("SERVER(FooCallback) heyItsYouIsntIt cb = %p responding", _cb.get());
|
ALOGI("SERVER(FooCallback) 4: heyItsYouIsntIt cb = %p responding", _cb.get());
|
||||||
mLock.lock();
|
nsecs_t end = systemTime();
|
||||||
invokeInfo[1].invoked = true;
|
{
|
||||||
invokeInfo[1].timeNs = systemTime() - start;
|
Mutex::Autolock lock(mLock);
|
||||||
mCond.signal();
|
invokeInfo[1].invoked = true;
|
||||||
mLock.unlock();
|
invokeInfo[1].timeNs = end - start;
|
||||||
|
mCond.signal();
|
||||||
|
}
|
||||||
|
ALOGI("SERVER(FooCallback) 5: heyItsYouIsntIt cb = %p responding", _cb.get());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> FooCallback::heyItsTheMeaningOfLife(uint8_t tmol) {
|
Return<void> FooCallback::heyItsTheMeaningOfLife(uint8_t tmol) {
|
||||||
nsecs_t start = systemTime();
|
nsecs_t start = systemTime();
|
||||||
ALOGI("SERVER(FooCallback) heyItsTheMeaningOfLife = %d sleeping for %" PRId64 " seconds", tmol, DELAY_S);
|
ALOGI("SERVER(FooCallback) 6.1: heyItsTheMeaningOfLife = %d sleeping for %" PRId64 " seconds", tmol, DELAY_S);
|
||||||
sleep(DELAY_S);
|
sleep(DELAY_S);
|
||||||
ALOGI("SERVER(FooCallback) heyItsTheMeaningOfLife = %d done sleeping", tmol);
|
ALOGI("SERVER(FooCallback) 6.2: heyItsTheMeaningOfLife = %d done sleeping", tmol);
|
||||||
mLock.lock();
|
nsecs_t end = systemTime();
|
||||||
invokeInfo[2].invoked = true;
|
{
|
||||||
invokeInfo[2].timeNs = systemTime() - start;
|
Mutex::Autolock lock(mLock);
|
||||||
mCond.signal();
|
invokeInfo[2].invoked = true;
|
||||||
mLock.unlock();
|
invokeInfo[2].timeNs = end - start;
|
||||||
|
mCond.signal();
|
||||||
|
}
|
||||||
|
ALOGI("SERVER(FooCallback) 6.3: heyItsTheMeaningOfLife returned");
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> FooCallback::reportResults(int64_t ns, reportResults_cb cb) {
|
Return<void> FooCallback::reportResults(int64_t ns, reportResults_cb cb) {
|
||||||
ALOGI("SERVER(FooCallback) reportResults(%" PRId64 " seconds)", nanoseconds_to_seconds(ns));
|
ALOGI("SERVER(FooCallback) 8.1: reportResults(%" PRId64 " seconds)", nanoseconds_to_seconds(ns));
|
||||||
nsecs_t leftToWaitNs = ns;
|
nsecs_t leftToWaitNs = ns;
|
||||||
mLock.lock();
|
bool cond;
|
||||||
while (!(invokeInfo[0].invoked && invokeInfo[1].invoked && invokeInfo[2].invoked) &&
|
{
|
||||||
leftToWaitNs > 0) {
|
Mutex::Autolock lock(mLock);
|
||||||
nsecs_t start = systemTime();
|
while ((cond = ((!invokeInfo[0].invoked ||
|
||||||
::android::status_t rc = mCond.waitRelative(mLock, leftToWaitNs);
|
!invokeInfo[1].invoked ||
|
||||||
if (rc != ::android::OK) {
|
!invokeInfo[2].invoked ||
|
||||||
ALOGI("SERVER(FooCallback)::reportResults(%" PRId64 " ns) Condition::waitRelative(%" PRId64 ") returned error (%d)", ns, leftToWaitNs, rc);
|
invokeInfo[0].callerBlockedNs == NOT_REPORTED ||
|
||||||
break;
|
invokeInfo[1].callerBlockedNs == NOT_REPORTED ||
|
||||||
}
|
invokeInfo[2].callerBlockedNs == NOT_REPORTED) &&
|
||||||
ALOGI("SERVER(FooCallback)::reportResults(%" PRId64 " ns) Condition::waitRelative was signalled", ns);
|
leftToWaitNs > 0))) {
|
||||||
leftToWaitNs -= systemTime() - start;
|
nsecs_t start = systemTime();
|
||||||
|
::android::status_t rc = mCond.waitRelative(mLock, leftToWaitNs);
|
||||||
|
if (rc != ::android::OK) {
|
||||||
|
ALOGW("SERVER(FooCallback)::reportResults(%" PRId64 " ns) Condition::waitRelative(%" PRId64 ") returned error (%d)", ns, leftToWaitNs, rc);
|
||||||
|
if (rc == -ETIMEDOUT) {
|
||||||
|
// time's up
|
||||||
|
leftToWaitNs = -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ALOGI("SERVER(FooCallback)::reportResults(%" PRId64 " ns) Condition::waitRelative was signalled", ns);
|
||||||
|
leftToWaitNs -= systemTime() - start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mLock.unlock();
|
ALOGI("SERVER(FooCallback) 8.2: reportResults returned;"
|
||||||
|
"invoked? %d, %d, %d; leftToWaitNs = %" PRId64 "; cond = %d",
|
||||||
|
invokeInfo[0].invoked, invokeInfo[1].invoked, invokeInfo[2].invoked,
|
||||||
|
leftToWaitNs, cond);
|
||||||
cb(leftToWaitNs, invokeInfo);
|
cb(leftToWaitNs, invokeInfo);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> FooCallback::youBlockedMeFor(const hidl_array<int64_t, 3> &ns) {
|
Return<void> FooCallback::youBlockedMeFor(const hidl_array<int64_t, 3> &ns) {
|
||||||
for (size_t i = 0; i < 3; i++) {
|
ALOGI("SERVER(FooCallback) 7.1: youBlockedMeFor");
|
||||||
invokeInfo[i].callerBlockedNs = ns[i];
|
{
|
||||||
|
Mutex::Autolock lock(mLock);
|
||||||
|
for (size_t i = 0; i < 3; i++) {
|
||||||
|
invokeInfo[i].callerBlockedNs = ns[i];
|
||||||
|
}
|
||||||
|
mCond.signal();
|
||||||
}
|
}
|
||||||
|
ALOGI("SERVER(FooCallback) 7.2: returned");
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ using ::android::hardware::hidl_string;
|
||||||
using ::android::sp;
|
using ::android::sp;
|
||||||
|
|
||||||
struct FooCallback : public IFooCallback {
|
struct FooCallback : public IFooCallback {
|
||||||
FooCallback() : mLock{}, mCond{} {}
|
FooCallback();
|
||||||
// Methods from ::android::hardware::tests::foo::V1_0::IFooCallback follow.
|
// Methods from ::android::hardware::tests::foo::V1_0::IFooCallback follow.
|
||||||
Return<void> heyItsYou(const sp<IFooCallback>& cb) override;
|
Return<void> heyItsYou(const sp<IFooCallback>& cb) override;
|
||||||
Return<bool> heyItsYouIsntIt(const sp<IFooCallback>& cb) override;
|
Return<bool> heyItsYouIsntIt(const sp<IFooCallback>& cb) override;
|
||||||
|
|
Loading…
Reference in a new issue