Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | #include "FrontendTests.h" |
| 18 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame^] | 19 | Return<void> FrontendCallback::onEvent(FrontendEventType frontendEventType) { |
| 20 | android::Mutex::Autolock autoLock(mMsgLock); |
| 21 | ALOGD("[vts] frontend event received. Type: %d", frontendEventType); |
| 22 | mEventReceived = true; |
| 23 | mMsgCondition.signal(); |
| 24 | switch (frontendEventType) { |
| 25 | case FrontendEventType::LOCKED: |
| 26 | mLockMsgReceived = true; |
| 27 | mLockMsgCondition.signal(); |
| 28 | return Void(); |
| 29 | default: |
| 30 | // do nothing |
| 31 | return Void(); |
| 32 | } |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | Return<void> FrontendCallback::onScanMessage(FrontendScanMessageType /*type*/, |
| 36 | const FrontendScanMessage& /*message*/) { |
| 37 | return Void(); |
| 38 | } |
| 39 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame^] | 40 | void FrontendCallback::tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings) { |
| 41 | Result result = frontend->tune(settings); |
| 42 | EXPECT_TRUE(result == Result::SUCCESS); |
| 43 | |
| 44 | android::Mutex::Autolock autoLock(mMsgLock); |
| 45 | while (!mLockMsgReceived) { |
| 46 | if (-ETIMEDOUT == mLockMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) { |
| 47 | EXPECT_TRUE(false) << "Event LOCKED not received within timeout"; |
| 48 | mLockMsgReceived = false; |
| 49 | return; |
| 50 | } |
| 51 | } |
| 52 | mLockMsgReceived = false; |
| 53 | } |
| 54 | |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 55 | AssertionResult FrontendTests::getFrontendIds() { |
| 56 | Result status; |
| 57 | mService->getFrontendIds([&](Result result, const hidl_vec<FrontendId>& frontendIds) { |
| 58 | status = result; |
| 59 | mFeIds = frontendIds; |
| 60 | }); |
| 61 | return AssertionResult(status == Result::SUCCESS); |
| 62 | } |
| 63 | |
| 64 | AssertionResult FrontendTests::getFrontendInfo(uint32_t frontendId) { |
| 65 | Result status; |
| 66 | mService->getFrontendInfo(frontendId, [&](Result result, const FrontendInfo& frontendInfo) { |
| 67 | mFrontendInfo = frontendInfo; |
| 68 | status = result; |
| 69 | }); |
| 70 | return AssertionResult(status == Result::SUCCESS); |
| 71 | } |
| 72 | |
| 73 | AssertionResult FrontendTests::openFrontendById(uint32_t frontendId) { |
| 74 | Result status; |
| 75 | mService->openFrontendById(frontendId, [&](Result result, const sp<IFrontend>& frontend) { |
| 76 | mFrontend = frontend; |
| 77 | status = result; |
| 78 | }); |
| 79 | return AssertionResult(status == Result::SUCCESS); |
| 80 | } |
| 81 | |
| 82 | AssertionResult FrontendTests::setFrontendCallback() { |
| 83 | EXPECT_TRUE(mFrontend) << "Test with openFrontendById first."; |
| 84 | mFrontendCallback = new FrontendCallback(); |
| 85 | auto callbackStatus = mFrontend->setCallback(mFrontendCallback); |
| 86 | return AssertionResult(callbackStatus.isOk()); |
| 87 | } |
| 88 | |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame^] | 89 | AssertionResult FrontendTests::tuneFrontend(FrontendConfig config, bool testWithDemux) { |
| 90 | EXPECT_TRUE(mFrontendCallback) |
| 91 | << "test with openFrontendById/setFrontendCallback/getFrontendInfo first."; |
| 92 | |
| 93 | EXPECT_TRUE(mFrontendInfo.type == config.type) |
| 94 | << "FrontendConfig does not match the frontend info of the given id."; |
| 95 | |
| 96 | mIsSoftwareFe = config.isSoftwareFe; |
| 97 | bool result = true; |
| 98 | if (mIsSoftwareFe && testWithDemux) { |
| 99 | result &= mDvrTests.openDvrInDemux(mDvrConfig.type, mDvrConfig.bufferSize) == success(); |
| 100 | result &= mDvrTests.configDvrPlayback(mDvrConfig.settings) == success(); |
| 101 | result &= mDvrTests.getDvrPlaybackMQDescriptor() == success(); |
| 102 | mDvrTests.startPlaybackInputThread(mDvrConfig.playbackInputFile, |
| 103 | mDvrConfig.settings.playback()); |
| 104 | if (!result) { |
| 105 | ALOGW("[vts] Software frontend dvr configure failed."); |
| 106 | return failure(); |
| 107 | } |
| 108 | } |
| 109 | mFrontendCallback->tuneTestOnLock(mFrontend, config.settings); |
| 110 | return AssertionResult(true); |
| 111 | } |
| 112 | |
| 113 | AssertionResult FrontendTests::stopTuneFrontend(bool testWithDemux) { |
| 114 | EXPECT_TRUE(mFrontend) << "Test with openFrontendById first."; |
| 115 | Result status; |
| 116 | status = mFrontend->stopTune(); |
| 117 | if (mIsSoftwareFe && testWithDemux) { |
| 118 | mDvrTests.stopPlaybackThread(); |
| 119 | mDvrTests.closeDvrPlayback(); |
| 120 | } |
| 121 | return AssertionResult(status == Result::SUCCESS); |
| 122 | } |
| 123 | |
Amy Zhang | 45cc57a | 2020-07-09 22:56:25 -0700 | [diff] [blame] | 124 | AssertionResult FrontendTests::closeFrontend() { |
| 125 | EXPECT_TRUE(mFrontend) << "Test with openFrontendById first."; |
| 126 | Result status; |
| 127 | status = mFrontend->close(); |
| 128 | mFrontend = nullptr; |
| 129 | mFrontendCallback = nullptr; |
| 130 | return AssertionResult(status == Result::SUCCESS); |
| 131 | } |
| 132 | |
| 133 | void FrontendTests::getFrontendIdByType(FrontendType feType, uint32_t& feId) { |
| 134 | ASSERT_TRUE(getFrontendIds()); |
| 135 | ASSERT_TRUE(mFeIds.size() > 0); |
| 136 | for (size_t i = 0; i < mFeIds.size(); i++) { |
| 137 | ASSERT_TRUE(getFrontendInfo(mFeIds[i])); |
| 138 | if (mFrontendInfo.type != feType) { |
| 139 | continue; |
| 140 | } |
| 141 | feId = mFeIds[i]; |
| 142 | return; |
| 143 | } |
| 144 | feId = INVALID_ID; |
Amy Zhang | 68afca6 | 2020-07-20 18:28:58 -0700 | [diff] [blame^] | 145 | } |