Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aclorch] unittest by gtest #924

Merged
merged 1 commit into from
Jun 6, 2019
Merged

[aclorch] unittest by gtest #924

merged 1 commit into from
Jun 6, 2019

Conversation

yehjunying
Copy link
Contributor

@yehjunying yehjunying commented Jun 5, 2019

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 junying_yeh@edge-core.com

@yehjunying
Copy link
Contributor Author

yehjunying commented Jun 5, 2019

Console output of Jenkins

make[1]: Leaving directory '/sonic/sonic-swss'
   debian/rules override_dh_auto_test
make[1]: Entering directory '/sonic/sonic-swss'
./tests/tests
Running main() from gtest_main.cc
[==========] Running 52 tests from 5 test cases.
[----------] Global test environment set-up.
...
[----------] 1 test from AclTest
[ RUN      ] AclTest.Create_L3_Acl_Table
[       OK ] AclTest.Create_L3_Acl_Table (1 ms)
[----------] 1 test from AclTest (1 ms total)

[----------] 3 tests from AclOrchTest
[ RUN      ] AclOrchTest.ACL_Creation_and_Destorying
[       OK ] AclOrchTest.ACL_Creation_and_Destorying (1001 ms)
[ RUN      ] AclOrchTest.L3Acl_Matches_Actions
[       OK ] AclOrchTest.L3Acl_Matches_Actions (1000 ms)
[ RUN      ] AclOrchTest.L3V6Acl_Matches_Actions
[       OK ] AclOrchTest.L3V6Acl_Matches_Actions (1001 ms)
[----------] 3 tests from AclOrchTest (3002 ms total)

[----------] Global test environment tear-down
[==========] 52 tests from 5 test cases ran. (3013 ms total)
[  PASSED  ] 52 tests.
make[1]: Leaving directory '/sonic/sonic-swss'
   create-stamp debian/debhelper-build-stamp
 fakeroot debian/rules binary
dh binary  --with autotools-dev

@@ -0,0 +1,104 @@
#Language: Cpp
AccessModifierOffset: -4
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice, does it get applied in the build or test process? if not, how should we enable it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First need install clang-format. Before build process, apply clang-format to committed files (or all files) and save the result into a tmp folder. Then compare committed files and files in tmp folder. If all files are the same, means submitter do clang-format before send PR.

Current I do it locally to make sure every files have the same style, follow aclorch.cpp nearly.
But it shall be another task if we want to enable it in build or test process.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to add enforce the format check on the pr test. can you add clang-format in the sonic-slave-stretch, and add a small script to perform the check. Then, i can run it in the pr test.

@stcheng
Copy link
Contributor

stcheng commented Jun 5, 2019

thanks for adding the tests

@lguohan lguohan merged commit 9d69dd5 into sonic-net:master Jun 6, 2019
EdenGri pushed a commit to EdenGri/sonic-swss that referenced this pull request Feb 28, 2022
oleksandrivantsiv pushed a commit to oleksandrivantsiv/sonic-swss that referenced this pull request Mar 1, 2023
* Add macsec xpn support

Signed-off-by: Ze Gan <ganze718@gmail.com>

* Add unit test for loadMACsecAttrFromMACsecSC

Signed-off-by: Ze Gan <ganze718@gmail.com>

* Add SWSS_LOG_ENTER

Signed-off-by: Ze Gan <ganze718@gmail.com>

* Fix bug and refactor code

Signed-off-by: Ubuntu <zegan@zegan-test-hk.0y0yh0pwahvetntlrcfftojvof.hx.internal.cloudapp.net>

Co-authored-by: Ubuntu <zegan@zegan-test-hk.0y0yh0pwahvetntlrcfftojvof.hx.internal.cloudapp.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants