Skip to content

[aclorch] unittest by gtest#870

Closed
yehjunying wants to merge 9 commits intosonic-net:masterfrom
yehjunying:aclorch-unittest
Closed

[aclorch] unittest by gtest#870
yehjunying wants to merge 9 commits intosonic-net:masterfrom
yehjunying:aclorch-unittest

Conversation

@yehjunying
Copy link
Contributor

What I did
Add unit test for aclorch.

Why I did it
Do unit test in development phase. The developer can check each variable in each stack frame. And also do memory leakage detection or buffer overrun test. That is different than pytest, it is black box test. But, this is white box test.

How I verified it
The new committed testes are all passed.

Details if related
The unit test of aclorch have two scopes. One is cover the whole aclorch behaviors. Second is for internal component like AclTable or AclRule.

The first scope. Each test will call doTask() that simulate configDB was changed. All reaction by AclOrch, AclTable or AclReult will save into libvs via SAI. Then we can verify the results via SAI to make sure every operation is correct.

The second scope using spy function to redirect SAI function pointer to c++ std::function for accessing local variable of test instance. It can verify the result directly without any library.

Because many orch will connect Redis when it is created by constructor, so run the test will need to start Redis first. The later tests will not access Redis.

Signed-off-by: JunYing Yeh [email protected]

@msftclas
Copy link

msftclas commented May 1, 2019

CLA assistant check
All CLA requirements met.

@lguohan
Copy link
Contributor

lguohan commented May 1, 2019

how to run the test?

@yehjunying
Copy link
Contributor Author

  1. Launch Redis to listen unix socket /var/run/redis/redis-server.sock
  2. Goto tests folder and make the executable file
  3. Run by ./test. Then you can see 4 new test be run
[----------] 1 test from AclTest
[ RUN      ] AclTest.Create_L3_Acl_Table
[       OK ] AclTest.Create_L3_Acl_Table (1 ms)
[----------] 1 test from AclTest (2 ms total)

[----------] 3 tests from AclOrchTest
[ RUN      ] AclOrchTest.ACL_Creation_and_Destorying
[       OK ] AclOrchTest.ACL_Creation_and_Destorying (1003 ms)
[ RUN      ] AclOrchTest.L3Acl_Matches_Actions
[       OK ] AclOrchTest.L3Acl_Matches_Actions (1007 ms)
[ RUN      ] AclOrchTest.L3V6Acl_Matches_Actions
[       OK ] AclOrchTest.L3V6Acl_Matches_Actions (1007 ms)
[----------] 3 tests from AclOrchTest (3023 ms total)

tests/check.h Outdated
#include "saiattributelist.h"

struct Check {
static bool AttrListEq(sai_object_type_t objecttype, const std::vector<sai_attribute_t>& act_attr_list, /*const*/ SaiAttributeList& exp_attr_list)
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/const/ [](start = 108, length = 9)

const or not? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No const. Will remove the comment.


// auto act = sai_serialize_attr_value(*meta, act_attr_list[i].value, false);
// auto exp = sai_serialize_attr_value(*meta, &exp_attr_list.get_attr_list()[i].value, false);

Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove unused code? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will remove these two lines.

tests/check.h Outdated
continue;
}

char act_buf[0x4000];
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

act_buf [](start = 17, length = 7)

Suggest not to create large array in stack. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, shall not create large array in stack. I will fix it.

sai_attr_id_t id = exp_attr_list.get_attr_list()[i].id;
auto meta = sai_metadata_get_attr_metadata(objecttype, id);

assert(meta != nullptr);
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert [](start = 12, length = 6)

'assert' will be nothing in non debug build and you skip the check. Is it your intent? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this meta query from expectation value. So it shall not happen in any time except developing phase.

// #if WITH_SAI == LIBSAIREDIS
// #include "hiredis.h"
// #include "saihelper.h"
// #endif
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will remove this unused code.

assert(sai_acl_api == nullptr);

sai_acl_api = new sai_acl_api_t();
auto sai_acl = std::shared_ptr<sai_acl_api_t>(sai_acl_api, [](sai_acl_api_t* p) {
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr<sai_acl_api_t> [](start = 23, length = 30)

use make_shared() directly? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Because I want to reset sai_acl_api. make_shared() under C++11, can not pass a customized remove function.


AclTest()
{
m_config_db = std::make_shared<swss::DBConnector>(CONFIG_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std:: [](start = 22, length = 5)

you can remove 'std::' #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. It can be removed.

return entries.size();
}

struct AclTestBase : public ::testing::Test {
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AclTestBase [](start = 7, length = 11)

Name is confusing. Has nothing related Acl. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name is no confuse. That is base class of AclTest and AclOrchTest.


void SetUp() override
{
assert(gCrmOrch == nullptr);
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert [](start = 8, length = 6)

the same #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using assert() because I want catch it on development phase. That is different between ASSERT_TRUE() that is used to catch result of test.

#include "saitypes.h"

// Spy C functin pointer to std::function to access closure
// Internal using static `spy` function pointer to invoke std::function `fake`
Copy link
Contributor

@qiluo-msft qiluo-msft May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the comment block and also the use case in aclorch_ut.cpp, still not get the design idea of SpyOn. Could you elaborate? We expected a design doc and/or community talk. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put the unit test for how to use the code in saispy_ut.cpp can you check it first ?

@qiluo-msft
Copy link
Contributor

qiluo-msft commented May 2, 2019

@lguohan Could you help add a PR check for the unit test? #Closed

@yehjunying
Copy link
Contributor Author

Should I add [aclorch] for each commit during code review ?

@yehjunying
Copy link
Contributor Author

Hi @lguohan, I found the check error is test_system_warmreboot_neighbor_syncup from pytest. The last blocked PR is #866. It seem this test is not stable. Because my first commit is passed and second commit is failed. Both commit doesn't touch any code in oarchagent and pytest.

Should we continue to review the code. At meantime monitor the error status ?

What's your suggestion ?

@yehjunying
Copy link
Contributor Author

yehjunying commented May 3, 2019

Hi @lguohan @qiluo-msft , I find the test in test_system_warmreboot_neighbor_syncup may have a timing issue.

def setup_initial_neighbors(dvs):
 ...
    for i in range(8, 8+NUM_INTF):
        for j in range(NUM_NEIGH_PER_INTF):
            dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)])
            dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)])

def test_system_warmreboot_neighbor_syncup(dvs, testlog):
 ...
    setup_initial_neighbors(dvs)

    # Check the neighbor entries are inserted correctly
    db = swsscommon.DBConnector(0, dvs.redis_sock, 0)
    tbl = swsscommon.Table(db, "NEIGH_TABLE")

    # number of neighbors should match what we configured
    # ipv4/ipv6 entries and loopback
    check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS)

I found setup_initial_neighbors using ping[6] command to trigger neighsyncd to learn new neighbor. But, in the test it read Redis after ping[6] immediately. That may cause neighsyncd too later to learn new neighbor (the path will from kernel -> netlink -> neighsyncd -> write (IPC) Redis).

Do you think ... if add a sleep(N) between setup_initial_neighbors(dvs) and check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) for 1 or more second to fix this issue ? That is accept to you ?

sai_acl_api = new sai_acl_api_t();
auto sai_acl = shared_ptr<sai_acl_api_t>(sai_acl_api, [](sai_acl_api_t* p) {
delete p;
sai_acl_api = nullptr;
Copy link
Contributor

@qiluo-msft qiluo-msft May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sai_acl_api [](start = 12, length = 11)

It abuses the design of deleter that you modify lambda-captured variable. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is the raw pointer ... however, I move the allocate/delete into SetUp() and TearDown().


using namespace std;

static size_t consumerAddToSync(Consumer* consumer, const deque<KeyOpFieldsValuesTuple>& entries)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I know static won't work here.
It's only C keyword for local functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove static keyword.

acltable.type = ACL_TABLE_L3;
auto res = createAclTable(acltable);

ASSERT_TRUE(res->ret_val == true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT_TRUE(res->ret_val);
It's already about true or not.
Otherwise we need to use ASSERT_EQ()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it.

};

auto status = sai_api_initialize(0, (sai_service_method_table_t*)&test_services);
ASSERT_TRUE(status == SAI_STATUS_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT_EQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will fix it.

{ APP_LAG_MEMBER_TABLE_NAME, portsorch_base_pri }
};

assert(gPortsOrch == nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use ASSERT_EQ here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will fix it.

Copy link
Contributor

@pavel-shirshov pavel-shirshov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address my comments.
Please use proper ASSERT_*.

@qiluo-msft
Copy link
Contributor

qiluo-msft commented May 10, 2019

ok to me. Still @lguohan please help add PR checker. #Closed

@yehjunying
Copy link
Contributor Author

Hi @lguohan,
Anything I can help you with?

@yehjunying
Copy link
Contributor Author

Hi @lguohan,
Do you still have other questions about this pull request ? Or something does not clear need me to explain ?

sai_object_id_t oid;

auto status = acl_api->create_acl_table(&oid, 1, 0, nullptr);
ASSERT_TRUE(oid == 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use ASSERT_EQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Will Fix.


auto status = acl_api->create_acl_table(&oid, 1, 0, nullptr);
ASSERT_TRUE(oid == 1);
ASSERT_TRUE(status == SAI_STATUS_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use ASSERT_EQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Will Fix.

ASSERT_TRUE(status == SAI_STATUS_SUCCESS);

status = acl_api->remove_acl_table(2);
ASSERT_TRUE(status == SAI_STATUS_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use ASSERT_EQ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Will Fix.

auto z_spy_ref = &z->spy;

acl_api->create_acl_table(&oid, 1, 0, nullptr);
ASSERT_TRUE(oid == exp_oid_1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use ASSERT_EQ? here and below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Will Fix.

@yehjunying
Copy link
Contributor Author

retest this please

@yehjunying
Copy link
Contributor Author

Last time I check the status of Jenkins. It seem show 'can not find test'. But now it show "502 Bad Gateway". Does something wrong in Jenkins ?

@yehjunying
Copy link
Contributor Author

Do any suggestions for this pull request ?
I know Jenkins said failure ... But, I can make sure the modification will not cause pytest failed.

@lguohan
Copy link
Contributor

lguohan commented May 20, 2019

by default debian package build will run make test or make check to run test packages. there is not need to add the test to pr build specifically. @yehjunying can add it to debian packaging.

@yehjunying
Copy link
Contributor Author

Hi @lguohan,
I think the test still run on default debian packaging ... no change anything for the default build behavior.
But to run the test. It will need to launch Redis first. For that.
Plan A, I will remove the limitation to create new mock function to replace DBConnector ctor. (prefer this)
Plan B, lanuch Redis before run test on debian packaging.

Is OK to you ?

@yehjunying
Copy link
Contributor Author

Hi @lguohan,
About this "there is not need to add the test to pr build specifically. @yehjunying can add it to debian packaging." I can not understand ... and don't know what's you want me to do.

After check the build_swss.sh, copy from Jenkins, it call dpkg-buildpackage -us -uc -b to build debin package. It do nothing about test. Include integrate test by pytest.

@yehjunying
Copy link
Contributor Author

yehjunying commented May 23, 2019

Hi @lguohan, Does your means is:
edit debian\rules to enable gtest by dh_auto_configure -- --enable-gtest

Then add new test command in Jenkins for build script ?

pushd sonic-swss/tests
+ ./tests
sudo py.test -v

@lguohan
Copy link
Contributor

lguohan commented Jun 4, 2019

@yehjunying
Copy link
Contributor Author

@lguohan, because this PR is conflicting, so I created another PR #924. You can check the unit test had run by dh_auth_test in Jenkins console.

@yehjunying yehjunying closed this Jun 6, 2019
@yehjunying
Copy link
Contributor Author

Code merged by #924

@yehjunying yehjunying deleted the aclorch-unittest branch June 6, 2019 10:06
@yehjunying yehjunying restored the aclorch-unittest branch June 6, 2019 21:59
EdenGri pushed a commit to EdenGri/sonic-swss that referenced this pull request Feb 28, 2022
Added support for VXLAN config and commands as described in the PR sonic-net/SONiC#437

config vxlan add/del and config vxlan evpn_nvo add/del 
config vxlan map/map_range add 
show vxlan remote vni/show vxlan remote mac 
show vxlan tunnel 

Co-authored-by: Tapash Das <[email protected]>
Co-authored-by: Karthikeyan Ananthakrishnan <[email protected]>
Co-authored-by: Tapash Das <[email protected]>
oleksandrivantsiv pushed a commit to oleksandrivantsiv/sonic-swss that referenced this pull request Mar 1, 2023
8db1eaf 2018-09-07 | added vxlan tunnel as possible condition for underlay interface attribute (sonic-net#870) (HEAD, origin/v1.3) [YonatanPitz]

Signed-off-by: Guohan Lu <[email protected]>
oleksandrivantsiv pushed a commit to oleksandrivantsiv/sonic-swss that referenced this pull request Mar 1, 2023
jianyuewu pushed a commit to jianyuewu/sonic-swss that referenced this pull request Dec 24, 2025
* Add Bookworm build to PR checks

Signed-off-by: Saikrishna Arcot <[email protected]>

* Keep debian_version as buster

Signed-off-by: Saikrishna Arcot <[email protected]>

---------

Signed-off-by: Saikrishna Arcot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants