OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/audio/PushPullFIFO.h" | 5 #include "platform/audio/PushPullFIFO.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
| 9 #include "platform/CrossThreadFunctional.h" |
| 10 #include "platform/WebTaskRunner.h" |
9 #include "platform/audio/AudioUtilities.h" | 11 #include "platform/audio/AudioUtilities.h" |
10 #include "platform/testing/TestingPlatformSupport.h" | 12 #include "platform/testing/TestingPlatformSupport.h" |
| 13 #include "platform/wtf/Functional.h" |
11 #include "platform/wtf/PtrUtil.h" | 14 #include "platform/wtf/PtrUtil.h" |
| 15 #include "public/platform/Platform.h" |
| 16 #include "public/platform/WebThread.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
13 | 18 |
14 namespace blink { | 19 namespace blink { |
15 | 20 |
16 namespace { | 21 namespace { |
17 | 22 |
18 // Check the basic contract of FIFO. | 23 // Check the basic contract of FIFO. This test only covers the single thread |
| 24 // scenario. |
19 TEST(PushPullFIFOBasicTest, BasicTests) { | 25 TEST(PushPullFIFOBasicTest, BasicTests) { |
20 // This suppresses the multi-thread warning for GTest. Potently it increases | 26 // This suppresses the multi-thread warning for GTest. Potently it increases |
21 // the test execution time, but this specific test is very short and simple. | 27 // the test execution time, but this specific test is very short and simple. |
22 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; | 28 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
23 | 29 |
24 // FIFO length exceeding the maximum length allowed will cause crash. | 30 // FIFO length exceeding the maximum length allowed will cause crash. |
25 // i.e.) m_fifoLength <= kMaxFIFOLength | 31 // i.e.) m_fifoLength <= kMaxFIFOLength |
26 EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), ""); | 32 EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), ""); |
27 | 33 |
28 std::unique_ptr<PushPullFIFO> test_fifo = | 34 std::unique_ptr<PushPullFIFO> test_fifo = |
29 WTF::WrapUnique(new PushPullFIFO(2, 1024)); | 35 WTF::WrapUnique(new PushPullFIFO(2, 1024)); |
30 | 36 |
31 // The input bus length must be |AudioUtilities::kRenderQuantumFrames|. | 37 // The input bus length must be |AudioUtilities::kRenderQuantumFrames|. |
32 // i.e.) inputBus->length() == kRenderQuantumFrames | 38 // i.e.) inputBus->length() == kRenderQuantumFrames |
33 RefPtr<AudioBus> input_bus_of129_frames = | 39 RefPtr<AudioBus> input_bus_129_frames = |
34 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1); | 40 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1); |
35 EXPECT_DEATH(test_fifo->Push(input_bus_of129_frames.Get()), ""); | 41 EXPECT_DEATH(test_fifo->Push(input_bus_129_frames.Get()), ""); |
36 RefPtr<AudioBus> input_bus_of127_frames = | 42 RefPtr<AudioBus> input_bus_127_frames = |
37 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1); | 43 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1); |
38 EXPECT_DEATH(test_fifo->Push(input_bus_of127_frames.Get()), ""); | 44 EXPECT_DEATH(test_fifo->Push(input_bus_127_frames.Get()), ""); |
39 | 45 |
40 // Pull request frames cannot exceed the length of output bus. | 46 // Pull request frames cannot exceed the length of output bus. |
41 // i.e.) framesRequested <= outputBus->length() | 47 // i.e.) framesRequested <= outputBus->length() |
42 RefPtr<AudioBus> output_bus_of512_frames = AudioBus::Create(2, 512); | 48 RefPtr<AudioBus> output_bus_512_frames = AudioBus::Create(2, 512); |
43 EXPECT_DEATH(test_fifo->Pull(output_bus_of512_frames.Get(), 513), ""); | 49 EXPECT_DEATH(test_fifo->Pull(output_bus_512_frames.Get(), 513), ""); |
44 | 50 |
45 // Pull request frames cannot exceed the length of FIFO. | 51 // Pull request frames cannot exceed the length of FIFO. |
46 // i.e.) framesRequested <= m_fifoLength | 52 // i.e.) framesRequested <= m_fifoLength |
47 RefPtr<AudioBus> output_bus_of1025_frames = AudioBus::Create(2, 1025); | 53 RefPtr<AudioBus> output_bus_1025_frames = AudioBus::Create(2, 1025); |
48 EXPECT_DEATH(test_fifo->Pull(output_bus_of1025_frames.Get(), 1025), ""); | 54 EXPECT_DEATH(test_fifo->Pull(output_bus_1025_frames.Get(), 1025), ""); |
49 } | 55 } |
50 | 56 |
51 // Fills each AudioChannel in an AudioBus with a series of linearly increasing | 57 // Fills each AudioChannel in an AudioBus with a series of linearly increasing |
52 // values starting from |startingValue| and incrementing by 1. Then return value | 58 // values starting from |startingValue| and incrementing by 1. Then return value |
53 // will be |startingValue| + |bus_length|. | 59 // will be |startingValue| + |bus_length|. |
54 size_t FillBusWithLinearRamp(AudioBus* target_bus, size_t starting_value) { | 60 size_t FillBusWithLinearRamp(AudioBus* target_bus, size_t starting_value) { |
55 for (unsigned c = 0; c < target_bus->NumberOfChannels(); ++c) { | 61 for (unsigned c = 0; c < target_bus->NumberOfChannels(); ++c) { |
56 float* bus_channel = target_bus->Channel(c)->MutableData(); | 62 float* bus_channel = target_bus->Channel(c)->MutableData(); |
57 for (size_t i = 0; i < target_bus->Channel(c)->length(); ++i) { | 63 for (size_t i = 0; i < target_bus->Channel(c)->length(); ++i) { |
58 bus_channel[i] = static_cast<float>(starting_value + i); | 64 bus_channel[i] = static_cast<float>(starting_value + i); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 const PushPullFIFOStateForTest actual_state = fifo->GetStateForTest(); | 168 const PushPullFIFOStateForTest actual_state = fifo->GetStateForTest(); |
163 | 169 |
164 // Verify the read/write indexes. | 170 // Verify the read/write indexes. |
165 EXPECT_EQ(expected_state.index_read, actual_state.index_read); | 171 EXPECT_EQ(expected_state.index_read, actual_state.index_read); |
166 EXPECT_EQ(expected_state.index_write, actual_state.index_write); | 172 EXPECT_EQ(expected_state.index_write, actual_state.index_write); |
167 EXPECT_EQ(expected_state.overflow_count, actual_state.overflow_count); | 173 EXPECT_EQ(expected_state.overflow_count, actual_state.overflow_count); |
168 EXPECT_EQ(expected_state.underflow_count, actual_state.underflow_count); | 174 EXPECT_EQ(expected_state.underflow_count, actual_state.underflow_count); |
169 | 175 |
170 // Verify in-FIFO samples. | 176 // Verify in-FIFO samples. |
171 for (const auto& sample : expected_state.fifo_samples) { | 177 for (const auto& sample : expected_state.fifo_samples) { |
172 EXPECT_TRUE(VerifyBusValueAtIndex(fifo->Bus(), sample.index, sample.value)); | 178 EXPECT_TRUE(VerifyBusValueAtIndex(fifo->GetFIFOBusForTest(), |
| 179 sample.index, sample.value)); |
173 } | 180 } |
174 | 181 |
175 // Verify samples from the most recent output bus. | 182 // Verify samples from the most recent output bus. |
176 for (const auto& sample : expected_state.output_samples) { | 183 for (const auto& sample : expected_state.output_samples) { |
177 EXPECT_TRUE( | 184 EXPECT_TRUE( |
178 VerifyBusValueAtIndex(output_bus.Get(), sample.index, sample.value)); | 185 VerifyBusValueAtIndex(output_bus.Get(), sample.index, sample.value)); |
179 } | 186 } |
180 } | 187 } |
181 | 188 |
182 FIFOTestParam g_feature_test_params[] = { | 189 FIFOTestParam g_feature_test_params[] = { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // - Output bus samples (index, expectedValue) = (0, 0), (143, 0) | 361 // - Output bus samples (index, expectedValue) = (0, 0), (143, 0) |
355 {0, 0, 0, 4, {{0, 0}, {1023, 0}}, {{0, 0}, {143, 0}}}}}; | 362 {0, 0, 0, 4, {{0, 0}, {1023, 0}}, {{0, 0}, {143, 0}}}}}; |
356 | 363 |
357 INSTANTIATE_TEST_CASE_P(PushPullFIFOFeatureTest, | 364 INSTANTIATE_TEST_CASE_P(PushPullFIFOFeatureTest, |
358 PushPullFIFOFeatureTest, | 365 PushPullFIFOFeatureTest, |
359 ::testing::ValuesIn(g_feature_test_params)); | 366 ::testing::ValuesIn(g_feature_test_params)); |
360 | 367 |
361 } // namespace | 368 } // namespace |
362 | 369 |
363 } // namespace blink | 370 } // namespace blink |
OLD | NEW |