From ebfa633103e4efbe4c39c8abf906ae597a1d7a5b Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Fri, 14 Oct 2016 10:41:41 -0700 Subject: [PATCH] Add interface methods for testing vec. Test: hidl_test Bug: 32160974 Change-Id: I7eda1650fcf8d58778b2aad97a5bd62afc95bc36 --- tests/bar/1.0/default/Android.bp | 1 + tests/bar/1.0/default/Bar.cpp | 12 ++++++++++++ tests/bar/1.0/default/Bar.h | 3 +++ tests/foo/1.0/IFoo.hal | 8 ++++++++ tests/foo/1.0/default/Android.bp | 1 + tests/foo/1.0/default/Foo.cpp | 33 ++++++++++++++++++++++++++++++++ tests/foo/1.0/default/Foo.h | 6 ++++++ 7 files changed, 64 insertions(+) diff --git a/tests/bar/1.0/default/Android.bp b/tests/bar/1.0/default/Android.bp index 0d47001c81..c2c2309bb8 100644 --- a/tests/bar/1.0/default/Android.bp +++ b/tests/bar/1.0/default/Android.bp @@ -10,6 +10,7 @@ cc_library_shared { shared_libs: [ "libbase", + "libcutils", "libhidl", "libhwbinder", "liblog", diff --git a/tests/bar/1.0/default/Bar.cpp b/tests/bar/1.0/default/Bar.cpp index 34ec087e23..b960524b20 100644 --- a/tests/bar/1.0/default/Bar.cpp +++ b/tests/bar/1.0/default/Bar.cpp @@ -130,6 +130,18 @@ Return Bar::haveAVectorOfGenericInterfaces( return Void(); } +Return Bar::createMyHandle(createMyHandle_cb _hidl_cb) { + return mFoo->createMyHandle(_hidl_cb); +} + +Return Bar::createHandles(uint32_t size, createHandles_cb _hidl_cb) { + return mFoo->createHandles(size, _hidl_cb); +} + +Return Bar::closeHandles() { + return mFoo->closeHandles(); +} + // Methods from ::android::hardware::tests::bar::V1_0::IBar follow. Return Bar::thisIsNew() { ALOGI("SERVER(Bar) thisIsNew"); diff --git a/tests/bar/1.0/default/Bar.h b/tests/bar/1.0/default/Bar.h index d2c2635e52..6fea563048 100644 --- a/tests/bar/1.0/default/Bar.h +++ b/tests/bar/1.0/default/Bar.h @@ -48,6 +48,9 @@ struct Bar : public IBar { virtual Return transpose2(const hidl_array& in, transpose2_cb _hidl_cb) override; virtual Return sendVec(const hidl_vec& data, sendVec_cb _hidl_cb) override; virtual Return sendVecVec(sendVecVec_cb _hidl_cb) override; + virtual Return createMyHandle(createMyHandle_cb _hidl_cb) override; + virtual Return createHandles(uint32_t size, createHandles_cb _hidl_cb) override; + virtual Return closeHandles() override; Return haveAVectorOfInterfaces( const hidl_vec > &in, diff --git a/tests/foo/1.0/IFoo.hal b/tests/foo/1.0/IFoo.hal index 2afaec1b5d..c06fc05b8f 100644 --- a/tests/foo/1.0/IFoo.hal +++ b/tests/foo/1.0/IFoo.hal @@ -80,6 +80,11 @@ interface IFoo { FloatArray myFloatArray; }; + struct MyHandle { + handle h; + int32_t guard; + }; + doThis(float param); doThatAndReturnSomething(int64_t param) generates (int32_t result); doQuiteABit(int32_t a, int64_t b, float c, double d) generates (double something); @@ -112,4 +117,7 @@ interface IFoo { haveAVectorOfGenericInterfaces(vec in) generates (vec out); + createMyHandle() generates (MyHandle h); + createHandles(uint32_t size) generates (vec handles); + closeHandles(); }; diff --git a/tests/foo/1.0/default/Android.bp b/tests/foo/1.0/default/Android.bp index 185e5ea465..f2ee521002 100644 --- a/tests/foo/1.0/default/Android.bp +++ b/tests/foo/1.0/default/Android.bp @@ -10,6 +10,7 @@ cc_library_shared { shared_libs: [ "libbase", + "libcutils", "libhidl", "libfootest", "libhwbinder", diff --git a/tests/foo/1.0/default/Foo.cpp b/tests/foo/1.0/default/Foo.cpp index f855f21e05..cf4f9755c6 100644 --- a/tests/foo/1.0/default/Foo.cpp +++ b/tests/foo/1.0/default/Foo.cpp @@ -291,7 +291,40 @@ Return Foo::haveAVectorOfGenericInterfaces( const hidl_vec > &in, haveAVectorOfGenericInterfaces_cb _hidl_cb) { _hidl_cb(in); + return Void(); +} +Return Foo::createMyHandle(createMyHandle_cb _hidl_cb) { + native_handle_t* nh = native_handle_create(0, 10); + int data[] = {2,3,5,7,11,13,17,19,21,23}; + CHECK(sizeof(data) == 10 * sizeof(int)); + memcpy(nh->data, data, sizeof(data)); + mHandles.push_back(nh); + + MyHandle h; + h.guard = 666; + h.h = nh; + _hidl_cb(h); + return Void(); +} + +Return Foo::createHandles(uint32_t size, createHandles_cb _hidl_cb) { + hidl_vec handles; + handles.resize(size); + for(uint32_t i = 0; i < size; ++i) { + createMyHandle([&](const MyHandle& h) { + handles[i] = h.h; + }); + } + _hidl_cb(handles); + return Void(); +} + +Return Foo::closeHandles() { + for(native_handle_t* h : mHandles) { + native_handle_delete(h); + } + mHandles.clear(); return Void(); } diff --git a/tests/foo/1.0/default/Foo.h b/tests/foo/1.0/default/Foo.h index b3785d2c1c..e61291d563 100644 --- a/tests/foo/1.0/default/Foo.h +++ b/tests/foo/1.0/default/Foo.h @@ -5,6 +5,7 @@ #include #include +#include namespace android { namespace hardware { namespace tests { @@ -44,6 +45,9 @@ struct Foo : public IFoo { virtual Return transpose2(const hidl_array& in, transpose2_cb _hidl_cb) override; virtual Return sendVec(const hidl_vec& data, sendVec_cb _hidl_cb) override; virtual Return sendVecVec(sendVecVec_cb _hidl_cb) override; + virtual Return createMyHandle(createMyHandle_cb _hidl_cb) override; + virtual Return createHandles(uint32_t size, createHandles_cb _hidl_cb) override; + virtual Return closeHandles() override; Return haveAVectorOfInterfaces( const hidl_vec > &in, @@ -52,6 +56,8 @@ struct Foo : public IFoo { Return haveAVectorOfGenericInterfaces( const hidl_vec > &in, haveAVectorOfGenericInterfaces_cb _hidl_cb) override; +private: + std::vector<::native_handle_t *> mHandles; }; extern "C" IFoo* HIDL_FETCH_IFoo(const char* name);