[aclorch] unittest by gtest#870
[aclorch] unittest by gtest#870yehjunying wants to merge 9 commits intosonic-net:masterfrom yehjunying:aclorch-unittest
Conversation
|
how to run the test? |
|
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) |
There was a problem hiding this comment.
/const/ [](start = 108, length = 9)
const or not? #Closed
There was a problem hiding this comment.
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); | ||
|
|
There was a problem hiding this comment.
Could you remove unused code? #Closed
There was a problem hiding this comment.
yes, will remove these two lines.
tests/check.h
Outdated
| continue; | ||
| } | ||
|
|
||
| char act_buf[0x4000]; |
There was a problem hiding this comment.
act_buf [](start = 17, length = 7)
Suggest not to create large array in stack. #Closed
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
assert [](start = 12, length = 6)
'assert' will be nothing in non debug build and you skip the check. Is it your intent? #Closed
There was a problem hiding this comment.
Because this meta query from expectation value. So it shall not happen in any time except developing phase.
tests/ut_helper.h
Outdated
| // #if WITH_SAI == LIBSAIREDIS | ||
| // #include "hiredis.h" | ||
| // #include "saihelper.h" | ||
| // #endif |
There was a problem hiding this comment.
yes, will remove this unused code.
tests/aclorch_ut.cpp
Outdated
| 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) { |
There was a problem hiding this comment.
std::shared_ptr<sai_acl_api_t> [](start = 23, length = 30)
use make_shared() directly? #Closed
There was a problem hiding this comment.
No. Because I want to reset sai_acl_api. make_shared() under C++11, can not pass a customized remove function.
tests/aclorch_ut.cpp
Outdated
|
|
||
| AclTest() | ||
| { | ||
| m_config_db = std::make_shared<swss::DBConnector>(CONFIG_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); |
There was a problem hiding this comment.
std:: [](start = 22, length = 5)
you can remove 'std::' #Closed
There was a problem hiding this comment.
yes. It can be removed.
| return entries.size(); | ||
| } | ||
|
|
||
| struct AclTestBase : public ::testing::Test { |
There was a problem hiding this comment.
AclTestBase [](start = 7, length = 11)
Name is confusing. Has nothing related Acl. #Closed
There was a problem hiding this comment.
I think the name is no confuse. That is base class of AclTest and AclOrchTest.
tests/aclorch_ut.cpp
Outdated
|
|
||
| void SetUp() override | ||
| { | ||
| assert(gCrmOrch == nullptr); |
There was a problem hiding this comment.
assert [](start = 8, length = 6)
the same #Closed
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I've put the unit test for how to use the code in saispy_ut.cpp can you check it first ?
|
@lguohan Could you help add a PR check for the unit test? #Closed |
|
Should I add |
|
Hi @lguohan, I found the check error is Should we continue to review the code. At meantime monitor the error status ? What's your suggestion ? |
|
Hi @lguohan @qiluo-msft , I find the test in I found Do you think ... if add a |
tests/aclorch_ut.cpp
Outdated
| 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; |
There was a problem hiding this comment.
sai_acl_api [](start = 12, length = 11)
It abuses the design of deleter that you modify lambda-captured variable. #Closed
There was a problem hiding this comment.
No, it is the raw pointer ... however, I move the allocate/delete into SetUp() and TearDown().
tests/aclorch_ut.cpp
Outdated
|
|
||
| using namespace std; | ||
|
|
||
| static size_t consumerAddToSync(Consumer* consumer, const deque<KeyOpFieldsValuesTuple>& entries) |
There was a problem hiding this comment.
As I know static won't work here.
It's only C keyword for local functions
There was a problem hiding this comment.
Will remove static keyword.
tests/aclorch_ut.cpp
Outdated
| acltable.type = ACL_TABLE_L3; | ||
| auto res = createAclTable(acltable); | ||
|
|
||
| ASSERT_TRUE(res->ret_val == true); |
There was a problem hiding this comment.
ASSERT_TRUE(res->ret_val);
It's already about true or not.
Otherwise we need to use ASSERT_EQ()
tests/aclorch_ut.cpp
Outdated
| }; | ||
|
|
||
| auto status = sai_api_initialize(0, (sai_service_method_table_t*)&test_services); | ||
| ASSERT_TRUE(status == SAI_STATUS_SUCCESS); |
There was a problem hiding this comment.
Yes, will fix it.
tests/aclorch_ut.cpp
Outdated
| { APP_LAG_MEMBER_TABLE_NAME, portsorch_base_pri } | ||
| }; | ||
|
|
||
| assert(gPortsOrch == nullptr); |
There was a problem hiding this comment.
Should we use ASSERT_EQ here?
There was a problem hiding this comment.
Yes, will fix it.
pavel-shirshov
left a comment
There was a problem hiding this comment.
Please address my comments.
Please use proper ASSERT_*.
|
ok to me. Still @lguohan please help add PR checker. #Closed |
|
Hi @lguohan, |
|
Hi @lguohan, |
tests/saispy_ut.cpp
Outdated
| sai_object_id_t oid; | ||
|
|
||
| auto status = acl_api->create_acl_table(&oid, 1, 0, nullptr); | ||
| ASSERT_TRUE(oid == 1); |
There was a problem hiding this comment.
Can you please use ASSERT_EQ?
tests/saispy_ut.cpp
Outdated
|
|
||
| auto status = acl_api->create_acl_table(&oid, 1, 0, nullptr); | ||
| ASSERT_TRUE(oid == 1); | ||
| ASSERT_TRUE(status == SAI_STATUS_SUCCESS); |
There was a problem hiding this comment.
Can you please use ASSERT_EQ?
tests/saispy_ut.cpp
Outdated
| ASSERT_TRUE(status == SAI_STATUS_SUCCESS); | ||
|
|
||
| status = acl_api->remove_acl_table(2); | ||
| ASSERT_TRUE(status == SAI_STATUS_SUCCESS); |
There was a problem hiding this comment.
Can you please use ASSERT_EQ?
tests/saispy_ut.cpp
Outdated
| auto z_spy_ref = &z->spy; | ||
|
|
||
| acl_api->create_acl_table(&oid, 1, 0, nullptr); | ||
| ASSERT_TRUE(oid == exp_oid_1); |
There was a problem hiding this comment.
Can you please use ASSERT_EQ? here and below
|
retest this please |
|
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 ? |
|
Do any suggestions for this pull request ? |
|
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. |
|
Hi @lguohan, Is OK to you ? |
|
Hi @lguohan, After check the |
|
Hi @lguohan, Does your means is: Then add new test command in Jenkins for build script ? |
|
@yehjunying , check this one. https://www.systutorials.com/docs/linux/man/1-dh_auto_test/ |
|
Code merged by #924 |
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]>
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]>
* 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]>
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 intolibvsvia 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]