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

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

Issue 10381030: Clean up testing of instructions. Allow testing to quit if test pattern tests (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 7 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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // to separate word 1 from word 2. 43 // to separate word 1 from word 2.
44 // Also, bits are specified from the largest bit downto the smallest 44 // Also, bits are specified from the largest bit downto the smallest
45 // bit. 45 // bit.
46 class DecoderTester { 46 class DecoderTester {
47 public: 47 public:
48 DecoderTester(); 48 DecoderTester();
49 virtual ~DecoderTester() {} 49 virtual ~DecoderTester() {}
50 50
51 // Once an instruction is decoded, this method is called to apply 51 // Once an instruction is decoded, this method is called to apply
52 // sanity checks on the matched decoder. The default checks that the 52 // sanity checks on the matched decoder. The default checks that the
53 // expected class name matches the name of the decoder, and that 53 // expected class name matches the name of the decoder, and that the
54 // the safety level MAY_BE_SAFE. 54 // safety level is MAY_BE_SAFE. Returns whether further checking of
55 virtual void ApplySanityChecks( 55 // the instruction should be performed. In particular, false is returned
56 // if there is some unencoded assumption that isn't put into the
57 // test patterns, and hence, should not be checked.
58 virtual bool ApplySanityChecks(
56 nacl_arm_dec::Instruction inst, 59 nacl_arm_dec::Instruction inst,
57 const NamedClassDecoder& decoder); 60 const NamedClassDecoder& decoder);
58 61
59 // Returns the expected decoder. 62 // Returns the expected decoder.
60 virtual const NamedClassDecoder& ExpectedDecoder() const = 0; 63 virtual const NamedClassDecoder& ExpectedDecoder() const = 0;
61 64
62 // Defines what should be done once a test pattern has been generated. 65 // Defines what should be done once a test pattern has been generated.
63 virtual void ProcessMatch() = 0; 66 virtual void ProcessMatch() = 0;
64 67
65 // Allows the injection of an instruction. Used one to inject the instruction 68 // Allows the injection of an instruction. Used one to inject the instruction
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // followed by the length-stride bits being set to the given value. 109 // followed by the length-stride bits being set to the given value.
107 // Note: Current implementation limits stride to less than 32. 110 // Note: Current implementation limits stride to less than 32.
108 void TestAtIndexExpandFillAll(int index, 111 void TestAtIndexExpandFillAll(int index,
109 int stride, int length, bool Value); 112 int stride, int length, bool Value);
110 113
111 // Fills the next length bits with the corresponding value being repeated 114 // Fills the next length bits with the corresponding value being repeated
112 // length times. 115 // length times.
113 void FillBitRange(int index, int length, bool value); 116 void FillBitRange(int index, int length, bool value);
114 }; 117 };
115 118
119 // Helper macro for testing if preconditions are met within the
120 // ApplySanityChecks method of a DecoderTester. That is, if the
121 // precondition is not met, exit the routine and return false.
122 // Otherwise, the precondition of the remaining code has been met,
123 // and execution continues.
124 #define NC_PRECOND(test) \
125 { if (!(test)) return false; }
126
127 // Helper macro for testing if an (error) precondition a != b is met
128 // within the ApplySanityChecks method of a DecoderTester. That is,
129 // if a == b, generate a gtest error and then stop the application
130 // from doing further checks for the given instruction.
131 #define NC_EXPECT_NE_PRECOND(a, b) \
132 { EXPECT_NE(a, b) << InstContents(); NC_PRECOND((a) == (b)); }
133
116 // Defines a decoder tester that enumerates an Arm32 instruction pattern, 134 // Defines a decoder tester that enumerates an Arm32 instruction pattern,
117 // and tests that all of the decoded patterns match the expected class 135 // and tests that all of the decoded patterns match the expected class
118 // decoder, and that any additional sanity checks, specific to the 136 // decoder, and that any additional sanity checks, specific to the
119 // instruction apply. 137 // instruction apply.
120 // 138 //
121 // Note: Patterns must be of length 32. 139 // Note: Patterns must be of length 32.
122 class Arm32DecoderTester : public DecoderTester { 140 class Arm32DecoderTester : public DecoderTester {
123 public: 141 public:
124 explicit Arm32DecoderTester( 142 explicit Arm32DecoderTester(
125 const NamedClassDecoder& expected_decoder); 143 const NamedClassDecoder& expected_decoder);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 290
273 private: 291 private:
274 friend class ThumbWord1DecoderTester; 292 friend class ThumbWord1DecoderTester;
275 friend class ThumbWord2DecoderTester; 293 friend class ThumbWord2DecoderTester;
276 NACL_DISALLOW_COPY_AND_ASSIGN(ThumbDecoderTester); 294 NACL_DISALLOW_COPY_AND_ASSIGN(ThumbDecoderTester);
277 }; 295 };
278 296
279 } // namespace 297 } // namespace
280 298
281 #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_ 299 #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_DECODER_TESTER_H_
OLDNEW
« no previous file with comments | « src/trusted/validator_arm/baseline_classes.cc ('k') | src/trusted/validator_arm/decoder_tester.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698