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

Side by Side Diff: src/trusted/validator_arm/decoder_tester.h

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

Powered by Google App Engine
This is Rietveld 408576698