예제 #1
0
bool RegressTest::config() {
	//Set hard options, populate correctness and performance file vectors by reading a config file

	_configFile.open(_configFilename.c_str());
	if (!_configFile.good()) {
		cerr << "Error: unable to open config file " << _configFilename << endl;
	}
	vector<string> fields;
	bool parseStatus = false;
	int numLinesToRead = 0;
	int linesRead = 0;
	string sLine;
	while (!_configFile.eof()) {
		sLine.clear();
		getline(_configFile, sLine);
		fields.clear();

		Tokenize(sLine, fields);
		if (fields.size() != 2) {
			continue;
		}

		const string &field1 = fields[0];
		const string &field2 = fields[1];

		if (field1 == _hardOptsCmd) {
			_hardOptions = field2.c_str();
			continue;
		} else if (field1 == _correctCmd || field1 == _performCmd) {
			numLinesToRead = atoi(field2.c_str());
			if (field1 == _correctCmd) {
				parseStatus = parseConfigLines(numLinesToRead, true);
			} else {
				parseStatus = parseConfigLines(numLinesToRead, false);
			}
			if (!parseStatus) {
				fprintf(stderr, "Error: failed to read and parse requested %d lines for %s\n",
						numLinesToRead, field1 == _correctCmd ? "Correctness tests" : "Performance tests");
				_configFile.close();
				return false;
			} else {
				linesRead += numLinesToRead;
			}
		} else {
			fprintf(stderr, "Error: Malformed config file %s\n.\tCheck that num files specified matches num provided.\n", _configFilename.c_str());
			_configFile.close();
			return false;
		}
	}
	if (linesRead == 0) {
		fprintf(stderr, "Error: No file lines read in config file %s\n", _configFilename.c_str());
		_configFile.close();
		return false;
	}

	_configFile.close();
	return true;
}
예제 #2
0
bool Settings::readConfigFile(const char *filename)
{
	std::ifstream is(filename);
	if (!is.good())
		return false;

	return parseConfigLines(is, "");
}