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

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: upload error retry 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"
11 #include "native_client/src/shared/utils/types.h"
11 #include "native_client/src/trusted/validator/ncvalidate.h" 12 #include "native_client/src/trusted/validator/ncvalidate.h"
12 #include "native_client/src/trusted/validator/validation_cache.h" 13 #include "native_client/src/trusted/validator/validation_cache.h"
13 14
14 #define CONTEXT_MARKER 31 15 #define CONTEXT_MARKER 31
15 #define QUERY_MARKER 37 16 #define QUERY_MARKER 37
16 17
17 #define CODE_SIZE 32 18 #define CODE_SIZE 32
18 19
19 // ret 20 // ret
20 const char ret[CODE_SIZE + 1] = 21 const char ret[CODE_SIZE + 1] =
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 cache.QueryKnownToValidate = MockQueryCodeValidates; 121 cache.QueryKnownToValidate = MockQueryCodeValidates;
121 cache.SetKnownToValidate = MockSetCodeValidates; 122 cache.SetKnownToValidate = MockSetCodeValidates;
122 cache.DestroyQuery = MockDestroyQuery; 123 cache.DestroyQuery = MockDestroyQuery;
123 124
124 NaClSetAllCPUFeatures(&cpu_features); 125 NaClSetAllCPUFeatures(&cpu_features);
125 126
126 memset(code_buffer, 0x90, sizeof(code_buffer)); 127 memset(code_buffer, 0x90, sizeof(code_buffer));
127 } 128 }
128 129
129 NaClValidationStatus Validate() { 130 NaClValidationStatus Validate() {
130 return NACL_SUBARCH_NAME(ApplyValidator, 131 const struct NaClValidatorInterface *validator = NaClCreateValidator();
131 NACL_TARGET_ARCH, 132 return validator->Validate(0, code_buffer, 32,
132 NACL_TARGET_SUBARCH)( 133 FALSE, /* stubout_mode= */
133 0, code_buffer, 32, 134 FALSE, /* readonly_test= */
134 /* stubout_mode= */ FALSE, 135 &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 const struct NaClValidatorInterface *validator = NaClCreateValidator();
151 NACL_SUBARCH_NAME(ApplyValidator, 151 NaClValidationStatus status = validator->Validate(
152 NACL_TARGET_ARCH, 152 0, code_buffer, CODE_SIZE,
153 NACL_TARGET_SUBARCH)( 153 FALSE, /* stubout_mode */
154 0, code_buffer, CODE_SIZE, 154 FALSE, /* readonly_test */
155 /* stubout_mode= */ FALSE, 155 &cpu_features,
156 /* readonly_test= */ FALSE, &cpu_features, 156 NULL);
157 NULL);
158 EXPECT_EQ(NaClValidationSucceeded, status); 157 EXPECT_EQ(NaClValidationSucceeded, status);
159 } 158 }
160 159
161 TEST_F(ValidationCachingInterfaceTests, CacheHit) { 160 TEST_F(ValidationCachingInterfaceTests, CacheHit) {
162 NaClValidationStatus status = Validate(); 161 NaClValidationStatus status = Validate();
163 EXPECT_EQ(NaClValidationSucceeded, status); 162 EXPECT_EQ(NaClValidationSucceeded, status);
164 EXPECT_EQ(true, context.query_destroyed); 163 EXPECT_EQ(true, context.query_destroyed);
165 } 164 }
166 165
167 TEST_F(ValidationCachingInterfaceTests, CacheMiss) { 166 TEST_F(ValidationCachingInterfaceTests, CacheMiss) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Test driver function. 208 // Test driver function.
210 int main(int argc, char *argv[]) { 209 int main(int argc, char *argv[]) {
211 // The IllegalInst test touches the log mutex deep inside the validator. 210 // 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 211 // This causes an SEH exception to be thrown on Windows if the mutex is not
213 // initialized. 212 // initialized.
214 // http://code.google.com/p/nativeclient/issues/detail?id=1696 213 // http://code.google.com/p/nativeclient/issues/detail?id=1696
215 NaClLogModuleInit(); 214 NaClLogModuleInit();
216 testing::InitGoogleTest(&argc, argv); 215 testing::InitGoogleTest(&argc, argv);
217 return RUN_ALL_TESTS(); 216 return RUN_ALL_TESTS();
218 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698