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

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

Issue 1234393005: A mechanism to identify/forbid/"rewrite" non-temporal instructions (and other) (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Fixing nits Created 5 years, 4 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
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 <fcntl.h> 9 #include <fcntl.h>
10 10
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize); 161 cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize);
162 EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL); 162 EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL);
163 validator->SetAllCPUFeatures(cpu_features); 163 validator->SetAllCPUFeatures(cpu_features);
164 164
165 memset(code_buffer, NOP, sizeof(code_buffer)); 165 memset(code_buffer, NOP, sizeof(code_buffer));
166 } 166 }
167 167
168 NaClValidationStatus Validate() { 168 NaClValidationStatus Validate() {
169 return validator->Validate(0, code_buffer, 32, 169 return validator->Validate(0, code_buffer, 32,
170 FALSE, /* stubout_mode */ 170 FALSE, /* stubout_mode */
171 0, /* flags */
171 FALSE, /* readonly_test */ 172 FALSE, /* readonly_test */
172 cpu_features, 173 cpu_features,
173 metadata_ptr, 174 metadata_ptr,
174 &cache); 175 &cache);
175 } 176 }
176 177
177 void TearDown() { 178 void TearDown() {
178 free(cpu_features); 179 free(cpu_features);
179 } 180 }
180 }; 181 };
181 182
182 TEST_F(ValidationCachingInterfaceTests, Sanity) { 183 TEST_F(ValidationCachingInterfaceTests, Sanity) {
183 void *query = cache.CreateQuery(cache.handle); 184 void *query = cache.CreateQuery(cache.handle);
184 context.add_count_expected = 2; 185 context.add_count_expected = 2;
185 cache.AddData(query, NULL, 6); 186 cache.AddData(query, NULL, 6);
186 cache.AddData(query, NULL, 128); 187 cache.AddData(query, NULL, 128);
187 EXPECT_EQ(1, cache.QueryKnownToValidate(query)); 188 EXPECT_EQ(1, cache.QueryKnownToValidate(query));
188 cache.DestroyQuery(query); 189 cache.DestroyQuery(query);
189 EXPECT_EQ(true, context.query_destroyed); 190 EXPECT_EQ(true, context.query_destroyed);
190 } 191 }
191 192
192 TEST_F(ValidationCachingInterfaceTests, NoCache) { 193 TEST_F(ValidationCachingInterfaceTests, NoCache) {
193 const struct NaClValidatorInterface *validator = NaClCreateValidator(); 194 const struct NaClValidatorInterface *validator = NaClCreateValidator();
194 NaClValidationStatus status = validator->Validate( 195 NaClValidationStatus status = validator->Validate(
195 0, code_buffer, CODE_SIZE, 196 0, code_buffer, CODE_SIZE,
196 FALSE, /* stubout_mode */ 197 FALSE, /* stubout_mode */
198 0, /* flags */
197 FALSE, /* readonly_test */ 199 FALSE, /* readonly_test */
198 cpu_features, 200 cpu_features,
199 NULL, /* metadata */ 201 NULL, /* metadata */
200 NULL); 202 NULL);
201 EXPECT_EQ(NaClValidationSucceeded, status); 203 EXPECT_EQ(NaClValidationSucceeded, status);
202 } 204 }
203 205
204 TEST_F(ValidationCachingInterfaceTests, CacheHit) { 206 TEST_F(ValidationCachingInterfaceTests, CacheHit) {
205 NaClValidationStatus status = Validate(); 207 NaClValidationStatus status = Validate();
206 EXPECT_EQ(NaClValidationSucceeded, status); 208 EXPECT_EQ(NaClValidationSucceeded, status);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // One file we know must exist is this executable. 413 // One file we know must exist is this executable.
412 AN_ARBITRARY_FILE_PATH = argv[0]; 414 AN_ARBITRARY_FILE_PATH = argv[0];
413 // The IllegalInst test touches the log mutex deep inside the validator. 415 // The IllegalInst test touches the log mutex deep inside the validator.
414 // This causes an SEH exception to be thrown on Windows if the mutex is not 416 // This causes an SEH exception to be thrown on Windows if the mutex is not
415 // initialized. 417 // initialized.
416 // http://code.google.com/p/nativeclient/issues/detail?id=1696 418 // http://code.google.com/p/nativeclient/issues/detail?id=1696
417 NaClLogModuleInit(); 419 NaClLogModuleInit();
418 testing::InitGoogleTest(&argc, argv); 420 testing::InitGoogleTest(&argc, argv);
419 return RUN_ALL_TESTS(); 421 return RUN_ALL_TESTS();
420 } 422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698