| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 bundle_size = 32; | 127 bundle_size = 32; |
| 128 | 128 |
| 129 memset(code_buffer, 0x90, sizeof(code_buffer)); | 129 memset(code_buffer, 0x90, sizeof(code_buffer)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 NaClValidationStatus Validate() { | 132 NaClValidationStatus Validate() { |
| 133 return NACL_SUBARCH_NAME(ApplyValidator, | 133 return NACL_SUBARCH_NAME(ApplyValidator, |
| 134 NACL_TARGET_ARCH, | 134 NACL_TARGET_ARCH, |
| 135 NACL_TARGET_SUBARCH)( | 135 NACL_TARGET_SUBARCH)( |
| 136 NACL_SB_DEFAULT, | 136 NACL_SB_DEFAULT, |
| 137 NaClApplyCodeValidation, | |
| 138 0, code_buffer, 32, | 137 0, code_buffer, 32, |
| 139 bundle_size, FALSE, &cpu_features, | 138 bundle_size, /* stubout_mode= */ FALSE, |
| 139 /* readonly_test= */ FALSE, &cpu_features, |
| 140 &cache); | 140 &cache); |
| 141 } | 141 } |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 TEST_F(ValidationCachingInterfaceTests, Sanity) { | 144 TEST_F(ValidationCachingInterfaceTests, Sanity) { |
| 145 void *query = cache.CreateQuery(cache.handle); | 145 void *query = cache.CreateQuery(cache.handle); |
| 146 cache.AddData(query, NULL, 6); | 146 cache.AddData(query, NULL, 6); |
| 147 cache.AddData(query, NULL, 128); | 147 cache.AddData(query, NULL, 128); |
| 148 EXPECT_EQ(1, cache.QueryKnownToValidate(query)); | 148 EXPECT_EQ(1, cache.QueryKnownToValidate(query)); |
| 149 cache.DestroyQuery(query); | 149 cache.DestroyQuery(query); |
| 150 EXPECT_EQ(true, context.query_destroyed); | 150 EXPECT_EQ(true, context.query_destroyed); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST_F(ValidationCachingInterfaceTests, NoCache) { | 153 TEST_F(ValidationCachingInterfaceTests, NoCache) { |
| 154 NaClValidationStatus status = | 154 NaClValidationStatus status = |
| 155 NACL_SUBARCH_NAME(ApplyValidator, | 155 NACL_SUBARCH_NAME(ApplyValidator, |
| 156 NACL_TARGET_ARCH, | 156 NACL_TARGET_ARCH, |
| 157 NACL_TARGET_SUBARCH)( | 157 NACL_TARGET_SUBARCH)( |
| 158 NACL_SB_DEFAULT, | 158 NACL_SB_DEFAULT, |
| 159 NaClApplyCodeValidation, | |
| 160 0, code_buffer, CODE_SIZE, | 159 0, code_buffer, CODE_SIZE, |
| 161 bundle_size, FALSE, &cpu_features, | 160 bundle_size, /* stubout_mode= */ FALSE, |
| 161 /* readonly_test= */ FALSE, &cpu_features, |
| 162 NULL); | 162 NULL); |
| 163 EXPECT_EQ(NaClValidationSucceeded, status); | 163 EXPECT_EQ(NaClValidationSucceeded, status); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_F(ValidationCachingInterfaceTests, CacheHit) { | 166 TEST_F(ValidationCachingInterfaceTests, CacheHit) { |
| 167 NaClValidationStatus status = Validate(); | 167 NaClValidationStatus status = Validate(); |
| 168 EXPECT_EQ(NaClValidationSucceeded, status); | 168 EXPECT_EQ(NaClValidationSucceeded, status); |
| 169 EXPECT_EQ(true, context.query_destroyed); | 169 EXPECT_EQ(true, context.query_destroyed); |
| 170 } | 170 } |
| 171 | 171 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // Test driver function. | 214 // Test driver function. |
| 215 int main(int argc, char *argv[]) { | 215 int main(int argc, char *argv[]) { |
| 216 // The IllegalInst test touches the log mutex deep inside the validator. | 216 // 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 | 217 // This causes an SEH exception to be thrown on Windows if the mutex is not |
| 218 // initialized. | 218 // initialized. |
| 219 // http://code.google.com/p/nativeclient/issues/detail?id=1696 | 219 // http://code.google.com/p/nativeclient/issues/detail?id=1696 |
| 220 NaClLogModuleInit(); | 220 NaClLogModuleInit(); |
| 221 testing::InitGoogleTest(&argc, argv); | 221 testing::InitGoogleTest(&argc, argv); |
| 222 return RUN_ALL_TESTS(); | 222 return RUN_ALL_TESTS(); |
| 223 } | 223 } |
| OLD | NEW |