| OLD | NEW |
| 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 "native_client/src/include/nacl_compiler_annotations.h" | 9 #include "native_client/src/include/nacl_compiler_annotations.h" |
| 10 #include "native_client/src/shared/platform/nacl_log.h" | 10 #include "native_client/src/shared/platform/nacl_log.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 mquery->state = QUERY_DESTROYED; | 98 mquery->state = QUERY_DESTROYED; |
| 99 mquery->context->query_destroyed = true; | 99 mquery->context->query_destroyed = true; |
| 100 free(mquery); | 100 free(mquery); |
| 101 } | 101 } |
| 102 | 102 |
| 103 class ValidationCachingInterfaceTests : public ::testing::Test { | 103 class ValidationCachingInterfaceTests : public ::testing::Test { |
| 104 protected: | 104 protected: |
| 105 MockContext context; | 105 MockContext context; |
| 106 NaClValidationCache cache; | 106 NaClValidationCache cache; |
| 107 NaClCPUFeatures cpu_features; | 107 NaClCPUFeatures cpu_features; |
| 108 int bundle_size; | |
| 109 | 108 |
| 110 unsigned char code_buffer[CODE_SIZE]; | 109 unsigned char code_buffer[CODE_SIZE]; |
| 111 | 110 |
| 112 void SetUp() { | 111 void SetUp() { |
| 113 context.marker = CONTEXT_MARKER; | 112 context.marker = CONTEXT_MARKER; |
| 114 context.query_result = 1; | 113 context.query_result = 1; |
| 115 context.set_validates_expected = false; | 114 context.set_validates_expected = false; |
| 116 context.query_destroyed = false; | 115 context.query_destroyed = false; |
| 117 | 116 |
| 118 cache.handle = &context; | 117 cache.handle = &context; |
| 119 cache.CreateQuery = MockCreateQuery; | 118 cache.CreateQuery = MockCreateQuery; |
| 120 cache.AddData = MockAddData; | 119 cache.AddData = MockAddData; |
| 121 cache.QueryKnownToValidate = MockQueryCodeValidates; | 120 cache.QueryKnownToValidate = MockQueryCodeValidates; |
| 122 cache.SetKnownToValidate = MockSetCodeValidates; | 121 cache.SetKnownToValidate = MockSetCodeValidates; |
| 123 cache.DestroyQuery = MockDestroyQuery; | 122 cache.DestroyQuery = MockDestroyQuery; |
| 124 | 123 |
| 125 NaClSetAllCPUFeatures(&cpu_features); | 124 NaClSetAllCPUFeatures(&cpu_features); |
| 126 | 125 |
| 127 bundle_size = 32; | |
| 128 | |
| 129 memset(code_buffer, 0x90, sizeof(code_buffer)); | 126 memset(code_buffer, 0x90, sizeof(code_buffer)); |
| 130 } | 127 } |
| 131 | 128 |
| 132 NaClValidationStatus Validate() { | 129 NaClValidationStatus Validate() { |
| 133 return NACL_SUBARCH_NAME(ApplyValidator, | 130 return NACL_SUBARCH_NAME(ApplyValidator, |
| 134 NACL_TARGET_ARCH, | 131 NACL_TARGET_ARCH, |
| 135 NACL_TARGET_SUBARCH)( | 132 NACL_TARGET_SUBARCH)( |
| 136 NACL_SB_DEFAULT, | 133 NACL_SB_DEFAULT, |
| 137 0, code_buffer, 32, | 134 0, code_buffer, 32, |
| 138 bundle_size, /* stubout_mode= */ FALSE, | 135 /* stubout_mode= */ FALSE, |
| 139 /* readonly_test= */ FALSE, &cpu_features, | 136 /* readonly_test= */ FALSE, &cpu_features, |
| 140 &cache); | 137 &cache); |
| 141 } | 138 } |
| 142 }; | 139 }; |
| 143 | 140 |
| 144 TEST_F(ValidationCachingInterfaceTests, Sanity) { | 141 TEST_F(ValidationCachingInterfaceTests, Sanity) { |
| 145 void *query = cache.CreateQuery(cache.handle); | 142 void *query = cache.CreateQuery(cache.handle); |
| 146 cache.AddData(query, NULL, 6); | 143 cache.AddData(query, NULL, 6); |
| 147 cache.AddData(query, NULL, 128); | 144 cache.AddData(query, NULL, 128); |
| 148 EXPECT_EQ(1, cache.QueryKnownToValidate(query)); | 145 EXPECT_EQ(1, cache.QueryKnownToValidate(query)); |
| 149 cache.DestroyQuery(query); | 146 cache.DestroyQuery(query); |
| 150 EXPECT_EQ(true, context.query_destroyed); | 147 EXPECT_EQ(true, context.query_destroyed); |
| 151 } | 148 } |
| 152 | 149 |
| 153 TEST_F(ValidationCachingInterfaceTests, NoCache) { | 150 TEST_F(ValidationCachingInterfaceTests, NoCache) { |
| 154 NaClValidationStatus status = | 151 NaClValidationStatus status = |
| 155 NACL_SUBARCH_NAME(ApplyValidator, | 152 NACL_SUBARCH_NAME(ApplyValidator, |
| 156 NACL_TARGET_ARCH, | 153 NACL_TARGET_ARCH, |
| 157 NACL_TARGET_SUBARCH)( | 154 NACL_TARGET_SUBARCH)( |
| 158 NACL_SB_DEFAULT, | 155 NACL_SB_DEFAULT, |
| 159 0, code_buffer, CODE_SIZE, | 156 0, code_buffer, CODE_SIZE, |
| 160 bundle_size, /* stubout_mode= */ FALSE, | 157 /* stubout_mode= */ FALSE, |
| 161 /* readonly_test= */ FALSE, &cpu_features, | 158 /* readonly_test= */ FALSE, &cpu_features, |
| 162 NULL); | 159 NULL); |
| 163 EXPECT_EQ(NaClValidationSucceeded, status); | 160 EXPECT_EQ(NaClValidationSucceeded, status); |
| 164 } | 161 } |
| 165 | 162 |
| 166 TEST_F(ValidationCachingInterfaceTests, CacheHit) { | 163 TEST_F(ValidationCachingInterfaceTests, CacheHit) { |
| 167 NaClValidationStatus status = Validate(); | 164 NaClValidationStatus status = Validate(); |
| 168 EXPECT_EQ(NaClValidationSucceeded, status); | 165 EXPECT_EQ(NaClValidationSucceeded, status); |
| 169 EXPECT_EQ(true, context.query_destroyed); | 166 EXPECT_EQ(true, context.query_destroyed); |
| 170 } | 167 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // Test driver function. | 211 // Test driver function. |
| 215 int main(int argc, char *argv[]) { | 212 int main(int argc, char *argv[]) { |
| 216 // The IllegalInst test touches the log mutex deep inside the validator. | 213 // The IllegalInst test touches the log mutex deep inside the validator. |
| 217 // This causes an SEH exception to be thrown on Windows if the mutex is not | 214 // This causes an SEH exception to be thrown on Windows if the mutex is not |
| 218 // initialized. | 215 // initialized. |
| 219 // http://code.google.com/p/nativeclient/issues/detail?id=1696 | 216 // http://code.google.com/p/nativeclient/issues/detail?id=1696 |
| 220 NaClLogModuleInit(); | 217 NaClLogModuleInit(); |
| 221 testing::InitGoogleTest(&argc, argv); | 218 testing::InitGoogleTest(&argc, argv); |
| 222 return RUN_ALL_TESTS(); | 219 return RUN_ALL_TESTS(); |
| 223 } | 220 } |
| OLD | NEW |