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 |
o1ka
2017/04/25 08:23:22
Add a comment that tests here do not test multi-th
hongchan
2017/04/25 20:36:42
Done.
| |
18 // Check the basic contract of FIFO. | 23 // Check the basic contract of FIFO. |
19 TEST(PushPullFIFOBasicTest, BasicTests) { | 24 TEST(PushPullFIFOBasicTest, BasicTests) { |
20 // This suppresses the multi-thread warning for GTest. Potently it increases | 25 // 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. | 26 // the test execution time, but this specific test is very short and simple. |
22 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; | 27 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
23 | 28 |
24 // FIFO length exceeding the maximum length allowed will cause crash. | 29 // FIFO length exceeding the maximum length allowed will cause crash. |
25 // i.e.) m_fifoLength <= kMaxFIFOLength | 30 // i.e.) m_fifoLength <= kMaxFIFOLength |
26 EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), ""); | 31 EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), ""); |
27 | 32 |
28 std::unique_ptr<PushPullFIFO> test_fifo = | 33 std::unique_ptr<PushPullFIFO> test_fifo = |
29 WTF::WrapUnique(new PushPullFIFO(2, 1024)); | 34 WTF::WrapUnique(new PushPullFIFO(2, 1024)); |
30 | 35 |
31 // The input bus length must be |AudioUtilities::kRenderQuantumFrames|. | 36 // The input bus length must be |AudioUtilities::kRenderQuantumFrames|. |
32 // i.e.) inputBus->length() == kRenderQuantumFrames | 37 // i.e.) inputBus->length() == kRenderQuantumFrames |
33 RefPtr<AudioBus> input_bus_of129_frames = | 38 RefPtr<AudioBus> input_bus_129_frames = |
34 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1); | 39 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1); |
35 EXPECT_DEATH(test_fifo->Push(input_bus_of129_frames.Get()), ""); | 40 EXPECT_DEATH(test_fifo->Push(input_bus_129_frames.Get()), ""); |
36 RefPtr<AudioBus> input_bus_of127_frames = | 41 RefPtr<AudioBus> input_bus_127_frames = |
37 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1); | 42 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1); |
38 EXPECT_DEATH(test_fifo->Push(input_bus_of127_frames.Get()), ""); | 43 EXPECT_DEATH(test_fifo->Push(input_bus_127_frames.Get()), ""); |
39 | 44 |
40 // Pull request frames cannot exceed the length of output bus. | 45 // Pull request frames cannot exceed the length of output bus. |
41 // i.e.) framesRequested <= outputBus->length() | 46 // i.e.) framesRequested <= outputBus->length() |
42 RefPtr<AudioBus> output_bus_of512_frames = AudioBus::Create(2, 512); | 47 RefPtr<AudioBus> output_bus_512_frames = AudioBus::Create(2, 512); |
43 EXPECT_DEATH(test_fifo->Pull(output_bus_of512_frames.Get(), 513), ""); | 48 EXPECT_DEATH(test_fifo->Pull(output_bus_512_frames.Get(), 513), ""); |
44 | 49 |
45 // Pull request frames cannot exceed the length of FIFO. | 50 // Pull request frames cannot exceed the length of FIFO. |
46 // i.e.) framesRequested <= m_fifoLength | 51 // i.e.) framesRequested <= m_fifoLength |
47 RefPtr<AudioBus> output_bus_of1025_frames = AudioBus::Create(2, 1025); | 52 RefPtr<AudioBus> output_bus_1025_frames = AudioBus::Create(2, 1025); |
48 EXPECT_DEATH(test_fifo->Pull(output_bus_of1025_frames.Get(), 1025), ""); | 53 EXPECT_DEATH(test_fifo->Pull(output_bus_1025_frames.Get(), 1025), ""); |
49 } | 54 } |
50 | 55 |
51 // Fills each AudioChannel in an AudioBus with a series of linearly increasing | 56 // Fills each AudioChannel in an AudioBus with a series of linearly increasing |
52 // values starting from |startingValue| and incrementing by 1. Then return value | 57 // values starting from |startingValue| and incrementing by 1. Then return value |
53 // will be |startingValue| + |bus_length|. | 58 // will be |startingValue| + |bus_length|. |
54 size_t FillBusWithLinearRamp(AudioBus* target_bus, size_t starting_value) { | 59 size_t FillBusWithLinearRamp(AudioBus* target_bus, size_t starting_value) { |
55 for (unsigned c = 0; c < target_bus->NumberOfChannels(); ++c) { | 60 for (unsigned c = 0; c < target_bus->NumberOfChannels(); ++c) { |
56 float* bus_channel = target_bus->Channel(c)->MutableData(); | 61 float* bus_channel = target_bus->Channel(c)->MutableData(); |
57 for (size_t i = 0; i < target_bus->Channel(c)->length(); ++i) { | 62 for (size_t i = 0; i < target_bus->Channel(c)->length(); ++i) { |
58 bus_channel[i] = static_cast<float>(starting_value + i); | 63 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(); | 167 const PushPullFIFOStateForTest actual_state = fifo->GetStateForTest(); |
163 | 168 |
164 // Verify the read/write indexes. | 169 // Verify the read/write indexes. |
165 EXPECT_EQ(expected_state.index_read, actual_state.index_read); | 170 EXPECT_EQ(expected_state.index_read, actual_state.index_read); |
166 EXPECT_EQ(expected_state.index_write, actual_state.index_write); | 171 EXPECT_EQ(expected_state.index_write, actual_state.index_write); |
167 EXPECT_EQ(expected_state.overflow_count, actual_state.overflow_count); | 172 EXPECT_EQ(expected_state.overflow_count, actual_state.overflow_count); |
168 EXPECT_EQ(expected_state.underflow_count, actual_state.underflow_count); | 173 EXPECT_EQ(expected_state.underflow_count, actual_state.underflow_count); |
169 | 174 |
170 // Verify in-FIFO samples. | 175 // Verify in-FIFO samples. |
171 for (const auto& sample : expected_state.fifo_samples) { | 176 for (const auto& sample : expected_state.fifo_samples) { |
172 EXPECT_TRUE(VerifyBusValueAtIndex(fifo->Bus(), sample.index, sample.value)); | 177 EXPECT_TRUE(VerifyBusValueAtIndex(fifo->GetFIFOBusForTest(), |
178 sample.index, sample.value)); | |
173 } | 179 } |
174 | 180 |
175 // Verify samples from the most recent output bus. | 181 // Verify samples from the most recent output bus. |
176 for (const auto& sample : expected_state.output_samples) { | 182 for (const auto& sample : expected_state.output_samples) { |
177 EXPECT_TRUE( | 183 EXPECT_TRUE( |
178 VerifyBusValueAtIndex(output_bus.Get(), sample.index, sample.value)); | 184 VerifyBusValueAtIndex(output_bus.Get(), sample.index, sample.value)); |
179 } | 185 } |
180 } | 186 } |
181 | 187 |
182 FIFOTestParam g_feature_test_params[] = { | 188 FIFOTestParam g_feature_test_params[] = { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 }}, | 356 }}, |
351 // - expectedIndexRead = 0, expectedIndexWrite = 0 | 357 // - expectedIndexRead = 0, expectedIndexWrite = 0 |
352 // - overflowCount = 0, underflowCount = 4 | 358 // - overflowCount = 0, underflowCount = 4 |
353 // - FIFO samples (index, expectedValue) = (0, 0), (1023, 0) | 359 // - FIFO samples (index, expectedValue) = (0, 0), (1023, 0) |
354 // - Output bus samples (index, expectedValue) = (0, 0), (143, 0) | 360 // - Output bus samples (index, expectedValue) = (0, 0), (143, 0) |
355 {0, 0, 0, 4, {{0, 0}, {1023, 0}}, {{0, 0}, {143, 0}}}}}; | 361 {0, 0, 0, 4, {{0, 0}, {1023, 0}}, {{0, 0}, {143, 0}}}}}; |
356 | 362 |
357 INSTANTIATE_TEST_CASE_P(PushPullFIFOFeatureTest, | 363 INSTANTIATE_TEST_CASE_P(PushPullFIFOFeatureTest, |
358 PushPullFIFOFeatureTest, | 364 PushPullFIFOFeatureTest, |
359 ::testing::ValuesIn(g_feature_test_params)); | 365 ::testing::ValuesIn(g_feature_test_params)); |
360 | |
361 } // namespace | 366 } // namespace |
362 | 367 |
363 } // namespace blink | 368 } // namespace blink |
OLD | NEW |