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

Side by Side Diff: src/trusted/validator/validation_cache_test.cc

Issue 10134056: Refactor the process of choosing validators. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: draft that does not fully build Created 8 years, 7 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) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "gtest/gtest.h" 7 #include "gtest/gtest.h"
8 8
9 #include "native_client/src/include/nacl_compiler_annotations.h" 9 #include "native_client/src/include/nacl_compiler_annotations.h"
10 #include "native_client/src/shared/platform/nacl_log.h" 10 #include "native_client/src/shared/platform/nacl_log.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 cache.QueryKnownToValidate = MockQueryCodeValidates; 120 cache.QueryKnownToValidate = MockQueryCodeValidates;
121 cache.SetKnownToValidate = MockSetCodeValidates; 121 cache.SetKnownToValidate = MockSetCodeValidates;
122 cache.DestroyQuery = MockDestroyQuery; 122 cache.DestroyQuery = MockDestroyQuery;
123 123
124 NaClSetAllCPUFeatures(&cpu_features); 124 NaClSetAllCPUFeatures(&cpu_features);
125 125
126 memset(code_buffer, 0x90, sizeof(code_buffer)); 126 memset(code_buffer, 0x90, sizeof(code_buffer));
127 } 127 }
128 128
129 NaClValidationStatus Validate() { 129 NaClValidationStatus Validate() {
130 return NACL_SUBARCH_NAME(ApplyValidator, 130 /* TODO: update this */
131 NACL_TARGET_ARCH, 131 struct NaClValidatorInterface *validator;
132 NACL_TARGET_SUBARCH)( 132 NaClSelectValidator(&validator);
133 0, code_buffer, 32, 133 return validator->Validate(0, code_buffer, 32,
134 /* stubout_mode= */ FALSE, 134 /* stubout_mode= */ FALSE,
135 /* readonly_test= */ FALSE, &cpu_features, 135 /* readonly_test= */ FALSE, &cpu_features,
136 &cache); 136 &cache);
137 } 137 }
138 }; 138 };
139 139
140 TEST_F(ValidationCachingInterfaceTests, Sanity) { 140 TEST_F(ValidationCachingInterfaceTests, Sanity) {
141 void *query = cache.CreateQuery(cache.handle); 141 void *query = cache.CreateQuery(cache.handle);
142 cache.AddData(query, NULL, 6); 142 cache.AddData(query, NULL, 6);
143 cache.AddData(query, NULL, 128); 143 cache.AddData(query, NULL, 128);
144 EXPECT_EQ(1, cache.QueryKnownToValidate(query)); 144 EXPECT_EQ(1, cache.QueryKnownToValidate(query));
145 cache.DestroyQuery(query); 145 cache.DestroyQuery(query);
146 EXPECT_EQ(true, context.query_destroyed); 146 EXPECT_EQ(true, context.query_destroyed);
147 } 147 }
148 148
149 TEST_F(ValidationCachingInterfaceTests, NoCache) { 149 TEST_F(ValidationCachingInterfaceTests, NoCache) {
150 NaClValidationStatus status = 150 /* TODO: link with something containing NaClSelectValidator. */
151 NACL_SUBARCH_NAME(ApplyValidator, 151 #if 0
152 NACL_TARGET_ARCH, 152 struct NaClValidatorInterface *validator;
153 NACL_TARGET_SUBARCH)( 153 NaClSelectValidator(&validator);
154 0, code_buffer, CODE_SIZE, 154 NaClValidationStatus status = validator->Validate(
155 /* stubout_mode= */ FALSE, 155 0, code_buffer, CODE_SIZE,
156 /* readonly_test= */ FALSE, &cpu_features, 156 FALSE, /* stubout_mode */
157 NULL); 157 FALSE, /* readonly_test */
158 &cpu_features,
159 NULL);
158 EXPECT_EQ(NaClValidationSucceeded, status); 160 EXPECT_EQ(NaClValidationSucceeded, status);
161 #endif
159 } 162 }
160 163
161 TEST_F(ValidationCachingInterfaceTests, CacheHit) { 164 TEST_F(ValidationCachingInterfaceTests, CacheHit) {
162 NaClValidationStatus status = Validate(); 165 NaClValidationStatus status = Validate();
163 EXPECT_EQ(NaClValidationSucceeded, status); 166 EXPECT_EQ(NaClValidationSucceeded, status);
164 EXPECT_EQ(true, context.query_destroyed); 167 EXPECT_EQ(true, context.query_destroyed);
165 } 168 }
166 169
167 TEST_F(ValidationCachingInterfaceTests, CacheMiss) { 170 TEST_F(ValidationCachingInterfaceTests, CacheMiss) {
168 context.query_result = 0; 171 context.query_result = 0;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Test driver function. 212 // Test driver function.
210 int main(int argc, char *argv[]) { 213 int main(int argc, char *argv[]) {
211 // The IllegalInst test touches the log mutex deep inside the validator. 214 // The IllegalInst test touches the log mutex deep inside the validator.
212 // This causes an SEH exception to be thrown on Windows if the mutex is not 215 // This causes an SEH exception to be thrown on Windows if the mutex is not
213 // initialized. 216 // initialized.
214 // http://code.google.com/p/nativeclient/issues/detail?id=1696 217 // http://code.google.com/p/nativeclient/issues/detail?id=1696
215 NaClLogModuleInit(); 218 NaClLogModuleInit();
216 testing::InitGoogleTest(&argc, argv); 219 testing::InitGoogleTest(&argc, argv);
217 return RUN_ALL_TESTS(); 220 return RUN_ALL_TESTS();
218 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698