summaryrefslogtreecommitdiffstats
path: root/src/lib/bench/benchmark_util.cc
diff options
context:
space:
mode:
authorJINMEI Tatuya <jinmei@isc.org>2010-07-12 09:18:40 +0200
committerJINMEI Tatuya <jinmei@isc.org>2010-07-12 09:18:40 +0200
commitf358c98613535dcdd83ed0abd2407519f8c66aea (patch)
treea24e43bc1d6592d8e62b51e9c933659cf5f4eaf0 /src/lib/bench/benchmark_util.cc
parentcopy from the experimental branch (diff)
downloadkea-f358c98613535dcdd83ed0abd2407519f8c66aea.tar.xz
kea-f358c98613535dcdd83ed0abd2407519f8c66aea.zip
added tests and an example.
git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac241@2490 e5f2f494-b856-4b98-b285-d166d9295462
Diffstat (limited to 'src/lib/bench/benchmark_util.cc')
-rw-r--r--src/lib/bench/benchmark_util.cc37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/bench/benchmark_util.cc b/src/lib/bench/benchmark_util.cc
index bd6318c509..3705821d74 100644
--- a/src/lib/bench/benchmark_util.cc
+++ b/src/lib/bench/benchmark_util.cc
@@ -40,25 +40,32 @@ namespace isc {
namespace bench {
void
loadQueryData(const char* const input_file, BenchQueries& queries,
- const RRClass& qclass)
+ const RRClass& qclass, const bool strict)
{
ifstream ifs;
ifs.open(input_file, ios_base::in);
if ((ifs.rdstate() & istream::failbit) != 0) {
- isc_throw(Exception, "failed to query data file: " +
+ isc_throw(BenchMarkError, "failed to load query data file: " +
string(input_file));
}
+ loadQueryData(ifs, queries, qclass, strict);
+ ifs.close();
+}
+void
+loadQueryData(istream& input, BenchQueries& queries, const RRClass& qclass,
+ const bool strict)
+{
string line;
unsigned int linenum = 0;
Message query_message(Message::RENDER);
OutputBuffer buffer(128); // this should be sufficiently large
MessageRenderer renderer(buffer);
- while (getline(ifs, line), !ifs.eof()) {
+ while (getline(input, line), !input.eof()) {
++linenum;
- if (ifs.bad() || ifs.fail()) {
- isc_throw(Exception,
+ if (input.bad() || input.fail()) {
+ isc_throw(BenchMarkError,
"Unexpected line in query data file around line " <<
linenum);
}
@@ -70,22 +77,23 @@ loadQueryData(const char* const input_file, BenchQueries& queries,
string qname_string, qtype_string;
iss >> qname_string >> qtype_string;
if (iss.bad() || iss.fail()) {
- cerr << "unexpected input around line " << linenum << " (ignored)"
- << endl;
+ if (strict) {
+ isc_throw(BenchMarkError,
+ "load query: unexpected input around line " <<
+ linenum);
+ }
continue;
}
// We expect broken lines of data, which will be ignored with a
// warning message.
try {
- Name qname(qname_string);
- RRType qtype(qtype_string);
-
query_message.clear(Message::RENDER);
query_message.setQid(0);
query_message.setOpcode(Opcode::QUERY());
query_message.setRcode(Rcode::NOERROR());
- query_message.addQuestion(Question(qname, qclass, qtype));
+ query_message.addQuestion(Question(Name(qname_string), qclass,
+ RRType(qtype_string)));
renderer.clear();
query_message.toWire(renderer);
@@ -95,8 +103,11 @@ loadQueryData(const char* const input_file, BenchQueries& queries,
buffer.getLength());
queries.push_back(query_data);
} catch (const Exception& error) {
- cerr << "failed to parse/create query around line " << linenum <<
- ": " << error.what() << " (ignored)" << endl;
+ if (strict) {
+ isc_throw(BenchMarkError,
+ "failed to parse/create query around line " <<
+ linenum);
+ }
continue;
}
}