GenericExperiment: limit output logger buffer

Limit the serial-output logger buffer to prevent overly large memory
consumption in case the target system ends up, e.g., in an endless loop.
The buffer is limited to (golden-run output size)+1 to be able to detect
the case when the target system makes a correct output but faultily adds
extra characters afterwards.

Change-Id: I50c082f8fb09a702d87ab83732ca3e3463c46597
This commit is contained in:
Horst Schirmeier
2016-02-26 09:43:14 +01:00
parent e08deef9d5
commit 5bd7c4a9c5
3 changed files with 14 additions and 1 deletions

View File

@ -176,6 +176,14 @@ bool GenericExperiment::cb_start_experiment() {
m_log << "enabled logging on port E9 for SDC-detection" << std::endl;
enabled_e9_sol = true;
e9_file = std::string(cmd[E9_FILE].first()->arg);
e9_goldenrun = loadFile(e9_file);
// Limit the serial-output logger buffer to prevent overly large memory
// consumption in case the target system ends up, e.g., in an endless
// loop. "+ 1" to be able to detect the case when the target system
// makes a correct output but faultily adds extra characters
// afterwards.
e9_sol.setLimit(e9_goldenrun.size() + 1);
}
if (cmd[WRITE_MEM_TEXT]) {
@ -290,7 +298,6 @@ void GenericExperiment::cb_after_resume(fail::BaseListener *event) {
// check experiment's data for SDC
if (enabled_e9_sol) {
// compare golden run to experiment
std::vector<char> e9_goldenrun = loadFile(e9_file);
std::string e9_experiment = e9_sol.getOutput();
if ( ! (e9_experiment.size() == e9_goldenrun.size()
&& equal(e9_experiment.begin(), e9_experiment.end(), e9_goldenrun.begin())) ) {

View File

@ -23,6 +23,7 @@ class GenericExperiment : public fail::DatabaseExperiment {
bool enabled_e9_sol;
std::string e9_file;
SerialOutputLogger e9_sol;
std::vector<char> e9_goldenrun;
bool enabled_mem_text;
fail::MemAccessListener l_mem_text;

View File

@ -40,6 +40,11 @@ public:
* Returns the output variable.
*/
std::string getOutput();
/**
* Sets the character limit. Does not truncate the stored data if it
* already exceeds the new limit. 0 = unlimited.
*/
void setLimit(unsigned char_limit) { m_limit = char_limit; }
};
#endif // __SERIAL_OUTPUT_LOGGER_HPP__