-
Notifications
You must be signed in to change notification settings - Fork 549
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
[UT] [Portsyncd] Added Unit Tests for portsyncd #2297
Merged
Merged
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1c6cd64
Refactored portsyncd structure to improve testability
vivekrnv 0ce3d92
Merge branch 'Azure:master' into ut_infra_improv
vivekrnv 7395544
Skeleton for portsyncd ut added
vivekrnv b98badf
Merge branch 'ut_infra_improv' of https://github.com/vivekreddynv/son…
vivekrnv dc384cd
Minor update
vivekrnv bc7528a
Class Init and reading from cfg_db ut's added
vivekrnv e052e20
Added missing comment
vivekrnv e267fd9
onMsg test added
vivekrnv 67a086d
2 new test cases added
vivekrnv 64a8ee1
Another case added
vivekrnv 6909333
Push infra modifications
vivekrnv 7f26e83
Moved common methods/ds to a different file
vivekrnv 0402330
bullseye link issue handled
vivekrnv 0523b8c
Merge branch 'master' of https://github.com/Azure/sonic-swss into ut_…
vivekrnv 8a3c138
Update UT to include ASAN changes
vivekrnv dfcba64
Restored original del func on mock_table
vivekrnv 1bc2d97
Refactored mock shell cmd
vivekrnv 6134e80
Minor fix
vivekrnv f757668
Merge branch 'master' of https://github.com/Azure/sonic-swss into ut_…
vivekrnv 06edeb9
Refactored mock_tests/ folder
vivekrnv 98b6358
p4orch tests updated
vivekrnv d436281
Revert "p4orch tests updated"
vivekrnv 70099b4
Revert "Refactored mock_tests/ folder"
vivekrnv 41d31e8
Moved the fun/global vars to orig location and removed tests
vivekrnv 94b9e30
Minor deviations
vivekrnv aa8e7e7
Minor deviations
vivekrnv 1edb07c
Merge branch 'sonic-net:master' into ut_infra_improv
vivekrnv 42cbbcf
Merge branch 'sonic-net:master' into ut_infra_improv
vivekrnv e974c82
Merge branch 'sonic-net:master' into ut_infra_improv
vivekrnv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "portsyncd/linksync.h" | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
/* | ||
* This g_portSet contains all the front panel ports that the corresponding | ||
* host interfaces needed to be created. When this LinkSync class is | ||
* initialized, we check the database to see if some of the ports' host | ||
* interfaces are already created and remove them from this set. We will | ||
* remove the rest of the ports in the set when receiving the first netlink | ||
* message indicating that the host interfaces are created. After the set | ||
* is empty, we send out the signal PortInitDone. g_init is used to limit the | ||
* command to be run only once. | ||
*/ | ||
set<string> g_portSet; | ||
bool g_init; | ||
|
||
static void notifyPortConfigDone(ProducerStateTable &p) | ||
{ | ||
/* Notify that all ports added */ | ||
FieldValueTuple finish_notice("count", to_string(g_portSet.size())); | ||
vector<FieldValueTuple> attrs = { finish_notice }; | ||
p.set("PortConfigDone", attrs); | ||
} | ||
|
||
void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
SWSS_LOG_NOTICE("Getting port configuration from ConfigDB..."); | ||
|
||
Table table(&cfgDb, CFG_PORT_TABLE_NAME); | ||
std::vector<FieldValueTuple> ovalues; | ||
std::vector<string> keys; | ||
table.getKeys(keys); | ||
|
||
if (keys.empty()) | ||
{ | ||
SWSS_LOG_NOTICE("ConfigDB does not have port information, " | ||
"however ports can be added later on, continuing..."); | ||
} | ||
|
||
for ( auto &k : keys ) | ||
{ | ||
table.get(k, ovalues); | ||
vector<FieldValueTuple> attrs; | ||
for ( auto &v : ovalues ) | ||
{ | ||
FieldValueTuple attr(v.first, v.second); | ||
attrs.push_back(attr); | ||
} | ||
if (!warm) | ||
{ | ||
p.set(k, attrs); | ||
} | ||
g_portSet.insert(k); | ||
} | ||
if (!warm) | ||
{ | ||
notifyPortConfigDone(p); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <string> | ||
#include <vector> | ||
|
||
/* Override this pointer for custom behavior */ | ||
int (*callback)(const std::string &cmd, std::string &stdout) = nullptr; | ||
|
||
int mockCmdReturn = 0; | ||
std::string mockCmdStdcout = ""; | ||
std::vector<std::string> mockCallArgs; | ||
|
||
namespace swss { | ||
int exec(const std::string &cmd, std::string &stdout) | ||
{ | ||
if (callback != nullptr) | ||
{ | ||
return callback(cmd, stdout); | ||
} | ||
else | ||
{ | ||
mockCallArgs.push_back(cmd); | ||
stdout = mockCmdStdcout; | ||
return mockCmdReturn; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we discussed it last time, please move this to portsyncd itself. I don't see a reason why it has to be part of helper file and cause merge conflicts for future bug fixes.
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.
If these are moved back to portsyncd.cpp, i won't be able to test those since i can't link my test binary with portsyncd.cpp. Because with gtest we already link it with -lgtest_main so the linker wouldn't allow another main() function to be present in any other files. Thus i need a seperate file to test handlePortConfigFromConfigDB method and g_portSet