Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1 | #define LOG_TAG "hidl_test" |
Yifan Hong | 11992a6 | 2016-11-09 18:07:40 -0800 | [diff] [blame] | 2 | |
| 3 | #include "FooCallback.h" |
| 4 | |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 5 | #include <android-base/logging.h> |
| 6 | |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 7 | #include <android/hidl/manager/1.0/IServiceManager.h> |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 8 | #include <android/hidl/manager/1.0/IServiceNotification.h> |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 9 | |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 10 | #include <android/hidl/memory/1.0/IAllocator.h> |
| 11 | #include <android/hidl/memory/1.0/IMemory.h> |
| 12 | |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 13 | #include <android/hidl/token/1.0/ITokenManager.h> |
| 14 | |
Steven Moreland | b48a7da | 2016-11-11 14:12:46 -0800 | [diff] [blame] | 15 | #include <android/hardware/tests/foo/1.0/IFoo.h> |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 16 | #include <android/hardware/tests/foo/1.0/BnHwSimple.h> |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 17 | #include <android/hardware/tests/foo/1.0/BsSimple.h> |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 18 | #include <android/hardware/tests/foo/1.0/BpHwSimple.h> |
Steven Moreland | b48a7da | 2016-11-11 14:12:46 -0800 | [diff] [blame] | 19 | #include <android/hardware/tests/bar/1.0/IBar.h> |
Yifan Hong | 5749b2c | 2016-11-28 12:52:36 -0800 | [diff] [blame] | 20 | #include <android/hardware/tests/bar/1.0/IComplicated.h> |
Yifan Hong | 87ff823 | 2017-01-09 12:07:05 -0800 | [diff] [blame] | 21 | #include <android/hardware/tests/bar/1.0/IImportRules.h> |
Steven Moreland | b48a7da | 2016-11-11 14:12:46 -0800 | [diff] [blame] | 22 | #include <android/hardware/tests/inheritance/1.0/IFetcher.h> |
| 23 | #include <android/hardware/tests/inheritance/1.0/IGrandparent.h> |
| 24 | #include <android/hardware/tests/inheritance/1.0/IParent.h> |
| 25 | #include <android/hardware/tests/inheritance/1.0/IChild.h> |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 26 | #include <android/hardware/tests/memory/1.0/IMemoryTest.h> |
Steven Moreland | b48a7da | 2016-11-11 14:12:46 -0800 | [diff] [blame] | 27 | #include <android/hardware/tests/pointer/1.0/IGraph.h> |
| 28 | #include <android/hardware/tests/pointer/1.0/IPointer.h> |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 29 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 30 | #include <gtest/gtest.h> |
| 31 | #if GTEST_IS_THREADSAFE |
| 32 | #include <sys/types.h> |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 33 | #include <sys/wait.h> |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 34 | #include <signal.h> |
| 35 | #include <errno.h> |
| 36 | #include <pthread.h> |
| 37 | #else |
| 38 | #error "GTest did not detect pthread library." |
| 39 | #endif |
| 40 | |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 41 | #include <algorithm> |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 42 | #include <condition_variable> |
Yifan Hong | d12398d | 2016-10-13 11:05:29 -0700 | [diff] [blame] | 43 | #include <getopt.h> |
| 44 | #include <inttypes.h> |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 45 | #include <mutex> |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 46 | #include <set> |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 47 | #include <sstream> |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 48 | #include <utility> |
Yifan Hong | d12398d | 2016-10-13 11:05:29 -0700 | [diff] [blame] | 49 | #include <vector> |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 50 | |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 51 | #include <hidl-test/FooHelper.h> |
| 52 | #include <hidl-test/PointerHelper.h> |
| 53 | |
Martijn Coenen | 9391510 | 2016-09-01 01:35:52 +0200 | [diff] [blame] | 54 | #include <hidl/Status.h> |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 55 | #include <hidlmemory/mapping.h> |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 56 | |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 57 | #include <hwbinder/IPCThreadState.h> |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 58 | |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 59 | #include <utils/Condition.h> |
| 60 | #include <utils/Timers.h> |
| 61 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 62 | #define EXPECT_OK(__ret__) EXPECT_TRUE(isOk(__ret__)) |
Yifan Hong | 8446590 | 2016-09-27 15:52:17 -0700 | [diff] [blame] | 63 | #define EXPECT_FAIL(__ret__) EXPECT_FALSE(isOk(__ret__)) |
Yifan Hong | 8c48ad7 | 2016-10-14 11:34:59 -0700 | [diff] [blame] | 64 | #define EXPECT_ARRAYEQ(__a1__, __a2__, __size__) EXPECT_TRUE(isArrayEqual(__a1__, __a2__, __size__)) |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 65 | |
| 66 | // TODO uncomment this when kernel is patched with pointer changes. |
| 67 | //#define HIDL_RUN_POINTER_TESTS 1 |
| 68 | |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 69 | // forward declarations. |
| 70 | class PassthroughEnvironment; |
| 71 | class BinderizedEnvironment; |
| 72 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 73 | // static storage |
| 74 | static enum TestMode { |
| 75 | BINDERIZED, |
| 76 | PASSTHROUGH |
| 77 | } gMode; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 78 | static PassthroughEnvironment *gPassthroughEnvironment = nullptr; |
| 79 | static BinderizedEnvironment *gBinderizedEnvironment = nullptr; |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 80 | // per process tag |
| 81 | static std::string gServiceName; |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 82 | // end static storage |
| 83 | |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 84 | using ::android::hardware::tests::foo::V1_0::Abc; |
Steven Moreland | 88ca451 | 2016-08-11 11:24:10 -0700 | [diff] [blame] | 85 | using ::android::hardware::tests::foo::V1_0::IFoo; |
| 86 | using ::android::hardware::tests::foo::V1_0::IFooCallback; |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 87 | using ::android::hardware::tests::foo::V1_0::ISimple; |
Yifan Hong | 11992a6 | 2016-11-09 18:07:40 -0800 | [diff] [blame] | 88 | using ::android::hardware::tests::foo::V1_0::implementation::FooCallback; |
Steven Moreland | 88ca451 | 2016-08-11 11:24:10 -0700 | [diff] [blame] | 89 | using ::android::hardware::tests::bar::V1_0::IBar; |
Yifan Hong | 5749b2c | 2016-11-28 12:52:36 -0800 | [diff] [blame] | 90 | using ::android::hardware::tests::bar::V1_0::IComplicated; |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 91 | using ::android::hardware::tests::inheritance::V1_0::IFetcher; |
| 92 | using ::android::hardware::tests::inheritance::V1_0::IGrandparent; |
| 93 | using ::android::hardware::tests::inheritance::V1_0::IParent; |
| 94 | using ::android::hardware::tests::inheritance::V1_0::IChild; |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 95 | using ::android::hardware::tests::pointer::V1_0::IGraph; |
| 96 | using ::android::hardware::tests::pointer::V1_0::IPointer; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 97 | using ::android::hardware::tests::memory::V1_0::IMemoryTest; |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 98 | using ::android::hardware::IPCThreadState; |
Iliyan Malchev | 2b6591b | 2016-08-18 19:15:19 -0700 | [diff] [blame] | 99 | using ::android::hardware::Return; |
Iliyan Malchev | d57066f | 2016-09-08 13:59:38 -0700 | [diff] [blame] | 100 | using ::android::hardware::Void; |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 101 | using ::android::hardware::configureRpcThreadpool; |
| 102 | using ::android::hardware::joinRpcThreadpool; |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 103 | using ::android::hardware::hidl_array; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 104 | using ::android::hardware::hidl_death_recipient; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 105 | using ::android::hardware::hidl_memory; |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 106 | using ::android::hardware::hidl_string; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 107 | using ::android::hardware::hidl_vec; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 108 | using ::android::hidl::base::V1_0::IBase; |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 109 | using ::android::hidl::manager::V1_0::IServiceManager; |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 110 | using ::android::hidl::manager::V1_0::IServiceNotification; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 111 | using ::android::hidl::memory::V1_0::IAllocator; |
| 112 | using ::android::hidl::memory::V1_0::IMemory; |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 113 | using ::android::hidl::token::V1_0::ITokenManager; |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 114 | using ::android::sp; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 115 | using ::android::wp; |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 116 | using ::android::to_string; |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 117 | using ::android::Mutex; |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 118 | using ::android::MultiDimensionalToString; |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 119 | using ::android::Condition; |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 120 | using ::android::DELAY_S; |
| 121 | using ::android::DELAY_NS; |
| 122 | using ::android::TOLERANCE_NS; |
| 123 | using ::android::ONEWAY_TOLERANCE_NS; |
| 124 | using std::to_string; |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 125 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 126 | template <typename T> |
| 127 | static inline ::testing::AssertionResult isOk(::android::hardware::Return<T> ret) { |
Steven Moreland | cd00b9b | 2016-12-29 10:34:03 -0800 | [diff] [blame] | 128 | return ret.isOk() |
| 129 | ? (::testing::AssertionSuccess() << ret.description()) |
| 130 | : (::testing::AssertionFailure() << ret.description()); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | template<typename T, typename S> |
| 134 | static inline bool isArrayEqual(const T arr1, const S arr2, size_t size) { |
| 135 | for(size_t i = 0; i < size; i++) |
| 136 | if(arr1[i] != arr2[i]) |
| 137 | return false; |
| 138 | return true; |
| 139 | } |
| 140 | |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 141 | template<typename T> |
| 142 | std::string to_string(std::set<T> set) { |
| 143 | std::stringstream ss; |
| 144 | ss << "{"; |
| 145 | |
| 146 | bool first = true; |
| 147 | for (const T &item : set) { |
| 148 | if (first) { |
| 149 | first = false; |
| 150 | } else { |
| 151 | ss << ", "; |
| 152 | } |
| 153 | |
| 154 | ss << to_string(item); |
| 155 | } |
| 156 | |
| 157 | ss << "}"; |
| 158 | |
| 159 | return ss.str(); |
| 160 | } |
| 161 | |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 162 | struct Simple : public ISimple { |
| 163 | Simple(int32_t cookie) |
| 164 | : mCookie(cookie) { |
| 165 | } |
| 166 | |
| 167 | Return<int32_t> getCookie() override { |
| 168 | return mCookie; |
| 169 | } |
| 170 | |
Yifan Hong | 5749b2c | 2016-11-28 12:52:36 -0800 | [diff] [blame] | 171 | Return<void> customVecInt(customVecInt_cb _cb) override { |
| 172 | _cb(hidl_vec<int32_t>()); |
| 173 | return Void(); |
| 174 | } |
| 175 | |
| 176 | Return<void> customVecStr(customVecStr_cb _cb) override { |
| 177 | hidl_vec<hidl_string> vec; |
| 178 | vec.resize(2); |
| 179 | _cb(vec); |
| 180 | return Void(); |
| 181 | } |
| 182 | |
| 183 | Return<void> mystr(mystr_cb _cb) override { |
| 184 | _cb(hidl_string()); |
| 185 | return Void(); |
| 186 | } |
| 187 | |
| 188 | Return<void> myhandle(myhandle_cb _cb) override { |
| 189 | auto h = native_handle_create(0, 1); |
| 190 | _cb(h); |
| 191 | native_handle_delete(h); |
| 192 | return Void(); |
| 193 | } |
| 194 | |
| 195 | private: |
| 196 | int32_t mCookie; |
| 197 | }; |
| 198 | |
| 199 | struct Complicated : public IComplicated { |
| 200 | Complicated(int32_t cookie) |
| 201 | : mCookie(cookie) { |
| 202 | } |
| 203 | |
| 204 | Return<int32_t> getCookie() override { |
| 205 | return mCookie; |
| 206 | } |
| 207 | |
| 208 | Return<void> customVecInt(customVecInt_cb _cb) override { |
| 209 | _cb(hidl_vec<int32_t>()); |
| 210 | return Void(); |
| 211 | } |
| 212 | Return<void> customVecStr(customVecStr_cb _cb) override { |
| 213 | hidl_vec<hidl_string> vec; |
| 214 | vec.resize(2); |
| 215 | _cb(vec); |
| 216 | return Void(); |
| 217 | } |
| 218 | |
| 219 | Return<void> mystr(mystr_cb _cb) override { |
| 220 | _cb(hidl_string()); |
| 221 | return Void(); |
| 222 | } |
| 223 | |
| 224 | Return<void> myhandle(myhandle_cb _cb) override { |
| 225 | auto h = native_handle_create(0, 1); |
| 226 | _cb(h); |
| 227 | native_handle_delete(h); |
| 228 | return Void(); |
| 229 | } |
| 230 | |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 231 | private: |
| 232 | int32_t mCookie; |
| 233 | }; |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 234 | |
Yifan Hong | 87ff823 | 2017-01-09 12:07:05 -0800 | [diff] [blame] | 235 | // Ensure (statically) that the types in IImportRules resolves to the correct types by |
| 236 | // overriding the methods with fully namespaced types as arguments. |
| 237 | struct MyImportRules : public ::android::hardware::tests::bar::V1_0::IImportRules { |
| 238 | Return<void> rule0a( |
| 239 | const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override { |
| 240 | return Void(); |
| 241 | } |
| 242 | |
| 243 | Return<void> rule0a1( |
| 244 | const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override { |
| 245 | return Void(); |
| 246 | } |
| 247 | |
| 248 | Return<void> rule0b( |
| 249 | const ::android::hardware::tests::bar::V1_0::IImportRules::Outer&) override { |
| 250 | return Void(); |
| 251 | } |
| 252 | |
| 253 | Return<void> rule0c(const ::android::hardware::tests::foo::V1_0::Outer&) override { |
| 254 | return Void(); |
| 255 | } |
| 256 | |
| 257 | Return<void> rule0d(const ::android::hardware::tests::foo::V1_0::Outer&) override { |
| 258 | return Void(); |
| 259 | } |
| 260 | |
| 261 | Return<void> rule0e( |
| 262 | const ::android::hardware::tests::bar::V1_0::IImportRules::Outer::Inner&) override { |
| 263 | return Void(); |
| 264 | } |
| 265 | |
| 266 | Return<void> rule0f( |
| 267 | const ::android::hardware::tests::bar::V1_0::IImportRules::Outer::Inner&) override { |
| 268 | return Void(); |
| 269 | } |
| 270 | |
| 271 | Return<void> rule0g(const ::android::hardware::tests::foo::V1_0::Outer::Inner&) override { |
| 272 | return Void(); |
| 273 | } |
| 274 | |
| 275 | Return<void> rule0h(const ::android::hardware::tests::foo::V1_0::Outer::Inner&) override { |
| 276 | return Void(); |
| 277 | } |
| 278 | |
| 279 | Return<void> rule1a(const ::android::hardware::tests::bar::V1_0::Def&) override { |
| 280 | return Void(); |
| 281 | } |
| 282 | |
| 283 | Return<void> rule1b(const ::android::hardware::tests::foo::V1_0::Def&) override { |
| 284 | return Void(); |
| 285 | } |
| 286 | |
| 287 | Return<void> rule2a(const ::android::hardware::tests::foo::V1_0::Unrelated&) override { |
| 288 | return Void(); |
| 289 | } |
| 290 | |
| 291 | Return<void> rule2b(const sp<::android::hardware::tests::foo::V1_0::IFooCallback>&) override { |
| 292 | return Void(); |
| 293 | } |
| 294 | }; |
| 295 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 296 | struct ServiceNotification : public IServiceNotification { |
| 297 | std::mutex mutex; |
| 298 | std::condition_variable condition; |
| 299 | |
| 300 | Return<void> onRegistration(const hidl_string &fqName, |
| 301 | const hidl_string &name, |
| 302 | bool preexisting) override { |
| 303 | if (preexisting) { |
| 304 | // not interested in things registered from previous runs of hidl_test |
| 305 | return Void(); |
| 306 | } |
| 307 | |
| 308 | std::unique_lock<std::mutex> lock(mutex); |
| 309 | |
| 310 | mRegistered.push_back(std::string(fqName.c_str()) + "/" + name.c_str()); |
| 311 | |
| 312 | lock.unlock(); |
| 313 | condition.notify_one(); |
| 314 | |
| 315 | return Void(); |
| 316 | } |
| 317 | |
| 318 | const std::vector<std::string> &getRegistrations() const { |
| 319 | return mRegistered; |
| 320 | } |
| 321 | |
| 322 | private: |
| 323 | std::vector<std::string> mRegistered{}; |
| 324 | }; |
| 325 | |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 326 | void signal_handler(int signal) |
| 327 | { |
| 328 | if (signal == SIGTERM) { |
| 329 | ALOGD("SERVER %s shutting down...", gServiceName.c_str()); |
| 330 | IPCThreadState::shutdown(); |
| 331 | ALOGD("SERVER %s shutdown.", gServiceName.c_str()); |
| 332 | exit(0); |
| 333 | } |
| 334 | } |
| 335 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 336 | template <class T> |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 337 | static pid_t forkServer(const std::string &serviceName) { |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 338 | pid_t pid; |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 339 | |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 340 | // use fork to create and kill to destroy server processes. |
| 341 | // getStub = true to get the passthrough version as the backend for the |
| 342 | // binderized service. |
| 343 | if ((pid = fork()) == 0) { |
| 344 | // in child process |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 345 | configureRpcThreadpool(1, true /*callerWillJoin*/); |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 346 | sp<T> server = T::getService(serviceName, true); |
| 347 | gServiceName = serviceName; |
| 348 | signal(SIGTERM, signal_handler); |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 349 | ALOGD("SERVER registering %s", serviceName.c_str()); |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 350 | ::android::status_t status = server->registerAsService(serviceName); |
| 351 | if (status != ::android::OK) { |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 352 | ALOGE("SERVER could not register %s", serviceName.c_str()); |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 353 | exit(-1); |
| 354 | } |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 355 | ALOGD("SERVER starting %s", serviceName.c_str()); |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 356 | joinRpcThreadpool(); |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 357 | ALOGD("SERVER %s ends.", serviceName.c_str()); |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 358 | exit(0); |
| 359 | } |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 360 | |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 361 | // in main process |
| 362 | return pid; |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 363 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 364 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 365 | static void killServer(pid_t pid, const char *serverName) { |
| 366 | if(kill(pid, SIGTERM)) { |
| 367 | ALOGE("Could not kill %s; errno = %d", serverName, errno); |
| 368 | } else { |
| 369 | int status; |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 370 | ALOGD("Waiting for %s to exit...", serverName); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 371 | waitpid(pid, &status, 0); |
Yifan Hong | 35d6600 | 2016-10-13 12:47:44 -0700 | [diff] [blame] | 372 | if (status != 0) { |
| 373 | ALOGE("%s terminates abnormally with status %d", serverName, status); |
| 374 | } |
| 375 | ALOGD("Continuing..."); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 379 | class HidlEnvironmentBase : public ::testing::Environment { |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 380 | protected: |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 381 | std::vector<std::pair<std::string, pid_t>> mPids; |
| 382 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 383 | public: |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 384 | sp<IServiceManager> manager; |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 385 | sp<ITokenManager> tokenManager; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 386 | sp<IAllocator> ashmemAllocator; |
| 387 | sp<IMemoryTest> memoryTest; |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 388 | sp<IFetcher> fetcher; |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 389 | sp<IFoo> foo; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 390 | sp<IFoo> dyingFoo; |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 391 | sp<IBar> bar; |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 392 | sp<IGraph> graphInterface; |
| 393 | sp<IPointer> pointerInterface; |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 394 | sp<IPointer> validationPointerInterface; |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 395 | |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 396 | template <class T> |
| 397 | void addServer(const std::string &name) { |
| 398 | mPids.push_back({name, forkServer<T>(name)}); |
| 399 | } |
| 400 | |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 401 | void getServices() { |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 402 | manager = IServiceManager::getService("manager"); |
| 403 | |
| 404 | // alternatively: |
| 405 | // manager = defaultServiceManager() |
| 406 | |
| 407 | ASSERT_NE(manager, nullptr); |
| 408 | ASSERT_TRUE(manager->isRemote()); // manager is always remote |
| 409 | |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 410 | tokenManager = ITokenManager::getService("manager"); |
| 411 | ASSERT_NE(tokenManager, nullptr); |
| 412 | ASSERT_TRUE(tokenManager->isRemote()); // tokenManager is always remote |
| 413 | |
Steven Moreland | 2a75353 | 2016-12-15 12:37:49 -0800 | [diff] [blame] | 414 | ashmemAllocator = IAllocator::getService("ashmem"); |
| 415 | ASSERT_NE(ashmemAllocator, nullptr); |
| 416 | ASSERT_TRUE(ashmemAllocator->isRemote()); // allocator is always remote |
| 417 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 418 | // getStub is true if we are in passthrough mode to skip checking |
| 419 | // binderized server, false for binderized mode. |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 420 | |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 421 | memoryTest = IMemoryTest::getService("memory", gMode == PASSTHROUGH /* getStub */); |
| 422 | ASSERT_NE(memoryTest, nullptr); |
| 423 | ASSERT_EQ(memoryTest->isRemote(), gMode == BINDERIZED); |
| 424 | |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 425 | fetcher = IFetcher::getService("fetcher", gMode == PASSTHROUGH /* getStub */); |
| 426 | ASSERT_NE(fetcher, nullptr); |
| 427 | ASSERT_EQ(fetcher->isRemote(), gMode == BINDERIZED); |
| 428 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 429 | foo = IFoo::getService("foo", gMode == PASSTHROUGH /* getStub */); |
Yifan Hong | 7a82772 | 2016-10-06 17:20:12 -0700 | [diff] [blame] | 430 | ASSERT_NE(foo, nullptr); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 431 | ASSERT_EQ(foo->isRemote(), gMode == BINDERIZED); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 432 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 433 | dyingFoo = IFoo::getService("dyingFoo", gMode == PASSTHROUGH /* getStub */); |
| 434 | ASSERT_NE(foo, nullptr); |
| 435 | ASSERT_EQ(foo->isRemote(), gMode == BINDERIZED); |
| 436 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 437 | bar = IBar::getService("foo", gMode == PASSTHROUGH /* getStub */); |
Yifan Hong | 7a82772 | 2016-10-06 17:20:12 -0700 | [diff] [blame] | 438 | ASSERT_NE(bar, nullptr); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 439 | ASSERT_EQ(bar->isRemote(), gMode == BINDERIZED); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 440 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 441 | graphInterface = IGraph::getService("graph", gMode == PASSTHROUGH /* getStub */); |
Yifan Hong | 7a82772 | 2016-10-06 17:20:12 -0700 | [diff] [blame] | 442 | ASSERT_NE(graphInterface, nullptr); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 443 | ASSERT_EQ(graphInterface->isRemote(), gMode == BINDERIZED); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 444 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 445 | pointerInterface = IPointer::getService("pointer", gMode == PASSTHROUGH /* getStub */); |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 446 | ASSERT_NE(pointerInterface, nullptr); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 447 | ASSERT_EQ(pointerInterface->isRemote(), gMode == BINDERIZED); |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 448 | |
| 449 | // use passthrough mode as the validation object. |
| 450 | validationPointerInterface = IPointer::getService("pointer", true /* getStub */); |
| 451 | ASSERT_NE(validationPointerInterface, nullptr); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 452 | } |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 453 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 454 | void killServer(const char *serverName) { |
| 455 | for (const auto &pair : mPids) { |
| 456 | if (pair.first == serverName) { |
| 457 | ::killServer(pair.second, pair.first.c_str()); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 462 | virtual void TearDown() { |
| 463 | // clean up by killing server processes. |
| 464 | ALOGI("Environment tear-down beginning..."); |
| 465 | ALOGI("Killing servers..."); |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 466 | for (const auto &pair : mPids) { |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 467 | ::killServer(pair.second, pair.first.c_str()); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 468 | } |
| 469 | ALOGI("Servers all killed."); |
| 470 | ALOGI("Environment tear-down complete."); |
| 471 | } |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 472 | }; |
| 473 | |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 474 | class PassthroughEnvironment : public HidlEnvironmentBase { |
| 475 | private: |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 476 | virtual void SetUp() { |
| 477 | ALOGI("Environment setup beginning..."); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 478 | // starts this even for passthrough mode. |
| 479 | // this is used in Bar's default implementation |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 480 | addServer<IChild>("child"); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 481 | sleep(1); |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 482 | getServices(); |
| 483 | ALOGI("Environment setup complete."); |
| 484 | } |
| 485 | }; |
| 486 | |
| 487 | class BinderizedEnvironment : public HidlEnvironmentBase { |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 488 | public: |
| 489 | virtual void SetUp() { |
| 490 | ALOGI("Environment setup beginning..."); |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 491 | |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 492 | addServer<IMemoryTest>("memory"); |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 493 | addServer<IChild>("child"); |
| 494 | addServer<IParent>("parent"); |
| 495 | addServer<IFetcher>("fetcher"); |
| 496 | addServer<IBar>("foo"); |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 497 | addServer<IFoo>("dyingFoo"); |
Yifan Hong | ccd782b | 2016-11-28 09:41:46 -0800 | [diff] [blame] | 498 | addServer<IGraph>("graph"); |
| 499 | addServer<IPointer>("pointer"); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 500 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 501 | sleep(1); |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 502 | getServices(); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 503 | ALOGI("Environment setup complete."); |
| 504 | } |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 505 | }; |
| 506 | |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 507 | class HidlTest : public ::testing::Test { |
| 508 | public: |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 509 | sp<IServiceManager> manager; |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 510 | sp<ITokenManager> tokenManager; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 511 | sp<IAllocator> ashmemAllocator; |
| 512 | sp<IMemoryTest> memoryTest; |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 513 | sp<IFetcher> fetcher; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 514 | sp<IFoo> foo; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 515 | sp<IFoo> dyingFoo; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 516 | sp<IBar> bar; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 517 | sp<IGraph> graphInterface; |
| 518 | sp<IPointer> pointerInterface; |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 519 | sp<IPointer> validationPointerInterface; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 520 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 521 | void killServer(const char *serverName) { |
| 522 | HidlEnvironmentBase *env; |
| 523 | if (gMode == BINDERIZED) { |
| 524 | env = gBinderizedEnvironment; |
| 525 | } else { |
| 526 | env = gPassthroughEnvironment; |
| 527 | } |
| 528 | env->killServer(serverName); |
| 529 | } |
| 530 | |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 531 | virtual void SetUp() override { |
| 532 | ALOGI("Test setup beginning..."); |
| 533 | HidlEnvironmentBase *env; |
| 534 | if (gMode == BINDERIZED) { |
| 535 | env = gBinderizedEnvironment; |
| 536 | } else { |
| 537 | env = gPassthroughEnvironment; |
| 538 | } |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 539 | manager = env->manager; |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 540 | tokenManager = env->tokenManager; |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 541 | ashmemAllocator = env->ashmemAllocator; |
| 542 | memoryTest = env->memoryTest; |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 543 | fetcher = env->fetcher; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 544 | foo = env->foo; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 545 | dyingFoo = env->dyingFoo; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 546 | bar = env->bar; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 547 | graphInterface = env->graphInterface; |
| 548 | pointerInterface = env->pointerInterface; |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 549 | validationPointerInterface = env->validationPointerInterface; |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 550 | ALOGI("Test setup complete"); |
| 551 | } |
| 552 | }; |
| 553 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 554 | TEST_F(HidlTest, ToStringTest) { |
| 555 | using namespace android::hardware; |
| 556 | |
| 557 | LOG(INFO) << toString(IFoo::Everything{}); |
| 558 | |
Martijn Coenen | f7b596b | 2017-01-13 14:07:59 +0100 | [diff] [blame] | 559 | // Note that handles don't need to be deleted because MQDescriptor takes ownership |
| 560 | // and deletes them when destructed. |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 561 | auto handle = native_handle_create(0, 1); |
Martijn Coenen | f7b596b | 2017-01-13 14:07:59 +0100 | [diff] [blame] | 562 | auto handle2 = native_handle_create(0, 1); |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 563 | handle->data[0] = 5; |
Martijn Coenen | f7b596b | 2017-01-13 14:07:59 +0100 | [diff] [blame] | 564 | handle2->data[0] = 6; |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 565 | IFoo::Everything e { |
| 566 | .u = {.p = reinterpret_cast<void *>(0x5)}, |
| 567 | .number = 10, |
| 568 | .h = handle, |
| 569 | .descSync = {std::vector<GrantorDescriptor>(), handle, 5}, |
Martijn Coenen | f7b596b | 2017-01-13 14:07:59 +0100 | [diff] [blame] | 570 | .descUnsync = {std::vector<GrantorDescriptor>(), handle2, 6}, |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 571 | .mem = hidl_memory("mymem", handle, 5), |
| 572 | .p = reinterpret_cast<void *>(0x6), |
| 573 | .vs = {"hello", "world"}, |
| 574 | .multidimArray = hidl_vec<hidl_string>{"hello", "great", "awesome", "nice"}.data(), |
| 575 | .sArray = hidl_vec<hidl_string>{"awesome", "thanks", "you're welcome"}.data(), |
| 576 | .anotherStruct = {.first = "first", .last = "last"}, |
| 577 | .bf = IFoo::BitField::V0 | IFoo::BitField::V2 |
| 578 | }; |
| 579 | LOG(INFO) << toString(e); |
| 580 | LOG(INFO) << toString(foo); |
| 581 | // toString is for debugging purposes only; no good EXPECT |
| 582 | // statement can be written here. |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 585 | TEST_F(HidlTest, ServiceListTest) { |
| 586 | static const std::set<std::string> binderizedSet = { |
| 587 | "android.hardware.tests.pointer@1.0::IPointer/pointer", |
| 588 | "android.hardware.tests.bar@1.0::IBar/foo", |
| 589 | "android.hardware.tests.inheritance@1.0::IFetcher/fetcher", |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 590 | "android.hardware.tests.inheritance@1.0::IParent/parent", |
| 591 | "android.hardware.tests.inheritance@1.0::IParent/child", |
| 592 | "android.hardware.tests.inheritance@1.0::IChild/child", |
| 593 | "android.hardware.tests.pointer@1.0::IGraph/graph", |
| 594 | "android.hardware.tests.inheritance@1.0::IGrandparent/child", |
| 595 | "android.hardware.tests.foo@1.0::IFoo/foo", |
| 596 | "android.hidl.manager@1.0::IServiceManager/manager", |
| 597 | }; |
| 598 | |
| 599 | static const std::set<std::string> passthroughSet = { |
| 600 | "android.hidl.manager@1.0::IServiceManager/manager" |
| 601 | }; |
| 602 | |
| 603 | std::set<std::string> activeSet; |
| 604 | |
| 605 | switch(gMode) { |
| 606 | case BINDERIZED: { |
| 607 | activeSet = binderizedSet; |
| 608 | } break; |
| 609 | |
| 610 | case PASSTHROUGH: { |
| 611 | activeSet = passthroughSet; |
| 612 | } break; |
| 613 | default: |
| 614 | EXPECT_TRUE(false) << "unrecognized mode"; |
| 615 | } |
| 616 | |
| 617 | EXPECT_OK(manager->list([&activeSet](const hidl_vec<hidl_string> ®istered){ |
| 618 | std::set<std::string> registeredSet; |
| 619 | |
| 620 | for (size_t i = 0; i < registered.size(); i++) { |
| 621 | registeredSet.insert(registered[i]); |
| 622 | } |
| 623 | |
| 624 | std::set<std::string> difference; |
| 625 | std::set_difference(activeSet.begin(), activeSet.end(), |
| 626 | registeredSet.begin(), registeredSet.end(), |
| 627 | std::inserter(difference, difference.begin())); |
| 628 | |
| 629 | EXPECT_EQ(difference.size(), 0u) << "service(s) not registered " << to_string(difference); |
| 630 | })); |
| 631 | } |
| 632 | |
| 633 | // passthrough TODO(b/32747392) |
| 634 | TEST_F(HidlTest, ServiceListByInterfaceTest) { |
| 635 | if (gMode == BINDERIZED) { |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 636 | EXPECT_OK(manager->listByInterface(IParent::descriptor, |
Steven Moreland | 01bcb77 | 2016-11-08 15:57:25 -0800 | [diff] [blame] | 637 | [](const hidl_vec<hidl_string> ®istered) { |
| 638 | std::set<std::string> registeredSet; |
| 639 | |
| 640 | for (size_t i = 0; i < registered.size(); i++) { |
| 641 | registeredSet.insert(registered[i]); |
| 642 | } |
| 643 | |
| 644 | std::set<std::string> activeSet = { |
| 645 | "parent", "child" |
| 646 | }; |
| 647 | std::set<std::string> difference; |
| 648 | std::set_difference(activeSet.begin(), activeSet.end(), |
| 649 | registeredSet.begin(), registeredSet.end(), |
| 650 | std::inserter(difference, difference.begin())); |
| 651 | |
| 652 | EXPECT_EQ(difference.size(), 0u) << "service(s) not registered " << to_string(difference); |
| 653 | })); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | // passthrough TODO(b/32747392) |
| 658 | TEST_F(HidlTest, ServiceParentTest) { |
| 659 | if (gMode == BINDERIZED) { |
| 660 | sp<IParent> parent = IParent::getService("child"); |
| 661 | |
| 662 | EXPECT_NE(parent, nullptr); |
| 663 | } |
| 664 | } |
| 665 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 666 | // passthrough TODO(b/32747392) |
| 667 | TEST_F(HidlTest, ServiceNotificationTest) { |
| 668 | if (gMode == BINDERIZED) { |
| 669 | ServiceNotification *notification = new ServiceNotification(); |
| 670 | |
| 671 | std::string instanceName = "test-instance"; |
| 672 | EXPECT_TRUE(ISimple::registerForNotifications(instanceName, notification)); |
| 673 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 674 | Simple* instance = new Simple(1); |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 675 | EXPECT_EQ(::android::OK, instance->registerAsService(instanceName)); |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 676 | |
| 677 | std::unique_lock<std::mutex> lock(notification->mutex); |
| 678 | |
| 679 | notification->condition.wait_for( |
| 680 | lock, |
| 681 | std::chrono::milliseconds(2), |
| 682 | [¬ification]() { |
| 683 | return notification->getRegistrations().size() >= 1; |
| 684 | }); |
| 685 | |
| 686 | std::vector<std::string> registrations = notification->getRegistrations(); |
| 687 | |
| 688 | EXPECT_EQ(registrations.size(), 1u); |
| 689 | |
| 690 | EXPECT_EQ(to_string(registrations.data(), registrations.size()), |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 691 | std::string("['") + Simple::descriptor + "/" + instanceName + "']"); |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | // passthrough TODO(b/32747392) |
| 696 | TEST_F(HidlTest, ServiceAllNotificationTest) { |
| 697 | if (gMode == BINDERIZED) { |
| 698 | ServiceNotification *notification = new ServiceNotification(); |
| 699 | |
| 700 | std::string instanceOne = "test-instance-one"; |
| 701 | std::string instanceTwo = "test-instance-two"; |
| 702 | EXPECT_TRUE(ISimple::registerForNotifications("", notification)); |
| 703 | |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 704 | Simple* instanceA = new Simple(1); |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 705 | EXPECT_EQ(::android::OK, instanceA->registerAsService(instanceOne)); |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 706 | Simple* instanceB = new Simple(2); |
Steven Moreland | c7167ca | 2016-11-28 11:29:55 -0800 | [diff] [blame] | 707 | EXPECT_EQ(::android::OK, instanceB->registerAsService(instanceTwo)); |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 708 | |
| 709 | std::unique_lock<std::mutex> lock(notification->mutex); |
| 710 | |
| 711 | notification->condition.wait_for( |
| 712 | lock, |
| 713 | std::chrono::milliseconds(2), |
| 714 | [¬ification]() { |
| 715 | return notification->getRegistrations().size() >= 2; |
| 716 | }); |
| 717 | |
| 718 | std::vector<std::string> registrations = notification->getRegistrations(); |
| 719 | std::sort(registrations.begin(), registrations.end()); |
| 720 | |
| 721 | EXPECT_EQ(registrations.size(), 2u); |
| 722 | |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 723 | std::string descriptor = ISimple::descriptor; |
Steven Moreland | 0693f31 | 2016-11-09 15:06:14 -0800 | [diff] [blame] | 724 | |
| 725 | EXPECT_EQ(to_string(registrations.data(), registrations.size()), |
| 726 | "['" + descriptor + "/" + instanceOne + "', '" |
| 727 | + descriptor + "/" + instanceTwo + "']"); |
| 728 | } |
| 729 | } |
| 730 | |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 731 | TEST_F(HidlTest, TestToken) { |
| 732 | Return<uint64_t> ret = tokenManager->createToken(manager); |
| 733 | EXPECT_OK(ret); |
| 734 | uint64_t token = ret; |
| 735 | |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 736 | Return<sp<IBase>> retService = tokenManager->get(token); |
| 737 | EXPECT_OK(retService); |
| 738 | if (retService.isOk()) { |
| 739 | sp<IBase> service = retService; |
| 740 | EXPECT_NE(nullptr, service.get()); |
| 741 | sp<IServiceManager> retManager = IServiceManager::castFrom(service); |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 742 | |
| 743 | // TODO(b/33818800): should have only one Bp per process |
| 744 | // EXPECT_EQ(manager, retManager); |
| 745 | |
| 746 | EXPECT_NE(nullptr, retManager.get()); |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 747 | } |
Steven Moreland | aa2b83a | 2016-12-21 15:52:11 -0800 | [diff] [blame] | 748 | |
| 749 | Return<bool> unregisterRet = tokenManager->unregister(token); |
| 750 | |
| 751 | EXPECT_OK(unregisterRet); |
| 752 | if (unregisterRet.isOk()) { |
| 753 | EXPECT_TRUE(ret); |
| 754 | } |
| 755 | } |
| 756 | |
Martijn Coenen | 99e6beb | 2016-12-01 15:48:42 +0100 | [diff] [blame] | 757 | TEST_F(HidlTest, TestSharedMemory) { |
| 758 | const uint8_t kValue = 0xCA; |
| 759 | hidl_memory mem_copy; |
| 760 | EXPECT_OK(ashmemAllocator->allocate(1024, [&](bool success, const hidl_memory& mem) { |
| 761 | EXPECT_EQ(success, true); |
| 762 | |
| 763 | sp<IMemory> memory = mapMemory(mem); |
| 764 | |
| 765 | EXPECT_NE(memory, nullptr); |
| 766 | |
| 767 | uint8_t* data = static_cast<uint8_t*>(static_cast<void*>(memory->getPointer())); |
| 768 | EXPECT_NE(data, nullptr); |
| 769 | |
| 770 | EXPECT_EQ(memory->getSize(), mem.size()); |
| 771 | |
| 772 | memory->update(); |
| 773 | memset(data, 0, memory->getSize()); |
| 774 | memory->commit(); |
| 775 | |
| 776 | mem_copy = mem; |
| 777 | memoryTest->fillMemory(mem, kValue); |
| 778 | for (size_t i = 0; i < mem.size(); i++) { |
| 779 | EXPECT_EQ(kValue, data[i]); |
| 780 | } |
| 781 | })); |
| 782 | |
| 783 | // Test the memory persists after the call |
| 784 | sp<IMemory> memory = mapMemory(mem_copy); |
| 785 | |
| 786 | EXPECT_NE(memory, nullptr); |
| 787 | |
| 788 | uint8_t* data = static_cast<uint8_t*>(static_cast<void*>(memory->getPointer())); |
| 789 | EXPECT_NE(data, nullptr); |
| 790 | |
| 791 | for (size_t i = 0; i < mem_copy.size(); i++) { |
| 792 | EXPECT_EQ(kValue, data[i]); |
| 793 | } |
| 794 | } |
| 795 | |
Steven Moreland | f31f165 | 2017-01-06 18:33:42 -0800 | [diff] [blame] | 796 | TEST_F(HidlTest, NullSharedMemory) { |
| 797 | hidl_memory memory{}; |
| 798 | |
| 799 | EXPECT_EQ(nullptr, memory.handle()); |
| 800 | |
| 801 | EXPECT_OK(memoryTest->haveSomeMemory(memory, [&](const hidl_memory &mem) { |
| 802 | EXPECT_EQ(nullptr, mem.handle()); |
| 803 | })); |
| 804 | } |
| 805 | |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 806 | TEST_F(HidlTest, FooGetDescriptorTest) { |
| 807 | EXPECT_OK(foo->interfaceDescriptor([&] (const auto &desc) { |
| 808 | EXPECT_EQ(desc, gMode == BINDERIZED |
| 809 | ? IBar::descriptor // service is actually IBar in binderized mode |
| 810 | : IFoo::descriptor); // dlopened, so service is IFoo |
| 811 | })); |
| 812 | } |
| 813 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 814 | TEST_F(HidlTest, FooDoThisTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 815 | ALOGI("CLIENT call doThis."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 816 | EXPECT_OK(foo->doThis(1.0f)); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 817 | ALOGI("CLIENT doThis returned."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 818 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 819 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 820 | TEST_F(HidlTest, FooDoThatAndReturnSomethingTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 821 | ALOGI("CLIENT call doThatAndReturnSomething."); |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 822 | int32_t result = foo->doThatAndReturnSomething(2.0f); |
| 823 | ALOGI("CLIENT doThatAndReturnSomething returned %d.", result); |
| 824 | EXPECT_EQ(result, 666); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 825 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 826 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 827 | TEST_F(HidlTest, FooDoQuiteABitTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 828 | ALOGI("CLIENT call doQuiteABit"); |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 829 | double something = foo->doQuiteABit(1, 2, 3.0f, 4.0); |
| 830 | ALOGI("CLIENT doQuiteABit returned %f.", something); |
| 831 | EXPECT_DOUBLE_EQ(something, 666.5); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | TEST_F(HidlTest, FooDoSomethingElseTest) { |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 835 | |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 836 | ALOGI("CLIENT call doSomethingElse"); |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 837 | hidl_array<int32_t, 15> param; |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 838 | for (size_t i = 0; i < sizeof(param) / sizeof(param[0]); ++i) { |
| 839 | param[i] = i; |
| 840 | } |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 841 | EXPECT_OK(foo->doSomethingElse(param, [&](const auto &something) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 842 | ALOGI("CLIENT doSomethingElse returned %s.", |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 843 | to_string(something).c_str()); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 844 | int32_t expect[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, |
| 845 | 26, 28, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2}; |
Steven Moreland | e70455b | 2016-09-14 15:46:36 -0700 | [diff] [blame] | 846 | EXPECT_TRUE(isArrayEqual(something, expect, 32)); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 847 | })); |
| 848 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 849 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 850 | TEST_F(HidlTest, FooDoStuffAndReturnAStringTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 851 | ALOGI("CLIENT call doStuffAndReturnAString"); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 852 | EXPECT_OK(foo->doStuffAndReturnAString([&](const auto &something) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 853 | ALOGI("CLIENT doStuffAndReturnAString returned '%s'.", |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 854 | something.c_str()); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 855 | EXPECT_STREQ(something.c_str(), "Hello, world"); |
Steven Moreland | 6e3f9f4 | 2017-01-30 11:41:49 -0800 | [diff] [blame] | 856 | EXPECT_EQ(strlen("Hello, world"), something.size()); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 857 | })); |
| 858 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 859 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 860 | TEST_F(HidlTest, FooMapThisVectorTest) { |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 861 | hidl_vec<int32_t> vecParam; |
| 862 | vecParam.resize(10); |
| 863 | for (size_t i = 0; i < 10; ++i) { |
| 864 | vecParam[i] = i; |
| 865 | } |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 866 | EXPECT_OK(foo->mapThisVector(vecParam, [&](const auto &something) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 867 | ALOGI("CLIENT mapThisVector returned %s.", |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 868 | to_string(something).c_str()); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 869 | int32_t expect[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18}; |
Steven Moreland | e70455b | 2016-09-14 15:46:36 -0700 | [diff] [blame] | 870 | EXPECT_TRUE(isArrayEqual(something, expect, something.size())); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 871 | })); |
| 872 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 873 | |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 874 | TEST_F(HidlTest, WrapTest) { |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 875 | using ::android::hardware::tests::foo::V1_0::BnHwSimple; |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 876 | using ::android::hardware::tests::foo::V1_0::BsSimple; |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 877 | using ::android::hardware::tests::foo::V1_0::BpHwSimple; |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 878 | using ::android::hardware::HidlInstrumentor; |
| 879 | nsecs_t now; |
| 880 | int i = 0; |
| 881 | |
| 882 | now = systemTime(); |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 883 | new BnHwSimple(new Simple(1)); |
| 884 | EXPECT_LT(systemTime() - now, 2000000) << " for BnHwSimple(nonnull)"; |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 885 | |
| 886 | now = systemTime(); |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 887 | new BnHwSimple(nullptr); |
| 888 | EXPECT_LT(systemTime() - now, 2000000) << " for BnHwSimple(null)"; |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 889 | |
| 890 | now = systemTime(); |
| 891 | new BsSimple(new Simple(1)); |
| 892 | EXPECT_LT(systemTime() - now, 2000000) << " for BsSimple(nonnull)"; |
| 893 | |
| 894 | now = systemTime(); |
| 895 | new BsSimple(nullptr); |
| 896 | EXPECT_LT(systemTime() - now, 2000000) << " for BsSimple(null)"; |
| 897 | |
| 898 | now = systemTime(); |
Yifan Hong | 01e7cde | 2017-01-09 17:45:45 -0800 | [diff] [blame] | 899 | new BpHwSimple(nullptr); |
| 900 | EXPECT_LT(systemTime() - now, 2000000) << " for BpHwSimple(null)"; |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 901 | |
| 902 | now = systemTime(); |
Zhuoyao Zhang | d10feea | 2017-01-23 17:29:58 -0800 | [diff] [blame] | 903 | new ::android::hardware::HidlInstrumentor("", ""); |
Yifan Hong | def2cfb | 2016-12-14 16:00:24 -0800 | [diff] [blame] | 904 | EXPECT_LT(systemTime() - now, 2000000) << " for HidlInstrumentor"; |
| 905 | |
| 906 | now = systemTime(); |
| 907 | i++; |
| 908 | EXPECT_LT(systemTime() - now, 1000) << " for nothing"; |
| 909 | } |
| 910 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 911 | TEST_F(HidlTest, FooCallMeTest) { |
Yifan Hong | 11992a6 | 2016-11-09 18:07:40 -0800 | [diff] [blame] | 912 | |
| 913 | sp<IFooCallback> fooCb = new FooCallback(); |
| 914 | |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 915 | ALOGI("CLIENT call callMe."); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 916 | // callMe is oneway, should return instantly. |
| 917 | nsecs_t now; |
| 918 | now = systemTime(); |
| 919 | EXPECT_OK(foo->callMe(fooCb)); |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 920 | EXPECT_LT(systemTime() - now, ONEWAY_TOLERANCE_NS); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 921 | ALOGI("CLIENT callMe returned."); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 922 | |
| 923 | // Bar::callMe will invoke three methods on FooCallback; one will return |
| 924 | // right away (even though it is a two-way method); the second one will |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 925 | // block Bar for DELAY_S seconds, and the third one will return |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 926 | // to Bar right away (is oneway) but will itself block for DELAY_S seconds. |
| 927 | // We need a way to make sure that these three things have happened within |
| 928 | // 2*DELAY_S seconds plus some small tolerance. |
| 929 | // |
| 930 | // Method FooCallback::reportResults() takes a timeout parameter. It blocks for |
| 931 | // that length of time, while waiting for the three methods above to |
| 932 | // complete. It returns the information of whether each method was invoked, |
| 933 | // as well as how long the body of the method took to execute. We verify |
| 934 | // the information returned by reportResults() against the timeout we pass (which |
| 935 | // is long enough for the method bodies to execute, plus tolerance), and |
| 936 | // verify that eachof them executed, as expected, and took the length of |
| 937 | // time to execute that we also expect. |
| 938 | |
Yifan Hong | fcf94e4 | 2016-12-07 15:49:51 -0800 | [diff] [blame] | 939 | const nsecs_t waitNs = |
| 940 | 3 * DELAY_NS + TOLERANCE_NS; |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 941 | const nsecs_t reportResultsNs = |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 942 | 2 * DELAY_NS + TOLERANCE_NS; |
Andreas Huber | 03866f5 | 2016-08-30 14:19:52 -0700 | [diff] [blame] | 943 | |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 944 | ALOGI("CLIENT: Waiting for up to %" PRId64 " seconds.", |
Yifan Hong | fcf94e4 | 2016-12-07 15:49:51 -0800 | [diff] [blame] | 945 | nanoseconds_to_seconds(waitNs)); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 946 | |
Yifan Hong | fcf94e4 | 2016-12-07 15:49:51 -0800 | [diff] [blame] | 947 | fooCb->reportResults(waitNs, |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 948 | [&](int64_t timeLeftNs, |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 949 | const hidl_array<IFooCallback::InvokeInfo, 3> &invokeResults) { |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 950 | ALOGI("CLIENT: FooCallback::reportResults() is returning data."); |
| 951 | ALOGI("CLIENT: Waited for %" PRId64 " milliseconds.", |
Yifan Hong | fcf94e4 | 2016-12-07 15:49:51 -0800 | [diff] [blame] | 952 | nanoseconds_to_milliseconds(waitNs - timeLeftNs)); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 953 | |
Yifan Hong | fcf94e4 | 2016-12-07 15:49:51 -0800 | [diff] [blame] | 954 | EXPECT_LE(waitNs - timeLeftNs, reportResultsNs) |
| 955 | << "waited for " |
| 956 | << (timeLeftNs >= 0 ? "" : "more than ") |
| 957 | << (timeLeftNs >= 0 ? (waitNs - timeLeftNs) : waitNs) |
| 958 | << "ns, expect to finish in " |
| 959 | << reportResultsNs << " ns"; |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 960 | |
| 961 | // two-way method, was supposed to return right away |
| 962 | EXPECT_TRUE(invokeResults[0].invoked); |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 963 | EXPECT_LE(invokeResults[0].timeNs, invokeResults[0].callerBlockedNs); |
| 964 | EXPECT_LE(invokeResults[0].callerBlockedNs, TOLERANCE_NS); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 965 | // two-way method, was supposed to block caller for DELAY_NS |
| 966 | EXPECT_TRUE(invokeResults[1].invoked); |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 967 | EXPECT_LE(invokeResults[1].timeNs, invokeResults[1].callerBlockedNs); |
| 968 | EXPECT_LE(invokeResults[1].callerBlockedNs, |
| 969 | DELAY_NS + TOLERANCE_NS); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 970 | // one-way method, do not block caller, but body was supposed to block for DELAY_NS |
| 971 | EXPECT_TRUE(invokeResults[2].invoked); |
Yifan Hong | 3eac8a3 | 2016-10-11 10:02:59 -0700 | [diff] [blame] | 972 | EXPECT_LE(invokeResults[2].callerBlockedNs, ONEWAY_TOLERANCE_NS); |
| 973 | EXPECT_LE(invokeResults[2].timeNs, DELAY_NS + TOLERANCE_NS); |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 974 | }); |
| 975 | } |
| 976 | |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 977 | |
| 978 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 979 | TEST_F(HidlTest, FooUseAnEnumTest) { |
| 980 | ALOGI("CLIENT call useAnEnum."); |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 981 | IFoo::SomeEnum sleepy = foo->useAnEnum(IFoo::SomeEnum::quux); |
| 982 | ALOGI("CLIENT useAnEnum returned %u", (unsigned)sleepy); |
| 983 | EXPECT_EQ(sleepy, IFoo::SomeEnum::goober); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 984 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 985 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 986 | TEST_F(HidlTest, FooHaveAGooberTest) { |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 987 | hidl_vec<IFoo::Goober> gooberVecParam; |
| 988 | gooberVecParam.resize(2); |
| 989 | gooberVecParam[0].name = "Hello"; |
| 990 | gooberVecParam[1].name = "World"; |
| 991 | |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 992 | ALOGI("CLIENT call haveAGooberVec."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 993 | EXPECT_OK(foo->haveAGooberVec(gooberVecParam)); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 994 | ALOGI("CLIENT haveAGooberVec returned."); |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 995 | |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 996 | ALOGI("CLIENT call haveaGoober."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 997 | EXPECT_OK(foo->haveAGoober(gooberVecParam[0])); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 998 | ALOGI("CLIENT haveaGoober returned."); |
| 999 | |
| 1000 | ALOGI("CLIENT call haveAGooberArray."); |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1001 | hidl_array<IFoo::Goober, 20> gooberArrayParam; |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1002 | EXPECT_OK(foo->haveAGooberArray(gooberArrayParam)); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1003 | ALOGI("CLIENT haveAGooberArray returned."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1004 | } |
Steven Moreland | 88ca451 | 2016-08-11 11:24:10 -0700 | [diff] [blame] | 1005 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1006 | TEST_F(HidlTest, FooHaveATypeFromAnotherFileTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1007 | ALOGI("CLIENT call haveATypeFromAnotherFile."); |
Steven Moreland | 88ca451 | 2016-08-11 11:24:10 -0700 | [diff] [blame] | 1008 | Abc abcParam{}; |
| 1009 | abcParam.x = "alphabet"; |
| 1010 | abcParam.y = 3.14f; |
Yifan Hong | a65bb2c | 2016-10-27 13:17:14 -0700 | [diff] [blame] | 1011 | native_handle_t *handle = native_handle_create(0, 0); |
| 1012 | abcParam.z = handle; |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1013 | EXPECT_OK(foo->haveATypeFromAnotherFile(abcParam)); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1014 | ALOGI("CLIENT haveATypeFromAnotherFile returned."); |
Yifan Hong | a65bb2c | 2016-10-27 13:17:14 -0700 | [diff] [blame] | 1015 | native_handle_delete(handle); |
Steven Moreland | 88ca451 | 2016-08-11 11:24:10 -0700 | [diff] [blame] | 1016 | abcParam.z = NULL; |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1017 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1018 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1019 | TEST_F(HidlTest, FooHaveSomeStringsTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1020 | ALOGI("CLIENT call haveSomeStrings."); |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1021 | hidl_array<hidl_string, 3> stringArrayParam; |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1022 | stringArrayParam[0] = "What"; |
| 1023 | stringArrayParam[1] = "a"; |
| 1024 | stringArrayParam[2] = "disaster"; |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1025 | EXPECT_OK(foo->haveSomeStrings( |
| 1026 | stringArrayParam, |
| 1027 | [&](const auto &out) { |
| 1028 | ALOGI("CLIENT haveSomeStrings returned %s.", |
| 1029 | to_string(out).c_str()); |
| 1030 | |
| 1031 | EXPECT_EQ(to_string(out), "['Hello', 'World']"); |
| 1032 | })); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1033 | ALOGI("CLIENT haveSomeStrings returned."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1034 | } |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1035 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1036 | TEST_F(HidlTest, FooHaveAStringVecTest) { |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1037 | ALOGI("CLIENT call haveAStringVec."); |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1038 | hidl_vec<hidl_string> stringVecParam; |
| 1039 | stringVecParam.resize(3); |
| 1040 | stringVecParam[0] = "What"; |
| 1041 | stringVecParam[1] = "a"; |
| 1042 | stringVecParam[2] = "disaster"; |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1043 | EXPECT_OK(foo->haveAStringVec( |
| 1044 | stringVecParam, |
| 1045 | [&](const auto &out) { |
| 1046 | ALOGI("CLIENT haveAStringVec returned %s.", |
| 1047 | to_string(out).c_str()); |
| 1048 | |
| 1049 | EXPECT_EQ(to_string(out), "['Hello', 'World']"); |
| 1050 | })); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1051 | ALOGI("CLIENT haveAStringVec returned."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1052 | } |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 1053 | |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1054 | TEST_F(HidlTest, FooTransposeMeTest) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1055 | hidl_array<float, 3, 5> in; |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1056 | float k = 1.0f; |
| 1057 | for (size_t i = 0; i < 3; ++i) { |
| 1058 | for (size_t j = 0; j < 5; ++j, ++k) { |
| 1059 | in[i][j] = k; |
| 1060 | } |
| 1061 | } |
| 1062 | |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1063 | ALOGI("CLIENT call transposeMe(%s).", to_string(in).c_str()); |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | EXPECT_OK(foo->transposeMe( |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1066 | in, |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1067 | [&](const auto &out) { |
| 1068 | ALOGI("CLIENT transposeMe returned %s.", |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1069 | to_string(out).c_str()); |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1070 | |
| 1071 | for (size_t i = 0; i < 3; ++i) { |
| 1072 | for (size_t j = 0; j < 5; ++j) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1073 | EXPECT_EQ(out[j][i], in[i][j]); |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | })); |
| 1077 | } |
| 1078 | |
| 1079 | TEST_F(HidlTest, FooCallingDrWhoTest) { |
| 1080 | IFoo::MultiDimensional in; |
| 1081 | |
| 1082 | size_t k = 0; |
| 1083 | for (size_t i = 0; i < 5; ++i) { |
| 1084 | for (size_t j = 0; j < 3; ++j, ++k) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1085 | in.quuxMatrix[i][j].first = ("First " + std::to_string(k)).c_str(); |
| 1086 | in.quuxMatrix[i][j].last = ("Last " + std::to_string(15-k)).c_str(); |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | ALOGI("CLIENT call callingDrWho(%s).", |
| 1091 | MultiDimensionalToString(in).c_str()); |
| 1092 | |
| 1093 | EXPECT_OK(foo->callingDrWho( |
| 1094 | in, |
| 1095 | [&](const auto &out) { |
| 1096 | ALOGI("CLIENT callingDrWho returned %s.", |
| 1097 | MultiDimensionalToString(out).c_str()); |
| 1098 | |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1099 | size_t k = 0; |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1100 | for (size_t i = 0; i < 5; ++i) { |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1101 | for (size_t j = 0; j < 3; ++j, ++k) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1102 | EXPECT_STREQ( |
| 1103 | out.quuxMatrix[i][j].first.c_str(), |
| 1104 | in.quuxMatrix[4 - i][2 - j].last.c_str()); |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1105 | |
| 1106 | EXPECT_STREQ( |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1107 | out.quuxMatrix[i][j].last.c_str(), |
| 1108 | in.quuxMatrix[4 - i][2 - j].first.c_str()); |
Andreas Huber | f9d49f1 | 2016-09-12 14:58:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | })); |
| 1112 | } |
| 1113 | |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1114 | static std::string numberToEnglish(int x) { |
| 1115 | static const char *const kDigits[] = { |
| 1116 | "zero", |
| 1117 | "one", |
| 1118 | "two", |
| 1119 | "three", |
| 1120 | "four", |
| 1121 | "five", |
| 1122 | "six", |
| 1123 | "seven", |
| 1124 | "eight", |
| 1125 | "nine", |
| 1126 | }; |
| 1127 | |
| 1128 | if (x < 0) { |
| 1129 | return "negative " + numberToEnglish(-x); |
| 1130 | } |
| 1131 | |
| 1132 | if (x < 10) { |
| 1133 | return kDigits[x]; |
| 1134 | } |
| 1135 | |
| 1136 | if (x <= 15) { |
| 1137 | static const char *const kSpecialTens[] = { |
| 1138 | "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", |
| 1139 | }; |
| 1140 | |
| 1141 | return kSpecialTens[x - 10]; |
| 1142 | } |
| 1143 | |
| 1144 | if (x < 20) { |
| 1145 | return std::string(kDigits[x % 10]) + "teen"; |
| 1146 | } |
| 1147 | |
| 1148 | if (x < 100) { |
| 1149 | static const char *const kDecades[] = { |
| 1150 | "twenty", "thirty", "forty", "fifty", "sixty", "seventy", |
| 1151 | "eighty", "ninety", |
| 1152 | }; |
| 1153 | |
| 1154 | return std::string(kDecades[x / 10 - 2]) + kDigits[x % 10]; |
| 1155 | } |
| 1156 | |
| 1157 | return "positively huge!"; |
| 1158 | } |
| 1159 | |
| 1160 | TEST_F(HidlTest, FooTransposeTest) { |
| 1161 | IFoo::StringMatrix5x3 in; |
| 1162 | |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1163 | for (int i = 0; i < 5; ++i) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1164 | for (int j = 0; j < 3; ++j) { |
| 1165 | in.s[i][j] = numberToEnglish(3 * i + j + 1).c_str(); |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | EXPECT_OK(foo->transpose( |
| 1170 | in, |
| 1171 | [&](const auto &out) { |
| 1172 | EXPECT_EQ( |
| 1173 | to_string(out), |
| 1174 | "[['one', 'four', 'seven', 'ten', 'thirteen'], " |
| 1175 | "['two', 'five', 'eight', 'eleven', 'fourteen'], " |
| 1176 | "['three', 'six', 'nine', 'twelve', 'fifteen']]"); |
| 1177 | })); |
| 1178 | } |
| 1179 | |
| 1180 | TEST_F(HidlTest, FooTranspose2Test) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1181 | hidl_array<hidl_string, 5, 3> in; |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1182 | |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1183 | for (int i = 0; i < 5; ++i) { |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1184 | for (int j = 0; j < 3; ++j) { |
| 1185 | in[i][j] = numberToEnglish(3 * i + j + 1).c_str(); |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | EXPECT_OK(foo->transpose2( |
| 1190 | in, |
| 1191 | [&](const auto &out) { |
| 1192 | EXPECT_EQ( |
Andreas Huber | f03332a | 2016-09-22 15:35:43 -0700 | [diff] [blame] | 1193 | to_string(out), |
Andreas Huber | 709b62d | 2016-09-19 11:21:18 -0700 | [diff] [blame] | 1194 | "[['one', 'four', 'seven', 'ten', 'thirteen'], " |
| 1195 | "['two', 'five', 'eight', 'eleven', 'fourteen'], " |
| 1196 | "['three', 'six', 'nine', 'twelve', 'fifteen']]"); |
| 1197 | })); |
| 1198 | } |
| 1199 | |
Yifan Hong | b725d67 | 2016-10-10 10:14:15 -0700 | [diff] [blame] | 1200 | TEST_F(HidlTest, FooNullNativeHandleTest) { |
Martijn Coenen | 9d97da2 | 2017-01-12 17:29:47 +0100 | [diff] [blame] | 1201 | Abc xyz; |
| 1202 | xyz.z = nullptr; |
| 1203 | EXPECT_OK(bar->expectNullHandle(nullptr, xyz, [](bool hIsNull, bool xyzHasNull) { |
| 1204 | EXPECT_TRUE(hIsNull); |
| 1205 | EXPECT_TRUE(xyzHasNull); |
| 1206 | })); |
Yifan Hong | b725d67 | 2016-10-10 10:14:15 -0700 | [diff] [blame] | 1207 | } |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1208 | |
Martijn Coenen | e163823 | 2016-10-26 12:51:34 +0200 | [diff] [blame] | 1209 | TEST_F(HidlTest, FooNullCallbackTest) { |
| 1210 | EXPECT_OK(foo->echoNullInterface(nullptr, |
| 1211 | [](const auto receivedNull, const auto &intf) { |
| 1212 | EXPECT_TRUE(receivedNull); |
| 1213 | EXPECT_EQ(intf, nullptr); |
| 1214 | })); |
| 1215 | } |
| 1216 | |
Steven Moreland | 67f67b4 | 2016-09-29 08:59:02 -0700 | [diff] [blame] | 1217 | TEST_F(HidlTest, FooNonNullCallbackTest) { |
| 1218 | hidl_array<hidl_string, 5, 3> in; |
| 1219 | |
| 1220 | EXPECT_FAIL(foo->transpose2(in, nullptr /* _hidl_cb */)); |
| 1221 | } |
| 1222 | |
Andreas Huber | 5e44a29 | 2016-09-27 14:52:39 -0700 | [diff] [blame] | 1223 | TEST_F(HidlTest, FooSendVecTest) { |
| 1224 | hidl_vec<uint8_t> in; |
| 1225 | in.resize(16); |
| 1226 | for (size_t i = 0; i < in.size(); ++i) { |
| 1227 | in[i] = i; |
| 1228 | } |
| 1229 | |
| 1230 | EXPECT_OK(foo->sendVec( |
| 1231 | in, |
| 1232 | [&](const auto &out) { |
| 1233 | EXPECT_EQ(to_string(in), to_string(out)); |
| 1234 | })); |
| 1235 | } |
| 1236 | |
Martijn Coenen | afb30cb | 2017-01-13 00:24:02 +0100 | [diff] [blame] | 1237 | TEST_F(HidlTest, FooSendEmptyVecTest) { |
| 1238 | hidl_vec<uint8_t> in; |
| 1239 | EXPECT_OK(foo->sendVec( |
| 1240 | in, |
| 1241 | [&](const auto &out) { |
| 1242 | EXPECT_EQ(out.size(), 0u); |
| 1243 | EXPECT_EQ(to_string(in), to_string(out)); |
| 1244 | })); |
| 1245 | } |
| 1246 | |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1247 | TEST_F(HidlTest, FooHaveAVectorOfInterfacesTest) { |
| 1248 | hidl_vec<sp<ISimple> > in; |
| 1249 | in.resize(16); |
| 1250 | for (size_t i = 0; i < in.size(); ++i) { |
| 1251 | in[i] = new Simple(i); |
| 1252 | } |
| 1253 | |
| 1254 | EXPECT_OK(foo->haveAVectorOfInterfaces( |
| 1255 | in, |
| 1256 | [&](const auto &out) { |
| 1257 | EXPECT_EQ(in.size(), out.size()); |
| 1258 | for (size_t i = 0; i < in.size(); ++i) { |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 1259 | int32_t inCookie = in[i]->getCookie(); |
| 1260 | int32_t outCookie = out[i]->getCookie(); |
| 1261 | EXPECT_EQ(inCookie, outCookie); |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1262 | } |
| 1263 | })); |
| 1264 | } |
| 1265 | |
| 1266 | TEST_F(HidlTest, FooHaveAVectorOfGenericInterfacesTest) { |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1267 | |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1268 | hidl_vec<sp<::android::hidl::base::V1_0::IBase> > in; |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1269 | in.resize(16); |
| 1270 | for (size_t i = 0; i < in.size(); ++i) { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1271 | sp<ISimple> s = new Simple(i); |
| 1272 | in[i] = s; |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | EXPECT_OK(foo->haveAVectorOfGenericInterfaces( |
| 1276 | in, |
| 1277 | [&](const auto &out) { |
| 1278 | EXPECT_EQ(in.size(), out.size()); |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1279 | |
| 1280 | EXPECT_OK(out[0]->interfaceChain([](const auto &names) { |
| 1281 | ASSERT_GT(names.size(), 0u); |
| 1282 | ASSERT_STREQ(names[0].c_str(), ISimple::descriptor); |
| 1283 | })); |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1284 | for (size_t i = 0; i < in.size(); ++i) { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 1285 | sp<ISimple> inSimple = ISimple::castFrom(in[i]); |
| 1286 | sp<ISimple> outSimple = ISimple::castFrom(out[i]); |
| 1287 | |
| 1288 | ASSERT_NE(inSimple.get(), nullptr); |
| 1289 | ASSERT_NE(outSimple.get(), nullptr); |
Martijn Coenen | 6ec2f0b | 2016-12-11 01:04:55 +0100 | [diff] [blame] | 1290 | EXPECT_EQ(in[i], inSimple.get()); // pointers must be equal! |
Steven Moreland | 2ae5bca | 2016-12-01 05:56:49 +0000 | [diff] [blame] | 1291 | int32_t inCookie = inSimple->getCookie(); |
| 1292 | int32_t outCookie = outSimple->getCookie(); |
| 1293 | EXPECT_EQ(inCookie, outCookie); |
Andreas Huber | 86a112b | 2016-10-19 14:25:16 -0700 | [diff] [blame] | 1294 | } |
| 1295 | })); |
| 1296 | } |
| 1297 | |
Yifan Hong | 8c48ad7 | 2016-10-14 11:34:59 -0700 | [diff] [blame] | 1298 | TEST_F(HidlTest, FooStructEmbeddedHandleTest) { |
| 1299 | EXPECT_OK(foo->createMyHandle([&](const auto &myHandle) { |
| 1300 | EXPECT_EQ(myHandle.guard, 666); |
Martijn Coenen | 2f69a5b | 2016-11-18 15:26:38 +0100 | [diff] [blame] | 1301 | const native_handle_t* handle = myHandle.h.getNativeHandle(); |
| 1302 | EXPECT_EQ(handle->numInts, 10); |
| 1303 | EXPECT_EQ(handle->numFds, 0); |
Yifan Hong | 8c48ad7 | 2016-10-14 11:34:59 -0700 | [diff] [blame] | 1304 | int data[] = {2,3,5,7,11,13,17,19,21,23}; |
Martijn Coenen | 2f69a5b | 2016-11-18 15:26:38 +0100 | [diff] [blame] | 1305 | EXPECT_ARRAYEQ(handle->data, data, 10); |
Yifan Hong | 8c48ad7 | 2016-10-14 11:34:59 -0700 | [diff] [blame] | 1306 | })); |
| 1307 | |
| 1308 | EXPECT_OK(foo->closeHandles()); |
| 1309 | } |
| 1310 | |
| 1311 | TEST_F(HidlTest, FooHandleVecTest) { |
| 1312 | EXPECT_OK(foo->createHandles(3, [&](const auto &handles) { |
| 1313 | EXPECT_EQ(handles.size(), 3ull); |
| 1314 | int data[] = {2,3,5,7,11,13,17,19,21,23}; |
| 1315 | for (size_t i = 0; i < 3; i++) { |
| 1316 | const native_handle_t *h = handles[i]; |
| 1317 | EXPECT_EQ(h->numInts, 10) << " for element " << i; |
| 1318 | EXPECT_EQ(h->numFds, 0) << " for element " << i; |
| 1319 | EXPECT_ARRAYEQ(h->data, data, 10); |
| 1320 | } |
| 1321 | })); |
| 1322 | |
| 1323 | EXPECT_OK(foo->closeHandles()); |
| 1324 | } |
| 1325 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 1326 | struct HidlDeathRecipient : hidl_death_recipient { |
| 1327 | std::mutex mutex; |
| 1328 | std::condition_variable condition; |
| 1329 | wp<IBase> who; |
| 1330 | bool fired = false; |
| 1331 | uint64_t cookie = 0; |
| 1332 | |
| 1333 | virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) { |
| 1334 | std::unique_lock<std::mutex> lock(mutex); |
| 1335 | fired = true; |
| 1336 | this->cookie = cookie; |
| 1337 | this->who = who; |
| 1338 | condition.notify_one(); |
| 1339 | }; |
| 1340 | }; |
| 1341 | |
| 1342 | TEST_F(HidlTest, DeathRecipientTest) { |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 1343 | sp<HidlDeathRecipient> recipient = new HidlDeathRecipient(); |
| 1344 | sp<HidlDeathRecipient> recipient2 = new HidlDeathRecipient(); |
| 1345 | |
| 1346 | EXPECT_TRUE(dyingFoo->linkToDeath(recipient, 0x1481)); |
| 1347 | EXPECT_TRUE(dyingFoo->linkToDeath(recipient2, 0x2592)); |
| 1348 | EXPECT_TRUE(dyingFoo->unlinkToDeath(recipient2)); |
| 1349 | |
| 1350 | if (gMode != BINDERIZED) { |
| 1351 | // Passthrough doesn't fire, nor does it keep state of |
| 1352 | // registered death recipients (so it won't fail unlinking |
| 1353 | // the same recipient twice). |
| 1354 | return; |
| 1355 | } |
| 1356 | |
| 1357 | EXPECT_FALSE(dyingFoo->unlinkToDeath(recipient2)); |
| 1358 | killServer("dyingFoo"); |
| 1359 | |
| 1360 | std::unique_lock<std::mutex> lock(recipient->mutex); |
| 1361 | recipient->condition.wait_for(lock, std::chrono::milliseconds(1000), [&recipient]() { |
| 1362 | return recipient->fired; |
| 1363 | }); |
| 1364 | EXPECT_TRUE(recipient->fired); |
| 1365 | EXPECT_EQ(recipient->cookie, 0x1481u); |
| 1366 | EXPECT_EQ(recipient->who, dyingFoo); |
| 1367 | std::unique_lock<std::mutex> lock2(recipient2->mutex); |
| 1368 | recipient2->condition.wait_for(lock2, std::chrono::milliseconds(1000), [&recipient2]() { |
| 1369 | return recipient2->fired; |
| 1370 | }); |
| 1371 | EXPECT_FALSE(recipient2->fired); |
| 1372 | |
| 1373 | // Verify servicemanager dropped its reference too |
| 1374 | sp<IFoo> deadFoo = IFoo::getService("dyingFoo", false); |
| 1375 | if (deadFoo != nullptr) { |
| 1376 | // Got a passthrough |
| 1377 | EXPECT_FALSE(deadFoo->isRemote()); |
| 1378 | } |
| 1379 | } |
| 1380 | |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1381 | TEST_F(HidlTest, BarThisIsNewTest) { |
Iliyan Malchev | 0acf419 | 2016-08-22 19:33:20 -0700 | [diff] [blame] | 1382 | // Now the tricky part, get access to the derived interface. |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1383 | ALOGI("CLIENT call thisIsNew."); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1384 | EXPECT_OK(bar->thisIsNew()); |
Iliyan Malchev | b31e10c | 2016-08-13 23:03:25 -0700 | [diff] [blame] | 1385 | ALOGI("CLIENT thisIsNew returned."); |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1388 | static void expectGoodChild(const sp<IChild> &child) { |
| 1389 | ASSERT_NE(child.get(), nullptr); |
| 1390 | EXPECT_OK(child->doGrandparent()); |
| 1391 | EXPECT_OK(child->doParent()); |
| 1392 | EXPECT_OK(child->doChild()); |
| 1393 | } |
| 1394 | |
| 1395 | static void expectGoodParent(const sp<IParent> &parent) { |
| 1396 | ASSERT_NE(parent.get(), nullptr); |
| 1397 | EXPECT_OK(parent->doGrandparent()); |
| 1398 | EXPECT_OK(parent->doParent()); |
| 1399 | sp<IChild> child = IChild::castFrom(parent); |
| 1400 | expectGoodChild(child); |
| 1401 | } |
| 1402 | |
| 1403 | static void expectGoodGrandparent(const sp<IGrandparent> &grandparent) { |
| 1404 | ASSERT_NE(grandparent.get(), nullptr); |
| 1405 | EXPECT_OK(grandparent->doGrandparent()); |
| 1406 | sp<IParent> parent = IParent::castFrom(grandparent); |
| 1407 | expectGoodParent(parent); |
| 1408 | } |
| 1409 | |
Yifan Hong | 5749b2c | 2016-11-28 12:52:36 -0800 | [diff] [blame] | 1410 | TEST_F(HidlTest, FooHaveAnInterfaceTest) { |
| 1411 | |
| 1412 | sp<ISimple> in = new Complicated(42); |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1413 | Return<sp<ISimple>> ret = bar->haveAInterface(in); |
| 1414 | EXPECT_OK(ret); |
| 1415 | sp<ISimple> out = ret; |
| 1416 | ASSERT_NE(out.get(), nullptr); |
| 1417 | EXPECT_EQ(out->getCookie(), 42); |
| 1418 | EXPECT_OK(out->customVecInt([&](const auto &) { })); |
| 1419 | EXPECT_OK(out->customVecStr([&](const auto &) { })); |
| 1420 | EXPECT_OK(out->interfaceChain([&](const auto &) { })); |
| 1421 | EXPECT_OK(out->mystr([&](const auto &) { })); |
| 1422 | EXPECT_OK(out->myhandle([&](const auto &) { })); |
Yifan Hong | 5749b2c | 2016-11-28 12:52:36 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1425 | TEST_F(HidlTest, InheritRemoteGrandparentTest) { |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1426 | Return<sp<IGrandparent>> ret = fetcher->getGrandparent(true); |
| 1427 | EXPECT_OK(ret); |
| 1428 | expectGoodGrandparent(ret); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | TEST_F(HidlTest, InheritLocalGrandparentTest) { |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1432 | Return<sp<IGrandparent>> ret = fetcher->getGrandparent(false); |
| 1433 | EXPECT_OK(ret); |
| 1434 | expectGoodGrandparent(ret); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Yifan Hong | 4b0214d | 2016-12-07 14:57:57 -0800 | [diff] [blame] | 1437 | TEST_F(HidlTest, InheritRemoteParentTest) { |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1438 | Return<sp<IParent>> ret = fetcher->getParent(true); |
| 1439 | EXPECT_OK(ret); |
| 1440 | expectGoodParent(ret); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Yifan Hong | 4b0214d | 2016-12-07 14:57:57 -0800 | [diff] [blame] | 1443 | TEST_F(HidlTest, InheritLocalParentTest) { |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1444 | Return<sp<IParent>> ret = fetcher->getParent(false); |
| 1445 | EXPECT_OK(ret); |
| 1446 | expectGoodParent(ret); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | TEST_F(HidlTest, InheritRemoteChildTest) { |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1450 | Return<sp<IChild>> ret = fetcher->getChild(true); |
| 1451 | EXPECT_OK(ret); |
| 1452 | expectGoodChild(ret); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | TEST_F(HidlTest, InheritLocalChildTest) { |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 1456 | Return<sp<IChild>> ret = fetcher->getChild(false); |
| 1457 | EXPECT_OK(ret); |
| 1458 | expectGoodChild(ret); |
Yifan Hong | 1e81c53 | 2016-10-18 18:43:46 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Andreas Huber | 5d03477 | 2016-09-28 14:23:51 -0700 | [diff] [blame] | 1461 | TEST_F(HidlTest, TestArrayDimensionality) { |
| 1462 | hidl_array<int, 2> oneDim; |
| 1463 | hidl_array<int, 2, 3> twoDim; |
| 1464 | hidl_array<int, 2, 3, 4> threeDim; |
| 1465 | |
| 1466 | EXPECT_EQ(oneDim.size(), 2u); |
| 1467 | EXPECT_EQ(twoDim.size(), std::make_tuple(2u, 3u)); |
| 1468 | EXPECT_EQ(threeDim.size(), std::make_tuple(2u, 3u, 4u)); |
| 1469 | } |
| 1470 | |
Yifan Hong | c6752dc | 2016-12-20 14:00:14 -0800 | [diff] [blame] | 1471 | TEST_F(HidlTest, StructEqualTest) { |
| 1472 | using G = IFoo::Goober; |
| 1473 | using F = IFoo::Fumble; |
| 1474 | G g1{ |
| 1475 | .q = 42, |
| 1476 | .name = "The Ultimate Question of Life, the Universe, and Everything", |
| 1477 | .address = "North Pole", |
| 1478 | .numbers = std::array<double, 10>{ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} }, |
| 1479 | .fumble = F{.data = {.data = 50}}, |
| 1480 | .gumble = F{.data = {.data = 60}} |
| 1481 | }; |
| 1482 | G g2{ |
| 1483 | .q = 42, |
| 1484 | .name = "The Ultimate Question of Life, the Universe, and Everything", |
| 1485 | .address = "North Pole", |
| 1486 | .numbers = std::array<double, 10>{ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} }, |
| 1487 | .fumble = F{.data = {.data = 50}}, |
| 1488 | .gumble = F{.data = {.data = 60}} |
| 1489 | }; |
| 1490 | G g3{ |
| 1491 | .q = 42, |
| 1492 | .name = "The Ultimate Question of Life, the Universe, and Everything", |
| 1493 | .address = "North Pole", |
| 1494 | .numbers = std::array<double, 10>{ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} }, |
| 1495 | .fumble = F{.data = {.data = 50}}, |
| 1496 | .gumble = F{.data = {.data = 61}} |
| 1497 | }; |
| 1498 | // explicitly invoke operator== here. |
| 1499 | EXPECT_TRUE(g1 == g2); |
| 1500 | EXPECT_TRUE(g1 != g3); |
| 1501 | } |
| 1502 | |
| 1503 | TEST_F(HidlTest, EnumEqualTest) { |
| 1504 | using E = IFoo::SomeEnum; |
| 1505 | E e1 = E::quux; |
| 1506 | E e2 = E::quux; |
| 1507 | E e3 = E::goober; |
| 1508 | // explicitly invoke operator== here. |
| 1509 | EXPECT_TRUE(e1 == e2); |
| 1510 | EXPECT_TRUE(e1 != e3); |
| 1511 | } |
| 1512 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1513 | #if HIDL_RUN_POINTER_TESTS |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1514 | |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1515 | TEST_F(HidlTest, PassAGraphTest) { |
| 1516 | IGraph::Graph g; |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 1517 | ::android::simpleGraph(g); |
| 1518 | ::android::logSimpleGraph("CLIENT", g); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1519 | ALOGI("CLIENT call passAGraph"); |
| 1520 | EXPECT_OK(graphInterface->passAGraph(g)); |
| 1521 | } |
| 1522 | |
| 1523 | TEST_F(HidlTest, GiveAGraphTest) { |
| 1524 | EXPECT_OK(graphInterface->giveAGraph([&](const auto &newGraph) { |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 1525 | ::android::logSimpleGraph("CLIENT", newGraph); |
| 1526 | EXPECT_TRUE(::android::isSimpleGraph(newGraph)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1527 | })); |
| 1528 | } |
| 1529 | TEST_F(HidlTest, PassANodeTest) { |
| 1530 | IGraph::Node node; node.data = 10; |
| 1531 | EXPECT_OK(graphInterface->passANode(node)); |
| 1532 | } |
| 1533 | TEST_F(HidlTest, PassTwoGraphsTest) { |
| 1534 | IGraph::Graph g; |
Yifan Hong | 398e6fb | 2016-10-17 11:38:09 -0700 | [diff] [blame] | 1535 | ::android::simpleGraph(g); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1536 | EXPECT_OK(graphInterface->passTwoGraphs(&g, &g)); |
| 1537 | } |
| 1538 | TEST_F(HidlTest, PassAGammaTest) { |
| 1539 | IGraph::Theta s; s.data = 500; |
| 1540 | IGraph::Alpha a; a.s_ptr = &s; |
| 1541 | IGraph::Beta b; b.s_ptr = &s; |
| 1542 | IGraph::Gamma c; c.a_ptr = &a; c.b_ptr = &b; |
| 1543 | ALOGI("CLIENT calling passAGamma: c.a = %p, c.b = %p, c.a->s = %p, c.b->s = %p", |
| 1544 | c.a_ptr, c.b_ptr, c.a_ptr->s_ptr, c.b_ptr->s_ptr); |
| 1545 | EXPECT_OK(graphInterface->passAGamma(c)); |
| 1546 | } |
| 1547 | TEST_F(HidlTest, PassNullTest) { |
| 1548 | IGraph::Gamma c; |
| 1549 | c.a_ptr = nullptr; |
| 1550 | c.b_ptr = nullptr; |
| 1551 | EXPECT_OK(graphInterface->passAGamma(c)); |
| 1552 | } |
| 1553 | TEST_F(HidlTest, PassASimpleRefTest) { |
| 1554 | IGraph::Theta s; |
| 1555 | s.data = 500; |
| 1556 | IGraph::Alpha a; |
| 1557 | a.s_ptr = &s; |
| 1558 | EXPECT_OK(graphInterface->passASimpleRef(&a)); |
| 1559 | } |
| 1560 | TEST_F(HidlTest, PassASimpleRefSTest) { |
| 1561 | IGraph::Theta s; |
| 1562 | s.data = 500; |
| 1563 | ALOGI("CLIENT call passASimpleRefS with %p", &s); |
| 1564 | EXPECT_OK(graphInterface->passASimpleRefS(&s)); |
| 1565 | } |
| 1566 | TEST_F(HidlTest, GiveASimpleRefTest) { |
| 1567 | EXPECT_OK(graphInterface->giveASimpleRef([&](const auto & a_ptr) { |
| 1568 | EXPECT_EQ(a_ptr->s_ptr->data, 500); |
| 1569 | })); |
| 1570 | } |
| 1571 | TEST_F(HidlTest, GraphReportErrorsTest) { |
| 1572 | Return<int32_t> ret = graphInterface->getErrors(); |
| 1573 | EXPECT_OK(ret); |
| 1574 | EXPECT_EQ(int32_t(ret), 0); |
| 1575 | } |
| 1576 | |
| 1577 | TEST_F(HidlTest, PointerPassOldBufferTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1578 | EXPECT_OK(validationPointerInterface->bar1([&](const auto& sptr, const auto& s) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1579 | EXPECT_OK(pointerInterface->foo1(sptr, s)); |
| 1580 | })); |
| 1581 | } |
| 1582 | TEST_F(HidlTest, PointerPassOldBufferTest2) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1583 | EXPECT_OK(validationPointerInterface->bar2([&](const auto& s, const auto& a) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1584 | EXPECT_OK(pointerInterface->foo2(s, a)); |
| 1585 | })); |
| 1586 | } |
| 1587 | TEST_F(HidlTest, PointerPassSameOldBufferPointerTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1588 | EXPECT_OK(validationPointerInterface->bar3([&](const auto& s, const auto& a, const auto& b) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1589 | EXPECT_OK(pointerInterface->foo3(s, a, b)); |
| 1590 | })); |
| 1591 | } |
| 1592 | TEST_F(HidlTest, PointerPassOnlyTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1593 | EXPECT_OK(validationPointerInterface->bar4([&](const auto& s) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1594 | EXPECT_OK(pointerInterface->foo4(s)); |
| 1595 | })); |
| 1596 | } |
| 1597 | TEST_F(HidlTest, PointerPassTwoEmbeddedTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1598 | EXPECT_OK(validationPointerInterface->bar5([&](const auto& a, const auto& b) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1599 | EXPECT_OK(pointerInterface->foo5(a, b)); |
| 1600 | })); |
| 1601 | } |
| 1602 | TEST_F(HidlTest, PointerPassIndirectBufferHasDataTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1603 | EXPECT_OK(validationPointerInterface->bar6([&](const auto& a) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1604 | EXPECT_OK(pointerInterface->foo6(a)); |
| 1605 | })); |
| 1606 | } |
| 1607 | TEST_F(HidlTest, PointerPassTwoIndirectBufferTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1608 | EXPECT_OK(validationPointerInterface->bar7([&](const auto& a, const auto& b) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1609 | EXPECT_OK(pointerInterface->foo7(a, b)); |
| 1610 | })); |
| 1611 | } |
| 1612 | TEST_F(HidlTest, PointerPassDeeplyIndirectTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1613 | EXPECT_OK(validationPointerInterface->bar8([&](const auto& d) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1614 | EXPECT_OK(pointerInterface->foo8(d)); |
| 1615 | })); |
| 1616 | } |
| 1617 | TEST_F(HidlTest, PointerPassStringRefTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1618 | EXPECT_OK(validationPointerInterface->bar9([&](const auto& str) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1619 | EXPECT_OK(pointerInterface->foo9(str)); |
| 1620 | })); |
| 1621 | } |
| 1622 | TEST_F(HidlTest, PointerPassRefVecTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1623 | EXPECT_OK(validationPointerInterface->bar10([&](const auto& v) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1624 | EXPECT_OK(pointerInterface->foo10(v)); |
| 1625 | })); |
| 1626 | } |
| 1627 | TEST_F(HidlTest, PointerPassVecRefTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1628 | EXPECT_OK(validationPointerInterface->bar11([&](const auto& v) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1629 | EXPECT_OK(pointerInterface->foo11(v)); |
| 1630 | })); |
| 1631 | } |
| 1632 | TEST_F(HidlTest, PointerPassArrayRefTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1633 | EXPECT_OK(validationPointerInterface->bar12([&](const auto& array) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1634 | EXPECT_OK(pointerInterface->foo12(array)); |
| 1635 | })); |
| 1636 | } |
| 1637 | TEST_F(HidlTest, PointerPassRefArrayTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1638 | EXPECT_OK(validationPointerInterface->bar13([&](const auto& array) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1639 | EXPECT_OK(pointerInterface->foo13(array)); |
| 1640 | })); |
| 1641 | } |
| 1642 | TEST_F(HidlTest, PointerPass3RefTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1643 | EXPECT_OK(validationPointerInterface->bar14([&](const auto& p3) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1644 | EXPECT_OK(pointerInterface->foo14(p3)); |
| 1645 | })); |
| 1646 | } |
| 1647 | TEST_F(HidlTest, PointerPassInt3RefTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1648 | EXPECT_OK(validationPointerInterface->bar15([&](const auto& p3) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1649 | EXPECT_OK(pointerInterface->foo15(p3)); |
| 1650 | })); |
| 1651 | } |
| 1652 | TEST_F(HidlTest, PointerPassEmbeddedPointersTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1653 | EXPECT_OK(validationPointerInterface->bar16([&](const auto& p) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1654 | EXPECT_OK(pointerInterface->foo16(p)); |
| 1655 | })); |
| 1656 | } |
| 1657 | TEST_F(HidlTest, PointerPassEmbeddedPointers2Test) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1658 | EXPECT_OK(validationPointerInterface->bar17([&](const auto& p) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1659 | EXPECT_OK(pointerInterface->foo17(p)); |
| 1660 | })); |
| 1661 | } |
| 1662 | TEST_F(HidlTest, PointerPassCopiedStringTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1663 | EXPECT_OK(validationPointerInterface->bar18([&](const auto& str_ref, const auto& str_ref2, const auto& str) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1664 | EXPECT_OK(pointerInterface->foo18(str_ref, str_ref2, str)); |
| 1665 | })); |
| 1666 | } |
| 1667 | TEST_F(HidlTest, PointerPassCopiedVecTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1668 | EXPECT_OK(validationPointerInterface->bar19([&](const auto& a_vec_ref, const auto& a_vec, const auto& a_vec_ref2) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1669 | EXPECT_OK(pointerInterface->foo19(a_vec_ref, a_vec, a_vec_ref2)); |
| 1670 | })); |
| 1671 | } |
Yifan Hong | 8446590 | 2016-09-27 15:52:17 -0700 | [diff] [blame] | 1672 | TEST_F(HidlTest, PointerPassBigRefVecTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1673 | EXPECT_OK(validationPointerInterface->bar20([&](const auto& v) { |
Yifan Hong | 8446590 | 2016-09-27 15:52:17 -0700 | [diff] [blame] | 1674 | EXPECT_FAIL(pointerInterface->foo20(v)); |
| 1675 | })); |
| 1676 | } |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1677 | TEST_F(HidlTest, PointerPassMultidimArrayRefTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1678 | EXPECT_OK(validationPointerInterface->bar21([&](const auto& v) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1679 | EXPECT_OK(pointerInterface->foo21(v)); |
| 1680 | })); |
| 1681 | } |
| 1682 | TEST_F(HidlTest, PointerPassRefMultidimArrayTest) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1683 | EXPECT_OK(validationPointerInterface->bar22([&](const auto& v) { |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1684 | EXPECT_OK(pointerInterface->foo22(v)); |
| 1685 | })); |
| 1686 | } |
| 1687 | TEST_F(HidlTest, PointerGiveOldBufferTest) { |
| 1688 | EXPECT_OK(pointerInterface->bar1([&](const auto& sptr, const auto& s) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1689 | EXPECT_OK(validationPointerInterface->foo1(sptr, s)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1690 | })); |
| 1691 | } |
| 1692 | TEST_F(HidlTest, PointerGiveOldBufferTest2) { |
| 1693 | EXPECT_OK(pointerInterface->bar2([&](const auto& s, const auto& a) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1694 | EXPECT_OK(validationPointerInterface->foo2(s, a)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1695 | })); |
| 1696 | } |
| 1697 | TEST_F(HidlTest, PointerGiveSameOldBufferPointerTest) { |
| 1698 | EXPECT_OK(pointerInterface->bar3([&](const auto& s, const auto& a, const auto& b) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1699 | EXPECT_OK(validationPointerInterface->foo3(s, a, b)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1700 | })); |
| 1701 | } |
| 1702 | TEST_F(HidlTest, PointerGiveOnlyTest) { |
| 1703 | EXPECT_OK(pointerInterface->bar4([&](const auto& s) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1704 | EXPECT_OK(validationPointerInterface->foo4(s)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1705 | })); |
| 1706 | } |
| 1707 | TEST_F(HidlTest, PointerGiveTwoEmbeddedTest) { |
| 1708 | EXPECT_OK(pointerInterface->bar5([&](const auto& a, const auto& b) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1709 | EXPECT_OK(validationPointerInterface->foo5(a, b)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1710 | })); |
| 1711 | } |
| 1712 | TEST_F(HidlTest, PointerGiveIndirectBufferHasDataTest) { |
| 1713 | EXPECT_OK(pointerInterface->bar6([&](const auto& a) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1714 | EXPECT_OK(validationPointerInterface->foo6(a)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1715 | })); |
| 1716 | } |
| 1717 | TEST_F(HidlTest, PointerGiveTwoIndirectBufferTest) { |
| 1718 | EXPECT_OK(pointerInterface->bar7([&](const auto& a, const auto& b) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1719 | EXPECT_OK(validationPointerInterface->foo7(a, b)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1720 | })); |
| 1721 | } |
| 1722 | TEST_F(HidlTest, PointerGiveDeeplyIndirectTest) { |
| 1723 | EXPECT_OK(pointerInterface->bar8([&](const auto& d) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1724 | EXPECT_OK(validationPointerInterface->foo8(d)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1725 | })); |
| 1726 | } |
| 1727 | TEST_F(HidlTest, PointerGiveStringRefTest) { |
| 1728 | EXPECT_OK(pointerInterface->bar9([&](const auto& str) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1729 | EXPECT_OK(validationPointerInterface->foo9(str)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1730 | })); |
| 1731 | } |
| 1732 | TEST_F(HidlTest, PointerGiveRefVecTest) { |
| 1733 | EXPECT_OK(pointerInterface->bar10([&](const auto& v) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1734 | EXPECT_OK(validationPointerInterface->foo10(v)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1735 | })); |
| 1736 | } |
| 1737 | TEST_F(HidlTest, PointerGiveVecRefTest) { |
| 1738 | EXPECT_OK(pointerInterface->bar11([&](const auto& v) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1739 | EXPECT_OK(validationPointerInterface->foo11(v)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1740 | })); |
| 1741 | } |
| 1742 | TEST_F(HidlTest, PointerGiveArrayRefTest) { |
| 1743 | EXPECT_OK(pointerInterface->bar12([&](const auto& array) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1744 | EXPECT_OK(validationPointerInterface->foo12(array)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1745 | })); |
| 1746 | } |
| 1747 | TEST_F(HidlTest, PointerGiveRefArrayTest) { |
| 1748 | EXPECT_OK(pointerInterface->bar13([&](const auto& array) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1749 | EXPECT_OK(validationPointerInterface->foo13(array)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1750 | })); |
| 1751 | } |
| 1752 | TEST_F(HidlTest, PointerGive3RefTest) { |
| 1753 | EXPECT_OK(pointerInterface->bar14([&](const auto& p3) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1754 | EXPECT_OK(validationPointerInterface->foo14(p3)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1755 | })); |
| 1756 | } |
| 1757 | TEST_F(HidlTest, PointerGiveInt3RefTest) { |
| 1758 | EXPECT_OK(pointerInterface->bar15([&](const auto& p3) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1759 | EXPECT_OK(validationPointerInterface->foo15(p3)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1760 | })); |
| 1761 | } |
| 1762 | TEST_F(HidlTest, PointerGiveEmbeddedPointersTest) { |
| 1763 | EXPECT_OK(pointerInterface->bar16([&](const auto& p) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1764 | EXPECT_OK(validationPointerInterface->foo16(p)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1765 | })); |
| 1766 | } |
| 1767 | TEST_F(HidlTest, PointerGiveEmbeddedPointers2Test) { |
| 1768 | EXPECT_OK(pointerInterface->bar17([&](const auto& p) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1769 | EXPECT_OK(validationPointerInterface->foo17(p)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1770 | })); |
| 1771 | } |
| 1772 | TEST_F(HidlTest, PointerGiveCopiedStringTest) { |
| 1773 | EXPECT_OK(pointerInterface->bar18([&](const auto& str_ref, const auto& str_ref2, const auto& str) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1774 | EXPECT_OK(validationPointerInterface->foo18(str_ref, str_ref2, str)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1775 | })); |
| 1776 | } |
| 1777 | TEST_F(HidlTest, PointerGiveCopiedVecTest) { |
| 1778 | EXPECT_OK(pointerInterface->bar19([&](const auto& a_vec_ref, const auto& a_vec, const auto& a_vec_ref2) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1779 | EXPECT_OK(validationPointerInterface->foo19(a_vec_ref, a_vec, a_vec_ref2)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1780 | })); |
| 1781 | } |
Yifan Hong | 8446590 | 2016-09-27 15:52:17 -0700 | [diff] [blame] | 1782 | // This cannot be enabled until _hidl_error is not ignored when |
| 1783 | // the remote writeEmbeddedReferencesToParcel. |
| 1784 | // TEST_F(HidlTest, PointerGiveBigRefVecTest) { |
| 1785 | // EXPECT_FAIL(pointerInterface->bar20([&](const auto& v) { |
| 1786 | // })); |
| 1787 | // } |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1788 | TEST_F(HidlTest, PointerGiveMultidimArrayRefTest) { |
| 1789 | EXPECT_OK(pointerInterface->bar21([&](const auto& v) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1790 | EXPECT_OK(validationPointerInterface->foo21(v)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1791 | })); |
| 1792 | } |
| 1793 | TEST_F(HidlTest, PointerGiveRefMultidimArrayTest) { |
| 1794 | EXPECT_OK(pointerInterface->bar22([&](const auto& v) { |
Yifan Hong | 3cccc0f | 2016-10-13 10:12:28 -0700 | [diff] [blame] | 1795 | EXPECT_OK(validationPointerInterface->foo22(v)); |
Yifan Hong | bf459bc | 2016-08-23 16:50:37 -0700 | [diff] [blame] | 1796 | })); |
| 1797 | } |
| 1798 | TEST_F(HidlTest, PointerReportErrorsTest) { |
| 1799 | Return<int32_t> ret = pointerInterface->getErrors(); |
| 1800 | EXPECT_OK(ret); |
| 1801 | EXPECT_EQ(int32_t(ret), 0); |
| 1802 | } |
| 1803 | #endif |
| 1804 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1805 | int forkAndRunTests(TestMode mode) { |
| 1806 | pid_t child; |
| 1807 | int status; |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1808 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1809 | const char* modeText = (mode == BINDERIZED) ? "BINDERIZED" : "PASSTHROUGH"; |
| 1810 | ALOGI("Start running tests in %s mode...", modeText); |
| 1811 | fprintf(stdout, "Start running tests in %s mode...\n", modeText); |
| 1812 | fflush(stdout); |
| 1813 | |
| 1814 | if ((child = fork()) == 0) { |
| 1815 | gMode = mode; |
| 1816 | if (gMode == PASSTHROUGH) { |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 1817 | gPassthroughEnvironment = static_cast<PassthroughEnvironment *>( |
| 1818 | ::testing::AddGlobalTestEnvironment(new PassthroughEnvironment)); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1819 | } else if (gMode == BINDERIZED) { |
Yifan Hong | ca89052 | 2016-10-12 10:03:41 -0700 | [diff] [blame] | 1820 | gBinderizedEnvironment = static_cast<BinderizedEnvironment *>( |
| 1821 | ::testing::AddGlobalTestEnvironment(new BinderizedEnvironment)); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1822 | } |
| 1823 | int testStatus = RUN_ALL_TESTS(); |
| 1824 | if(testStatus == 0) { |
| 1825 | exit(0); |
| 1826 | } |
| 1827 | int failed = ::testing::UnitTest::GetInstance()->failed_test_count(); |
| 1828 | if (failed == 0) { |
| 1829 | exit(-testStatus); |
| 1830 | } |
| 1831 | exit(failed); |
| 1832 | } |
| 1833 | waitpid(child, &status, 0 /* options */); |
| 1834 | ALOGI("All tests finished in %s mode.", modeText); |
| 1835 | fprintf(stdout, "All tests finished in %s mode.\n", modeText); |
| 1836 | fflush(stdout); |
Yifan Hong | 1dc8793 | 2016-08-19 09:51:01 -0700 | [diff] [blame] | 1837 | return status; |
Andreas Huber | 9cd48d0 | 2016-08-03 14:25:59 -0700 | [diff] [blame] | 1838 | } |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1839 | |
| 1840 | void handleStatus(int status, const char *mode) { |
| 1841 | if (status != 0) { |
| 1842 | if (WIFEXITED(status)) { |
| 1843 | status = WEXITSTATUS(status); |
| 1844 | if (status < 0) { |
Yifan Hong | 48562fd | 2016-10-24 15:26:10 -0700 | [diff] [blame] | 1845 | fprintf(stdout, " RUN_ALL_TESTS returns %d for %s mode.\n", -status, mode); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1846 | } else { |
Yifan Hong | 48562fd | 2016-10-24 15:26:10 -0700 | [diff] [blame] | 1847 | fprintf(stdout, " %d test(s) failed for %s mode.\n", status, mode); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1848 | } |
| 1849 | } else { |
Yifan Hong | 48562fd | 2016-10-24 15:26:10 -0700 | [diff] [blame] | 1850 | fprintf(stdout, " ERROR: %s child process exited abnormally with %d\n", mode, status); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | |
Yifan Hong | d12398d | 2016-10-13 11:05:29 -0700 | [diff] [blame] | 1855 | static void usage(const char *me) { |
| 1856 | fprintf(stderr, |
| 1857 | "usage: %s [-b] [-p] [GTEST_OPTIONS]\n", |
| 1858 | me); |
| 1859 | |
| 1860 | fprintf(stderr, " -b binderized mode only\n"); |
| 1861 | fprintf(stderr, " -p passthrough mode only\n"); |
| 1862 | fprintf(stderr, " (if -b and -p are both missing or both present, " |
| 1863 | "both modes are tested.)\n"); |
| 1864 | } |
| 1865 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1866 | int main(int argc, char **argv) { |
Yifan Hong | d12398d | 2016-10-13 11:05:29 -0700 | [diff] [blame] | 1867 | const char *me = argv[0]; |
| 1868 | bool b = false; |
| 1869 | bool p = false; |
| 1870 | struct option longopts[] = {{0,0,0,0}}; |
| 1871 | int res; |
| 1872 | while ((res = getopt_long(argc, argv, "hbp", longopts, NULL)) >= 0) { |
| 1873 | switch (res) { |
| 1874 | case 'h': { |
| 1875 | usage(me); |
| 1876 | exit(1); |
| 1877 | } break; |
| 1878 | |
| 1879 | case 'b': { |
| 1880 | b = true; |
| 1881 | } break; |
| 1882 | |
| 1883 | case 'p': { |
| 1884 | p = true; |
| 1885 | } break; |
| 1886 | |
| 1887 | case '?': |
| 1888 | default: { |
| 1889 | // ignore. pass to gTest. |
| 1890 | } break; |
| 1891 | } |
| 1892 | } |
| 1893 | if (!b && !p) { |
| 1894 | b = p = true; |
| 1895 | } |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1896 | |
| 1897 | ::testing::InitGoogleTest(&argc, argv); |
| 1898 | // put test in child process because RUN_ALL_TESTS |
| 1899 | // should not be run twice. |
Yifan Hong | d12398d | 2016-10-13 11:05:29 -0700 | [diff] [blame] | 1900 | int pStatus = p ? forkAndRunTests(PASSTHROUGH) : 0; |
| 1901 | int bStatus = b ? forkAndRunTests(BINDERIZED) : 0; |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1902 | |
Yifan Hong | 48562fd | 2016-10-24 15:26:10 -0700 | [diff] [blame] | 1903 | fprintf(stdout, "\n=========================================================\n\n" |
| 1904 | " Summary:\n\n"); |
Yifan Hong | d12398d | 2016-10-13 11:05:29 -0700 | [diff] [blame] | 1905 | if (p) { |
| 1906 | ALOGI("PASSTHROUGH Test result = %d", pStatus); |
| 1907 | handleStatus(pStatus, "PASSTHROUGH"); |
| 1908 | } |
| 1909 | if (b) { |
| 1910 | ALOGI("BINDERIZED Test result = %d", bStatus); |
| 1911 | handleStatus(bStatus, "BINDERIZED "); |
| 1912 | } |
| 1913 | |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1914 | if (pStatus == 0 && bStatus == 0) { |
Yifan Hong | 48562fd | 2016-10-24 15:26:10 -0700 | [diff] [blame] | 1915 | fprintf(stdout, " Hooray! All tests passed.\n"); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1916 | } |
Yifan Hong | 48562fd | 2016-10-24 15:26:10 -0700 | [diff] [blame] | 1917 | fprintf(stdout, "\n=========================================================\n\n"); |
Yifan Hong | c70f0d8 | 2016-10-10 14:50:22 -0700 | [diff] [blame] | 1918 | |
| 1919 | return pStatus + bStatus; |
| 1920 | } |