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

SAI PTF 2: sai_base_test infra #1335

Merged
merged 15 commits into from Dec 22, 2021
Merged

Conversation

aljer
Copy link
Contributor

@aljer aljer commented Nov 2, 2021

The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

  • sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
  • sai_base_test.py - python module with base test classes with common tests configuration
  • sai_utils.py - python module with some helper function used in SAI PTF tests
  • saitest.py - first test module with simple framework test

Aleksandra Jereczek added 4 commits November 2, 2021 19:52
Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Nov 2, 2021

This pull request introduces 36 alerts when merging 855a461 into 422fc84 - view on LGTM.com

new alerts:

  • 32 for Imprecise assert
  • 3 for 'import *' may pollute namespace
  • 1 for Module is imported with 'import' and 'import from'

@ravi861
Copy link
Contributor

ravi861 commented Nov 2, 2021

@rlhui @richardyu-ms fyi

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Nov 3, 2021

This pull request introduces 36 alerts when merging dfc9e0a into be03407 - view on LGTM.com

new alerts:

  • 32 for Imprecise assert
  • 3 for 'import *' may pollute namespace
  • 1 for Module is imported with 'import' and 'import from'

Aleksandra Jereczek added 2 commits November 3, 2021 13:20
Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Nov 3, 2021

This pull request introduces 36 alerts when merging d371ec0 into be03407 - view on LGTM.com

new alerts:

  • 32 for Imprecise assert
  • 3 for 'import *' may pollute namespace
  • 1 for Module is imported with 'import' and 'import from'

@@ -0,0 +1,870 @@
/**
* Copyright (c) 2021 Microsoft Open Technologies, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this file be located in ptf directory ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file make use of autogenerated RPC code which also is to be placed in meta directory and its subdirectories. Please see: https://github.com/opencomputeproject/SAI/pull/1325/files

Copy link
Contributor

Choose a reason for hiding this comment

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

We can maybe allow the gensairpc script to allow to generate the files in a different directory than meta as an argument. Would it help if we create a top-level "thriftrpc" directory to place this and other related files?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kcudnik - please confirm?

Copy link
Collaborator

Choose a reason for hiding this comment

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

what should i confirm here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kcudnik - wanted to make sure if we're in agreement on "create a top-level "thriftrpc" directory to place this and other related files"

Copy link
Collaborator

Choose a reason for hiding this comment

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

that should be fine

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Nov 4, 2021

This pull request introduces 36 alerts when merging 6cfeabc into be03407 - view on LGTM.com

new alerts:

  • 32 for Imprecise assert
  • 3 for 'import *' may pollute namespace
  • 1 for Module is imported with 'import' and 'import from'

@rlhui
Copy link
Collaborator

rlhui commented Nov 16, 2021

Adding @smaheshm to review as well.

@kcudnik
Copy link
Collaborator

kcudnik commented Dec 9, 2021

new alerts:

  • 32 for Imprecise assert
  • 3 for 'import *' may pollute namespace
  • 1 for Module is imported with 'import' and 'import from'

please address LGTM issues

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 9, 2021

This pull request introduces 2 alerts when merging acd7f69 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

@aljer
Copy link
Contributor Author

aljer commented Dec 9, 2021

This pull request introduces 2 alerts when merging acd7f69 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

@kcudnik I addressed almost all issues. Those two which remain are required from the perspective of tests infrastructure.

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 10, 2021

This pull request introduces 2 alerts when merging ddcba71 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 10, 2021

This pull request introduces 2 alerts when merging 6d10ea9 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

@smaheshm
Copy link
Contributor

Regarding "sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included"

Why not keep these two separate? why mix auto generated file with manual addition?

@ravi861
Copy link
Contributor

ravi861 commented Dec 11, 2021

Regarding "sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included"

Why not keep these two separate? why mix auto generated file with manual addition?

The helper functions are defined in sai_rpc_frontend.cpp and used in the generated sai_rpc_server.cpp.
The sai_rpc_server.cpp is a large class definition with all the member functions declared and defined inline and use the handwritten helper functions.
So there is a circular dependency on who includes the other. The sai_rpc_server.cpp is included in sai_rpc_frontend.cpp with a #include right after the helper function definitions, which, I agree is a little unconventional.


using namespace ::sai;

unsigned int sai_thrift_mac_t_parse(const std::string s, void *data) {
Copy link
Contributor

@smaheshm smaheshm Dec 13, 2021

Choose a reason for hiding this comment

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

can you add comments to describe what the functions are doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will add them

return (j == 12);
}

void sai_thrift_ip4_t_parse(const std::string s, unsigned int *m) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding unit tests for the APIs performing SAI thrift to SAI and vice versa.

#include "sai_rpc_server.cpp"

class sai_rpcHandlerFrontend : virtual public sai_rpcHandler {
int64_t sai_thrift_object_type_get_availability(
Copy link
Contributor

Choose a reason for hiding this comment

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

curious why this (and others) had to be written manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These two manually written 'sai_thrift_' functions are specific and they don't match the patterns the generator is working with. There are only two of such functions related to CRM verification.

time.sleep(timeout + aging_interval_buffer)


class SaiHelper(SaiHelperBase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to rename this class since it sets up a specific configuration that all tests may not be able to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean this class should not be named "SaiHelper"? Actually this class "helps" to set designed configuration which we use in most of the tests. This is even more common than using SaiHelperBace as a parent class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Most tests which are being upstreamed use this as the base class and use the configuration defined in this class. New tests may choose to use SaiHelperBase instead to define their own configuration.

@smaheshm
Copy link
Contributor

Rest looks good. I think adding unit tests (gtests) to the conversion APIs will be useful to catch regression when someone changes those functions.

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 15, 2021

This pull request introduces 2 alerts when merging d558751 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

…tests

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 15, 2021

This pull request introduces 2 alerts when merging d2cbed8 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

ptf/lpm.py Outdated

Please check the test_lpm.py file to see the details of how this class works.
'''
class LpmDict():
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this object instantiated? If not used can you remove this file and add when it's being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This module is to be used in saiswitch tests that will be upstreamed soon. But in general it is a part of the infrastructure and may be used in any other test modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Code shouldn't be added with the assumption it will be used, this way we may end up with unused code lying around. Can you remove this file and add it when it's being used, i.e. along with saiswitch tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, as you wish

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 16, 2021

This pull request introduces 2 alerts when merging 953dd9f into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
@lgtm-com
Copy link

lgtm-com bot commented Dec 16, 2021

This pull request introduces 2 alerts when merging a5a7d94 into 05648bc - view on LGTM.com

new alerts:

  • 2 for 'import *' may pollute namespace

@smaheshm
Copy link
Contributor

thanks for removing the file. can you address the LGTM alerts.

@aljer
Copy link
Contributor Author

aljer commented Dec 16, 2021

thanks for removing the file. can you address the LGTM alerts.

@smaheshm As I explained here #1335 (comment) these two imports causing the alerts are required by all other test modules. This is one of a framework assumptions.

Copy link
Contributor

@smaheshm smaheshm left a comment

Choose a reason for hiding this comment

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

:shipit:

@rlhui rlhui merged commit 0a18470 into opencomputeproject:master Dec 22, 2021
@aljer aljer deleted the sai_ptf_infra branch December 22, 2021 07:23
RyoYang pushed a commit to RyoYang/SAI that referenced this pull request Jan 5, 2022
The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
sai_base_test.py - python module with base test classes with common tests configuration
sai_utils.py - python module with some helper function used in SAI PTF tests
saitest.py - first test module with simple framework test

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
richardyu-ms added a commit that referenced this pull request Jan 6, 2022
[Cherry-Pick]SAI PTF 2: sai_base_test infra (#1335)
RyoYang pushed a commit to RyoYang/SAI that referenced this pull request Jan 26, 2022
The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
sai_base_test.py - python module with base test classes with common tests configuration
sai_utils.py - python module with some helper function used in SAI PTF tests
saitest.py - first test module with simple framework test

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
RyoYang pushed a commit to RyoYang/SAI that referenced this pull request Mar 14, 2022
The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
sai_base_test.py - python module with base test classes with common tests configuration
sai_utils.py - python module with some helper function used in SAI PTF tests
saitest.py - first test module with simple framework test

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
RyoYang pushed a commit to RyoYang/SAI that referenced this pull request Mar 14, 2022
The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
sai_base_test.py - python module with base test classes with common tests configuration
sai_utils.py - python module with some helper function used in SAI PTF tests
saitest.py - first test module with simple framework test

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
RyoYang pushed a commit to RyoYang/SAI that referenced this pull request Mar 14, 2022
The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
sai_base_test.py - python module with base test classes with common tests configuration
sai_utils.py - python module with some helper function used in SAI PTF tests
saitest.py - first test module with simple framework test

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>
richardyu-ms added a commit that referenced this pull request Mar 14, 2022
* SAI PTF 1: Proposal (#1325)

This is an autogeneration framework for PTF based SAI tests.  Before in order to add a new test it is necessary to:

1. Add an entry in switch_sai.thrift.
2. Add RPC server method for new entry in switch_sai_rpc_server.cpp.
3. Add a python wrapper in switch.py (if applicable).
4. Write a new test

The main goal of autogeneration framework is to generate first three steps based on SAI headers to facilitate the process of writing new tests.

* Create SAI-Proposal-SAI_PTF.md
* Adding generator script
* New makefile target and cleanup

Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* SAI PTF 2: sai_base_test infra (#1335)

The changes introduce SAI PTF framework base tests infrastructure. Following files have been added:

sai_rpc_frontend.cpp - RPC server frontend file - there is a set of manually written helper functions that converts/parses SAI and thrift attributes and also here we have autogenerated SAI RPC server functions included
sai_base_test.py - python module with base test classes with common tests configuration
sai_utils.py - python module with some helper function used in SAI PTF tests
saitest.py - first test module with simple framework test

Signed-off-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* Proposal for init switch and destroy switch from PRC (#1387)

keep the switch id in creat_switch and remove it from remove_switch

1. support to create the create_switch only once before the test run and use the same switch id within multi-round of testing
2. support remove the switch id

Signed-off-by: Richard Yu <richard.yu@microsoft.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* [SAIServer]Add new SaiServer to support ptf-SAI test structure (#1388)

* [SAIServer]Add new SaiServer to support ptf-SAI test structure

Add build script to generate the necessary package as saiserverv2
Add new saiserver to support new structure - without switch init and with thrift 0.13.0
Add makefile
add sai_rpc_frontend
simplify saiserver and remove init method
add permission for copy_saithriftv2.s
copy saiserver at dh builddeb

ctypesgen for sai-ptf and install python-saithrift for two version

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* add a package name for sai_adapter

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* address review comments

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* add more comments for the command in the Makefile

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* Add platform support and a sanity test sample (#1390) (#1415)

* Add a middle layer (strategy and factory) under the test cases which can

no more if-else for platform selecting
no more code injection for different platforms, just need to abstract to a method on the differences
auto select the platform by the parameters in the test starter (shell, happed in run_p4_tests, not published here)
easy-distinct structure for the difference from platforms
prepared for future statistic
Add a sanity sample, it can

configure across all the ports (base on port's configuration file)
simple FDB and VLAN naming according to port's number
make a basic check on the status of the devices
use as a sample for how to use the new middle layer

fix and suppress LGTM alters

Signed-off-by: Richard Yu <richard.yu@microsoft.com>

* code refactor part I

- add comments for class and method
- reformat code
- move platform related method to corresponding class

code refactor Part II

optimize the class hirerarchy
simplify the import items
add more docs

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>

* suppress lgtm warnings

fix lgtm warning

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* [FIX]Fix the circular reference issue when build sai header py (#1427)

Fix circular reference issue.

Test done:
build the saiserver and check the sai_headers.py

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* Skip brcm teardown assertion (#1423) (#1428)

Signed-off-by: Yang Wang <yangwang1@microsoft.com>

* Add two more API as RPC for warmboot testing (#1421) (#1437)

try to expose the sai api object_type_query and switch_id_query for
warmboot testing
Modify the template file for generate code from meta.

Signed-off-by: richardyu-ms <richard.yu@microsoft.com>
Signed-off-by: Yang Wang <yangwang1@microsoft.com>

Co-authored-by: Patrycja Kochmanska <patrycja.kochmanska@intel.com>
Co-authored-by: Aleksandra Jereczek <aleksandra.jereczek@intel.com>
Co-authored-by: Richard.Yu <richard.yu@microsoft.com>
Comment on lines +799 to +800
// including it here we never have to modify the generated file
#include "sai_rpc_server.cpp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is wrong way to do it :(

Comment on lines +407 to +423
switch_resources = sai_thrift_get_switch_attribute(
self.client,
available_ipv4_route_entry=True,
available_ipv6_route_entry=True,
available_ipv4_nexthop_entry=True,
available_ipv6_nexthop_entry=True,
available_ipv4_neighbor_entry=True,
available_ipv6_neighbor_entry=True,
available_next_hop_group_entry=True,
available_next_hop_group_member_entry=True,
available_fdb_entry=True,
available_ipmc_entry=True,
available_snat_entry=True,
available_dnat_entry=True,
available_double_nat_entry=True,
number_of_ecmp_groups=True,
ecmp_members=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is actually wrong approach, since not a lot of vendors has those implemented, for example current DASH implementation, and this function will throw sai thrift exception if any of those values will not be success, and this will then generate SkipTest exception if error is SAI_STATUS_NOT_SUPPORTED, which is what happens, and many test will/can be skipped if those values are not present, but they not prevent actually for test to be executed, each test should handle this independently or this function here should handle this in a way that if not supported, then set this resource to zero

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@kcudnik It does seem like the PTF infrastructure makes some assumptions about base capabilities of any SAI target which has caused some issues in DASH and forced some workarounds. It's arguable whether this is a flaw in the PTF framework and its assumptions, or that the DASH behavioral model falls too short of the mark for emulating a target in all its SAI support. Recent work by some vendors in SAI made many allowances for DASH such as supporting only 2-port devices, etc. but it didn't try to accommodate all the shortcomings if the current DASH behavioral model.

If there is opportunity to establish the capabilities/resources of the target and use that information to skip tests, that would be preferred.

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.

None yet

7 participants