-
Notifications
You must be signed in to change notification settings - Fork 273
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
[VOQ][saidump] Enhance saidump with new option -r to parser the JSON file and displays/format the right output, fix compiling error #1335
base: 202305
Are you sure you want to change the base?
Conversation
you will need to pass code coverage to merge this |
I checked the files sonic-slave-buster/Dockerfile.j2 and sonic-slave-bullseye/Dockerfile.j2. They all installed the library below. |
this is for codeql ? |
this is for code ql, edit sonic-sairedis/.github/workflows/codeql-analysis.yml 202305 branch |
Yes. And for the error during the stage of coverage.Azure.sonic-sairedis.amd64, I think I need add unit test codes to fix them, right? |
yes, for code coverage you need add unittests for that |
Hi, @kcudnik. I looked into the subdirectories: sonic-sairedis/tests and sonic-sairedis/unittest, there are not any existed saidump test codes. How did the previous saidump codes pass the code coverage test? Need I create a new code file sonic-sairedis/unittest/saidump/TestSaidump.cpp to do the whole unit test of it? Thanks. |
previous saidump passed since unittest coverage was enabled when saidump was already present that project is old, starting from 2016, and its not brought up to todays code quality standard, it would need to be converted to OOP and have classes for command line and command line parser and saidump itsel, and be converted to library with samall main.cpp file, which would gratefully improve testing abbility, please take a look at sairedis/saiplayer/*cpp and *.h and Makefile.am files as a base how it should be done in todays standard saiplayer also dont have unittest enabled, if you want to see strucutre how to place test files, you can take a look for vslib and syncd, but those are much complicated, of course you dont need to look everything, just the main concept, and saiplayer is good enough for that to easy understand |
and in the long run it will make sense to convert it o OOP since it will be more manageable to write future code and unittest, but at current state, its a lot of work to bring upfront |
@JunhongMao Any update on the requires test cases? |
you can make tests to code coverage this as is, but its not be easy, it will still needs to be converted to oop as suggested before, but that is even more work |
Hi, @kcudnik @gechiang, @mlok-nokia, the PRs of the similar modification have merged into the master branch. This PR is only intended to fix a compiling error of 202305 branch. Could we bypass this code-testing coverage issue to merge it first and create a new PR to fix the code-testing coverage issue in the future? What are the details of how to convert to OOP as suggested before? I think there will be more communication. As Kcudnik commented, much effort will be needed. Thanks. |
yes, you will need to make more changes in the test area to satisfy coverage |
@kcudnik , how to update this PR's checking policy to bypass the coverage check blocking? |
you cant bypass, you need to add unittests that will coverage the code in 80% |
@kcudnik, @gechiang @mlok-nokia , could we bypass this code-testing coverage issue to merge it first and create a new PR to fix the code-testing coverage issue in the future? I'm on leave. I will go back to the office and fix this issue next Monday. |
@kcudnik Junhong is new to this module. He may need some guideline how to add the UNIT test case. Is there any example which he can follow? Thanks. |
Usually each PR have unittests, please take a look a recent prs and into unittests directory, for those each file needs to be added corresponding with Test prefix and each function should be tested, if you need more info let me know |
Code coverage is strictly required policy from the top and is checked time to time, and we get into trouble for bypassing unittests |
@kcudnik Thanks. I'm working on it. |
72e11a1
to
3979646
Compare
Hi @kcudnik, I have added the unit test codes in sonic-sairedis\unittest\saidump, but the Coverage check results showed that the new unit test codes were not called. Could you help to check why? Thanks. Total: 95 lines |
unittest/saidump/main.cpp
Outdated
@@ -0,0 +1,55 @@ | |||
#include <gtest/gtest.h> | |||
#include "saidump.cpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't do that, don't include cpp files in another cpp files, i mentioned in comments that you would need to convert that saidump.cpp to library and then use taht library in the unittests, and saidump binary, then your test cases will be executed, since this file right now is treated as include not actual source, thats why is not covered even if tests are executed
Hi @kcudnik, I have converted the saidump.cpp to libsaidump.a. But there was still an error below: I checked the building scripts and found that they didn't include nlohmann-json3-dev. So, I think I need to create a separate PR that only installs nlohmann-json3-dev. After merging that PR, this PR could be checked successfully. What do you think of it? |
I created new PR: |
approved |
not sure why tou need json package if so far everything was compiling fine |
Why I did it During the process of fix PR1335, #1335 There was an error: dpkg-checkbuilddeps: error: Unmet build dependencies: nlohmann-json3-dev. I checked the building scripts and found that they didn't include nlohmann-json3-dev. So, I think I need to create a separate PR that only installs nlohmann-json3-dev. After merging that PR, the PR1335 could be checked successfully. sudo apt-get install -y libxml-simple-perl aspell
saidump/saidump.h
Outdated
}; | ||
|
||
void printUsage(); | ||
CmdOptions handleCmdLine(int argc, char **argv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not make global functions make them as static in class look for syncd commandline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kcudnik, could you please give more details about your comments? If I modified them as below:
static void printUsage();
staic CmdOptions handleCmdLine(int argc, char **argv);
When I compiling unittest/saidump, there were errors below:
jumao@8f4d6eacacca:/sonic/src/sonic-sairedis/unittest/saidump$ make check
g++ -DHAVE_CONFIG_H -I. -I../.. -g -I../../SAI/inc -I../../SAI/experimental -I../../SAI/meta -I../../saidump -I../../lib -I../../vslib -I../../meta -ansi -fPIC -std=c++14 -Wall -Wcast-align -Wcast-qual -Wconversion -Wdisabled-optimization -Werror -Wextra -Wfloat-equal -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Wno-inline -Winvalid-pch -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wno-aggregate-return -Wno-padded -Wno-switch-enum -Wno-unused-parameter -Wpacked -Wpointer-arith -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-aliasing=3 -Wswitch -Wswitch-default -Wunreachable-code -Wunused -Wvariadic-macros -Wwrite-strings -Wno-switch-default -Wconversion -Wno-psabi -Wcast-align=strict -g -O2 -MT tests-main.o -MD -MP -MF .deps/tests-main.Tpo -c -o tests-main.o `test -f 'main.cpp' || echo './'`main.cpp
In file included from main.cpp:3:
../../saidump/saidump.h:16:13: error: 'void printUsage()' declared 'static' but never defined [-Werror=unused-function]
16 | static void printUsage();
| ^~~~~~~~~~
../../saidump/saidump.h:16:13: error: 'void printUsage()' used but never defined [-Werror]
cc1plus: all warnings being treated as errors
make: *** [Makefile:496: tests-main.o] Error 1
Did you mean to add a saidump class to include all the functions? Such as below:
class saidump
{
static void printUsage();
staic CmdOptions handleCmdLine(int argc, char **argv);
}
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, take a look at command line options.cpp and h in syncs directory you didn't put syncd namespace and class sorsaidump for printusage hence error you get
@kcudnik @gechiang I found the failures of the below checks are wired. Azure.sonic-sairedis (Build amd64) Failing after 33m — Build amd64 failed The similar failures are excited in many recent commits below: |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
i think 202305 azpipeline eneeds to be updated |
This is why you get unit tests to fail you have a lot of white spaces in those lines Please carefully read errors on builds and tests |
Why I did it
Based on the PR1288
#1288
and the comment from gechiang
#1288 (comment)
in 202305, we should use "#include " swss/json.hpp " " other than #include <nlohmann/json.hpp>,
Below is the information on the PR1288.
Fix issue: sonic-net/sonic-buildimage#13561
The existing saidump use https://github.com/sonic-net/sonic-swss-common/blob/master/common/table_dump.lua script which loops the ASIC_DB more than 5 seconds and blocks other processes access.
This solution uses the redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table.
Related PRs:
sonic-net/sonic-utilities#2972
sonic-net/sonic-buildimage#16466
MSFT ADO: 25892357
How I did it
To use the Redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table and saving it.
How to verify it
Method 1
Method 2
docker exec -it syncd0 bash
root@ixre-egl-board40:/# saidump | sha1sum
821d442938028114b614bd810ecf844d564fd812 -
root@ixre-egl-board40:/# saidump.sh | sha1sum
821d442938028114b614bd810ecf844d564fd812 -
How to do unit tests manually.
jumao@4b61df49afa7:/sonic/src/sonic-sairedis/unittest
Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)