Skip to content

Commit

Permalink
Merge "Improve organization of bgp show instance or table tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Aug 14, 2015
2 parents 4e408f7 + b3304d1 commit b7bbed1
Show file tree
Hide file tree
Showing 5 changed files with 1,366 additions and 1,246 deletions.
12 changes: 12 additions & 0 deletions src/bgp/test/SConscript
Expand Up @@ -220,6 +220,16 @@ bgp_sg_test = env.UnitTest('bgp_sg_test',
['bgp_sg_test.cc'])
env.Alias('src/bgp:bgp_sg_test', bgp_sg_test)

bgp_show_evpn_table_test = env.UnitTest('bgp_show_evpn_table_test',
['bgp_show_evpn_table_test.cc'])
env.Alias('src/bgp:bgp_show_evpn_table_test',
bgp_show_evpn_table_test)

bgp_show_instance_config_test = env.UnitTest('bgp_show_instance_config_test',
['bgp_show_instance_config_test.cc'])
env.Alias('src/bgp:bgp_show_instance_config_test',
bgp_show_instance_config_test)

bgp_show_neighbor_test = env.UnitTest('bgp_show_neighbor_test',
['bgp_show_neighbor_test.cc'])
env.Alias('src/bgp:bgp_show_neighbor_test',
Expand Down Expand Up @@ -396,6 +406,8 @@ test_suite = [
bgp_server_test,
bgp_session_test,
bgp_sg_test,
bgp_show_evpn_table_test,
bgp_show_instance_config_test,
bgp_show_neighbor_test,
bgp_show_route_summary_test,
bgp_show_routing_instance_test,
Expand Down
105 changes: 105 additions & 0 deletions src/bgp/test/bgp_show_evpn_table_test.cc
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#include "bgp/test/bgp_show_instance_or_table_test.h"

typedef TypeDefinition<
ShowEvpnTableReq,
ShowEvpnTableReqIterate,
ShowEvpnTableResp> RegularReq;

typedef TypeDefinition<
ShowEvpnTableSummaryReq,
ShowEvpnTableSummaryReqIterate,
ShowEvpnTableSummaryResp> SummaryReq;

// Common routine for regular and summary requests.
static void AddEvpnTableName(vector<string> *names, const string &name) {
string table_name;
if (name == BgpConfigManager::kMasterInstance) {
table_name = "bgp.evpn.0";
} else {
table_name = name + ".evpn.0";
}
names->push_back(table_name);
}

// Specialization of AddInstanceOrTableName for regular request.
template<>
void BgpShowInstanceOrTableTest<RegularReq>::AddInstanceOrTableName(
vector<string> *names, const string &name) {
AddEvpnTableName(names, name);
}

// Specialization of AddInstanceOrTableName for summary request.
template<>
void BgpShowInstanceOrTableTest<SummaryReq>::AddInstanceOrTableName(
vector<string> *names, const string &name) {
AddEvpnTableName(names, name);
}

// Common routine for regular and summary requests.
template <typename RespT>
static void ValidateEvpnResponse(Sandesh *sandesh, vector<string> &result,
const string &next_batch) {
RespT *resp = dynamic_cast<RespT *>(sandesh);
TASK_UTIL_EXPECT_TRUE(resp != NULL);
TASK_UTIL_EXPECT_EQ(result.size(), resp->get_tables().size());
TASK_UTIL_EXPECT_EQ(next_batch, resp->get_next_batch());
for (size_t i = 0; i < resp->get_tables().size(); ++i) {
TASK_UTIL_EXPECT_EQ(result[i], resp->get_tables()[i].get_name());
cout << resp->get_tables()[i].log() << endl;
}
}

// Specialization of ValidateResponse for regular request.
template<>
void BgpShowInstanceOrTableTest<RegularReq>::ValidateResponse(
Sandesh *sandesh, vector<string> &result, const string &next_batch) {
ValidateEvpnResponse<RegularReq::RespT>(sandesh, result, next_batch);
validate_done_ = true;
}

// Specialization of ValidateResponse for summary request.
template<>
void BgpShowInstanceOrTableTest<SummaryReq>::ValidateResponse(
Sandesh *sandesh, vector<string> &result, const string &next_batch) {
ValidateEvpnResponse<SummaryReq::RespT>(sandesh, result, next_batch);
validate_done_ = true;
}

// Instantiate all test patterns for ShowEvpnTableReq.
INSTANTIATE_TYPED_TEST_CASE_P(Regular, BgpShowInstanceOrTableTest, RegularReq);

// Instantiate all test patterns for ShowEvpnTableSummaryReq.
INSTANTIATE_TYPED_TEST_CASE_P(Summary, BgpShowInstanceOrTableTest, SummaryReq);

class TestEnvironment : public ::testing::Environment {
virtual ~TestEnvironment() { }
};

static void SetUp() {
ControlNode::SetDefaultSchedulingPolicy();
BgpServerTest::GlobalSetUp();
XmppObjectFactory::Register<XmppStateMachine>(
boost::factory<XmppStateMachineTest *>());
BgpObjectFactory::Register<BgpXmppMessageBuilder>(
boost::factory<BgpXmppMessageBuilder *>());
}

static void TearDown() {
task_util::WaitForIdle();
TaskScheduler *scheduler = TaskScheduler::GetInstance();
scheduler->Terminate();
}

int main(int argc, char **argv) {
bgp_log_test::init();
::testing::InitGoogleTest(&argc, argv);
::testing::AddGlobalTestEnvironment(new TestEnvironment());
SetUp();
int result = RUN_ALL_TESTS();
TearDown();
return result;
}
48 changes: 48 additions & 0 deletions src/bgp/test/bgp_show_instance_config_test.cc
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#include "bgp/test/bgp_show_instance_or_table_test.h"

typedef TypeDefinition<
ShowBgpInstanceConfigReq,
ShowBgpInstanceConfigReqIterate,
ShowBgpInstanceConfigResp> ConfigReq;

// Specialization to identify config request.
template<>
bool BgpShowInstanceOrTableTest<ConfigReq>::RequestIsConfig() const {
return true;
}

// Instantiate all test patterns for ShowBgpInstanceConfigReq.
INSTANTIATE_TYPED_TEST_CASE_P(Config, BgpShowInstanceOrTableTest, ConfigReq);

class TestEnvironment : public ::testing::Environment {
virtual ~TestEnvironment() { }
};

static void SetUp() {
ControlNode::SetDefaultSchedulingPolicy();
BgpServerTest::GlobalSetUp();
XmppObjectFactory::Register<XmppStateMachine>(
boost::factory<XmppStateMachineTest *>());
BgpObjectFactory::Register<BgpXmppMessageBuilder>(
boost::factory<BgpXmppMessageBuilder *>());
}

static void TearDown() {
task_util::WaitForIdle();
TaskScheduler *scheduler = TaskScheduler::GetInstance();
scheduler->Terminate();
}

int main(int argc, char **argv) {
bgp_log_test::init();
::testing::InitGoogleTest(&argc, argv);
::testing::AddGlobalTestEnvironment(new TestEnvironment());
SetUp();
int result = RUN_ALL_TESTS();
TearDown();
return result;
}

0 comments on commit b7bbed1

Please sign in to comment.