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

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

Issue 1309953002: x86 validator: Rewrite non-temporal stores into cached memory accesses (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Review nit Created 4 years, 10 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 2015 The Native Client Authors. All rights reserved. 2 * Copyright 2015 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/shared/platform/nacl_log.h" 9 #include "native_client/src/shared/platform/nacl_log.h"
10 #include "native_client/src/shared/utils/types.h" 10 #include "native_client/src/shared/utils/types.h"
(...skipping 17 matching lines...) Expand all
28 void SetUp() { 28 void SetUp() {
29 metadata_ptr = NULL; 29 metadata_ptr = NULL;
30 validator = NaClCreateValidator(); 30 validator = NaClCreateValidator();
31 cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize); 31 cpu_features = (NaClCPUFeatures *) malloc(validator->CPUFeatureSize);
32 EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL); 32 EXPECT_NE(cpu_features, (NaClCPUFeatures *) NULL);
33 memset(cpu_features, 0, validator->CPUFeatureSize); 33 memset(cpu_features, 0, validator->CPUFeatureSize);
34 validator->SetAllCPUFeatures(cpu_features); 34 validator->SetAllCPUFeatures(cpu_features);
35 memset(code_buffer, NOP, sizeof(code_buffer)); 35 memset(code_buffer, NOP, sizeof(code_buffer));
36 } 36 }
37 37
38 NaClValidationStatus Validate(uint32_t flags) { 38 NaClValidationStatus Validate(uint32_t flags, Bool readonly_text) {
39 return validator->Validate(0, code_buffer, 32, 39 return validator->Validate(0, code_buffer, 32,
40 FALSE, /* stubout_mode */ 40 FALSE, /* stubout_mode */
41 flags, 41 flags,
42 FALSE, /* readonly_text */ 42 readonly_text,
43 cpu_features, 43 cpu_features,
44 metadata_ptr, 44 metadata_ptr,
45 NULL); 45 NULL);
46 } 46 }
47 47
48 void TearDown() { 48 void TearDown() {
49 free(cpu_features); 49 free(cpu_features);
50 } 50 }
51 }; 51 };
52 52
53 TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) { 53 TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) {
54 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); 54 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
55 NaClValidationStatus status = Validate(0); 55 NaClValidationStatus status = Validate(0, FALSE);
56 // If we are not disabling non-temporal instructions, use the original 56 // If we are not disabling non-temporal instructions, we should rewrite
57 // validation rule, i.e., allow them. In future, we will do rewriting. 57 // them and return validation success.
58 EXPECT_EQ(NaClValidationSucceeded, status); 58 EXPECT_EQ(NaClValidationSucceeded, status);
59 // Code should not change. 59 // Just make sure code has changed. The rewriting itself is tested in
60 // validation_rewrite_test.cc
61 EXPECT_NE(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
62 }
63
64 TEST_F(ValidationDisableNonTemporalsTests, FailAndNotRewriteWhenReadOnlyText) {
65 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
66 NaClValidationStatus status = Validate(0, TRUE);
67 // If we are not disabling non-temporal instructions, we should rewrite
68 // them. However, readonly_text = TRUE would make the text
69 // non-modifiable. In this case, we should return validation failed, and
70 // not do rewriting.
71 EXPECT_EQ(NaClValidationFailed, status);
60 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); 72 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
61 } 73 }
62 74
63 TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) { 75 TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) {
64 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); 76 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
65 NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86); 77 NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86, FALSE);
66 // Disable non-temporal instructions. 78 // Disable non-temporal instructions.
67 EXPECT_EQ(NaClValidationFailed, status); 79 EXPECT_EQ(NaClValidationFailed, status);
68 // Code should not change. 80 // Code should not change.
69 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); 81 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
70 } 82 }
71 83
72 int main(int argc, char *argv[]) { 84 int main(int argc, char *argv[]) {
73 // The IllegalInst test touches the log mutex deep inside the validator. 85 // The IllegalInst test touches the log mutex deep inside the validator.
74 // This causes an SEH exception to be thrown on Windows if the mutex is not 86 // This causes an SEH exception to be thrown on Windows if the mutex is not
75 // initialized. 87 // initialized.
76 // http://code.google.com/p/nativeclient/issues/detail?id=1696 88 // http://code.google.com/p/nativeclient/issues/detail?id=1696
77 NaClLogModuleInit(); 89 NaClLogModuleInit();
78 testing::InitGoogleTest(&argc, argv); 90 testing::InitGoogleTest(&argc, argv);
79 return RUN_ALL_TESTS(); 91 return RUN_ALL_TESTS();
80 } 92 }
OLDNEW
« no previous file with comments | « src/trusted/validator/validation_cache_test.cc ('k') | src/trusted/validator/validation_rewrite_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698