Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "VtsHalAudioV2_0TargetTest" |
| 18 | |
| 19 | #include <algorithm> |
| 20 | #include <cmath> |
| 21 | #include <cstddef> |
| 22 | #include <cstdio> |
| 23 | #include <limits> |
| 24 | #include <list> |
| 25 | #include <string> |
| 26 | #include <type_traits> |
| 27 | #include <vector> |
| 28 | |
Tri Vo | 6c00ac3 | 2017-10-12 15:47:32 -0700 | [diff] [blame] | 29 | #include <fcntl.h> |
| 30 | #include <unistd.h> |
| 31 | |
Yuexi Ma | 161b564 | 2017-03-10 13:44:22 -0800 | [diff] [blame] | 32 | #include <VtsHalHidlTargetTestBase.h> |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 33 | |
| 34 | #include <android-base/logging.h> |
| 35 | |
| 36 | #include <android/hardware/audio/2.0/IDevice.h> |
| 37 | #include <android/hardware/audio/2.0/IDevicesFactory.h> |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 38 | #include <android/hardware/audio/2.0/IPrimaryDevice.h> |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 39 | #include <android/hardware/audio/2.0/types.h> |
| 40 | #include <android/hardware/audio/common/2.0/types.h> |
| 41 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 42 | #include "utility/AssertOk.h" |
| 43 | #include "utility/PrettyPrintAudioTypes.h" |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 44 | #include "utility/ReturnIn.h" |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 45 | |
| 46 | using std::string; |
| 47 | using std::to_string; |
| 48 | using std::vector; |
| 49 | |
| 50 | using ::android::sp; |
| 51 | using ::android::hardware::Return; |
| 52 | using ::android::hardware::hidl_handle; |
| 53 | using ::android::hardware::hidl_string; |
| 54 | using ::android::hardware::hidl_vec; |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 55 | using ::android::hardware::MQDescriptorSync; |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 56 | using ::android::hardware::audio::V2_0::AudioDrain; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 57 | using ::android::hardware::audio::V2_0::DeviceAddress; |
| 58 | using ::android::hardware::audio::V2_0::IDevice; |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 59 | using ::android::hardware::audio::V2_0::IPrimaryDevice; |
| 60 | using TtyMode = ::android::hardware::audio::V2_0::IPrimaryDevice::TtyMode; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 61 | using ::android::hardware::audio::V2_0::IDevicesFactory; |
| 62 | using ::android::hardware::audio::V2_0::IStream; |
| 63 | using ::android::hardware::audio::V2_0::IStreamIn; |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 64 | using ::android::hardware::audio::V2_0::TimeSpec; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 65 | using ReadParameters = |
| 66 | ::android::hardware::audio::V2_0::IStreamIn::ReadParameters; |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 67 | using ReadStatus = ::android::hardware::audio::V2_0::IStreamIn::ReadStatus; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 68 | using ::android::hardware::audio::V2_0::IStreamOut; |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 69 | using ::android::hardware::audio::V2_0::IStreamOutCallback; |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 70 | using ::android::hardware::audio::V2_0::MmapBufferInfo; |
| 71 | using ::android::hardware::audio::V2_0::MmapPosition; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 72 | using ::android::hardware::audio::V2_0::ParameterValue; |
| 73 | using ::android::hardware::audio::V2_0::Result; |
| 74 | using ::android::hardware::audio::common::V2_0::AudioChannelMask; |
| 75 | using ::android::hardware::audio::common::V2_0::AudioConfig; |
| 76 | using ::android::hardware::audio::common::V2_0::AudioDevice; |
| 77 | using ::android::hardware::audio::common::V2_0::AudioFormat; |
| 78 | using ::android::hardware::audio::common::V2_0::AudioHandleConsts; |
| 79 | using ::android::hardware::audio::common::V2_0::AudioInputFlag; |
| 80 | using ::android::hardware::audio::common::V2_0::AudioIoHandle; |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 81 | using ::android::hardware::audio::common::V2_0::AudioMode; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 82 | using ::android::hardware::audio::common::V2_0::AudioOffloadInfo; |
| 83 | using ::android::hardware::audio::common::V2_0::AudioOutputFlag; |
| 84 | using ::android::hardware::audio::common::V2_0::AudioSource; |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 85 | using ::android::hardware::audio::common::V2_0::ThreadInfo; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 86 | |
| 87 | using utility::returnIn; |
| 88 | |
Kevin Rocard | 96f46c4 | 2017-05-08 11:53:07 -0700 | [diff] [blame] | 89 | const char* getTestName() { |
| 90 | return ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 91 | } |
| 92 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 93 | namespace doc { |
| 94 | /** Document the current test case. |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 95 | * Eg: calling `doc::test("Dump the state of the hal")` in the "debugDump" test |
| 96 | * will output: |
| 97 | * <testcase name="debugDump" status="run" time="6" |
| 98 | * classname="AudioPrimaryHidlTest" |
| 99 | description="Dump the state of the hal." /> |
| 100 | * see |
| 101 | https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#logging-additional-information |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 102 | */ |
| 103 | void test(const std::string& testCaseDocumentation) { |
| 104 | ::testing::Test::RecordProperty("description", testCaseDocumentation); |
| 105 | } |
| 106 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 107 | /** Document why a test was not fully run. Usually due to an optional feature |
| 108 | * not implemented. */ |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 109 | void partialTest(const std::string& reason) { |
Kevin Rocard | 96f46c4 | 2017-05-08 11:53:07 -0700 | [diff] [blame] | 110 | LOG(INFO) << "Test " << getTestName() << " partially run: " << reason; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 111 | ::testing::Test::RecordProperty("partialyRunTest", reason); |
| 112 | } |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 113 | |
| 114 | /** Add a note to the test. */ |
| 115 | void note(const std::string& note) { |
Kevin Rocard | 96f46c4 | 2017-05-08 11:53:07 -0700 | [diff] [blame] | 116 | LOG(INFO) << "Test " << getTestName() << " noted: " << note; |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 117 | ::testing::Test::RecordProperty("note", note); |
| 118 | } |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // Register callback for static object destruction |
| 122 | // Avoid destroying static objects after main return. |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 123 | // Post main return destruction leads to incorrect gtest timing measurements as |
| 124 | // well as harder |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 125 | // debuging if anything goes wrong during destruction. |
| 126 | class Environment : public ::testing::Environment { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 127 | public: |
| 128 | using TearDownFunc = std::function<void()>; |
| 129 | void registerTearDown(TearDownFunc&& tearDown) { |
| 130 | tearDowns.push_back(std::move(tearDown)); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 133 | private: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 134 | void TearDown() override { |
| 135 | // Call the tear downs in reverse order of insertion |
| 136 | for (auto& tearDown : tearDowns) { |
| 137 | tearDown(); |
| 138 | } |
| 139 | } |
| 140 | std::list<TearDownFunc> tearDowns; |
| 141 | }; |
| 142 | // Instance to register global tearDown |
| 143 | static Environment* environment; |
| 144 | |
Yuexi Ma | 161b564 | 2017-03-10 13:44:22 -0800 | [diff] [blame] | 145 | class HidlTest : public ::testing::VtsHalHidlTargetTestBase { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 146 | protected: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 147 | // Convenient member to store results |
| 148 | Result res; |
| 149 | }; |
| 150 | |
| 151 | ////////////////////////////////////////////////////////////////////////////// |
| 152 | ////////////////////// getService audio_devices_factory ////////////////////// |
| 153 | ////////////////////////////////////////////////////////////////////////////// |
| 154 | |
| 155 | // Test all audio devices |
| 156 | class AudioHidlTest : public HidlTest { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 157 | public: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 158 | void SetUp() override { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 159 | ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 160 | |
| 161 | if (devicesFactory == nullptr) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 162 | environment->registerTearDown([] { devicesFactory.clear(); }); |
| 163 | devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService< |
| 164 | IDevicesFactory>(); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 165 | } |
| 166 | ASSERT_TRUE(devicesFactory != nullptr); |
| 167 | } |
| 168 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 169 | protected: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 170 | // Cache the devicesFactory retrieval to speed up each test by ~0.5s |
| 171 | static sp<IDevicesFactory> devicesFactory; |
| 172 | }; |
| 173 | sp<IDevicesFactory> AudioHidlTest::devicesFactory; |
| 174 | |
| 175 | TEST_F(AudioHidlTest, GetAudioDevicesFactoryService) { |
| 176 | doc::test("test the getService (called in SetUp)"); |
| 177 | } |
| 178 | |
Mikhail Naganov | 8604a73 | 2017-04-24 09:29:22 -0700 | [diff] [blame] | 179 | TEST_F(AudioHidlTest, OpenDeviceInvalidParameter) { |
| 180 | doc::test("test passing an invalid parameter to openDevice"); |
| 181 | IDevicesFactory::Result result; |
| 182 | sp<IDevice> device; |
| 183 | ASSERT_OK(devicesFactory->openDevice(IDevicesFactory::Device(-1), |
| 184 | returnIn(result, device))); |
| 185 | ASSERT_EQ(IDevicesFactory::Result::INVALID_ARGUMENTS, result); |
| 186 | ASSERT_TRUE(device == nullptr); |
| 187 | } |
| 188 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 189 | ////////////////////////////////////////////////////////////////////////////// |
| 190 | /////////////////////////////// openDevice primary /////////////////////////// |
| 191 | ////////////////////////////////////////////////////////////////////////////// |
| 192 | |
| 193 | // Test the primary device |
| 194 | class AudioPrimaryHidlTest : public AudioHidlTest { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 195 | public: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 196 | /** Primary HAL test are NOT thread safe. */ |
| 197 | void SetUp() override { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 198 | ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUp()); // setup base |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 199 | |
| 200 | if (device == nullptr) { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 201 | IDevicesFactory::Result result; |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 202 | sp<IDevice> baseDevice; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 203 | ASSERT_OK( |
| 204 | devicesFactory->openDevice(IDevicesFactory::Device::PRIMARY, |
| 205 | returnIn(result, baseDevice))); |
Kevin Rocard | fba442a | 2017-03-31 19:34:41 -0700 | [diff] [blame] | 206 | ASSERT_OK(result); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 207 | ASSERT_TRUE(baseDevice != nullptr); |
| 208 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 209 | environment->registerTearDown([] { device.clear(); }); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 210 | device = IPrimaryDevice::castFrom(baseDevice); |
| 211 | ASSERT_TRUE(device != nullptr); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 212 | } |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 215 | protected: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 216 | // Cache the device opening to speed up each test by ~0.5s |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 217 | static sp<IPrimaryDevice> device; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 218 | }; |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 219 | sp<IPrimaryDevice> AudioPrimaryHidlTest::device; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 220 | |
| 221 | TEST_F(AudioPrimaryHidlTest, OpenPrimaryDevice) { |
| 222 | doc::test("Test the openDevice (called in SetUp)"); |
| 223 | } |
| 224 | |
| 225 | TEST_F(AudioPrimaryHidlTest, Init) { |
| 226 | doc::test("Test that the audio primary hal initialized correctly"); |
| 227 | ASSERT_OK(device->initCheck()); |
| 228 | } |
| 229 | |
| 230 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 231 | ///////////////////// {set,get}{Master,Mic}{Mute,Volume} ///////////////////// |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 232 | ////////////////////////////////////////////////////////////////////////////// |
| 233 | |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 234 | template <class Property> |
| 235 | class AccessorPrimaryHidlTest : public AudioPrimaryHidlTest { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 236 | protected: |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 237 | /** Test a property getter and setter. */ |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 238 | template <class Getter, class Setter> |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 239 | void testAccessors(const string& propertyName, |
| 240 | const vector<Property>& valuesToTest, Setter setter, |
| 241 | Getter getter, |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 242 | const vector<Property>& invalidValues = {}) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 243 | Property initialValue; // Save initial value to restore it at the end |
| 244 | // of the test |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 245 | ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue))); |
| 246 | ASSERT_OK(res); |
| 247 | |
| 248 | for (Property setValue : valuesToTest) { |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 249 | SCOPED_TRACE("Test " + propertyName + " getter and setter for " + |
| 250 | testing::PrintToString(setValue)); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 251 | ASSERT_OK((device.get()->*setter)(setValue)); |
| 252 | Property getValue; |
| 253 | // Make sure the getter returns the same value just set |
| 254 | ASSERT_OK((device.get()->*getter)(returnIn(res, getValue))); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 255 | ASSERT_OK(res); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 256 | EXPECT_EQ(setValue, getValue); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 257 | } |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 258 | |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 259 | for (Property invalidValue : invalidValues) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 260 | SCOPED_TRACE("Try to set " + propertyName + |
| 261 | " with the invalid value " + |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 262 | testing::PrintToString(invalidValue)); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 263 | EXPECT_RESULT(Result::INVALID_ARGUMENTS, |
| 264 | (device.get()->*setter)(invalidValue)); |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 267 | ASSERT_OK( |
| 268 | (device.get()->*setter)(initialValue)); // restore initial value |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** Test the getter and setter of an optional feature. */ |
| 272 | template <class Getter, class Setter> |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 273 | void testOptionalAccessors(const string& propertyName, |
| 274 | const vector<Property>& valuesToTest, |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 275 | Setter setter, Getter getter, |
| 276 | const vector<Property>& invalidValues = {}) { |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 277 | doc::test("Test the optional " + propertyName + " getters and setter"); |
| 278 | { |
| 279 | SCOPED_TRACE("Test feature support by calling the getter"); |
| 280 | Property initialValue; |
| 281 | ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue))); |
| 282 | if (res == Result::NOT_SUPPORTED) { |
| 283 | doc::partialTest(propertyName + " getter is not supported"); |
| 284 | return; |
| 285 | } |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 286 | ASSERT_OK(res); // If it is supported it must succeed |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 287 | } |
| 288 | // The feature is supported, test it |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 289 | testAccessors(propertyName, valuesToTest, setter, getter, |
| 290 | invalidValues); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 291 | } |
| 292 | }; |
| 293 | |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 294 | using BoolAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<bool>; |
| 295 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 296 | TEST_F(BoolAccessorPrimaryHidlTest, MicMuteTest) { |
| 297 | doc::test("Check that the mic can be muted and unmuted"); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 298 | testAccessors("mic mute", {true, false, true}, &IDevice::setMicMute, |
| 299 | &IDevice::getMicMute); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 300 | // TODO: check that the mic is really muted (all sample are 0) |
| 301 | } |
| 302 | |
| 303 | TEST_F(BoolAccessorPrimaryHidlTest, MasterMuteTest) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 304 | doc::test( |
| 305 | "If master mute is supported, try to mute and unmute the master " |
| 306 | "output"); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 307 | testOptionalAccessors("master mute", {true, false, true}, |
| 308 | &IDevice::setMasterMute, &IDevice::getMasterMute); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 309 | // TODO: check that the master volume is really muted |
| 310 | } |
| 311 | |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 312 | using FloatAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<float>; |
| 313 | TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) { |
| 314 | doc::test("Test the master volume if supported"); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 315 | testOptionalAccessors("master volume", {0, 0.5, 1}, |
Kevin Rocard | 92ce35d | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 316 | &IDevice::setMasterVolume, &IDevice::getMasterVolume, |
| 317 | {-0.1, 1.1, NAN, INFINITY, -INFINITY, |
| 318 | 1 + std::numeric_limits<float>::epsilon()}); |
| 319 | // TODO: check that the master volume is really changed |
| 320 | } |
| 321 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 322 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 323 | //////////////////////////////// AudioPatches //////////////////////////////// |
| 324 | ////////////////////////////////////////////////////////////////////////////// |
| 325 | |
| 326 | class AudioPatchPrimaryHidlTest : public AudioPrimaryHidlTest { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 327 | protected: |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 328 | bool areAudioPatchesSupported() { |
| 329 | auto result = device->supportsAudioPatches(); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 330 | EXPECT_IS_OK(result); |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 331 | return result; |
| 332 | } |
| 333 | }; |
| 334 | |
| 335 | TEST_F(AudioPatchPrimaryHidlTest, AudioPatches) { |
| 336 | doc::test("Test if audio patches are supported"); |
| 337 | if (!areAudioPatchesSupported()) { |
| 338 | doc::partialTest("Audio patches are not supported"); |
| 339 | return; |
| 340 | } |
| 341 | // TODO: test audio patches |
| 342 | } |
| 343 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 344 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 345 | //////////////// Required and recommended audio format support /////////////// |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 346 | // From: |
| 347 | // https://source.android.com/compatibility/android-cdd.html#5_4_audio_recording |
| 348 | // From: |
| 349 | // https://source.android.com/compatibility/android-cdd.html#5_5_audio_playback |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 350 | /////////// TODO: move to the beginning of the file for easier update //////// |
| 351 | ////////////////////////////////////////////////////////////////////////////// |
| 352 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 353 | class AudioConfigPrimaryTest : public AudioPatchPrimaryHidlTest { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 354 | public: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 355 | // Cache result ? |
| 356 | static const vector<AudioConfig> getRequiredSupportPlaybackAudioConfig() { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 357 | return combineAudioConfig( |
| 358 | {AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO}, |
| 359 | {8000, 11025, 16000, 22050, 32000, 44100}, |
| 360 | {AudioFormat::PCM_16_BIT}); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 361 | } |
| 362 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 363 | static const vector<AudioConfig> |
| 364 | getRecommendedSupportPlaybackAudioConfig() { |
| 365 | return combineAudioConfig( |
| 366 | {AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO}, |
| 367 | {24000, 48000}, {AudioFormat::PCM_16_BIT}); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static const vector<AudioConfig> getSupportedPlaybackAudioConfig() { |
| 371 | // TODO: retrieve audio config supported by the platform |
| 372 | // as declared in the policy configuration |
| 373 | return {}; |
| 374 | } |
| 375 | |
| 376 | static const vector<AudioConfig> getRequiredSupportCaptureAudioConfig() { |
| 377 | return combineAudioConfig({AudioChannelMask::IN_MONO}, |
| 378 | {8000, 11025, 16000, 44100}, |
| 379 | {AudioFormat::PCM_16_BIT}); |
| 380 | } |
| 381 | static const vector<AudioConfig> getRecommendedSupportCaptureAudioConfig() { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 382 | return combineAudioConfig({AudioChannelMask::IN_STEREO}, {22050, 48000}, |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 383 | {AudioFormat::PCM_16_BIT}); |
| 384 | } |
| 385 | static const vector<AudioConfig> getSupportedCaptureAudioConfig() { |
| 386 | // TODO: retrieve audio config supported by the platform |
| 387 | // as declared in the policy configuration |
| 388 | return {}; |
| 389 | } |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 390 | |
| 391 | private: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 392 | static const vector<AudioConfig> combineAudioConfig( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 393 | vector<AudioChannelMask> channelMasks, vector<uint32_t> sampleRates, |
| 394 | vector<AudioFormat> formats) { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 395 | vector<AudioConfig> configs; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 396 | for (auto channelMask : channelMasks) { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 397 | for (auto sampleRate : sampleRates) { |
| 398 | for (auto format : formats) { |
| 399 | AudioConfig config{}; |
| 400 | // leave offloadInfo to 0 |
| 401 | config.channelMask = channelMask; |
| 402 | config.sampleRateHz = sampleRate; |
| 403 | config.format = format; |
| 404 | // FIXME: leave frameCount to 0 ? |
| 405 | configs.push_back(config); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | return configs; |
| 410 | } |
| 411 | }; |
| 412 | |
Kevin Rocard | 9c36914 | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 413 | /** Generate a test name based on an audio config. |
| 414 | * |
| 415 | * As the only parameter changing are channel mask and sample rate, |
| 416 | * only print those ones in the test name. |
| 417 | */ |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 418 | static string generateTestName( |
| 419 | const testing::TestParamInfo<AudioConfig>& info) { |
Kevin Rocard | 9c36914 | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 420 | const AudioConfig& config = info.param; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 421 | return to_string(info.index) + "__" + to_string(config.sampleRateHz) + "_" + |
| 422 | // "MONO" is more clear than "FRONT_LEFT" |
| 423 | ((config.channelMask == AudioChannelMask::OUT_MONO || |
| 424 | config.channelMask == AudioChannelMask::IN_MONO) |
| 425 | ? "MONO" |
| 426 | : toString(config.channelMask)); |
Kevin Rocard | 9c36914 | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 429 | ////////////////////////////////////////////////////////////////////////////// |
| 430 | ///////////////////////////// getInputBufferSize ///////////////////////////// |
| 431 | ////////////////////////////////////////////////////////////////////////////// |
| 432 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 433 | // FIXME: execute input test only if platform declares |
| 434 | // android.hardware.microphone |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 435 | // how to get this value ? is it a property ??? |
| 436 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 437 | class AudioCaptureConfigPrimaryTest |
| 438 | : public AudioConfigPrimaryTest, |
| 439 | public ::testing::WithParamInterface<AudioConfig> { |
| 440 | protected: |
| 441 | void inputBufferSizeTest(const AudioConfig& audioConfig, |
| 442 | bool supportRequired) { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 443 | uint64_t bufferSize; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 444 | ASSERT_OK( |
| 445 | device->getInputBufferSize(audioConfig, returnIn(res, bufferSize))); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 446 | |
| 447 | switch (res) { |
| 448 | case Result::INVALID_ARGUMENTS: |
| 449 | EXPECT_FALSE(supportRequired); |
| 450 | break; |
| 451 | case Result::OK: |
| 452 | // Check that the buffer is of a sane size |
| 453 | // For now only that it is > 0 |
| 454 | EXPECT_GT(bufferSize, uint64_t(0)); |
| 455 | break; |
| 456 | default: |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 457 | FAIL() << "Invalid return status: " |
| 458 | << ::testing::PrintToString(res); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | }; |
| 462 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 463 | // Test that the required capture config and those declared in the policy are |
| 464 | // indeed supported |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 465 | class RequiredInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {}; |
| 466 | TEST_P(RequiredInputBufferSizeTest, RequiredInputBufferSizeTest) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 467 | doc::test( |
| 468 | "Input buffer size must be retrievable for a format with required " |
| 469 | "support."); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 470 | inputBufferSizeTest(GetParam(), true); |
| 471 | } |
| 472 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 473 | RequiredInputBufferSize, RequiredInputBufferSizeTest, |
| 474 | ::testing::ValuesIn( |
| 475 | AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()), |
| 476 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 477 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 478 | SupportedInputBufferSize, RequiredInputBufferSizeTest, |
| 479 | ::testing::ValuesIn( |
| 480 | AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()), |
| 481 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 482 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 483 | // Test that the recommended capture config are supported or lead to a |
| 484 | // INVALID_ARGUMENTS return |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 485 | class OptionalInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {}; |
| 486 | TEST_P(OptionalInputBufferSizeTest, OptionalInputBufferSizeTest) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 487 | doc::test( |
| 488 | "Input buffer size should be retrievable for a format with recommended " |
| 489 | "support."); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 490 | inputBufferSizeTest(GetParam(), false); |
| 491 | } |
| 492 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 493 | RecommendedCaptureAudioConfigSupport, OptionalInputBufferSizeTest, |
| 494 | ::testing::ValuesIn( |
| 495 | AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()), |
| 496 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 497 | |
| 498 | ////////////////////////////////////////////////////////////////////////////// |
| 499 | /////////////////////////////// setScreenState /////////////////////////////// |
| 500 | ////////////////////////////////////////////////////////////////////////////// |
| 501 | |
| 502 | TEST_F(AudioPrimaryHidlTest, setScreenState) { |
| 503 | doc::test("Check that the hal can receive the screen state"); |
| 504 | for (bool turnedOn : {false, true, true, false, false}) { |
| 505 | auto ret = device->setScreenState(turnedOn); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 506 | ASSERT_IS_OK(ret); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 507 | Result result = ret; |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 508 | auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED}; |
| 509 | ASSERT_RESULT(okOrNotSupported, result); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | ////////////////////////////////////////////////////////////////////////////// |
| 514 | //////////////////////////// {get,set}Parameters ///////////////////////////// |
| 515 | ////////////////////////////////////////////////////////////////////////////// |
| 516 | |
| 517 | TEST_F(AudioPrimaryHidlTest, getParameters) { |
| 518 | doc::test("Check that the hal can set and get parameters"); |
| 519 | hidl_vec<hidl_string> keys; |
| 520 | hidl_vec<ParameterValue> values; |
| 521 | ASSERT_OK(device->getParameters(keys, returnIn(res, values))); |
| 522 | ASSERT_OK(device->setParameters(values)); |
| 523 | values.resize(0); |
| 524 | ASSERT_OK(device->setParameters(values)); |
| 525 | } |
| 526 | |
| 527 | ////////////////////////////////////////////////////////////////////////////// |
| 528 | //////////////////////////////// debugDebug ////////////////////////////////// |
| 529 | ////////////////////////////////////////////////////////////////////////////// |
| 530 | |
Kevin Rocard | b903124 | 2017-03-13 12:20:54 -0700 | [diff] [blame] | 531 | template <class DebugDump> |
| 532 | static void testDebugDump(DebugDump debugDump) { |
Tri Vo | 6c00ac3 | 2017-10-12 15:47:32 -0700 | [diff] [blame] | 533 | // File descriptors to our pipe. fds[0] corresponds to the read end and |
| 534 | // fds[1] to the write end. |
| 535 | int fds[2]; |
| 536 | ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 537 | |
Tri Vo | 7d35a3d | 2017-10-17 11:07:29 -0700 | [diff] [blame] | 538 | // Make sure that the pipe is at least 1 MB in size. The test process runs |
| 539 | // in su domain, so it should be safe to make this call. |
| 540 | fcntl(fds[0], F_SETPIPE_SZ, 1 << 20); |
| 541 | |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 542 | // Wrap the temporary file file descriptor in a native handle |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 543 | auto* nativeHandle = native_handle_create(1, 0); |
| 544 | ASSERT_NE(nullptr, nativeHandle); |
Tri Vo | 6c00ac3 | 2017-10-12 15:47:32 -0700 | [diff] [blame] | 545 | nativeHandle->data[0] = fds[1]; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 546 | |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 547 | // Wrap this native handle in a hidl handle |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 548 | hidl_handle handle; |
Tri Vo | 6c00ac3 | 2017-10-12 15:47:32 -0700 | [diff] [blame] | 549 | handle.setTo(nativeHandle, false /*take ownership*/); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 550 | |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 551 | ASSERT_OK(debugDump(handle)); |
| 552 | |
| 553 | // Check that at least one bit was written by the hal |
Kevin Rocard | ee771e9 | 2017-03-08 17:17:25 -0800 | [diff] [blame] | 554 | // TODO: debugDump does not return a Result. |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 555 | // This mean that the hal can not report that it not implementing the |
| 556 | // function. |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 557 | char buff; |
Tri Vo | 6c00ac3 | 2017-10-12 15:47:32 -0700 | [diff] [blame] | 558 | if (read(fds[0], &buff, 1) != 1) { |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 559 | doc::note("debugDump does not seem implemented"); |
| 560 | } |
Tri Vo | 6c00ac3 | 2017-10-12 15:47:32 -0700 | [diff] [blame] | 561 | EXPECT_EQ(0, close(fds[0])) << errno; |
| 562 | EXPECT_EQ(0, close(fds[1])) << errno; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 565 | TEST_F(AudioPrimaryHidlTest, DebugDump) { |
Kevin Rocard | b903124 | 2017-03-13 12:20:54 -0700 | [diff] [blame] | 566 | doc::test("Check that the hal can dump its state without error"); |
Chih-Hung Hsieh | d3bc681 | 2017-05-15 12:31:25 -0700 | [diff] [blame] | 567 | testDebugDump([](const auto& handle) { return device->debugDump(handle); }); |
Kevin Rocard | b903124 | 2017-03-13 12:20:54 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Kevin Rocard | 5e5783d | 2017-05-02 18:41:46 -0700 | [diff] [blame] | 570 | TEST_F(AudioPrimaryHidlTest, DebugDumpInvalidArguments) { |
Mikhail Naganov | 3e6fe75 | 2017-04-24 10:44:08 -0700 | [diff] [blame] | 571 | doc::test("Check that the hal dump doesn't crash on invalid arguments"); |
| 572 | ASSERT_OK(device->debugDump(hidl_handle())); |
| 573 | } |
| 574 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 575 | ////////////////////////////////////////////////////////////////////////////// |
| 576 | ////////////////////////// open{Output,Input}Stream ////////////////////////// |
| 577 | ////////////////////////////////////////////////////////////////////////////// |
| 578 | |
| 579 | template <class Stream> |
| 580 | class OpenStreamTest : public AudioConfigPrimaryTest, |
| 581 | public ::testing::WithParamInterface<AudioConfig> { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 582 | protected: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 583 | template <class Open> |
| 584 | void testOpen(Open openStream, const AudioConfig& config) { |
| 585 | // FIXME: Open a stream without an IOHandle |
| 586 | // This is not required to be accepted by hal implementations |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 587 | AudioIoHandle ioHandle = |
| 588 | (AudioIoHandle)AudioHandleConsts::AUDIO_IO_HANDLE_NONE; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 589 | AudioConfig suggestedConfig{}; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 590 | ASSERT_OK(openStream(ioHandle, config, |
| 591 | returnIn(res, stream, suggestedConfig))); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 592 | |
| 593 | // TODO: only allow failure for RecommendedPlaybackAudioConfig |
| 594 | switch (res) { |
| 595 | case Result::OK: |
| 596 | ASSERT_TRUE(stream != nullptr); |
| 597 | audioConfig = config; |
| 598 | break; |
| 599 | case Result::INVALID_ARGUMENTS: |
| 600 | ASSERT_TRUE(stream == nullptr); |
| 601 | AudioConfig suggestedConfigRetry; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 602 | // Could not open stream with config, try again with the |
| 603 | // suggested one |
| 604 | ASSERT_OK( |
| 605 | openStream(ioHandle, suggestedConfig, |
| 606 | returnIn(res, stream, suggestedConfigRetry))); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 607 | // This time it must succeed |
| 608 | ASSERT_OK(res); |
Kevin Rocard | 4aefd1c | 2017-05-02 18:58:58 -0700 | [diff] [blame] | 609 | ASSERT_TRUE(stream != nullptr); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 610 | audioConfig = suggestedConfig; |
| 611 | break; |
| 612 | default: |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 613 | FAIL() << "Invalid return status: " |
| 614 | << ::testing::PrintToString(res); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 615 | } |
| 616 | open = true; |
| 617 | } |
| 618 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 619 | Return<Result> closeStream() { |
| 620 | open = false; |
| 621 | return stream->close(); |
| 622 | } |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 623 | |
| 624 | private: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 625 | void TearDown() override { |
| 626 | if (open) { |
| 627 | ASSERT_OK(stream->close()); |
| 628 | } |
| 629 | } |
| 630 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 631 | protected: |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 632 | AudioConfig audioConfig; |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 633 | DeviceAddress address = {}; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 634 | sp<Stream> stream; |
| 635 | bool open = false; |
| 636 | }; |
| 637 | |
| 638 | ////////////////////////////// openOutputStream ////////////////////////////// |
| 639 | |
| 640 | class OutputStreamTest : public OpenStreamTest<IStreamOut> { |
| 641 | virtual void SetUp() override { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 642 | ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 643 | address.device = AudioDevice::OUT_DEFAULT; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 644 | const AudioConfig& config = GetParam(); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 645 | AudioOutputFlag flags = |
| 646 | AudioOutputFlag::NONE; // TODO: test all flag combination |
| 647 | testOpen( |
| 648 | [&](AudioIoHandle handle, AudioConfig config, auto cb) { |
| 649 | return device->openOutputStream(handle, address, config, flags, |
| 650 | cb); |
| 651 | }, |
| 652 | config); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 653 | } |
| 654 | }; |
| 655 | TEST_P(OutputStreamTest, OpenOutputStreamTest) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 656 | doc::test( |
| 657 | "Check that output streams can be open with the required and " |
| 658 | "recommended config"); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 659 | // Open done in SetUp |
| 660 | } |
| 661 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 662 | RequiredOutputStreamConfigSupport, OutputStreamTest, |
| 663 | ::testing::ValuesIn( |
| 664 | AudioConfigPrimaryTest::getRequiredSupportPlaybackAudioConfig()), |
| 665 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 666 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 667 | SupportedOutputStreamConfig, OutputStreamTest, |
| 668 | ::testing::ValuesIn( |
| 669 | AudioConfigPrimaryTest::getSupportedPlaybackAudioConfig()), |
| 670 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 671 | |
| 672 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 673 | RecommendedOutputStreamConfigSupport, OutputStreamTest, |
| 674 | ::testing::ValuesIn( |
| 675 | AudioConfigPrimaryTest::getRecommendedSupportPlaybackAudioConfig()), |
| 676 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 677 | |
| 678 | ////////////////////////////// openInputStream ////////////////////////////// |
| 679 | |
| 680 | class InputStreamTest : public OpenStreamTest<IStreamIn> { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 681 | virtual void SetUp() override { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 682 | ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 683 | address.device = AudioDevice::IN_DEFAULT; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 684 | const AudioConfig& config = GetParam(); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 685 | AudioInputFlag flags = |
| 686 | AudioInputFlag::NONE; // TODO: test all flag combination |
| 687 | AudioSource source = |
| 688 | AudioSource::DEFAULT; // TODO: test all flag combination |
| 689 | testOpen( |
| 690 | [&](AudioIoHandle handle, AudioConfig config, auto cb) { |
| 691 | return device->openInputStream(handle, address, config, flags, |
| 692 | source, cb); |
| 693 | }, |
| 694 | config); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 695 | } |
| 696 | }; |
| 697 | |
| 698 | TEST_P(InputStreamTest, OpenInputStreamTest) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 699 | doc::test( |
| 700 | "Check that input streams can be open with the required and " |
| 701 | "recommended config"); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 702 | // Open done in setup |
| 703 | } |
| 704 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 705 | RequiredInputStreamConfigSupport, InputStreamTest, |
| 706 | ::testing::ValuesIn( |
| 707 | AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()), |
| 708 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 709 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 710 | SupportedInputStreamConfig, InputStreamTest, |
| 711 | ::testing::ValuesIn( |
| 712 | AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()), |
| 713 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 714 | |
| 715 | INSTANTIATE_TEST_CASE_P( |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 716 | RecommendedInputStreamConfigSupport, InputStreamTest, |
| 717 | ::testing::ValuesIn( |
| 718 | AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()), |
| 719 | &generateTestName); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 720 | |
| 721 | ////////////////////////////////////////////////////////////////////////////// |
| 722 | ////////////////////////////// IStream getters /////////////////////////////// |
| 723 | ////////////////////////////////////////////////////////////////////////////// |
| 724 | |
| 725 | /** Unpack the provided result. |
| 726 | * If the result is not OK, register a failure and return an undefined value. */ |
| 727 | template <class R> |
| 728 | static R extract(Return<R> ret) { |
| 729 | if (!ret.isOk()) { |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 730 | EXPECT_IS_OK(ret); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 731 | return R{}; |
| 732 | } |
| 733 | return ret; |
| 734 | } |
| 735 | |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 736 | /* Could not find a way to write a test for two parametrized class fixure |
| 737 | * thus use this macro do duplicate tests for Input and Output stream */ |
| 738 | #define TEST_IO_STREAM(test_name, documentation, code) \ |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 739 | TEST_P(InputStreamTest, test_name) { \ |
| 740 | doc::test(documentation); \ |
| 741 | code; \ |
| 742 | } \ |
| 743 | TEST_P(OutputStreamTest, test_name) { \ |
| 744 | doc::test(documentation); \ |
| 745 | code; \ |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 748 | TEST_IO_STREAM( |
| 749 | GetFrameCount, |
| 750 | "Check that the stream frame count == the one it was opened with", |
| 751 | ASSERT_EQ(audioConfig.frameCount, extract(stream->getFrameCount()))) |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 752 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 753 | TEST_IO_STREAM( |
| 754 | GetSampleRate, |
| 755 | "Check that the stream sample rate == the one it was opened with", |
Kevin Rocard | fd297c6 | 2017-05-12 15:25:09 -0700 | [diff] [blame] | 756 | stream->getSampleRate()) |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 757 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 758 | TEST_IO_STREAM( |
| 759 | GetChannelMask, |
| 760 | "Check that the stream channel mask == the one it was opened with", |
Kevin Rocard | fd297c6 | 2017-05-12 15:25:09 -0700 | [diff] [blame] | 761 | stream->getChannelMask()) |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 762 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 763 | TEST_IO_STREAM(GetFormat, |
| 764 | "Check that the stream format == the one it was opened with", |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 765 | ASSERT_EQ(audioConfig.format, extract(stream->getFormat()))) |
| 766 | |
| 767 | // TODO: for now only check that the framesize is not incoherent |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 768 | TEST_IO_STREAM(GetFrameSize, |
| 769 | "Check that the stream frame size == the one it was opened with", |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 770 | ASSERT_GT(extract(stream->getFrameSize()), 0U)) |
| 771 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 772 | TEST_IO_STREAM(GetBufferSize, |
| 773 | "Check that the stream buffer size== the one it was opened with", |
| 774 | ASSERT_GE(extract(stream->getBufferSize()), |
| 775 | extract(stream->getFrameSize()))); |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 776 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 777 | template <class Property, class CapabilityGetter, class Getter, class Setter> |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 778 | static void testCapabilityGetter(const string& name, IStream* stream, |
| 779 | Property currentValue, |
| 780 | CapabilityGetter capablityGetter, |
| 781 | Getter getter, Setter setter) { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 782 | hidl_vec<Property> capabilities; |
| 783 | ASSERT_OK((stream->*capablityGetter)(returnIn(capabilities))); |
| 784 | if (capabilities.size() == 0) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 785 | // The default hal should probably return a NOT_SUPPORTED if the hal |
| 786 | // does not expose |
| 787 | // capability retrieval. For now it returns an empty list if not |
| 788 | // implemented |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 789 | doc::partialTest(name + " is not supported"); |
| 790 | return; |
| 791 | }; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 792 | // TODO: This code has never been tested on a hal that supports |
| 793 | // getSupportedSampleRates |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 794 | EXPECT_NE(std::find(capabilities.begin(), capabilities.end(), currentValue), |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 795 | capabilities.end()) |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 796 | << "current " << name << " is not in the list of the supported ones " |
| 797 | << toString(capabilities); |
| 798 | |
| 799 | // Check that all declared supported values are indeed supported |
| 800 | for (auto capability : capabilities) { |
| 801 | ASSERT_OK((stream->*setter)(capability)); |
| 802 | ASSERT_EQ(capability, extract((stream->*getter)())); |
| 803 | } |
| 804 | } |
| 805 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 806 | TEST_IO_STREAM(SupportedSampleRate, |
| 807 | "Check that the stream sample rate is declared as supported", |
| 808 | testCapabilityGetter("getSupportedSampleRate", stream.get(), |
| 809 | extract(stream->getSampleRate()), |
| 810 | &IStream::getSupportedSampleRates, |
| 811 | &IStream::getSampleRate, |
| 812 | &IStream::setSampleRate)) |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 813 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 814 | TEST_IO_STREAM(SupportedChannelMask, |
| 815 | "Check that the stream channel mask is declared as supported", |
| 816 | testCapabilityGetter("getSupportedChannelMask", stream.get(), |
| 817 | extract(stream->getChannelMask()), |
| 818 | &IStream::getSupportedChannelMasks, |
| 819 | &IStream::getChannelMask, |
| 820 | &IStream::setChannelMask)) |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 821 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 822 | TEST_IO_STREAM(SupportedFormat, |
| 823 | "Check that the stream format is declared as supported", |
| 824 | testCapabilityGetter("getSupportedFormat", stream.get(), |
| 825 | extract(stream->getFormat()), |
| 826 | &IStream::getSupportedFormats, |
Kevin Rocard | a7df7fc | 2017-03-10 18:37:46 -0800 | [diff] [blame] | 827 | &IStream::getFormat, &IStream::setFormat)) |
| 828 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 829 | static void testGetDevice(IStream* stream, AudioDevice expectedDevice) { |
Kevin Rocard | 8f8730c | 2017-05-02 19:34:29 -0700 | [diff] [blame] | 830 | // Unfortunately the interface does not allow the implementation to return |
| 831 | // NOT_SUPPORTED |
| 832 | // Thus allow NONE as signaling that the call is not supported. |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 833 | auto ret = stream->getDevice(); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 834 | ASSERT_IS_OK(ret); |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 835 | AudioDevice device = ret; |
Kevin Rocard | 8f8730c | 2017-05-02 19:34:29 -0700 | [diff] [blame] | 836 | ASSERT_TRUE(device == expectedDevice || device == AudioDevice::NONE) |
| 837 | << "Expected: " << ::testing::PrintToString(expectedDevice) |
| 838 | << "\n Actual: " << ::testing::PrintToString(device); |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 841 | TEST_IO_STREAM(GetDevice, |
| 842 | "Check that the stream device == the one it was opened with", |
| 843 | areAudioPatchesSupported() |
| 844 | ? doc::partialTest("Audio patches are supported") |
| 845 | : testGetDevice(stream.get(), address.device)) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 846 | |
| 847 | static void testSetDevice(IStream* stream, const DeviceAddress& address) { |
| 848 | DeviceAddress otherAddress = address; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 849 | otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 |
| 850 | ? AudioDevice::OUT_SPEAKER |
| 851 | : AudioDevice::IN_BUILTIN_MIC; |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 852 | EXPECT_OK(stream->setDevice(otherAddress)); |
| 853 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 854 | ASSERT_OK(stream->setDevice(address)); // Go back to the original value |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 857 | TEST_IO_STREAM( |
| 858 | SetDevice, |
| 859 | "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC", |
| 860 | areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported") |
| 861 | : testSetDevice(stream.get(), address)) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 862 | |
Kevin Rocard | fd297c6 | 2017-05-12 15:25:09 -0700 | [diff] [blame] | 863 | static void testGetAudioProperties(IStream* stream) { |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 864 | uint32_t sampleRateHz; |
| 865 | AudioChannelMask mask; |
| 866 | AudioFormat format; |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 867 | stream->getAudioProperties(returnIn(sampleRateHz, mask, format)); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 868 | } |
| 869 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 870 | TEST_IO_STREAM( |
| 871 | GetAudioProperties, |
| 872 | "Check that the stream audio properties == the ones it was opened with", |
Kevin Rocard | fd297c6 | 2017-05-12 15:25:09 -0700 | [diff] [blame] | 873 | testGetAudioProperties(stream.get())) |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 874 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 875 | static void testConnectedState(IStream* stream) { |
| 876 | DeviceAddress address = {}; |
| 877 | using AD = AudioDevice; |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 878 | for (auto device : |
| 879 | {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) { |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 880 | address.device = device; |
| 881 | |
| 882 | ASSERT_OK(stream->setConnectedState(address, true)); |
| 883 | ASSERT_OK(stream->setConnectedState(address, false)); |
| 884 | } |
| 885 | } |
| 886 | TEST_IO_STREAM(SetConnectedState, |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 887 | "Check that the stream can be notified of device connection and " |
| 888 | "deconnection", |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 889 | testConnectedState(stream.get())) |
| 890 | |
Kevin Rocard | f8500dc | 2017-05-03 10:43:21 -0700 | [diff] [blame] | 891 | static auto invalidArgsOrNotSupportedOrOK = {Result::INVALID_ARGUMENTS, |
| 892 | Result::NOT_SUPPORTED, Result::OK}; |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 893 | TEST_IO_STREAM(SetHwAvSync, "Try to set hardware sync to an invalid value", |
Kevin Rocard | f8500dc | 2017-05-03 10:43:21 -0700 | [diff] [blame] | 894 | ASSERT_RESULT(invalidArgsOrNotSupportedOrOK, |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 895 | stream->setHwAvSync(666))) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 896 | |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 897 | TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 898 | ASSERT_IS_OK(device->getHwAvSync())); |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 899 | |
Kevin Rocard | fa3b4a9 | 2017-05-02 17:38:34 -0700 | [diff] [blame] | 900 | static void checkGetNoParameter(IStream* stream, hidl_vec<hidl_string> keys, |
| 901 | vector<Result> expectedResults) { |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 902 | hidl_vec<ParameterValue> parameters; |
| 903 | Result res; |
| 904 | ASSERT_OK(stream->getParameters(keys, returnIn(res, parameters))); |
| 905 | ASSERT_RESULT(expectedResults, res); |
| 906 | if (res == Result::OK) { |
Kevin Rocard | 4aefd1c | 2017-05-02 18:58:58 -0700 | [diff] [blame] | 907 | for (auto& parameter : parameters) { |
| 908 | ASSERT_EQ(0U, parameter.value.size()) << toString(parameter); |
| 909 | } |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 913 | /* Get/Set parameter is intended to be an opaque channel between vendors app and |
| 914 | * their HALs. |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 915 | * Thus can not be meaningfully tested. |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 916 | */ |
| 917 | TEST_IO_STREAM(getEmptySetParameter, "Retrieve the values of an empty set", |
Kevin Rocard | fa3b4a9 | 2017-05-02 17:38:34 -0700 | [diff] [blame] | 918 | checkGetNoParameter(stream.get(), {} /* keys */, {Result::OK})) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 919 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 920 | TEST_IO_STREAM(getNonExistingParameter, |
| 921 | "Retrieve the values of an non existing parameter", |
Kevin Rocard | fa3b4a9 | 2017-05-02 17:38:34 -0700 | [diff] [blame] | 922 | checkGetNoParameter(stream.get(), |
| 923 | {"Non existing key"} /* keys */, |
| 924 | {Result::NOT_SUPPORTED})) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 925 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 926 | TEST_IO_STREAM(setEmptySetParameter, |
| 927 | "Set the values of an empty set of parameters", |
Kevin Rocard | f8500dc | 2017-05-03 10:43:21 -0700 | [diff] [blame] | 928 | ASSERT_RESULT(Result::OK, stream->setParameters({}))) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 929 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 930 | TEST_IO_STREAM( |
| 931 | setNonExistingParameter, "Set the values of an non existing parameter", |
Kevin Rocard | f8500dc | 2017-05-03 10:43:21 -0700 | [diff] [blame] | 932 | // Unfortunately, the set_parameter legacy interface did not return any |
| 933 | // error code when a key is not supported. |
| 934 | // To allow implementation to just wrapped the legacy one, consider OK as a |
| 935 | // valid result for setting a non existing parameter. |
| 936 | ASSERT_RESULT(invalidArgsOrNotSupportedOrOK, |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 937 | stream->setParameters({{"non existing key", "0"}}))) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 938 | |
Kevin Rocard | b903124 | 2017-03-13 12:20:54 -0700 | [diff] [blame] | 939 | TEST_IO_STREAM(DebugDump, |
| 940 | "Check that a stream can dump its state without error", |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 941 | testDebugDump([this](const auto& handle) { |
| 942 | return stream->debugDump(handle); |
| 943 | })) |
Kevin Rocard | b903124 | 2017-03-13 12:20:54 -0700 | [diff] [blame] | 944 | |
Mikhail Naganov | 3e6fe75 | 2017-04-24 10:44:08 -0700 | [diff] [blame] | 945 | TEST_IO_STREAM(DebugDumpInvalidArguments, |
| 946 | "Check that the stream dump doesn't crash on invalid arguments", |
| 947 | ASSERT_OK(stream->debugDump(hidl_handle()))) |
| 948 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 949 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 950 | ////////////////////////////// addRemoveEffect /////////////////////////////// |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 951 | ////////////////////////////////////////////////////////////////////////////// |
| 952 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 953 | TEST_IO_STREAM(AddNonExistingEffect, "Adding a non existing effect should fail", |
| 954 | ASSERT_RESULT(Result::INVALID_ARGUMENTS, stream->addEffect(666))) |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 955 | TEST_IO_STREAM(RemoveNonExistingEffect, |
| 956 | "Removing a non existing effect should fail", |
| 957 | ASSERT_RESULT(Result::INVALID_ARGUMENTS, |
| 958 | stream->removeEffect(666))) |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 959 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 960 | // TODO: positive tests |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 961 | |
| 962 | ////////////////////////////////////////////////////////////////////////////// |
| 963 | /////////////////////////////// Control //////////////////////////////// |
| 964 | ////////////////////////////////////////////////////////////////////////////// |
| 965 | |
| 966 | TEST_IO_STREAM(standby, "Make sure the stream can be put in stanby", |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 967 | ASSERT_OK(stream->standby())) // can not fail |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 968 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 969 | static vector<Result> invalidStateOrNotSupported = {Result::INVALID_STATE, |
| 970 | Result::NOT_SUPPORTED}; |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 971 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 972 | TEST_IO_STREAM(startNoMmap, |
| 973 | "Starting a mmaped stream before mapping it should fail", |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 974 | ASSERT_RESULT(invalidStateOrNotSupported, stream->start())) |
| 975 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 976 | TEST_IO_STREAM(stopNoMmap, |
| 977 | "Stopping a mmaped stream before mapping it should fail", |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 978 | ASSERT_RESULT(invalidStateOrNotSupported, stream->stop())) |
| 979 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 980 | TEST_IO_STREAM(getMmapPositionNoMmap, |
| 981 | "Get a stream Mmap position before mapping it should fail", |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 982 | ASSERT_RESULT(invalidStateOrNotSupported, stream->stop())) |
| 983 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 984 | TEST_IO_STREAM(close, "Make sure a stream can be closed", |
| 985 | ASSERT_OK(closeStream())) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 986 | TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice", |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 987 | ASSERT_OK(closeStream()); |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 988 | ASSERT_RESULT(Result::INVALID_STATE, closeStream())) |
| 989 | |
Kevin Rocard | f8500dc | 2017-05-03 10:43:21 -0700 | [diff] [blame] | 990 | static auto invalidArgsOrNotSupported = {Result::INVALID_ARGUMENTS, |
| 991 | Result::NOT_SUPPORTED}; |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 992 | static void testCreateTooBigMmapBuffer(IStream* stream) { |
| 993 | MmapBufferInfo info; |
| 994 | Result res; |
| 995 | // Assume that int max is a value too big to be allocated |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 996 | // This is true currently with a 32bit media server, but might not when it |
| 997 | // will run in 64 bit |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 998 | auto minSizeFrames = std::numeric_limits<int32_t>::max(); |
| 999 | ASSERT_OK(stream->createMmapBuffer(minSizeFrames, returnIn(res, info))); |
| 1000 | ASSERT_RESULT(invalidArgsOrNotSupported, res); |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1003 | TEST_IO_STREAM(CreateTooBigMmapBuffer, "Create mmap buffer too big should fail", |
| 1004 | testCreateTooBigMmapBuffer(stream.get())) |
| 1005 | |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1006 | static void testGetMmapPositionOfNonMmapedStream(IStream* stream) { |
| 1007 | Result res; |
| 1008 | MmapPosition position; |
| 1009 | ASSERT_OK(stream->getMmapPosition(returnIn(res, position))); |
| 1010 | ASSERT_RESULT(invalidArgsOrNotSupported, res); |
| 1011 | } |
| 1012 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1013 | TEST_IO_STREAM( |
| 1014 | GetMmapPositionOfNonMmapedStream, |
| 1015 | "Retrieving the mmap position of a non mmaped stream should fail", |
| 1016 | testGetMmapPositionOfNonMmapedStream(stream.get())) |
Kevin Rocard | 8878b4b | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1017 | |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 1018 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1019 | ///////////////////////////////// StreamIn /////////////////////////////////// |
| 1020 | ////////////////////////////////////////////////////////////////////////////// |
| 1021 | |
| 1022 | TEST_P(InputStreamTest, GetAudioSource) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1023 | doc::test( |
| 1024 | "Retrieving the audio source of an input stream should always succeed"); |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1025 | AudioSource source; |
| 1026 | ASSERT_OK(stream->getAudioSource(returnIn(res, source))); |
Kevin Rocard | 98390a6 | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1027 | if (res == Result::NOT_SUPPORTED) { |
| 1028 | doc::partialTest("getAudioSource is not supported"); |
| 1029 | return; |
| 1030 | } |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1031 | ASSERT_OK(res); |
| 1032 | ASSERT_EQ(AudioSource::DEFAULT, source); |
| 1033 | } |
| 1034 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1035 | static void testUnitaryGain(std::function<Return<Result>(float)> setGain) { |
Kevin Rocard | c4f1b2f | 2017-05-03 11:19:25 -0700 | [diff] [blame] | 1036 | for (float value : |
| 1037 | (float[]){-INFINITY, -1.0, 1.0 + std::numeric_limits<float>::epsilon(), |
| 1038 | 2.0, INFINITY, NAN}) { |
Kevin Rocard | a1d6ea4 | 2017-05-08 17:08:11 -0700 | [diff] [blame] | 1039 | EXPECT_RESULT(Result::INVALID_ARGUMENTS, setGain(value)) << "value=" |
| 1040 | << value; |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1041 | } |
Kevin Rocard | c4f1b2f | 2017-05-03 11:19:25 -0700 | [diff] [blame] | 1042 | // Do not consider -0.0 as an invalid value as it is == with 0.0 |
| 1043 | for (float value : {-0.0, 0.0, 0.01, 0.5, 0.09, 1.0 /* Restore volume*/}) { |
Kevin Rocard | a1d6ea4 | 2017-05-08 17:08:11 -0700 | [diff] [blame] | 1044 | EXPECT_OK(setGain(value)) << "value=" << value; |
Kevin Rocard | c4f1b2f | 2017-05-03 11:19:25 -0700 | [diff] [blame] | 1045 | } |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Kevin Rocard | 98390a6 | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1048 | static void testOptionalUnitaryGain( |
| 1049 | std::function<Return<Result>(float)> setGain, string debugName) { |
| 1050 | auto result = setGain(1); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 1051 | ASSERT_IS_OK(result); |
Kevin Rocard | 98390a6 | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1052 | if (result == Result::NOT_SUPPORTED) { |
| 1053 | doc::partialTest(debugName + " is not supported"); |
| 1054 | return; |
| 1055 | } |
| 1056 | testUnitaryGain(setGain); |
| 1057 | } |
| 1058 | |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1059 | TEST_P(InputStreamTest, SetGain) { |
| 1060 | doc::test("The gain of an input stream should only be set between [0,1]"); |
Kevin Rocard | 98390a6 | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1061 | testOptionalUnitaryGain( |
| 1062 | [this](float volume) { return stream->setGain(volume); }, |
| 1063 | "InputStream::setGain"); |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1066 | static void testPrepareForReading(IStreamIn* stream, uint32_t frameSize, |
| 1067 | uint32_t framesCount) { |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1068 | Result res; |
| 1069 | // Ignore output parameters as the call should fail |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1070 | ASSERT_OK(stream->prepareForReading( |
| 1071 | frameSize, framesCount, |
| 1072 | [&res](auto r, auto&, auto&, auto&, auto&) { res = r; })); |
Kevin Rocard | fcf186b | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1073 | EXPECT_RESULT(Result::INVALID_ARGUMENTS, res); |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Kevin Rocard | 195205b | 2017-05-02 18:34:59 -0700 | [diff] [blame] | 1076 | TEST_P(InputStreamTest, PrepareForReadingWithZeroBuffer) { |
| 1077 | doc::test( |
| 1078 | "Preparing a stream for reading with a 0 sized buffer should fail"); |
| 1079 | testPrepareForReading(stream.get(), 0, 0); |
| 1080 | } |
| 1081 | |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1082 | TEST_P(InputStreamTest, PrepareForReadingWithHugeBuffer) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1083 | doc::test( |
| 1084 | "Preparing a stream for reading with a 2^32 sized buffer should fail"); |
| 1085 | testPrepareForReading(stream.get(), 1, |
| 1086 | std::numeric_limits<uint32_t>::max()); |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | TEST_P(InputStreamTest, PrepareForReadingCheckOverflow) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1090 | doc::test( |
| 1091 | "Preparing a stream for reading with a overflowing sized buffer should " |
| 1092 | "fail"); |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1093 | auto uintMax = std::numeric_limits<uint32_t>::max(); |
| 1094 | testPrepareForReading(stream.get(), uintMax, uintMax); |
| 1095 | } |
| 1096 | |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1097 | TEST_P(InputStreamTest, GetInputFramesLost) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1098 | doc::test( |
| 1099 | "The number of frames lost on a never started stream should be 0"); |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1100 | auto ret = stream->getInputFramesLost(); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 1101 | ASSERT_IS_OK(ret); |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1102 | uint32_t framesLost{ret}; |
| 1103 | ASSERT_EQ(0U, framesLost); |
| 1104 | } |
| 1105 | |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1106 | TEST_P(InputStreamTest, getCapturePosition) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1107 | doc::test( |
| 1108 | "The capture position of a non prepared stream should not be " |
| 1109 | "retrievable"); |
Kevin Rocard | c996352 | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1110 | uint64_t frames; |
| 1111 | uint64_t time; |
| 1112 | ASSERT_OK(stream->getCapturePosition(returnIn(res, frames, time))); |
| 1113 | ASSERT_RESULT(invalidStateOrNotSupported, res); |
| 1114 | } |
| 1115 | |
| 1116 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1117 | ///////////////////////////////// StreamIn /////////////////////////////////// |
| 1118 | ////////////////////////////////////////////////////////////////////////////// |
| 1119 | |
| 1120 | TEST_P(OutputStreamTest, getLatency) { |
| 1121 | doc::test("Make sure latency is over 0"); |
| 1122 | auto result = stream->getLatency(); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 1123 | ASSERT_IS_OK(result); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1124 | ASSERT_GT(result, 0U); |
| 1125 | } |
| 1126 | |
| 1127 | TEST_P(OutputStreamTest, setVolume) { |
| 1128 | doc::test("Try to set the output volume"); |
Kevin Rocard | 98390a6 | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1129 | testOptionalUnitaryGain( |
| 1130 | [this](float volume) { return stream->setVolume(volume, volume); }, |
| 1131 | "setVolume"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1134 | static void testPrepareForWriting(IStreamOut* stream, uint32_t frameSize, |
| 1135 | uint32_t framesCount) { |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1136 | Result res; |
| 1137 | // Ignore output parameters as the call should fail |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1138 | ASSERT_OK(stream->prepareForWriting( |
| 1139 | frameSize, framesCount, |
| 1140 | [&res](auto r, auto&, auto&, auto&, auto&) { res = r; })); |
Kevin Rocard | fcf186b | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1141 | EXPECT_RESULT(Result::INVALID_ARGUMENTS, res); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Kevin Rocard | 195205b | 2017-05-02 18:34:59 -0700 | [diff] [blame] | 1144 | TEST_P(OutputStreamTest, PrepareForWriteWithZeroBuffer) { |
| 1145 | doc::test( |
| 1146 | "Preparing a stream for writing with a 0 sized buffer should fail"); |
| 1147 | testPrepareForWriting(stream.get(), 0, 0); |
| 1148 | } |
| 1149 | |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1150 | TEST_P(OutputStreamTest, PrepareForWriteWithHugeBuffer) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1151 | doc::test( |
| 1152 | "Preparing a stream for writing with a 2^32 sized buffer should fail"); |
| 1153 | testPrepareForWriting(stream.get(), 1, |
| 1154 | std::numeric_limits<uint32_t>::max()); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | TEST_P(OutputStreamTest, PrepareForWritingCheckOverflow) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1158 | doc::test( |
| 1159 | "Preparing a stream for writing with a overflowing sized buffer should " |
| 1160 | "fail"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1161 | auto uintMax = std::numeric_limits<uint32_t>::max(); |
| 1162 | testPrepareForWriting(stream.get(), uintMax, uintMax); |
| 1163 | } |
| 1164 | |
| 1165 | struct Capability { |
| 1166 | Capability(IStreamOut* stream) { |
| 1167 | EXPECT_OK(stream->supportsPauseAndResume(returnIn(pause, resume))); |
| 1168 | auto ret = stream->supportsDrain(); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 1169 | EXPECT_IS_OK(ret); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1170 | if (ret.isOk()) { |
| 1171 | drain = ret; |
| 1172 | } |
| 1173 | } |
| 1174 | bool pause = false; |
| 1175 | bool resume = false; |
| 1176 | bool drain = false; |
| 1177 | }; |
| 1178 | |
| 1179 | TEST_P(OutputStreamTest, SupportsPauseAndResumeAndDrain) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1180 | doc::test( |
| 1181 | "Implementation must expose pause, resume and drain capabilities"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1182 | Capability(stream.get()); |
| 1183 | } |
| 1184 | |
Kevin Rocard | 304b6c8 | 2017-05-03 10:57:06 -0700 | [diff] [blame] | 1185 | template <class Value> |
| 1186 | static void checkInvalidStateOr0(Result res, Value value) { |
| 1187 | switch (res) { |
| 1188 | case Result::INVALID_STATE: |
| 1189 | break; |
| 1190 | case Result::OK: |
| 1191 | ASSERT_EQ(0U, value); |
| 1192 | break; |
| 1193 | default: |
| 1194 | FAIL() << "Unexpected result " << toString(res); |
| 1195 | } |
| 1196 | } |
| 1197 | |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1198 | TEST_P(OutputStreamTest, GetRenderPosition) { |
Kevin Rocard | 304b6c8 | 2017-05-03 10:57:06 -0700 | [diff] [blame] | 1199 | doc::test("A new stream render position should be 0 or INVALID_STATE"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1200 | uint32_t dspFrames; |
| 1201 | ASSERT_OK(stream->getRenderPosition(returnIn(res, dspFrames))); |
| 1202 | if (res == Result::NOT_SUPPORTED) { |
| 1203 | doc::partialTest("getRenderPosition is not supported"); |
| 1204 | return; |
| 1205 | } |
Kevin Rocard | 304b6c8 | 2017-05-03 10:57:06 -0700 | [diff] [blame] | 1206 | checkInvalidStateOr0(res, dspFrames); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | TEST_P(OutputStreamTest, GetNextWriteTimestamp) { |
Kevin Rocard | 304b6c8 | 2017-05-03 10:57:06 -0700 | [diff] [blame] | 1210 | doc::test("A new stream next write timestamp should be 0 or INVALID_STATE"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1211 | uint64_t timestampUs; |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1212 | ASSERT_OK(stream->getNextWriteTimestamp(returnIn(res, timestampUs))); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1213 | if (res == Result::NOT_SUPPORTED) { |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1214 | doc::partialTest("getNextWriteTimestamp is not supported"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1215 | return; |
| 1216 | } |
Kevin Rocard | 304b6c8 | 2017-05-03 10:57:06 -0700 | [diff] [blame] | 1217 | checkInvalidStateOr0(res, timestampUs); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | /** Stub implementation of out stream callback. */ |
| 1221 | class MockOutCallbacks : public IStreamOutCallback { |
| 1222 | Return<void> onWriteReady() override { return {}; } |
| 1223 | Return<void> onDrainReady() override { return {}; } |
| 1224 | Return<void> onError() override { return {}; } |
| 1225 | }; |
| 1226 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1227 | static bool isAsyncModeSupported(IStreamOut* stream) { |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1228 | auto res = stream->setCallback(new MockOutCallbacks); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1229 | stream->clearCallback(); // try to restore the no callback state, ignore |
| 1230 | // any error |
| 1231 | auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED}; |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1232 | EXPECT_RESULT(okOrNotSupported, res); |
| 1233 | return res.isOk() ? res == Result::OK : false; |
| 1234 | } |
| 1235 | |
| 1236 | TEST_P(OutputStreamTest, SetCallback) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1237 | doc::test( |
| 1238 | "If supported, registering callback for async operation should never " |
| 1239 | "fail"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1240 | if (!isAsyncModeSupported(stream.get())) { |
| 1241 | doc::partialTest("The stream does not support async operations"); |
| 1242 | return; |
| 1243 | } |
| 1244 | ASSERT_OK(stream->setCallback(new MockOutCallbacks)); |
| 1245 | ASSERT_OK(stream->setCallback(new MockOutCallbacks)); |
| 1246 | } |
| 1247 | |
| 1248 | TEST_P(OutputStreamTest, clearCallback) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1249 | doc::test( |
| 1250 | "If supported, clearing a callback to go back to sync operation should " |
| 1251 | "not fail"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1252 | if (!isAsyncModeSupported(stream.get())) { |
| 1253 | doc::partialTest("The stream does not support async operations"); |
| 1254 | return; |
| 1255 | } |
| 1256 | // TODO: Clarify if clearing a non existing callback should fail |
| 1257 | ASSERT_OK(stream->setCallback(new MockOutCallbacks)); |
| 1258 | ASSERT_OK(stream->clearCallback()); |
| 1259 | } |
| 1260 | |
| 1261 | TEST_P(OutputStreamTest, Resume) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1262 | doc::test( |
| 1263 | "If supported, a stream should fail to resume if not previously " |
| 1264 | "paused"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1265 | if (!Capability(stream.get()).resume) { |
| 1266 | doc::partialTest("The output stream does not support resume"); |
| 1267 | return; |
| 1268 | } |
| 1269 | ASSERT_RESULT(Result::INVALID_STATE, stream->resume()); |
| 1270 | } |
| 1271 | |
| 1272 | TEST_P(OutputStreamTest, Pause) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1273 | doc::test( |
| 1274 | "If supported, a stream should fail to pause if not previously " |
| 1275 | "started"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1276 | if (!Capability(stream.get()).pause) { |
| 1277 | doc::partialTest("The output stream does not support pause"); |
| 1278 | return; |
| 1279 | } |
| 1280 | ASSERT_RESULT(Result::INVALID_STATE, stream->resume()); |
| 1281 | } |
| 1282 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1283 | static void testDrain(IStreamOut* stream, AudioDrain type) { |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1284 | if (!Capability(stream).drain) { |
Kevin Rocard | 6f22680 | 2017-04-03 10:29:34 -0700 | [diff] [blame] | 1285 | doc::partialTest("The output stream does not support drain"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1286 | return; |
| 1287 | } |
| 1288 | ASSERT_RESULT(Result::OK, stream->drain(type)); |
| 1289 | } |
| 1290 | |
| 1291 | TEST_P(OutputStreamTest, DrainAll) { |
Kevin Rocard | 6f22680 | 2017-04-03 10:29:34 -0700 | [diff] [blame] | 1292 | doc::test("If supported, a stream should always succeed to drain"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1293 | testDrain(stream.get(), AudioDrain::ALL); |
| 1294 | } |
| 1295 | |
| 1296 | TEST_P(OutputStreamTest, DrainEarlyNotify) { |
Kevin Rocard | 6f22680 | 2017-04-03 10:29:34 -0700 | [diff] [blame] | 1297 | doc::test("If supported, a stream should always succeed to drain"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1298 | testDrain(stream.get(), AudioDrain::EARLY_NOTIFY); |
| 1299 | } |
| 1300 | |
| 1301 | TEST_P(OutputStreamTest, FlushStop) { |
Kevin Rocard | 6f22680 | 2017-04-03 10:29:34 -0700 | [diff] [blame] | 1302 | doc::test("If supported, a stream should always succeed to flush"); |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1303 | auto ret = stream->flush(); |
Kevin Rocard | f26f67a | 2017-05-02 19:21:58 -0700 | [diff] [blame] | 1304 | ASSERT_IS_OK(ret); |
Kevin Rocard | e9a8fb7 | 2017-03-21 11:39:55 -0700 | [diff] [blame] | 1305 | if (ret == Result::NOT_SUPPORTED) { |
| 1306 | doc::partialTest("Flush is not supported"); |
| 1307 | return; |
| 1308 | } |
| 1309 | ASSERT_OK(ret); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | TEST_P(OutputStreamTest, GetPresentationPositionStop) { |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1313 | doc::test( |
| 1314 | "If supported, a stream should always succeed to retrieve the " |
| 1315 | "presentation position"); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1316 | uint64_t frames; |
| 1317 | TimeSpec mesureTS; |
| 1318 | ASSERT_OK(stream->getPresentationPosition(returnIn(res, frames, mesureTS))); |
| 1319 | if (res == Result::NOT_SUPPORTED) { |
| 1320 | doc::partialTest("getpresentationPosition is not supported"); |
| 1321 | return; |
| 1322 | } |
| 1323 | ASSERT_EQ(0U, frames); |
| 1324 | |
Kevin Rocard | 476e38f | 2017-05-03 10:52:43 -0700 | [diff] [blame] | 1325 | if (mesureTS.tvNSec == 0 && mesureTS.tvSec == 0) { |
| 1326 | // As the stream has never written a frame yet, |
| 1327 | // the timestamp does not really have a meaning, allow to return 0 |
| 1328 | return; |
| 1329 | } |
| 1330 | |
| 1331 | // Make sure the return measure is not more than 1s old. |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1332 | struct timespec currentTS; |
| 1333 | ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, ¤tTS)) << errno; |
| 1334 | |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1335 | auto toMicroSec = [](uint64_t sec, auto nsec) { |
| 1336 | return sec * 1e+6 + nsec / 1e+3; |
| 1337 | }; |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1338 | auto currentTime = toMicroSec(currentTS.tv_sec, currentTS.tv_nsec); |
| 1339 | auto mesureTime = toMicroSec(mesureTS.tvSec, mesureTS.tvNSec); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1340 | ASSERT_PRED2([](auto c, auto m) { return c - m < 1e+6; }, currentTime, |
| 1341 | mesureTime); |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Kevin Rocard | 624800c | 2017-03-10 18:47:37 -0800 | [diff] [blame] | 1344 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1345 | /////////////////////////////// PrimaryDevice //////////////////////////////// |
| 1346 | ////////////////////////////////////////////////////////////////////////////// |
| 1347 | |
| 1348 | TEST_F(AudioPrimaryHidlTest, setVoiceVolume) { |
| 1349 | doc::test("Make sure setVoiceVolume only succeed if volume is in [0,1]"); |
Chih-Hung Hsieh | d3bc681 | 2017-05-15 12:31:25 -0700 | [diff] [blame] | 1350 | testUnitaryGain([](float volume) { return device->setVoiceVolume(volume); }); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | TEST_F(AudioPrimaryHidlTest, setMode) { |
Kevin Rocard | 04364ed | 2017-05-02 18:16:00 -0700 | [diff] [blame] | 1354 | doc::test( |
| 1355 | "Make sure setMode always succeeds if mode is valid " |
| 1356 | "and fails otherwise"); |
| 1357 | // Test Invalid values |
| 1358 | for (AudioMode mode : |
| 1359 | {AudioMode::INVALID, AudioMode::CURRENT, AudioMode::CNT}) { |
| 1360 | SCOPED_TRACE("mode=" + toString(mode)); |
| 1361 | ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(mode)); |
| 1362 | } |
| 1363 | // Test valid values |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1364 | for (AudioMode mode : |
| 1365 | {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE, |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1366 | AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) { |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1367 | SCOPED_TRACE("mode=" + toString(mode)); |
| 1368 | ASSERT_OK(device->setMode(mode)); |
| 1369 | } |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1372 | TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) { |
| 1373 | doc::test("Query and set the BT SCO NR&EC state"); |
| 1374 | testOptionalAccessors("BtScoNrecEnabled", {true, false, true}, |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1375 | &IPrimaryDevice::setBtScoNrecEnabled, |
| 1376 | &IPrimaryDevice::getBtScoNrecEnabled); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | TEST_F(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) { |
| 1380 | doc::test("Query and set the SCO whideband state"); |
| 1381 | testOptionalAccessors("BtScoWideband", {true, false, true}, |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1382 | &IPrimaryDevice::setBtScoWidebandEnabled, |
| 1383 | &IPrimaryDevice::getBtScoWidebandEnabled); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | using TtyModeAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<TtyMode>; |
| 1387 | TEST_F(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) { |
| 1388 | doc::test("Query and set the TTY mode state"); |
Kevin Rocard | 72e50e2 | 2017-05-05 14:02:55 -0700 | [diff] [blame] | 1389 | testOptionalAccessors( |
| 1390 | "TTY mode", {TtyMode::OFF, TtyMode::HCO, TtyMode::VCO, TtyMode::FULL}, |
| 1391 | &IPrimaryDevice::setTtyMode, &IPrimaryDevice::getTtyMode); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) { |
| 1395 | doc::test("Query and set the HAC state"); |
Kevin Rocard | 98390a6 | 2017-05-03 11:16:05 -0700 | [diff] [blame] | 1396 | testOptionalAccessors("HAC", {true, false, true}, |
| 1397 | &IPrimaryDevice::setHacEnabled, |
| 1398 | &IPrimaryDevice::getHacEnabled); |
Kevin Rocard | 3c405a7 | 2017-03-08 16:46:51 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | ////////////////////////////////////////////////////////////////////////////// |
Kevin Rocard | f035788 | 2017-02-10 16:19:28 -0800 | [diff] [blame] | 1402 | //////////////////// Clean caches on global tear down //////////////////////// |
| 1403 | ////////////////////////////////////////////////////////////////////////////// |
| 1404 | |
| 1405 | int main(int argc, char** argv) { |
| 1406 | environment = new Environment; |
| 1407 | ::testing::AddGlobalTestEnvironment(environment); |
| 1408 | ::testing::InitGoogleTest(&argc, argv); |
| 1409 | int status = RUN_ALL_TESTS(); |
| 1410 | LOG(INFO) << "Test result = " << status; |
| 1411 | return status; |
| 1412 | } |