Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "platform/audio/PushPullFIFO.h" | |
| 6 | |
| 7 #include "platform/audio/AudioUtilities.h" | |
| 8 #include "platform/testing/TestingPlatformSupport.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "wtf/PtrUtil.h" | |
| 11 #include <memory> | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 void fillBusWithValue(AudioBus* targetBus, float value) { | |
| 18 for (unsigned c = 0; c < targetBus->numberOfChannels(); ++c) { | |
| 19 float* busChannel = targetBus->channel(c)->mutableData(); | |
| 20 std::fill(busChannel, busChannel + targetBus->channel(c)->length(), value); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 // Fills up an array with a series of indexes; [0, 1, 2, 3, 4, 5, 6, ....] | |
| 25 void fillBusWithIncrementalIndex(AudioBus* targetBus) { | |
| 26 for (unsigned c = 0; c < targetBus->numberOfChannels(); ++c) { | |
| 27 float* busChannel = targetBus->channel(c)->mutableData(); | |
| 28 for (unsigned i = 0; i < targetBus->channel(c)->length(); ++i) | |
| 29 busChannel[i] = i; | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 bool verifyBusValueAtIndex(AudioBus* targetBus, int index, float value) { | |
| 34 for (unsigned c = 0; c < targetBus->numberOfChannels(); ++c) { | |
| 35 float* busChannel = targetBus->channel(c)->mutableData(); | |
| 36 if (busChannel[index] != value) { | |
| 37 LOG(ERROR) << "[FAIL] index = " << index | |
| 38 << " value = " << busChannel[index]; | |
| 39 return false; | |
| 40 } | |
| 41 } | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 struct PushPullFIFOTestParam { | |
| 46 PushPullFIFOTestParam(size_t fifoSize, | |
| 47 unsigned numberOfChannels, | |
| 48 size_t framesAvailable, | |
| 49 size_t framesToPush, | |
| 50 size_t framesToPull, | |
| 51 unsigned expectedReadIndex, | |
| 52 float expectedValueAtReadIndex, | |
| 53 unsigned expectedWriteIndex, | |
| 54 float expectedValueAtWriteIndex) | |
| 55 : fifoSize(fifoSize), | |
| 56 numberOfChannels(numberOfChannels), | |
| 57 framesAvailable(framesAvailable), | |
| 58 framesToPush(framesToPush), | |
| 59 framesToPull(framesToPull), | |
| 60 expectedReadIndex(expectedReadIndex), | |
| 61 expectedValueAtReadIndex(expectedValueAtReadIndex), | |
| 62 expectedWriteIndex(expectedWriteIndex), | |
| 63 expectedValueAtWriteIndex(expectedValueAtWriteIndex) {} | |
| 64 ~PushPullFIFOTestParam() {} | |
| 65 | |
| 66 const size_t fifoSize; | |
|
o1ka
2017/01/24 11:09:02
Could you provide comments on what each value mean
hongchan
2017/01/26 22:33:18
I have restructured the unit test. PTAL the new de
| |
| 67 const unsigned numberOfChannels; | |
| 68 const size_t framesAvailable; | |
| 69 const size_t framesToPush; | |
| 70 const size_t framesToPull; | |
| 71 const unsigned expectedReadIndex; | |
| 72 const float expectedValueAtReadIndex; | |
| 73 const unsigned expectedWriteIndex; | |
| 74 const float expectedValueAtWriteIndex; | |
| 75 }; | |
| 76 | |
| 77 std::ostream& operator<<(std::ostream& out, | |
| 78 const PushPullFIFOTestParam& param) { | |
| 79 out << "fifoSze=" << param.fifoSize | |
| 80 << " numberOfChannels=" << param.numberOfChannels | |
| 81 << " framesAvailable=" << param.framesAvailable | |
| 82 << " framesToPush=" << param.framesToPush | |
| 83 << " framesToPull=" << param.framesToPull | |
| 84 << " expectedReadIndex=" << param.expectedReadIndex | |
| 85 << " expectedValueAtReadIndex=" << param.expectedValueAtReadIndex | |
| 86 << " expectedWriteIndex=" << param.expectedWriteIndex | |
| 87 << " expectedValueAtWriteIndex=" << param.expectedValueAtWriteIndex; | |
| 88 return out; | |
| 89 } | |
| 90 | |
| 91 class PushPullFIFOTest | |
| 92 : public ::testing::TestWithParam<PushPullFIFOTestParam> {}; | |
| 93 | |
| 94 TEST_P(PushPullFIFOTest, BasicOperation) { | |
| 95 std::unique_ptr<PushPullFIFO> fifo = WTF::wrapUnique( | |
| 96 new PushPullFIFO(GetParam().numberOfChannels, GetParam().fifoSize)); | |
| 97 | |
| 98 // Simulates existing frames in the FIFO. These frames are initialized with | |
| 99 // -1. | |
| 100 RefPtr<AudioBus> existingBus = | |
| 101 AudioBus::create(GetParam().numberOfChannels, GetParam().framesAvailable); | |
| 102 fillBusWithValue(existingBus.get(), -1); | |
| 103 fifo->push(existingBus.get()); | |
| 104 | |
| 105 // Then push data with given length. The content of input bus is a series of | |
| 106 // incremental index. | |
| 107 RefPtr<AudioBus> inputBus = | |
| 108 AudioBus::create(GetParam().numberOfChannels, GetParam().framesToPush); | |
| 109 fillBusWithIncrementalIndex(inputBus.get()); | |
| 110 fifo->push(inputBus.get()); | |
| 111 | |
| 112 // Lastly, pull the data from FIFO to reach the state required by | |
| 113 // |framesToPull|. | |
| 114 RefPtr<AudioBus> outputBus = | |
|
o1ka
2017/01/24 11:09:02
This looks good.
Another set of cases to test is l
hongchan
2017/01/26 22:33:18
Done.
| |
| 115 AudioBus::create(GetParam().numberOfChannels, GetParam().framesToPull); | |
| 116 fifo->pull(outputBus.get(), GetParam().framesToPull); | |
| 117 | |
| 118 // Verify the position of current indexes and their values. | |
|
o1ka
2017/01/24 11:09:02
We also want to check the content of |outputBus|.
hongchan
2017/01/26 22:33:18
Done.
| |
| 119 EXPECT_EQ(true, | |
| 120 verifyBusValueAtIndex(fifo->bus(), GetParam().expectedReadIndex, | |
| 121 GetParam().expectedValueAtReadIndex)); | |
| 122 EXPECT_EQ(true, | |
| 123 verifyBusValueAtIndex(fifo->bus(), GetParam().expectedWriteIndex, | |
| 124 GetParam().expectedValueAtWriteIndex)); | |
| 125 } | |
| 126 | |
| 127 INSTANTIATE_TEST_CASE_P( | |
| 128 PushPullFIFOTest, | |
| 129 PushPullFIFOTest, | |
| 130 ::testing::Values( | |
| 131 PushPullFIFOTestParam(8192, 2, 128, 256, 128, 128, 0, 384, 0))); | |
| 132 | |
| 133 } // namespace | |
| 134 | |
| 135 } // namespace blink | |
| OLD | NEW |