| 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 /* | 7 /* |
| 8 * Tests the decoder. | 8 * Tests the decoder. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ | 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ |
| 12 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ | 12 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ |
| 13 | 13 |
| 14 #include "native_client/src/trusted/validator_arm/gen/arm32_decode_named.h" | 14 #ifndef NACL_TRUSTED_BUT_NOT_TCB |
| 15 #error This file is not meant for use in the TCB |
| 16 #endif |
| 17 |
| 18 #include "native_client/src/trusted/validator_arm/named_class_decoder.h" |
| 19 #include "native_client/src/trusted/validator_arm/gen/arm32_decode_named_decoder
.h" |
| 15 | 20 |
| 16 namespace nacl_arm_test { | 21 namespace nacl_arm_test { |
| 17 | 22 |
| 18 // Defines a decoder tester that enumerates an instruction pattern, | 23 // Defines a decoder tester that enumerates an instruction pattern, |
| 19 // and tests that all of the decoded patterns match the expected | 24 // and tests that all of the decoded patterns match the expected |
| 20 // class decoder, and that any additional sanity checks, specific | 25 // class decoder, and that any additional sanity checks, specific |
| 21 // to the instruction apply. | 26 // to the instruction apply. |
| 22 // | 27 // |
| 23 // Patterns are sequences of characters as follows: | 28 // Patterns are sequences of characters as follows: |
| 24 // '1' - Bit must be value 1. | 29 // '1' - Bit must be value 1. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 class DecoderTester { | 46 class DecoderTester { |
| 42 public: | 47 public: |
| 43 DecoderTester(); | 48 DecoderTester(); |
| 44 virtual ~DecoderTester() {} | 49 virtual ~DecoderTester() {} |
| 45 | 50 |
| 46 protected: | 51 protected: |
| 47 // Once an instruction is decoded, this method is called to apply | 52 // Once an instruction is decoded, this method is called to apply |
| 48 // sanity checks on the matched decoder. The default checks that the | 53 // sanity checks on the matched decoder. The default checks that the |
| 49 // expected class name matches the name of the decoder, and that | 54 // expected class name matches the name of the decoder, and that |
| 50 // the safety level MAY_BE_SAFE. | 55 // the safety level MAY_BE_SAFE. |
| 51 virtual void ApplySanityChecks(nacl_arm_dec::Instruction inst, | 56 virtual void ApplySanityChecks( |
| 52 const nacl_arm_dec::ClassDecoder& decoder); | 57 nacl_arm_dec::Instruction inst, |
| 58 const NamedClassDecoder& decoder); |
| 53 | 59 |
| 54 // Returns the expected decoder. | 60 // Returns the expected decoder. |
| 55 virtual const nacl_arm_dec::ClassDecoder& ExpectedDecoder() const = 0; | 61 virtual const NamedClassDecoder& ExpectedDecoder() const = 0; |
| 56 | 62 |
| 57 // Returns a printable version of the contents of the tested instruction. | 63 // Returns a printable version of the contents of the tested instruction. |
| 58 // Used to print out useful test failures. | 64 // Used to print out useful test failures. |
| 59 // Note: This function may not be thread safe, and the result may | 65 // Note: This function may not be thread safe, and the result may |
| 60 // only be valid till the next call to this method. | 66 // only be valid till the next call to this method. |
| 61 virtual const char* InstContents() const = 0; | 67 virtual const char* InstContents() const = 0; |
| 62 | 68 |
| 63 // Returns the character at the given index in the pattern that | 69 // Returns the character at the given index in the pattern that |
| 64 // should be tested. | 70 // should be tested. |
| 65 virtual char Pattern(int index) const = 0; | 71 virtual char Pattern(int index) const = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 107 |
| 102 // Defines a decoder tester that enumerates an Arm32 instruction pattern, | 108 // Defines a decoder tester that enumerates an Arm32 instruction pattern, |
| 103 // and tests that all of the decoded patterns match the expected class | 109 // and tests that all of the decoded patterns match the expected class |
| 104 // decoder, and that any additional sanity checks, specific to the | 110 // decoder, and that any additional sanity checks, specific to the |
| 105 // instruction apply. | 111 // instruction apply. |
| 106 // | 112 // |
| 107 // Note: Patterns must be of length 32. | 113 // Note: Patterns must be of length 32. |
| 108 class Arm32DecoderTester : public DecoderTester { | 114 class Arm32DecoderTester : public DecoderTester { |
| 109 public: | 115 public: |
| 110 explicit Arm32DecoderTester( | 116 explicit Arm32DecoderTester( |
| 111 const nacl_arm_dec::ClassDecoder& expected_decoder); | 117 const NamedClassDecoder& expected_decoder); |
| 112 virtual ~Arm32DecoderTester(); | 118 virtual ~Arm32DecoderTester(); |
| 113 void Test(const char* pattern); | 119 void Test(const char* pattern); |
| 114 | 120 |
| 115 protected: | 121 protected: |
| 116 virtual const nacl_arm_dec::ClassDecoder& ExpectedDecoder() const; | 122 virtual const NamedClassDecoder& ExpectedDecoder() const; |
| 117 virtual const char* InstContents() const; | 123 virtual const char* InstContents() const; |
| 118 virtual char Pattern(int index) const; | 124 virtual char Pattern(int index) const; |
| 119 virtual void ProcessMatch(); | 125 virtual void ProcessMatch(); |
| 120 virtual void SetBit(int index, bool value); | 126 virtual void SetBit(int index, bool value); |
| 121 virtual void SetBitRange(int index, int length, uint32_t value); | 127 virtual void SetBitRange(int index, int length, uint32_t value); |
| 122 | 128 |
| 123 // The expected decoder class. | 129 // The expected decoder class. |
| 124 const nacl_arm_dec::ClassDecoder& expected_decoder_; | 130 const NamedClassDecoder& expected_decoder_; |
| 125 | 131 |
| 126 // The pattern being enumerated. | 132 // The pattern being enumerated. |
| 127 const char* pattern_; | 133 const char* pattern_; |
| 128 | 134 |
| 129 // The decoder to use. | 135 // The decoder to use. |
| 130 nacl_arm_dec::NamedArm32DecoderState state_; | 136 NamedArm32DecoderState state_; |
| 131 | 137 |
| 132 // The instruction currently being enumerated. | 138 // The instruction currently being enumerated. |
| 133 nacl_arm_dec::Instruction inst_; | 139 nacl_arm_dec::Instruction inst_; |
| 134 }; | 140 }; |
| 135 | 141 |
| 136 class ThumbDecoderTester; | 142 class ThumbDecoderTester; |
| 137 | 143 |
| 138 // Defines a decoder tester that enumerates the first word of | 144 // Defines a decoder tester that enumerates the first word of |
| 139 // a thumb instruction pattern, and tests that all of the decoded patterns | 145 // a thumb instruction pattern, and tests that all of the decoded patterns |
| 140 // match the expected class decoder, and that any additional sanity checks, | 146 // match the expected class decoder, and that any additional sanity checks, |
| 141 // specific to the instruction apply. | 147 // specific to the instruction apply. |
| 142 // | 148 // |
| 143 // Note: This class is used by a ThumbDecoderTester to enumerate the | 149 // Note: This class is used by a ThumbDecoderTester to enumerate the |
| 144 // first word of the thumb instruction pattern. | 150 // first word of the thumb instruction pattern. |
| 145 class ThumbWord1DecoderTester : public DecoderTester { | 151 class ThumbWord1DecoderTester : public DecoderTester { |
| 146 public: | 152 public: |
| 147 explicit ThumbWord1DecoderTester(ThumbDecoderTester* thumb_tester); | 153 explicit ThumbWord1DecoderTester(ThumbDecoderTester* thumb_tester); |
| 148 virtual ~ThumbWord1DecoderTester(); | 154 virtual ~ThumbWord1DecoderTester(); |
| 149 | 155 |
| 150 // Defines the pattern to use for word 1. | 156 // Defines the pattern to use for word 1. |
| 151 void SetPattern(const char* pattern); | 157 void SetPattern(const char* pattern); |
| 152 | 158 |
| 153 // Test all possible patterns for word 1. | 159 // Test all possible patterns for word 1. |
| 154 void Test(); | 160 void Test(); |
| 155 | 161 |
| 156 protected: | 162 protected: |
| 157 virtual const nacl_arm_dec::ClassDecoder& ExpectedDecoder() const; | 163 virtual const NamedClassDecoder& ExpectedDecoder() const; |
| 158 virtual const char* InstContents() const; | 164 virtual const char* InstContents() const; |
| 159 virtual char Pattern(int index) const; | 165 virtual char Pattern(int index) const; |
| 160 virtual void ProcessMatch(); | 166 virtual void ProcessMatch(); |
| 161 virtual void SetBit(int index, bool value); | 167 virtual void SetBit(int index, bool value); |
| 162 virtual void SetBitRange(int index, int length, uint32_t value); | 168 virtual void SetBitRange(int index, int length, uint32_t value); |
| 163 | 169 |
| 164 // The thumb tester that uses this decoder. | 170 // The thumb tester that uses this decoder. |
| 165 ThumbDecoderTester* thumb_tester_; | 171 ThumbDecoderTester* thumb_tester_; |
| 166 | 172 |
| 167 // The pattern for the first word of the thumb instruction. | 173 // The pattern for the first word of the thumb instruction. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 183 explicit ThumbWord2DecoderTester(ThumbDecoderTester* thumb_tester); | 189 explicit ThumbWord2DecoderTester(ThumbDecoderTester* thumb_tester); |
| 184 virtual ~ThumbWord2DecoderTester(); | 190 virtual ~ThumbWord2DecoderTester(); |
| 185 | 191 |
| 186 // Defines the pattern to use for word 2. | 192 // Defines the pattern to use for word 2. |
| 187 void SetPattern(const char* pattern); | 193 void SetPattern(const char* pattern); |
| 188 | 194 |
| 189 // Tests all patterns for word 2. | 195 // Tests all patterns for word 2. |
| 190 void Test(); | 196 void Test(); |
| 191 | 197 |
| 192 protected: | 198 protected: |
| 193 virtual const nacl_arm_dec::ClassDecoder& ExpectedDecoder() const; | 199 virtual const NamedClassDecoder& ExpectedDecoder() const; |
| 194 virtual const char* InstContents() const; | 200 virtual const char* InstContents() const; |
| 195 virtual char Pattern(int index) const; | 201 virtual char Pattern(int index) const; |
| 196 virtual void ProcessMatch(); | 202 virtual void ProcessMatch(); |
| 197 virtual void SetBit(int index, bool value); | 203 virtual void SetBit(int index, bool value); |
| 198 virtual void SetBitRange(int index, int length, uint32_t value); | 204 virtual void SetBitRange(int index, int length, uint32_t value); |
| 199 | 205 |
| 200 // The thumb tester that uses this decoder. | 206 // The thumb tester that uses this decoder. |
| 201 ThumbDecoderTester* thumb_tester_; | 207 ThumbDecoderTester* thumb_tester_; |
| 202 | 208 |
| 203 // The pattern for the second word of the thumb instruction. | 209 // The pattern for the second word of the thumb instruction. |
| 204 const char* pattern_; | 210 const char* pattern_; |
| 205 | 211 |
| 206 friend class ThumbDecoderTester; | 212 friend class ThumbDecoderTester; |
| 207 }; | 213 }; |
| 208 | 214 |
| 209 // Defines a decoder tester that enumerates a thumb instruction pattern, | 215 // Defines a decoder tester that enumerates a thumb instruction pattern, |
| 210 // and tests that all of the decoded patterns match the expected class | 216 // and tests that all of the decoded patterns match the expected class |
| 211 // decoder, and that any additional sanity checks, specific to the | 217 // decoder, and that any additional sanity checks, specific to the |
| 212 // instruction apply. | 218 // instruction apply. |
| 213 // | 219 // |
| 214 // Note: One word thumb instructions must be of length 16. | 220 // Note: One word thumb instructions must be of length 16. |
| 215 // Two word thumb instructions must be of length 32 (with a '|' | 221 // Two word thumb instructions must be of length 32 (with a '|' |
| 216 // separating each 16 character word pattern). | 222 // separating each 16 character word pattern). |
| 217 class ThumbDecoderTester : public DecoderTester { | 223 class ThumbDecoderTester : public DecoderTester { |
| 218 // TODO(karl): Make this use the thumb decoder rather than Arm32. | 224 // TODO(karl): Make this use the thumb decoder rather than Arm32. |
| 219 friend class ThumbWord1DecoderTester; | 225 friend class ThumbWord1DecoderTester; |
| 220 friend class ThumbWord2DecoderTester; | 226 friend class ThumbWord2DecoderTester; |
| 221 public: | 227 public: |
| 222 explicit ThumbDecoderTester( | 228 explicit ThumbDecoderTester( |
| 223 const nacl_arm_dec::ClassDecoder& expected_decoder); | 229 const NamedClassDecoder& expected_decoder); |
| 224 virtual ~ThumbDecoderTester(); | 230 virtual ~ThumbDecoderTester(); |
| 225 void Test(const char* pattern); | 231 void Test(const char* pattern); |
| 226 | 232 |
| 227 protected: | 233 protected: |
| 228 virtual const nacl_arm_dec::ClassDecoder& ExpectedDecoder() const; | 234 virtual const NamedClassDecoder& ExpectedDecoder() const; |
| 229 virtual const char* InstContents() const; | 235 virtual const char* InstContents() const; |
| 230 virtual char Pattern(int index) const; | 236 virtual char Pattern(int index) const; |
| 231 virtual void ProcessMatch(); | 237 virtual void ProcessMatch(); |
| 232 virtual void SetBit(int index, bool value); | 238 virtual void SetBit(int index, bool value); |
| 233 virtual void SetBitRange(int index, int length, uint32_t value); | 239 virtual void SetBitRange(int index, int length, uint32_t value); |
| 234 | 240 |
| 235 // The expected decoder class name. | 241 // The expected decoder class name. |
| 236 const nacl_arm_dec::ClassDecoder& expected_decoder_; | 242 const NamedClassDecoder& expected_decoder_; |
| 237 | 243 |
| 238 // The pattern being enumerated. | 244 // The pattern being enumerated. |
| 239 const char* pattern_; | 245 const char* pattern_; |
| 240 | 246 |
| 241 // TODO(karl): replace with thumb decoder state once defined. | 247 // TODO(karl): replace with thumb decoder state once defined. |
| 242 // The decoder to use. | 248 // The decoder to use. |
| 243 nacl_arm_dec::NamedArm32DecoderState state_; | 249 NamedArm32DecoderState state_; |
| 244 | 250 |
| 245 // The instruction currently being enumerated. | 251 // The instruction currently being enumerated. |
| 246 nacl_arm_dec::Instruction inst_; | 252 nacl_arm_dec::Instruction inst_; |
| 247 | 253 |
| 248 // Decoder tester for the first word of the thumb instruction. | 254 // Decoder tester for the first word of the thumb instruction. |
| 249 ThumbWord1DecoderTester word1_tester_; | 255 ThumbWord1DecoderTester word1_tester_; |
| 250 | 256 |
| 251 // Decoeder tester for the second word of the thumb instruction. | 257 // Decoeder tester for the second word of the thumb instruction. |
| 252 ThumbWord2DecoderTester word2_tester_; | 258 ThumbWord2DecoderTester word2_tester_; |
| 253 }; | 259 }; |
| 254 | 260 |
| 255 } // namespace | 261 } // namespace |
| 256 | 262 |
| 257 #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ | 263 #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ |
| OLD | NEW |