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

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

Issue 1269113003: Rewrite non-temporal instructions Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Format 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
« no previous file with comments | « src/trusted/validator/build.scons ('k') | src/trusted/validator/validation_rewrite_32_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_test */ 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 them
57 // validation rule, i.e., allow them. In future, we will do rewriting. 57 // 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_32(64)_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 them.
68 // However, readonly_text = TRUE would make the text non-modifiable. In this
69 // case, we should return validation failed, and not do rewriting.
70 EXPECT_EQ(NaClValidationFailed, status);
60 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); 71 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
61 } 72 }
62 73
63 TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) { 74 TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) {
64 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); 75 memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
65 NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86); 76 NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86, FALSE);
66 // Disable non-temporal instructions. 77 // Disable non-temporal instructions.
67 EXPECT_EQ(NaClValidationFailed, status); 78 EXPECT_EQ(NaClValidationFailed, status);
68 // Code should not change. 79 // Code should not change.
69 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); 80 EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
70 } 81 }
71 82
72 int main(int argc, char *argv[]) { 83 int main(int argc, char *argv[]) {
73 // The IllegalInst test touches the log mutex deep inside the validator. 84 // 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 85 // This causes an SEH exception to be thrown on Windows if the mutex is not
75 // initialized. 86 // initialized.
76 // http://code.google.com/p/nativeclient/issues/detail?id=1696 87 // http://code.google.com/p/nativeclient/issues/detail?id=1696
77 NaClLogModuleInit(); 88 NaClLogModuleInit();
78 testing::InitGoogleTest(&argc, argv); 89 testing::InitGoogleTest(&argc, argv);
79 return RUN_ALL_TESTS(); 90 return RUN_ALL_TESTS();
80 } 91 }
OLDNEW
« no previous file with comments | « src/trusted/validator/build.scons ('k') | src/trusted/validator/validation_rewrite_32_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698