Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: source/libvpx/test/vp9_thread_test.cc

Issue 390713002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: libvpx: Pull from upstream Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "third_party/googletest/src/include/gtest/gtest.h" 13 #include "third_party/googletest/src/include/gtest/gtest.h"
14 #include "./vpx_config.h" 14 #include "./vpx_config.h"
15 #include "test/codec_factory.h" 15 #include "test/codec_factory.h"
16 #include "test/decode_test_driver.h" 16 #include "test/decode_test_driver.h"
17 #include "test/md5_helper.h" 17 #include "test/md5_helper.h"
18 #if CONFIG_WEBM_IO 18 #if CONFIG_WEBM_IO
19 #include "test/webm_video_source.h" 19 #include "test/webm_video_source.h"
20 #endif 20 #endif
21 #include "vp9/decoder/vp9_thread.h" 21 #include "vp9/common/vp9_thread.h"
22 22
23 namespace { 23 namespace {
24 24
25 using std::string; 25 using std::string;
26 26
27 class VP9WorkerThreadTest : public ::testing::TestWithParam<bool> { 27 class VP9WorkerThreadTest : public ::testing::TestWithParam<bool> {
28 protected: 28 protected:
29 virtual ~VP9WorkerThreadTest() {} 29 virtual ~VP9WorkerThreadTest() {}
30 virtual void SetUp() { 30 virtual void SetUp() {
31 vp9_get_worker_interface()->init(&worker_); 31 vp9_get_worker_interface()->init(&worker_);
32 } 32 }
33 33
34 virtual void TearDown() { 34 virtual void TearDown() {
35 vp9_get_worker_interface()->end(&worker_); 35 vp9_get_worker_interface()->end(&worker_);
36 } 36 }
37 37
38 void Run(VP9Worker* worker) {
39 const bool synchronous = GetParam();
40 if (synchronous) {
41 vp9_get_worker_interface()->execute(worker);
42 } else {
43 vp9_get_worker_interface()->launch(worker);
44 }
45 }
46
38 VP9Worker worker_; 47 VP9Worker worker_;
39 }; 48 };
40 49
41 int ThreadHook(void* data, void* return_value) { 50 int ThreadHook(void* data, void* return_value) {
42 int* const hook_data = reinterpret_cast<int*>(data); 51 int* const hook_data = reinterpret_cast<int*>(data);
43 *hook_data = 5; 52 *hook_data = 5;
44 return *reinterpret_cast<int*>(return_value); 53 return *reinterpret_cast<int*>(return_value);
45 } 54 }
46 55
47 TEST_P(VP9WorkerThreadTest, HookSuccess) { 56 TEST_P(VP9WorkerThreadTest, HookSuccess) {
48 // should be a no-op. 57 // should be a no-op.
49 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0); 58 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
50 59
51 for (int i = 0; i < 2; ++i) { 60 for (int i = 0; i < 2; ++i) {
52 EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0); 61 EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
53 62
54 int hook_data = 0; 63 int hook_data = 0;
55 int return_value = 1; // return successfully from the hook 64 int return_value = 1; // return successfully from the hook
56 worker_.hook = ThreadHook; 65 worker_.hook = ThreadHook;
57 worker_.data1 = &hook_data; 66 worker_.data1 = &hook_data;
58 worker_.data2 = &return_value; 67 worker_.data2 = &return_value;
59 68
60 const bool synchronous = GetParam(); 69 Run(&worker_);
61 if (synchronous) {
62 vp9_get_worker_interface()->execute(&worker_);
63 } else {
64 vp9_get_worker_interface()->launch(&worker_);
65 }
66 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0); 70 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
67 EXPECT_FALSE(worker_.had_error); 71 EXPECT_FALSE(worker_.had_error);
68 EXPECT_EQ(5, hook_data); 72 EXPECT_EQ(5, hook_data);
69 73
70 // should be a no-op. 74 // should be a no-op.
71 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0); 75 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
72 } 76 }
73 } 77 }
74 78
75 TEST_P(VP9WorkerThreadTest, HookFailure) { 79 TEST_P(VP9WorkerThreadTest, HookFailure) {
76 EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0); 80 EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
77 81
78 int hook_data = 0; 82 int hook_data = 0;
79 int return_value = 0; // return failure from the hook 83 int return_value = 0; // return failure from the hook
80 worker_.hook = ThreadHook; 84 worker_.hook = ThreadHook;
81 worker_.data1 = &hook_data; 85 worker_.data1 = &hook_data;
82 worker_.data2 = &return_value; 86 worker_.data2 = &return_value;
83 87
84 const bool synchronous = GetParam(); 88 Run(&worker_);
85 if (synchronous) {
86 vp9_get_worker_interface()->execute(&worker_);
87 } else {
88 vp9_get_worker_interface()->launch(&worker_);
89 }
90 EXPECT_FALSE(vp9_get_worker_interface()->sync(&worker_)); 89 EXPECT_FALSE(vp9_get_worker_interface()->sync(&worker_));
91 EXPECT_EQ(1, worker_.had_error); 90 EXPECT_EQ(1, worker_.had_error);
92 91
93 // Ensure _reset() clears the error and _launch() can be called again. 92 // Ensure _reset() clears the error and _launch() can be called again.
94 return_value = 1; 93 return_value = 1;
95 EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0); 94 EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
96 EXPECT_FALSE(worker_.had_error); 95 EXPECT_FALSE(worker_.had_error);
97 vp9_get_worker_interface()->launch(&worker_); 96 vp9_get_worker_interface()->launch(&worker_);
98 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0); 97 EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
99 EXPECT_FALSE(worker_.had_error); 98 EXPECT_FALSE(worker_.had_error);
100 } 99 }
101 100
101 TEST_P(VP9WorkerThreadTest, EndWithoutSync) {
102 // Create a large number of threads to increase the chances of detecting a
103 // race. Doing more work in the hook is no guarantee as any race would occur
104 // post hook execution in the main thread loop driver.
105 static const int kNumWorkers = 64;
106 VP9Worker workers[kNumWorkers];
107 int hook_data[kNumWorkers];
108 int return_value[kNumWorkers];
109
110 for (int n = 0; n < kNumWorkers; ++n) {
111 vp9_get_worker_interface()->init(&workers[n]);
112 return_value[n] = 1; // return successfully from the hook
113 workers[n].hook = ThreadHook;
114 workers[n].data1 = &hook_data[n];
115 workers[n].data2 = &return_value[n];
116 }
117
118 for (int i = 0; i < 2; ++i) {
119 for (int n = 0; n < kNumWorkers; ++n) {
120 EXPECT_NE(vp9_get_worker_interface()->reset(&workers[n]), 0);
121 hook_data[n] = 0;
122 }
123
124 for (int n = 0; n < kNumWorkers; ++n) {
125 Run(&workers[n]);
126 }
127
128 for (int n = kNumWorkers - 1; n >= 0; --n) {
129 vp9_get_worker_interface()->end(&workers[n]);
130 }
131 }
132 }
133
102 TEST(VP9WorkerThreadTest, TestInterfaceAPI) { 134 TEST(VP9WorkerThreadTest, TestInterfaceAPI) {
103 EXPECT_EQ(0, vp9_set_worker_interface(NULL)); 135 EXPECT_EQ(0, vp9_set_worker_interface(NULL));
104 EXPECT_TRUE(vp9_get_worker_interface() != NULL); 136 EXPECT_TRUE(vp9_get_worker_interface() != NULL);
105 for (int i = 0; i < 6; ++i) { 137 for (int i = 0; i < 6; ++i) {
106 VP9WorkerInterface winterface = *vp9_get_worker_interface(); 138 VP9WorkerInterface winterface = *vp9_get_worker_interface();
107 switch (i) { 139 switch (i) {
108 default: 140 default:
109 case 0: winterface.init = NULL; break; 141 case 0: winterface.init = NULL; break;
110 case 1: winterface.reset = NULL; break; 142 case 1: winterface.reset = NULL; break;
111 case 2: winterface.sync = NULL; break; 143 case 2: winterface.sync = NULL; break;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 { NULL, NULL } 305 { NULL, NULL }
274 }; 306 };
275 307
276 DecodeFiles(files); 308 DecodeFiles(files);
277 } 309 }
278 #endif // CONFIG_WEBM_IO 310 #endif // CONFIG_WEBM_IO
279 311
280 INSTANTIATE_TEST_CASE_P(Synchronous, VP9WorkerThreadTest, ::testing::Bool()); 312 INSTANTIATE_TEST_CASE_P(Synchronous, VP9WorkerThreadTest, ::testing::Bool());
281 313
282 } // namespace 314 } // namespace
OLDNEW
« no previous file with comments | « source/libvpx/test/vp9_spatial_svc_encoder.sh ('k') | source/libvpx/test/vpx_temporal_svc_encoder.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698