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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/trusted/validator/validation_disable_nontemporals_test.cc
diff --git a/src/trusted/validator/validation_disable_nontemporals_test.cc b/src/trusted/validator/validation_disable_nontemporals_test.cc
index 211288d2407295b2c17043332d239f2f39ce42f9..75b80403d7b2c32d70a9e2757fa107755653a73b 100644
--- a/src/trusted/validator/validation_disable_nontemporals_test.cc
+++ b/src/trusted/validator/validation_disable_nontemporals_test.cc
@@ -35,11 +35,11 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test {
memset(code_buffer, NOP, sizeof(code_buffer));
}
- NaClValidationStatus Validate(uint32_t flags) {
+ NaClValidationStatus Validate(uint32_t flags, Bool readonly_text) {
return validator->Validate(0, code_buffer, 32,
FALSE, /* stubout_mode */
flags,
- FALSE, /* readonly_test */
+ readonly_text,
cpu_features,
metadata_ptr,
NULL);
@@ -52,17 +52,28 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test {
TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) {
memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
- NaClValidationStatus status = Validate(0);
- // If we are not disabling non-temporal instructions, use the original
- // validation rule, i.e., allow them. In future, we will do rewriting.
+ NaClValidationStatus status = Validate(0, FALSE);
+ // If we are not disabling non-temporal instructions, we should rewrite them
+ // and return validation success.
EXPECT_EQ(NaClValidationSucceeded, status);
- // Code should not change.
+ // Just make sure code has changed. The rewriting itself is tested in
+ // validation_rewrite_32(64)_test.cc
+ EXPECT_NE(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
+}
+
+TEST_F(ValidationDisableNonTemporalsTests, FailAndNotRewriteWhenReadOnlyText) {
+ memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
+ NaClValidationStatus status = Validate(0, TRUE);
+ // If we are not disabling non-temporal instructions, we should rewrite them.
+ // However, readonly_text = TRUE would make the text non-modifiable. In this
+ // case, we should return validation failed, and not do rewriting.
+ EXPECT_EQ(NaClValidationFailed, status);
EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE));
}
TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) {
memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE);
- NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86);
+ NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86, FALSE);
// Disable non-temporal instructions.
EXPECT_EQ(NaClValidationFailed, status);
// Code should not change.
« 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