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

Side by Side Diff: ppapi/native_client/tests/ppapi_browser/ppb_var/ppapi_ppb_var.cc

Issue 8883035: Update ppb_var NaCl test to use 1.1 interface (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <pthread.h> 5 #include <pthread.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 #include <new> 8 #include <new>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 const PPB_Var* var_interface = NULL; 24 const PPB_Var* var_interface = NULL;
25 25
26 // Creates a bunch of new PP_Var(string), then deletes them. 26 // Creates a bunch of new PP_Var(string), then deletes them.
27 // This tests locking on the dictionary that looks up PP_Vars. 27 // This tests locking on the dictionary that looks up PP_Vars.
28 void* StringCreateDeleteThreadFunc(void* thread_argument) { 28 void* StringCreateDeleteThreadFunc(void* thread_argument) {
29 PP_Var* vars = new(std::nothrow) PP_Var[kNumTriesPerThread]; 29 PP_Var* vars = new(std::nothrow) PP_Var[kNumTriesPerThread];
30 EXPECT(vars); 30 EXPECT(vars);
31 static const char* kTestString = "A test string"; 31 static const char* kTestString = "A test string";
32 const uint32_t kTestStringLen = strlen(kTestString); 32 const uint32_t kTestStringLen = strlen(kTestString);
33 for (int i = 0; i < kNumTriesPerThread; ++i) { 33 for (int i = 0; i < kNumTriesPerThread; ++i) {
34 vars[i] = 34 vars[i] = var_interface->VarFromUtf8(kTestString, kTestStringLen);
35 var_interface->VarFromUtf8(pp_module(), kTestString, kTestStringLen);
36 } 35 }
37 for (int i = 0; i < kNumTriesPerThread; ++i) { 36 for (int i = 0; i < kNumTriesPerThread; ++i) {
38 var_interface->Release(vars[i]); 37 var_interface->Release(vars[i]);
39 } 38 }
40 delete vars; 39 delete vars;
41 return NULL; 40 return NULL;
42 } 41 }
43 42
44 // Tests creation and deletion. 43 // Tests creation and deletion.
45 // Spawns kNumThreads threads, each of which creates kNumTriesPerThread PP_Vars 44 // Spawns kNumThreads threads, each of which creates kNumTriesPerThread PP_Vars
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 80
82 // Tests reference count atomicity. 81 // Tests reference count atomicity.
83 // Creates one variable and spawns kNumThreads, each of which does: 82 // Creates one variable and spawns kNumThreads, each of which does:
84 // 1) kNumTriesPerThread AddRefs 83 // 1) kNumTriesPerThread AddRefs
85 // 2) kNumTriesPerThread Releases 84 // 2) kNumTriesPerThread Releases
86 // 3) kNumTriesPerThread (AddRef, Release) pairs 85 // 3) kNumTriesPerThread (AddRef, Release) pairs
87 void TestStringVarRefCount() { 86 void TestStringVarRefCount() {
88 pthread_t tid[kNumThreads]; 87 pthread_t tid[kNumThreads];
89 static const char* kTestString = "A test string"; 88 static const char* kTestString = "A test string";
90 const uint32_t kTestStringLen = strlen(kTestString); 89 const uint32_t kTestStringLen = strlen(kTestString);
91 PP_Var test_var = 90 PP_Var test_var = var_interface->VarFromUtf8(kTestString, kTestStringLen);
92 var_interface->VarFromUtf8(pp_module(), kTestString, kTestStringLen);
93 for (int i = 0; i < kNumThreads; ++i) { 91 for (int i = 0; i < kNumThreads; ++i) {
94 EXPECT(pthread_create(&tid[i], 92 EXPECT(pthread_create(&tid[i],
95 NULL, 93 NULL,
96 StringVarRefCountThreadFunc, 94 StringVarRefCountThreadFunc,
97 &test_var) == 0); 95 &test_var) == 0);
98 } 96 }
99 // Join the threads back before reporting success. 97 // Join the threads back before reporting success.
100 for (int i = 0; i < kNumThreads; ++i) { 98 for (int i = 0; i < kNumThreads; ++i) {
101 EXPECT(pthread_join(tid[i], NULL) == 0); 99 EXPECT(pthread_join(tid[i], NULL) == 0);
102 } 100 }
103 var_interface->Release(test_var); 101 var_interface->Release(test_var);
104 TEST_PASSED; 102 TEST_PASSED;
105 } 103 }
106 104
107 } // namespace 105 } // namespace
108 106
109 void SetupTests() { 107 void SetupTests() {
110 var_interface = PPBVar(); 108 var_interface = PPBVar();
111 EXPECT(var_interface != NULL); 109 EXPECT(var_interface != NULL);
112 RegisterTest("TestStringVarCreateDelete", TestStringVarCreateDelete); 110 RegisterTest("TestStringVarCreateDelete", TestStringVarCreateDelete);
113 RegisterTest("TestStringVarRefCount", TestStringVarRefCount); 111 RegisterTest("TestStringVarRefCount", TestStringVarRefCount);
114 } 112 }
115 113
116 void SetupPluginInterfaces() { 114 void SetupPluginInterfaces() {
117 // none 115 // none
118 } 116 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698