13
13
// Generates a bitcode memory buffer from an array containing 1 or
14
14
// more PNaCl records. Used to test errors in PNaCl bitcode.
15
15
//
16
- // Bitcode records are modeleled using arrays using the format
16
+ // Bitcode records are modeled using arrays using the format
17
17
// specified in NaClBitcodeMungeUtils.h.
18
18
//
19
19
// Note: Since the header record doesn't have any abbreviation indices
47
47
48
48
namespace llvm {
49
49
50
- class NaClBitstreamWriter ;
51
50
class NaClBitCodeAbbrev ;
52
51
53
52
// / Base class to run tests on munged bitcode files.
@@ -57,10 +56,21 @@ class NaClBitcodeMunger {
57
56
NaClBitcodeMunger (const uint64_t Records[], size_t RecordsSize,
58
57
uint64_t RecordTerminator)
59
58
: MungedBitcode(Records, RecordsSize, RecordTerminator),
60
- RecordTerminator (RecordTerminator), WriteBlockID(- 1 ), SetBID(- 1 ),
59
+ RecordTerminator (RecordTerminator),
61
60
DumpResults(" Error: No previous dump results!\n " ),
62
- DumpStream(nullptr ), Writer(nullptr ), FoundErrors(false ),
63
- FatalBuffer(), FatalStream(FatalBuffer) {}
61
+ DumpStream(nullptr ), FoundErrors(false ), RunAsDeathTest(false ) {}
62
+
63
+ // / Returns true if running as death test.
64
+ bool getRunAsDeathTest () const {
65
+ return RunAsDeathTest;
66
+ }
67
+
68
+ // / Sets death test flag. When true, output will be redirected to
69
+ // / the errs() (rather than buffered) so that the test can be
70
+ // / debugged.
71
+ void setRunAsDeathTest (bool NewValue) {
72
+ RunAsDeathTest = NewValue;
73
+ }
64
74
65
75
// / Creates MungedInput and DumpStream for running tests, based on
66
76
// / given Munges.
@@ -88,52 +98,43 @@ class NaClBitcodeMunger {
88
98
return getLinesWithTextMatch (Prefix, true );
89
99
}
90
100
101
+ // / When NewValue, use error recovery when writing bitcode during
102
+ // / next test.
103
+ void setTryToRecoverOnWrite (bool NewValue) {
104
+ WriteFlags.setTryToRecover (NewValue);
105
+ }
106
+
107
+ // / When NewValue, write bad abbreviation index into bitcode when
108
+ // / writing during next test.
109
+ void setWriteBadAbbrevIndex (bool NewValue) {
110
+ WriteFlags.setWriteBadAbbrevIndex (NewValue);
111
+ }
112
+
91
113
protected:
92
114
// The bitcode records being munged.
93
115
NaClMungedBitcode MungedBitcode;
94
116
// The value used as record terminator.
95
117
uint64_t RecordTerminator;
96
- // The block ID associated with the block being written.
97
- int WriteBlockID;
98
- // The SetBID for the blockinfo block.
99
- int SetBID;
100
118
// The results buffer of the last dump.
101
119
std::string DumpResults;
102
120
// The memory buffer containing the munged input.
103
121
std::unique_ptr<MemoryBuffer> MungedInput;
104
122
// The stream containing errors and the objdump of the generated bitcode file.
105
123
raw_ostream *DumpStream;
106
- // The bitstream writer to use to generate the bitcode file.
107
- NaClBitstreamWriter *Writer;
108
124
// True if any errors were reported.
109
125
bool FoundErrors;
110
- // The buffer to hold the generated fatal message.
111
- std::string FatalBuffer;
112
- // The stream to write the fatal message to.
113
- raw_string_ostream FatalStream;
114
- // The stack of maximum abbreviation indices allowed by block enter record.
115
- SmallVector<uint64_t , 3 > AbbrevIndexLimitStack;
116
126
// The buffer for the contents of the munged input.
117
127
SmallVector<char , 1024 > MungedInputBuffer;
128
+ // / The write flags to use when writing bitcode.
129
+ NaClMungedBitcode::WriteFlags WriteFlags;
130
+ // Flag to redirect dump stream if running death test.
131
+ bool RunAsDeathTest;
118
132
119
133
// Records that an error occurred, and returns stream to print error
120
134
// message to.
121
135
raw_ostream &Error () {
122
136
FoundErrors = true ;
123
- return *DumpStream << " Error: " ;
124
- }
125
-
126
- // Returns stream to print fatal error message to.
127
- // Note: Once the fatal error message has been dumped to the stream,
128
- // one must call ReportFatalError to display the error and terminate
129
- // execution.
130
- raw_ostream &Fatal () {
131
- return FatalStream << " Fatal: " ;
132
- }
133
-
134
- // Displays the fatal error message and exits the program.
135
- void ReportFatalError () {
136
- report_fatal_error (FatalStream.str ());
137
+ return getDumpStream () << " Error: " ;
137
138
}
138
139
139
140
// Returns the lines containing the given Substring, from the string
@@ -142,14 +143,12 @@ class NaClBitcodeMunger {
142
143
std::string getLinesWithTextMatch (const std::string &Substring,
143
144
bool MustBePrefix = false ) const ;
144
145
145
- // Writes out munged bitcode records.
146
- void writeMungedBitcode (const NaClMungedBitcode &Bitcode, bool AddHeader);
147
-
148
- // Emits the given record to the bitcode file.
149
- void emitRecord (const NaClBitcodeAbbrevRecord &Record);
150
-
151
- // Converts the abbreviation record to the corresponding abbreviation.
152
- NaClBitCodeAbbrev *buildAbbrev (const NaClBitcodeAbbrevRecord &Record);
146
+ // Returns the log stream to use. When running death tests, redirect output
147
+ // to the error stream (rather than buffering in DumpStream), so that
148
+ // the output can be seen in gtest death tests.
149
+ raw_ostream &getDumpStream () const {
150
+ return RunAsDeathTest ? errs () : *DumpStream;
151
+ }
153
152
};
154
153
155
154
// / Class to run tests for function llvm::NaClObjDump.
@@ -159,8 +158,7 @@ class NaClObjDumpMunger : public NaClBitcodeMunger {
159
158
// / Creates a bitcode munger, based on the given array of values.
160
159
NaClObjDumpMunger (const uint64_t Records[], size_t RecordsSize,
161
160
uint64_t RecordTerminator)
162
- : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator),
163
- RunAsDeathTest (false ) {}
161
+ : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
164
162
165
163
// / Runs function NaClObjDump on the sequence of records associated
166
164
// / with the instance. The memory buffer containing the bitsequence
@@ -178,18 +176,6 @@ class NaClObjDumpMunger : public NaClBitcodeMunger {
178
176
NoAssembly);
179
177
}
180
178
181
- // / Returns true if running as death test.
182
- bool getRunAsDeathTest () const {
183
- return RunAsDeathTest;
184
- }
185
-
186
- // / Sets death test flag. When true, output will be redirected to
187
- // / the errs() (rather than buffered) so that the test can be
188
- // / debugged.
189
- void setRunAsDeathTest (bool NewValue) {
190
- RunAsDeathTest = NewValue;
191
- }
192
-
193
179
// / Same as above except it runs function NaClObjDump with flags
194
180
// / NoRecords and NoAssembly set to false, and AddHeader set to true.
195
181
bool runTest (const char *TestName) {
@@ -235,11 +221,6 @@ class NaClObjDumpMunger : public NaClBitcodeMunger {
235
221
size_t MungesSize) {
236
222
return runTestWithFlags (TestName, Munges, MungesSize, true , true , true );
237
223
}
238
-
239
- private:
240
- // Flag to redirect dump stream if running death test.
241
- bool RunAsDeathTest;
242
-
243
224
};
244
225
245
226
// Class to run tests for function NaClParseBitcodeFile.
0 commit comments