Chromium Code Reviews| Index: src/trusted/validator/validation_rewrite_32_test.cc |
| diff --git a/src/trusted/validator/validation_disable_nontemporals_test.cc b/src/trusted/validator/validation_rewrite_32_test.cc |
| similarity index 59% |
| copy from src/trusted/validator/validation_disable_nontemporals_test.cc |
| copy to src/trusted/validator/validation_rewrite_32_test.cc |
| index 211288d2407295b2c17043332d239f2f39ce42f9..85ef49f4421b5a2edded04906941b5c349d0cb4c 100644 |
| --- a/src/trusted/validator/validation_disable_nontemporals_test.cc |
| +++ b/src/trusted/validator/validation_rewrite_32_test.cc |
| @@ -4,6 +4,7 @@ |
| * found in the LICENSE file. |
| */ |
| +#include <string.h> |
|
Mark Seaborn
2015/08/14 21:12:59
Nit: add empty line after this, to separate standa
ruiq
2015/08/15 04:46:40
Done.
|
| #include "gtest/gtest.h" |
| #include "native_client/src/shared/platform/nacl_log.h" |
| @@ -12,12 +13,17 @@ |
| #define CODE_SIZE 32 |
| #define NOP 0x90 |
| -#define MOVNTI_CODE_SIZE 8 |
| -// mov %edi,%edi; movnti %rax,0x68(%r15,%rdi,1) |
| -const char* movnti_code = "\x89\xff\x49\x0f\xc3\x44\x3f\x68"; |
| +extern "C" { |
| + extern const char no_rewrite_code[]; |
| + extern const char no_rewrite_code_post_rewrite[]; |
| + extern const char movntq_code[]; |
| + extern const char movntq_code_post_rewrite[]; |
| + extern const char movntdq_code[]; |
| + extern const char movntdq_code_post_rewrite[]; |
| +} |
| -class ValidationDisableNonTemporalsTests : public ::testing::Test { |
| +class ValidationMovntRewriteTests : public ::testing::Test { |
| protected: |
| NaClValidationMetadata *metadata_ptr; |
| const struct NaClValidatorInterface *validator; |
| @@ -36,7 +42,7 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test { |
| } |
| NaClValidationStatus Validate(uint32_t flags) { |
| - return validator->Validate(0, code_buffer, 32, |
| + return validator->Validate(0, code_buffer, CODE_SIZE, |
| FALSE, /* stubout_mode */ |
| flags, |
| FALSE, /* readonly_test */ |
| @@ -50,23 +56,31 @@ class ValidationDisableNonTemporalsTests : public ::testing::Test { |
| } |
| }; |
| -TEST_F(ValidationDisableNonTemporalsTests, NotDisableNonTemporals) { |
| - memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); |
| +TEST_F(ValidationMovntRewriteTests, DisableNonTemporalsNoRewrite) { |
| + memcpy(code_buffer, no_rewrite_code, strlen(no_rewrite_code)); |
| + NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86); |
| + EXPECT_EQ(NaClValidationFailed, status); |
| + EXPECT_EQ(0, memcmp(code_buffer, |
| + no_rewrite_code_post_rewrite, |
| + strlen(no_rewrite_code_post_rewrite))); |
| +} |
| + |
| +TEST_F(ValidationMovntRewriteTests, RewriteMovntq) { |
| + memcpy(code_buffer, movntq_code, strlen(movntq_code)); |
| 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. |
| EXPECT_EQ(NaClValidationSucceeded, status); |
| - // Code should not change. |
| - EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); |
| + EXPECT_EQ(0, memcmp(code_buffer, |
| + movntq_code_post_rewrite, |
| + strlen(movntq_code_post_rewrite))); |
| } |
| -TEST_F(ValidationDisableNonTemporalsTests, DisableNonTemporals) { |
| - memcpy(code_buffer, movnti_code, MOVNTI_CODE_SIZE); |
| - NaClValidationStatus status = Validate(NACL_DISABLE_NONTEMPORALS_X86); |
| - // Disable non-temporal instructions. |
| - EXPECT_EQ(NaClValidationFailed, status); |
| - // Code should not change. |
| - EXPECT_EQ(0, memcmp(code_buffer, movnti_code, MOVNTI_CODE_SIZE)); |
| +TEST_F(ValidationMovntRewriteTests, RewriteMovntdq) { |
| + memcpy(code_buffer, movntdq_code, strlen(movntdq_code)); |
| + NaClValidationStatus status = Validate(0); |
| + EXPECT_EQ(NaClValidationSucceeded, status); |
| + EXPECT_EQ(0, memcmp(code_buffer, |
| + movntdq_code_post_rewrite, |
| + strlen(movntdq_code_post_rewrite))); |
| } |
| int main(int argc, char *argv[]) { |