2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-28 20:47:48 +00:00

[trac4480] Update per review comments

Create a LogContentTest class and move the functions to manipulate
a test to check on the log output there.  This will make it available
for other tests in the future.  As part of this bundle a bit more
work into the class to minimze the calls in the test routines.

Where reasonable remove extra copys of the values being pushed
onto the stack - instead of generating a copy just for the logging
simply use the value from the top of the stack directly.

Swtich to using single quotes around text values.

Added some more description in the classify document
This commit is contained in:
Shawn Routhier 2016-05-26 21:36:36 -07:00
parent b8b931c501
commit cf62ec17c8
10 changed files with 559 additions and 482 deletions

View File

@ -1,5 +1,7 @@
11XX. [func] sar 11XX. [func] sar
Add debug logging to the classification tokens. Add debug logging to the classification tokens. This uses
the loggers "kea-dhcp4.eval" and "kea-dhcp6.eval" to capture
details of the classification expression evaluations.
(Trac #4480, git TBD) (Trac #4480, git TBD)
1114. [bug] stephen 1114. [bug] stephen

View File

@ -639,6 +639,36 @@
The specific loggers are "kea-dhcp4.eval" and "kea-dhcp6.eval". The specific loggers are "kea-dhcp4.eval" and "kea-dhcp6.eval".
</para> </para>
<para>
In order to understand the logging statements one must understand a
bit about how expressions are evaluated, for a more complete description
refer to the design document at <ulink url="http://kea.isc.org/wiki/KeaDesigns"/>.
In brief there are two structures used during the evaluation of an expression
a list of tokens which represent the expressions and a value stack which
represents the values being manipulated.
</para>
<para>
The list of tokens is created when the configuration file is processed with
most expressions and values being converted to a token. The list is organized
in reverse polish notation. During execution the list will be traversed
in order. As each token is executed it will be able to pop values
from the top of the stack and eventually push its result on the top of the
stack. Imagine the following expression:
<screen>
"test": "substring(option[61].hex,0,3) == 'foo'",
</screen>
This will result in the following tokens:
<screen>
option, number (0), number (3), substring, text ('foo'), equals
</screen>
In this example the first three tokens will simply push values onto the
stack. The substring token will then remove those three values and
compute a result that it places on the stack. The text option also
places a value on the stack and finally the equals token removes the
two tokens on the stack and places its result on the stack.
</para>
<para> <para>
When debug logging is enabled each time a token is evaluated it will When debug logging is enabled each time a token is evaluated it will
emit a log line indicating the values of any objects that were popped emit a log line indicating the values of any objects that were popped
@ -678,8 +708,12 @@
The debug logging may be quite verbose if you have a number of expressions The debug logging may be quite verbose if you have a number of expressions
to evaluate. It is intended as an aide in helping you create and debug to evaluate. It is intended as an aide in helping you create and debug
your expressions. You should plan to disable debug logging when you have your your expressions. You should plan to disable debug logging when you have your
expressions working correctly. You also may wish to debug only one set of expressions working correctly. You also may wish to include only one set of
expressions at a time to limit the log statements. expressions at a time in the configuration file while debugging them in order
to limit the log statements. For example when adding a new set of expressions
you might find it more convenient to create a configuration file that only
includes the new expressions until you have them working correctly and then
add the new set to the main configuration file.
</para></note> </para></note>
</section> </section>

View File

@ -21,12 +21,9 @@ namespace dhcp {
// The first level traces normal operations, // The first level traces normal operations,
const int EVAL_DBG_TRACE = DBGLVL_TRACE_BASIC; const int EVAL_DBG_TRACE = DBGLVL_TRACE_BASIC;
// The next level traces each call to eval code.
const int EVAL_DBG_CALLS = DBGLVL_TRACE_BASIC_DATA;
// Additional information on the calls. Report the values that were // Additional information on the calls. Report the values that were
// popped from or pushed to the value stack. // popped from or pushed to the value stack.
const int EVAL_DBG_EXTENDED_CALLS = DBGLVL_TRACE_DETAIL_DATA; const int EVAL_DBG_STACK = DBGLVL_TRACE_DETAIL_DATA;
/// @brief Eval Logger /// @brief Eval Logger
/// ///

View File

@ -43,6 +43,7 @@ libeval_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
libeval_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la libeval_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la
libeval_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la libeval_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
libeval_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la libeval_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
libeval_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
libeval_unittests_LDADD += $(CRYPTO_LIBS) $(LOG4CPLUS_LIBS) libeval_unittests_LDADD += $(CRYPTO_LIBS) $(LOG4CPLUS_LIBS)
libeval_unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD) libeval_unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD)

View File

@ -15,6 +15,7 @@
#include <log/logger_manager.h> #include <log/logger_manager.h>
#include <log/logger_name.h> #include <log/logger_name.h>
#include <log/logger_support.h> #include <log/logger_support.h>
#include <testutils/log_utils.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
@ -26,6 +27,7 @@ using namespace std;
using namespace isc::dhcp; using namespace isc::dhcp;
using namespace isc::asiolink; using namespace isc::asiolink;
using namespace isc::log; using namespace isc::log;
using namespace isc::dhcp::test;
namespace { namespace {
@ -34,7 +36,7 @@ namespace {
/// This class provides several convenience objects to be used during testing /// This class provides several convenience objects to be used during testing
/// of the Token family of classes. /// of the Token family of classes.
class TokenTest : public ::testing::Test { class TokenTest : public LogContentTest {
public: public:
/// @brief Initializes Pkt4,Pkt6 and options that can be useful for /// @brief Initializes Pkt4,Pkt6 and options that can be useful for
@ -49,54 +51,6 @@ public:
pkt4_->addOption(option_str4_); pkt4_->addOption(option_str4_);
pkt6_->addOption(option_str6_); pkt6_->addOption(option_str6_);
// Set up the logger for use in checking the debug statements.
// We send the debug statements to a file which we can
// check after the evaluations have completed. We also
// set the log severity and debug levels so that the log
// statements are executed.
LoggerSpecification spec(getRootLoggerName(),
keaLoggerSeverity(isc::log::DEBUG),
keaLoggerDbglevel(isc::log::MAX_DEBUG_LEVEL));
OutputOption option;
option.destination = OutputOption::DEST_FILE;
option.filename = string(TokenTest::LOG_FILE);
spec.addOutputOption(option);
LoggerManager manager;
manager.process(spec);
}
/// @brief check that the requested strings are in the
/// test log file in the requested order.
///
/// @param exp_strings vector of strings to match
/// @return true if all of the strings match
bool checkFile(const vector<string>& exp_strings) {
ifstream file(LOG_FILE);
EXPECT_TRUE(file.is_open());
string line, exp_line;
int i = 0;
bool found = true;
while (getline(file, line) && (i != exp_strings.size())) {
exp_line = exp_strings[i];
i++;
if (string::npos == line.find(exp_line)) {
found = false;
}
}
file.close();
if ((i != exp_strings.size()) || (found == false))
return (false);
return (true);
}
/// @brief remove the test log file
void remFile() {
static_cast<void>(remove(LOG_FILE));
} }
/// @brief Inserts RAI option with several suboptions /// @brief Inserts RAI option with several suboptions
@ -284,14 +238,8 @@ public:
/// @todo: Add more option types here /// @todo: Add more option types here
/// Name of the log file used during tests
static const char * LOG_FILE;
}; };
// Set up the name of the LOG_FILE for use in checking
// the debug statements
const char *TokenTest::LOG_FILE = "test.log";
// This tests the toBool() conversions // This tests the toBool() conversions
TEST_F(TokenTest, toBool) { TEST_F(TokenTest, toBool) {
@ -324,13 +272,11 @@ TEST_F(TokenTest, string4) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("foo", values_.top()); EXPECT_EQ("foo", values_.top());
// Check that the debug output was correct, we create a vector // Check that the debug output was correct. Add the strings
// of all the strings we expect (in this case only 1) and send // to the test vector in the class and then call checkFile
// it to checkFile for comparison. // for comparison
vector<string> exp_strings; addString("EVAL_DEBUG_STRING Pushing text string 'foo'");
exp_strings.push_back("EVAL_DEBUG_STRING Pushing text string \"foo\""); EXPECT_TRUE(checkFile());
EXPECT_TRUE(checkFile(exp_strings));
remFile();
} }
// This simple test checks that a TokenString, representing a constant string, // This simple test checks that a TokenString, representing a constant string,
@ -347,13 +293,11 @@ TEST_F(TokenTest, string6) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("foo", values_.top()); EXPECT_EQ("foo", values_.top());
// Check that the debug output was correct, we create a vector // Check that the debug output was correct. Add the strings
// of all the strings we expect (in this case only 1) and send // to the test vector in the class and then call checkFile
// it to checkFile for comparison. // for comparison
vector<string> exp_strings; addString("EVAL_DEBUG_STRING Pushing text string 'foo'");
exp_strings.push_back("EVAL_DEBUG_STRING Pushing text string \"foo\""); EXPECT_TRUE(checkFile());
EXPECT_TRUE(checkFile(exp_strings));
remFile();
} }
// This simple test checks that a TokenHexString, representing a constant // This simple test checks that a TokenHexString, representing a constant
@ -411,18 +355,17 @@ TEST_F(TokenTest, hexstring4) {
values_.pop(); values_.pop();
EXPECT_EQ("", values_.top()); EXPECT_EQ("", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x07"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x07");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x666F6F"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x666F6F");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x63825363"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x63825363");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This simple test checks that a TokenHexString, representing a constant // This simple test checks that a TokenHexString, representing a constant
@ -479,18 +422,17 @@ TEST_F(TokenTest, hexstring6) {
values_.pop(); values_.pop();
EXPECT_EQ("", values_.top()); EXPECT_EQ("", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x07"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x07");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x666F6F"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x666F6F");
exp_strings.push_back("EVAL_DEBUG_HEXSTRING Pushing hex string 0x63825363"); addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x63825363");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks that a TokenIpAddress, representing an IP address as // This test checks that a TokenIpAddress, representing an IP address as
@ -537,16 +479,15 @@ TEST_F(TokenTest, ipaddress) {
EXPECT_EQ(4, values_.top().size()); EXPECT_EQ(4, values_.top().size());
EXPECT_EQ(0, memcmp(expected4, &values_.top()[0], 4)); EXPECT_EQ(0, memcmp(expected4, &values_.top()[0], 4));
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x0A000001"); addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x0A000001");
exp_strings.push_back("EVAL_DEBUG_IPADDRESS Pushing IPAddress " addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress "
"0x20010DB8000000000000000000000001"); "0x20010DB8000000000000000000000001");
exp_strings.push_back("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x"); addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x");
exp_strings.push_back("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x"); addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an option value is able to extract // This test checks if a token representing an option value is able to extract
@ -576,13 +517,12 @@ TEST_F(TokenTest, optionString4) {
// Then the content of the option 100. // Then the content of the option 100.
EXPECT_EQ("hundred4", values_.top()); EXPECT_EQ("hundred4", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"hundred4\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'hundred4'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 101 with value ''");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing option value is able to extract // This test checks if a token representing option value is able to extract
@ -613,14 +553,12 @@ TEST_F(TokenTest, optionHexString4) {
// Then the content of the option 100. // Then the content of the option 100.
EXPECT_EQ("hundred4", values_.top()); EXPECT_EQ("hundred4", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value " addString("EVAL_DEBUG_OPTION Pushing option 100 with value 0x68756E6472656434");
"0x68756E6472656434"); addString("EVAL_DEBUG_OPTION Pushing option 101 with value 0x");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value 0x"); EXPECT_TRUE(checkFile());
EXPECT_TRUE(checkFile(exp_strings));
remFile();
} }
// This test checks if a token representing an option value is able to check // This test checks if a token representing an option value is able to check
@ -644,13 +582,12 @@ TEST_F(TokenTest, optionExistsString4) {
values_.pop(); values_.pop();
EXPECT_EQ("true", values_.top()); EXPECT_EQ("true", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"true\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'true'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value \"false\""); addString("EVAL_DEBUG_OPTION Pushing option 101 with value 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an option value is able to extract // This test checks if a token representing an option value is able to extract
@ -680,13 +617,12 @@ TEST_F(TokenTest, optionString6) {
// Then the content of the option 100. // Then the content of the option 100.
EXPECT_EQ("hundred6", values_.top()); EXPECT_EQ("hundred6", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"hundred6\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'hundred6'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 101 with value ''");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an option value is able to extract // This test checks if a token representing an option value is able to extract
@ -717,14 +653,12 @@ TEST_F(TokenTest, optionHexString6) {
// Then the content of the option 100. // Then the content of the option 100.
EXPECT_EQ("hundred6", values_.top()); EXPECT_EQ("hundred6", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value " addString("EVAL_DEBUG_OPTION Pushing option 100 with value 0x68756E6472656436");
"0x68756E6472656436"); addString("EVAL_DEBUG_OPTION Pushing option 101 with value 0x");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value 0x"); EXPECT_TRUE(checkFile());
EXPECT_TRUE(checkFile(exp_strings));
remFile();
} }
// This test checks if a token representing an option value is able to check // This test checks if a token representing an option value is able to check
@ -748,13 +682,12 @@ TEST_F(TokenTest, optionExistsString6) {
values_.pop(); values_.pop();
EXPECT_EQ("true", values_.top()); EXPECT_EQ("true", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"true\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'true'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value \"false\""); addString("EVAL_DEBUG_OPTION Pushing option 101 with value 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks that the existing relay4 option can be found. // This test checks that the existing relay4 option can be found.
@ -776,12 +709,11 @@ TEST_F(TokenTest, relay4Option) {
// content of that sub-option, i.e. "thirteen" // content of that sub-option, i.e. "thirteen"
EXPECT_EQ("thirteen", values_.top()); EXPECT_EQ("thirteen", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 13 with value \"thirteen\""); addString("EVAL_DEBUG_OPTION Pushing option 13 with value 'thirteen'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks that the code properly handles cases when // This test checks that the code properly handles cases when
@ -804,12 +736,11 @@ TEST_F(TokenTest, relay4OptionNoSuboption) {
// so the expression should evaluate to "" // so the expression should evaluate to ""
EXPECT_EQ("", values_.top()); EXPECT_EQ("", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 15 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 15 with value ''");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks that the code properly handles cases when // This test checks that the code properly handles cases when
@ -831,12 +762,11 @@ TEST_F(TokenTest, relay4OptionNoRai) {
// so the expression should evaluate to "" // so the expression should evaluate to ""
EXPECT_EQ("", values_.top()); EXPECT_EQ("", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 13 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 13 with value ''");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks that only the RAI is searched for the requested // This test checks that only the RAI is searched for the requested
@ -894,16 +824,15 @@ TEST_F(TokenTest, relay4RAIOnly) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("false", values_.top()); EXPECT_EQ("false", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 13 with value \"thirteen\""); addString("EVAL_DEBUG_OPTION Pushing option 13 with value 'thirteen'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 1 with value \"one\""); addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'one'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 70 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 70 with value ''");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 1 with value \"true\""); addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'true'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 70 with value \"false\""); addString("EVAL_DEBUG_OPTION Pushing option 70 with value 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Verifies if the DHCPv4 packet fields can be extracted. // Verifies if the DHCPv4 packet fields can be extracted.
@ -985,25 +914,17 @@ TEST_F(TokenTest, pkt4Fields) {
ASSERT_NO_THROW(t_.reset(new TokenPkt4(TokenPkt4::HLEN))); ASSERT_NO_THROW(t_.reset(new TokenPkt4(TokenPkt4::HLEN)));
EXPECT_THROW(t_->evaluate(*pkt6_, values_), EvalTypeError); EXPECT_THROW(t_->evaluate(*pkt6_, values_), EvalTypeError);
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field mac " addString("EVAL_DEBUG_PKT4 Pushing PKT4 field mac with value 0x01020304050607");
"with value 0x01020304050607"); addString("EVAL_DEBUG_PKT4 Pushing PKT4 field hlen with value 0x00000007");
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field hlen " addString("EVAL_DEBUG_PKT4 Pushing PKT4 field htype with value 0x0000007B");
"with value 0x00000007"); addString("EVAL_DEBUG_PKT4 Pushing PKT4 field giaddr with value 0xC0000201");
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field htype " addString("EVAL_DEBUG_PKT4 Pushing PKT4 field ciaddr with value 0xC0000202");
"with value 0x0000007B"); addString("EVAL_DEBUG_PKT4 Pushing PKT4 field yiaddr with value 0xC0000203");
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field giaddr " addString("EVAL_DEBUG_PKT4 Pushing PKT4 field siaddr with value 0xC0000204");
"with value 0xC0000201"); EXPECT_TRUE(checkFile());
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field ciaddr "
"with value 0xC0000202");
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field yiaddr "
"with value 0xC0000203");
exp_strings.push_back("EVAL_DEBUG_PKT4 Pushing PKT4 field siaddr "
"with value 0xC0000204");
EXPECT_TRUE(checkFile(exp_strings));
remFile();
} }
// This test checks if a token representing an == operator is able to // This test checks if a token representing an == operator is able to
@ -1036,13 +957,12 @@ TEST_F(TokenTest, optionEqualFalse) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("false", values_.top()); EXPECT_EQ("false", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_EQUAL Popping 0x626172 and 0x666F6F " addString("EVAL_DEBUG_EQUAL Popping 0x626172 and 0x666F6F "
"pushing result \"false\""); "pushing result 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an == operator is able to // This test checks if a token representing an == operator is able to
@ -1060,13 +980,12 @@ TEST_F(TokenTest, optionEqualTrue) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("true", values_.top()); EXPECT_EQ("true", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_EQUAL Popping 0x666F6F and 0x666F6F " addString("EVAL_DEBUG_EQUAL Popping 0x666F6F and 0x666F6F "
"pushing result \"true\""); "pushing result 'true'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing a not is able to // This test checks if a token representing a not is able to
@ -1101,13 +1020,12 @@ TEST_F(TokenTest, operatorNot) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("true", values_.top()); EXPECT_EQ("true", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_NOT Popping \"true\" pushing \"false\""); addString("EVAL_DEBUG_NOT Popping 'true' pushing 'false'");
exp_strings.push_back("EVAL_DEBUG_NOT Popping \"false\" pushing \"true\""); addString("EVAL_DEBUG_NOT Popping 'false' pushing 'true'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an and is able to // This test checks if a token representing an and is able to
@ -1160,14 +1078,13 @@ TEST_F(TokenTest, operatorAndFalse) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("false", values_.top()); EXPECT_EQ("false", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_AND Popping \"false\" and \"true\" pushing \"false\""); addString("EVAL_DEBUG_AND Popping 'false' and 'true' pushing 'false'");
exp_strings.push_back("EVAL_DEBUG_AND Popping \"true\" and \"false\" pushing \"false\""); addString("EVAL_DEBUG_AND Popping 'true' and 'false' pushing 'false'");
exp_strings.push_back("EVAL_DEBUG_AND Popping \"false\" and \"false\" pushing \"false\""); addString("EVAL_DEBUG_AND Popping 'false' and 'false' pushing 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an and is able to // This test checks if a token representing an and is able to
@ -1184,12 +1101,11 @@ TEST_F(TokenTest, operatorAndTrue) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("true", values_.top()); EXPECT_EQ("true", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_AND Popping \"true\" and \"true\" pushing \"true\""); addString("EVAL_DEBUG_AND Popping 'true' and 'true' pushing 'true'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an or is able to // This test checks if a token representing an or is able to
@ -1230,12 +1146,11 @@ TEST_F(TokenTest, operatorOrFalse) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("false", values_.top()); EXPECT_EQ("false", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OR Popping \"false\" and \"false\" pushing \"false\""); addString("EVAL_DEBUG_OR Popping 'false' and 'false' pushing 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing an == operator is able to // This test checks if a token representing an == operator is able to
@ -1264,14 +1179,13 @@ TEST_F(TokenTest, operatorOrTrue) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("true", values_.top()); EXPECT_EQ("true", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OR Popping \"true\" and \"false\" pushing \"true\""); addString("EVAL_DEBUG_OR Popping 'true' and 'false' pushing 'true'");
exp_strings.push_back("EVAL_DEBUG_OR Popping \"false\" and \"true\" pushing \"true\""); addString("EVAL_DEBUG_OR Popping 'false' and 'true' pushing 'true'");
exp_strings.push_back("EVAL_DEBUG_OR Popping \"true\" and \"true\" pushing \"true\""); addString("EVAL_DEBUG_OR Popping 'true' and 'true' pushing 'true'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing a substring request // This test checks if a token representing a substring request
@ -1300,13 +1214,12 @@ TEST_F(TokenTest, substringNotEnoughValues) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("", values_.top()); EXPECT_EQ("", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_EMPTY Popping length 0, start 0, " addString("EVAL_DEBUG_SUBSTRING_EMPTY Popping length 0, start 0, "
"string 0x pushing result 0x"); "string 0x pushing result 0x");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Test getting the whole string in different ways // Test getting the whole string in different ways
@ -1323,19 +1236,18 @@ TEST_F(TokenTest, substringWholeString) {
// Get the whole string counting from the back // Get the whole string counting from the back
verifySubstringEval("foobar", "-6", "all", "foobar"); verifySubstringEval("foobar", "-6", "all", "foobar");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 6, start 0, " addString("EVAL_DEBUG_SUBSTRING Popping length 6, start 0, "
"string 0x666F6F626172 pushing result 0x666F6F626172"); "string 0x666F6F626172 pushing result 0x666F6F626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length all, start 0, " addString("EVAL_DEBUG_SUBSTRING Popping length all, start 0, "
"string 0x666F6F626172 pushing result 0x666F6F626172"); "string 0x666F6F626172 pushing result 0x666F6F626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 123456, start 0, " addString("EVAL_DEBUG_SUBSTRING Popping length 123456, start 0, "
"string 0x666F6F626172 pushing result 0x666F6F626172"); "string 0x666F6F626172 pushing result 0x666F6F626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length all, start -6, " addString("EVAL_DEBUG_SUBSTRING Popping length all, start -6, "
"string 0x666F6F626172 pushing result 0x666F6F626172"); "string 0x666F6F626172 pushing result 0x666F6F626172");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Test getting a suffix, in this case the last 3 characters // Test getting a suffix, in this case the last 3 characters
@ -1345,19 +1257,18 @@ TEST_F(TokenTest, substringTrailer) {
verifySubstringEval("foobar", "-3", "all", "bar"); verifySubstringEval("foobar", "-3", "all", "bar");
verifySubstringEval("foobar", "-3", "123", "bar"); verifySubstringEval("foobar", "-3", "123", "bar");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 3, start 3, " addString("EVAL_DEBUG_SUBSTRING Popping length 3, start 3, "
"string 0x666F6F626172 pushing result 0x626172"); "string 0x666F6F626172 pushing result 0x626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length all, start 3, " addString("EVAL_DEBUG_SUBSTRING Popping length all, start 3, "
"string 0x666F6F626172 pushing result 0x626172"); "string 0x666F6F626172 pushing result 0x626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length all, start -3, " addString("EVAL_DEBUG_SUBSTRING Popping length all, start -3, "
"string 0x666F6F626172 pushing result 0x626172"); "string 0x666F6F626172 pushing result 0x626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 123, start -3, " addString("EVAL_DEBUG_SUBSTRING Popping length 123, start -3, "
"string 0x666F6F626172 pushing result 0x626172"); "string 0x666F6F626172 pushing result 0x626172");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Test getting the middle of the string in different ways // Test getting the middle of the string in different ways
@ -1367,19 +1278,18 @@ TEST_F(TokenTest, substringMiddle) {
verifySubstringEval("foobar", "-1", "-4", "ooba"); verifySubstringEval("foobar", "-1", "-4", "ooba");
verifySubstringEval("foobar", "5", "-4", "ooba"); verifySubstringEval("foobar", "5", "-4", "ooba");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, "
"string 0x666F6F626172 pushing result 0x6F6F6261"); "string 0x666F6F626172 pushing result 0x6F6F6261");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start -5, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start -5, "
"string 0x666F6F626172 pushing result 0x6F6F6261"); "string 0x666F6F626172 pushing result 0x6F6F6261");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length -4, start -1, " addString("EVAL_DEBUG_SUBSTRING Popping length -4, start -1, "
"string 0x666F6F626172 pushing result 0x6F6F6261"); "string 0x666F6F626172 pushing result 0x6F6F6261");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length -4, start 5, " addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 5, "
"string 0x666F6F626172 pushing result 0x6F6F6261"); "string 0x666F6F626172 pushing result 0x6F6F6261");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Test getting the last letter in different ways // Test getting the last letter in different ways
@ -1391,23 +1301,22 @@ TEST_F(TokenTest, substringLastLetter) {
verifySubstringEval("foobar", "-1", "1", "r"); verifySubstringEval("foobar", "-1", "1", "r");
verifySubstringEval("foobar", "-1", "5", "r"); verifySubstringEval("foobar", "-1", "5", "r");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length all, start 5, " addString("EVAL_DEBUG_SUBSTRING Popping length all, start 5, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 1, start 5, " addString("EVAL_DEBUG_SUBSTRING Popping length 1, start 5, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 5, start 5, " addString("EVAL_DEBUG_SUBSTRING Popping length 5, start 5, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length all, start -1, " addString("EVAL_DEBUG_SUBSTRING Popping length all, start -1, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 1, start -1, " addString("EVAL_DEBUG_SUBSTRING Popping length 1, start -1, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 5, start -1, " addString("EVAL_DEBUG_SUBSTRING Popping length 5, start -1, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Test we get only what is available if we ask for a longer string // Test we get only what is available if we ask for a longer string
@ -1424,27 +1333,26 @@ TEST_F(TokenTest, substringLength) {
verifySubstringEval("foobar", "5", "4", "r"); verifySubstringEval("foobar", "5", "4", "r");
verifySubstringEval("foobar", "6", "4", ""); verifySubstringEval("foobar", "6", "4", "");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length -4, start 0, " addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 0, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length -4, start 1, " addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 1, "
"string 0x666F6F626172 pushing result 0x66"); "string 0x666F6F626172 pushing result 0x66");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length -4, start 2, " addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 2, "
"string 0x666F6F626172 pushing result 0x666F"); "string 0x666F6F626172 pushing result 0x666F");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length -4, start 3, " addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 3, "
"string 0x666F6F626172 pushing result 0x666F6F"); "string 0x666F6F626172 pushing result 0x666F6F");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start 3, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 3, "
"string 0x666F6F626172 pushing result 0x626172"); "string 0x666F6F626172 pushing result 0x626172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start 4, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 4, "
"string 0x666F6F626172 pushing result 0x6172"); "string 0x666F6F626172 pushing result 0x6172");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start 5, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 5, "
"string 0x666F6F626172 pushing result 0x72"); "string 0x666F6F626172 pushing result 0x72");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length 4, start 6, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length 4, start 6, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Test that we get nothing if the starting postion is out of the string // Test that we get nothing if the starting postion is out of the string
@ -1459,23 +1367,22 @@ TEST_F(TokenTest, substringStartingPosition) {
verifySubstringEval("foobar", "6", "-11", ""); verifySubstringEval("foobar", "6", "-11", "");
verifySubstringEval("foobar", "6", "all", ""); verifySubstringEval("foobar", "6", "all", "");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length 1, start -7, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length 1, start -7, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length -11, start -7, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length -11, start -7, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length all, start -7, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length all, start -7, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length 1, start 6, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length 1, start 6, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length -11, start 6, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length -11, start 6, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_RANGE Popping length all, start 6, " addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length all, start 6, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Check what happens if we use strings that aren't numbers for start or length // Check what happens if we use strings that aren't numbers for start or length
@ -1491,7 +1398,6 @@ TEST_F(TokenTest, substringBadParams) {
// These should result in a throw which should generate it's own // These should result in a throw which should generate it's own
// log entry // log entry
remFile();
} }
// lastly check that we don't get anything if the string is empty or // lastly check that we don't get anything if the string is empty or
@ -1500,15 +1406,14 @@ TEST_F(TokenTest, substringReturnEmpty) {
verifySubstringEval("", "0", "all", ""); verifySubstringEval("", "0", "all", "");
verifySubstringEval("foobar", "0", "0", ""); verifySubstringEval("foobar", "0", "0", "");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING_EMPTY Popping length all, start 0, " addString("EVAL_DEBUG_SUBSTRING_EMPTY Popping length all, start 0, "
"string 0x pushing result 0x"); "string 0x pushing result 0x");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 0, start 0, " addString("EVAL_DEBUG_SUBSTRING Popping length 0, start 0, "
"string 0x666F6F626172 pushing result 0x"); "string 0x666F6F626172 pushing result 0x");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Check if we can use the substring and equal tokens together // Check if we can use the substring and equal tokens together
@ -1564,19 +1469,18 @@ TEST_F(TokenTest, substringEquals) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("false", values_.top()); EXPECT_EQ("false", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, "
"string 0x666F6F626172 pushing result 0x6F6F6261"); "string 0x666F6F626172 pushing result 0x6F6F6261");
exp_strings.push_back("EVAL_DEBUG_EQUAL Popping 0x6F6F6261 and 0x6F6F6261 " addString("EVAL_DEBUG_EQUAL Popping 0x6F6F6261 and 0x6F6F6261 "
"pushing result \"true\""); "pushing result 'true'");
exp_strings.push_back("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, " addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, "
"string 0x666F6F626172 pushing result 0x6F6F6261"); "string 0x666F6F626172 pushing result 0x6F6F6261");
exp_strings.push_back("EVAL_DEBUG_EQUAL Popping 0x6F6F6261 and 0x666F6F62 " addString("EVAL_DEBUG_EQUAL Popping 0x6F6F6261 and 0x666F6F62 "
"pushing result \"false\""); "pushing result 'false'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if a token representing a concat request // This test checks if a token representing a concat request
@ -1600,13 +1504,12 @@ TEST_F(TokenTest, concat) {
ASSERT_EQ(1, values_.size()); ASSERT_EQ(1, values_.size());
EXPECT_EQ("foobar", values_.top()); EXPECT_EQ("foobar", values_.top());
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_CONCAT Popping 0x626172 and 0x666F6F " addString("EVAL_DEBUG_CONCAT Popping 0x626172 and 0x666F6F "
"pushing 0x666F6F626172"); "pushing 0x666F6F626172");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if we can properly extract the link and peer // This test checks if we can properly extract the link and peer
@ -1661,29 +1564,28 @@ TEST_F(TokenTest, relay6Field) {
// be tidy // be tidy
clearStack(); clearStack();
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 0 " addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 0 "
"with value 0x00000000000000000000000000000000"); "with value 0x00000000000000000000000000000000");
exp_strings.push_back("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 0 " addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 0 "
"with value 0x00000000000000000000000000000000"); "with value 0x00000000000000000000000000000000");
exp_strings.push_back("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 1 " addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 1 "
"with value 0x00010000000000000000000000000001"); "with value 0x00010000000000000000000000000001");
exp_strings.push_back("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 1 " addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 1 "
"with value 0x00010000000000000000000000000002"); "with value 0x00010000000000000000000000000002");
exp_strings.push_back("EVAL_DEBUG_RELAY6_RANGE Pushing PKT6 relay field linkaddr nest 2 " addString("EVAL_DEBUG_RELAY6_RANGE Pushing PKT6 relay field linkaddr nest 2 "
"with value 0x"); "with value 0x");
exp_strings.push_back("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 1 " addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 1 "
"with value 0x00010000000000000000000000000001"); "with value 0x00010000000000000000000000000001");
exp_strings.push_back("EVAL_DEBUG_IPADDRESS Pushing IPAddress " addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress "
"0x00010000000000000000000000000001"); "0x00010000000000000000000000000001");
exp_strings.push_back("EVAL_DEBUG_EQUAL Popping 0x00010000000000000000000000000001 " addString("EVAL_DEBUG_EQUAL Popping 0x00010000000000000000000000000001 "
"and 0x00010000000000000000000000000001 pushing result \"true\""); "and 0x00010000000000000000000000000001 pushing result 'true'");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// This test checks if we can properly extract an option // This test checks if we can properly extract an option
@ -1718,23 +1620,22 @@ TEST_F(TokenTest, relay6Option) {
// Level 2, no encapsulation so no options // Level 2, no encapsulation so no options
verifyRelay6Option(2, 100, TokenOption::TEXTUAL, ""); verifyRelay6Option(2, 100, TokenOption::TEXTUAL, "");
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"hundred.zero\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'hundred.zero'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"true\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'true'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value \"hundredone.zero\""); addString("EVAL_DEBUG_OPTION Pushing option 101 with value 'hundredone.zero'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 102 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 102 with value ''");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 102 with value \"false\""); addString("EVAL_DEBUG_OPTION Pushing option 102 with value 'false'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"hundred.one\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'hundred.one'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 101 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 101 with value ''");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 102 with value \"hundredtwo.one\""); addString("EVAL_DEBUG_OPTION Pushing option 102 with value 'hundredtwo.one'");
exp_strings.push_back("EVAL_DEBUG_OPTION Pushing option 100 with value \"\""); addString("EVAL_DEBUG_OPTION Pushing option 100 with value ''");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
// Verifies if the DHCPv6 packet fields can be extracted. // Verifies if the DHCPv6 packet fields can be extracted.
@ -1762,15 +1663,12 @@ TEST_F(TokenTest, pkt6Fields) {
ASSERT_NO_THROW(t_.reset(new TokenPkt6(TokenPkt6::TRANSID))); ASSERT_NO_THROW(t_.reset(new TokenPkt6(TokenPkt6::TRANSID)));
EXPECT_THROW(t_->evaluate(*pkt4_, values_), EvalTypeError); EXPECT_THROW(t_->evaluate(*pkt4_, values_), EvalTypeError);
// Check that the debug output was correct, we create a vector of all // Check that the debug output was correct. Add the strings
// the strings we expect and send it to checkFile for comparison. // to the test vector in the class and then call checkFile
vector<string> exp_strings; // for comparison
exp_strings.push_back("EVAL_DEBUG_PKT6 Pushing PKT6 field msgtype " addString("EVAL_DEBUG_PKT6 Pushing PKT6 field msgtype with value 0x00000001");
"with value 0x00000001"); addString("EVAL_DEBUG_PKT6 Pushing PKT6 field transid with value 0x00003039");
exp_strings.push_back("EVAL_DEBUG_PKT6 Pushing PKT6 field transid "
"with value 0x00003039");
EXPECT_TRUE(checkFile(exp_strings)); EXPECT_TRUE(checkFile());
remFile();
} }
}; };

View File

@ -23,8 +23,8 @@ TokenString::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.push(value_); values.push(value_);
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_STRING) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_STRING)
.arg('"' + value_ + '"'); .arg('\'' + value_ + '\'');
} }
TokenHexString::TokenHexString(const string& str) : value_("") { TokenHexString::TokenHexString(const string& str) : value_("") {
@ -61,7 +61,7 @@ TokenHexString::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.push(value_); values.push(value_);
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_HEXSTRING) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_HEXSTRING)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value_.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value_.begin(),
value_.end()))); value_.end())));
} }
@ -87,7 +87,7 @@ TokenIpAddress::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.push(value_); values.push(value_);
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_IPADDRESS) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_IPADDRESS)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value_.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value_.begin(),
value_.end()))); value_.end())));
} }
@ -125,14 +125,14 @@ TokenOption::evaluate(const Pkt& pkt, ValueStack& values) {
// and can be output directly. We also include the code number // and can be output directly. We also include the code number
// of the requested option. // of the requested option.
if (representation_type_ == HEXADECIMAL) { if (representation_type_ == HEXADECIMAL) {
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_OPTION) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_OPTION)
.arg(option_code_) .arg(option_code_)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(opt_str.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(opt_str.begin(),
opt_str.end()))); opt_str.end())));
} else { } else {
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_OPTION) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_OPTION)
.arg(option_code_) .arg(option_code_)
.arg('"' + opt_str + '"'); .arg('\'' + opt_str + '\'');
} }
} }
@ -232,10 +232,10 @@ TokenPkt4::evaluate(const Pkt& pkt, ValueStack& values) {
values.push(value); values.push(value);
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_PKT4) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_PKT4)
.arg(type_str) .arg(type_str)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value.begin(),
value.end()))); value.end())));
} }
void void
@ -251,21 +251,18 @@ TokenEqual::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
string op2 = values.top(); string op2 = values.top();
values.pop(); // Dammit, std::stack interface is awkward. values.pop(); // Dammit, std::stack interface is awkward.
string result;
if (op1 == op2) if (op1 == op2)
result = "true"; values.push("true");
else else
result = "false"; values.push("false");
values.push(result);
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_EQUAL) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_EQUAL)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op1.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op1.begin(),
op1.end()))) op1.end())))
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op2.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op2.begin(),
op2.end()))) op2.end())))
.arg('"' + result + '"'); .arg('\'' + values.top() + '\'');
} }
void void
@ -288,7 +285,7 @@ TokenSubstring::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.push(""); values.push("");
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_SUBSTRING_EMPTY) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_SUBSTRING_EMPTY)
.arg(len_str) .arg(len_str)
.arg(start_str) .arg(start_str)
.arg("0x") .arg("0x")
@ -328,7 +325,7 @@ TokenSubstring::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.push(""); values.push("");
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_SUBSTRING_RANGE) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_SUBSTRING_RANGE)
.arg(len_str) .arg(len_str)
.arg(start_str) .arg(start_str)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(string_str.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(string_str.begin(),
@ -354,19 +351,17 @@ TokenSubstring::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
} }
} }
// and finally get the substring // and finally get the substring
string result = string_str.substr(start_pos, length); values.push(string_str.substr(start_pos, length));
values.push(result);
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_SUBSTRING) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_SUBSTRING)
.arg(len_str) .arg(len_str)
.arg(start_str) .arg(start_str)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(string_str.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(string_str.begin(),
string_str.end()))) string_str.end())))
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(result.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(values.top().begin(),
result.end()))); values.top().end())));
} }
void void
@ -383,17 +378,16 @@ TokenConcat::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.pop(); // Dammit, std::stack interface is awkward. values.pop(); // Dammit, std::stack interface is awkward.
// The top of the stack was evaluated last so this is the right order // The top of the stack was evaluated last so this is the right order
string result = op2 + op1; values.push(op2 + op1);
values.push(result);
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_CONCAT) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_CONCAT)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op1.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op1.begin(),
op1.end()))) op1.end())))
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op2.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(op2.begin(),
op2.end()))) op2.end())))
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(result.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(values.top().begin(),
result.end()))); values.top().end())));
} }
void void
@ -407,18 +401,16 @@ TokenNot::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.pop(); values.pop();
bool val = toBool(op); bool val = toBool(op);
string result;
if (!val) { if (!val) {
result = "true"; values.push("true");
} else { } else {
result = "false"; values.push("false");
} }
values.push(result);
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_NOT) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_NOT)
.arg('"' + op + '"') .arg('\'' + op + '\'')
.arg('"' + result + '"'); .arg('\'' + values.top() + '\'');
} }
void void
@ -436,19 +428,17 @@ TokenAnd::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.pop(); // Dammit, std::stack interface is awkward. values.pop(); // Dammit, std::stack interface is awkward.
bool val2 = toBool(op2); bool val2 = toBool(op2);
string result;
if (val1 && val2) { if (val1 && val2) {
result = "true"; values.push("true");
} else { } else {
result = "false"; values.push("false");
} }
values.push(result);
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_AND) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_AND)
.arg('"' + op1 + '"') .arg('\'' + op1 + '\'')
.arg("\"" + op2 + "\"") .arg('\'' + op2 + '\'')
.arg("\"" + result + "\""); .arg('\'' + values.top() + '\'');
} }
void void
@ -466,19 +456,17 @@ TokenOr::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.pop(); // Dammit, std::stack interface is awkward. values.pop(); // Dammit, std::stack interface is awkward.
bool val2 = toBool(op2); bool val2 = toBool(op2);
string result;
if (val1 || val2) { if (val1 || val2) {
result = "true"; values.push("true");
} else { } else {
result = "false"; values.push("false");
} }
values.push(result);
// Log what we popped and pushed // Log what we popped and pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_OR) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_OR)
.arg('"' + op1 + '"') .arg('\'' + op1 + '\'')
.arg('"' + op2 + '"') .arg('\'' + op2 + '\'')
.arg('"' + result + '"'); .arg('\'' + values.top() + '\'');
} }
OptionPtr TokenRelay6Option::getOption(const Pkt& pkt) { OptionPtr TokenRelay6Option::getOption(const Pkt& pkt) {
@ -535,7 +523,7 @@ TokenRelay6Field::evaluate(const Pkt& pkt, ValueStack& values) {
// level is invalid. We push "" in that case. // level is invalid. We push "" in that case.
values.push(""); values.push("");
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_RELAY6_RANGE) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_RELAY6_RANGE)
.arg(type_str) .arg(type_str)
.arg(unsigned(nest_level_)) .arg(unsigned(nest_level_))
.arg("0x"); .arg("0x");
@ -553,7 +541,7 @@ TokenRelay6Field::evaluate(const Pkt& pkt, ValueStack& values) {
values.push(value); values.push(value);
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_RELAY6) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_RELAY6)
.arg(type_str) .arg(type_str)
.arg(unsigned(nest_level_)) .arg(unsigned(nest_level_))
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value.begin(),
@ -606,7 +594,7 @@ TokenPkt6::evaluate(const Pkt& pkt, ValueStack& values) {
values.push(value); values.push(value);
// Log what we pushed // Log what we pushed
LOG_DEBUG(eval_logger, EVAL_DBG_EXTENDED_CALLS, EVAL_DEBUG_PKT6) LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_PKT6)
.arg(type_str) .arg(type_str)
.arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value.begin(), .arg("0x" + util::encode::encodeHex(std::vector<uint8_t>(value.begin(),
value.end()))); value.end())));

View File

@ -568,7 +568,7 @@ protected:
uint8_t nest_level_; ///< nesting level of the relay block to use uint8_t nest_level_; ///< nesting level of the relay block to use
}; };
/// @breif Token that represents a value of a field within a DHCPv6 relay /// @brief Token that represents a value of a field within a DHCPv6 relay
/// encapsulation /// encapsulation
/// ///
/// This represents a reference to a field with a given DHCPv6 relay encapsulation. /// This represents a reference to a field with a given DHCPv6 relay encapsulation.

View File

@ -8,6 +8,7 @@ if HAVE_GTEST
noinst_LTLIBRARIES = libkea-testutils.la noinst_LTLIBRARIES = libkea-testutils.la
libkea_testutils_la_SOURCES = io_utils.cc io_utils.h libkea_testutils_la_SOURCES = io_utils.cc io_utils.h
libkea_testutils_la_SOURCES += log_utils.cc log_utils.h
libkea_testutils_la_SOURCES += unix_control_client.h unix_control_client.cc libkea_testutils_la_SOURCES += unix_control_client.h unix_control_client.cc
libkea_testutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) libkea_testutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
libkea_testutils_la_LIBADD = $(top_builddir)/src/lib/asiolink/libkea-asiolink.la libkea_testutils_la_LIBADD = $(top_builddir)/src/lib/asiolink/libkea-asiolink.la

View File

@ -0,0 +1,74 @@
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <testutils/log_utils.h>
namespace isc {
namespace dhcp {
namespace test {
LogContentTest::LogContentTest() {
// Get rid of any old files
remFile();
// Set up the logger for use in checking the debug statements.
// We send the debug statements to a file which we can
// check after the evaluations have completed. We also
// set the log severity and debug levels so that the log
// statements are executed.
LoggerSpecification spec(getRootLoggerName(),
keaLoggerSeverity(isc::log::DEBUG),
keaLoggerDbglevel(isc::log::MAX_DEBUG_LEVEL));
OutputOption option;
option.destination = OutputOption::DEST_FILE;
option.filename = string(LogContentTest::LOG_FILE);
spec.addOutputOption(option);
LoggerManager manager;
manager.process(spec);
}
LogContentTest:: ~LogContentTest() {
remFile();
}
bool LogContentTest::checkFile() {
ifstream file(LOG_FILE);
EXPECT_TRUE(file.is_open());
string line, exp_line;
int i = 0;
bool found = true;
while (getline(file, line) && (i != exp_strings_.size())) {
exp_line = exp_strings_[i];
i++;
if (string::npos == line.find(exp_line)) {
found = false;
}
}
file.close();
if ((i != exp_strings_.size()) || (found == false))
return (false);
return (true);
}
void LogContentTest::remFile() {
static_cast<void>(remove(LOG_FILE));
}
void LogContentTest::addString(const string& new_string) {
exp_strings_.push_back(new_string);
}
// Set up the name of the LOG_FILE for use in checking
// the debug statements
const char *LogContentTest::LOG_FILE = "test.log";
}; // end of isc::dhcp::test namespace
}; // end of isc::dhcp namespace
}; // end of isc namespace

View File

@ -0,0 +1,82 @@
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef TEST_LOG_UTILS_H
#define TEST_LOG_UTILS_H
#include <string>
#include <fstream>
//#include <config.h>
#include <log/logger_manager.h>
#include <log/logger_name.h>
#include <log/logger_support.h>
//#include <boost/shared_ptr.hpp>
//#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
using namespace std;
using namespace isc::log;
namespace isc {
namespace dhcp {
namespace test {
/// @brief Test class for testing things that emit log entries
///
/// This class provides a convenient method for testing out
/// things that emit log entries. The class sets up the logging
/// to log everything into a file and provides a routine to
/// check the expected strings vs the actual log entries.
/// The user needs to call the addString function for each of
/// the strings they expect in the output in the order they
/// will be emitted.
class LogContentTest : public ::testing::Test {
public:
/// @brief Initializes the logger setup for using
/// in checking log statements
///
/// @todo add support to adjust the severity and debug level
/// to allow for better control over the statements that
/// get logged.
LogContentTest();
virtual ~LogContentTest();
/// @brief check that the requested strings are in the
/// test log file in the requested order.
///
/// This routine expects that the caller has properly
/// set up the vector of expected strings by calling
/// addString() with the necessary strings.
///
/// @return true if all of the strings match
bool checkFile();
/// @brief remove the test log file
void remFile();
/// @brief Add a string to the vector of expected strings
///
/// @param new_string the string to add to the end of the vector
/// @return void
void addString(const string& new_string);
vector<string> exp_strings_;
static const char* LOG_FILE;
};
}; // end of isc::dhcp::test namespace
}; // end of isc::dhcp namespace
}; // end of isc namespace
#endif // TEST_LOG_UTILS_H