From 90f42aec83281cd141fdec463477dd6acba0bdac Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 16 May 2024 19:56:25 +0200 Subject: [PATCH 1/3] Add check for global SAI api used This test will make sure only SAI global api are used in expected places --- tests/Makefile.am | 2 +- tests/checksaiapi.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 tests/checksaiapi.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index 7405bab0d..b86eb095b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,4 +33,4 @@ testdash_gtest_LDADD = -lgtest -lhiredis -lswsscommon -lpthread \ $(top_srcdir)/lib/libsairedis.la $(top_srcdir)/syncd/libSyncd.a \ -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) -TESTS = aspellcheck.pl conflictnames.pl swsslogentercheck.sh checkwhitespace.sh tests BCM56850.pl MLNX2700.pl BCM56971B0.pl NVDAMBF2H536C.pl testdash_gtest +TESTS = checksaiapi.sh aspellcheck.pl conflictnames.pl swsslogentercheck.sh checkwhitespace.sh tests BCM56850.pl MLNX2700.pl BCM56971B0.pl NVDAMBF2H536C.pl testdash_gtest diff --git a/tests/checksaiapi.sh b/tests/checksaiapi.sh new file mode 100755 index 000000000..508198925 --- /dev/null +++ b/tests/checksaiapi.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# this script checks if only allowed files are using global sai apis + +# in entire project we only allow VendorSai.cpp and saisdkdump.cpp to use global SAI API, + +# PLEASE DO NOT ADD ANY MORE EXCEPTIONS + +# we want to keep track of usage global apis to minimize scope of usage for +# possible future mistakes that we will be using dynmically loaded libsai.so +# and by mistake someone will be calling global api that was linked with syncd, +# this will be hard error to locate + +set -e + +cd .. + +find -name "*.o" | +grep -v pyext | +grep -v tests | +while read all; +do + echo -n $all; + nm $all | + grep "U sai_" | + grep -vP "sai_metadata|sai_serialize|sai_deserialize" | + perl -npe 'chomp' + echo +done | +grep "U sai_" | +awk '{print $1}' | +perl -ne 'chomp; die "file $_ is using global sai_xxx API, please correct your code" if not /VendorSai.o|saisdkdump/' + +REGEX=`cat SAI/meta/saimetadata.c|grep dlsym|grep handle|perl -ne 'print "$1|" if /(sai_\w+)/'|perl -pe 'chop'|perl -ne 'print "\\\\b($_)\\\\b"'` + +set +e +find -name "*.cpp" -o -name "*.c" | +xargs grep -P "$REGEX" | +grep -vP "/unittest/|/tests/|/SAI/|/pyext/|tests.cpp|sai_vs_interfacequery|sai_redis_interfacequery|saisdkdump|SWSS_LOG|.cpp:\s+\*|.cpp:\s+//|sai_status_t\s+sai_|VendorSai.cpp:.+=\s*&sai_" + +if [ $? == 0 ]; then + echo not allowed files are using global sai_xxx API, please correct your code, only VendorSai.cpp and saisdkdump are allowed to use global SAI apis + exit 1 +fi + From e9fce53521fcaddc557d24137483fdfc0f8d8b8e Mon Sep 17 00:00:00 2001 From: kcudnik Date: Mon, 20 May 2024 19:25:46 +0200 Subject: [PATCH 2/3] Fix white space --- tests/checksaiapi.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/checksaiapi.sh b/tests/checksaiapi.sh index 508198925..6353fbcd6 100755 --- a/tests/checksaiapi.sh +++ b/tests/checksaiapi.sh @@ -16,17 +16,17 @@ set -e cd .. find -name "*.o" | -grep -v pyext | -grep -v tests | -while read all; -do - echo -n $all; - nm $all | - grep "U sai_" | - grep -vP "sai_metadata|sai_serialize|sai_deserialize" | +grep -v pyext | +grep -v tests | +while read all; +do + echo -n $all; + nm $all | + grep "U sai_" | + grep -vP "sai_metadata|sai_serialize|sai_deserialize" | perl -npe 'chomp' echo -done | +done | grep "U sai_" | awk '{print $1}' | perl -ne 'chomp; die "file $_ is using global sai_xxx API, please correct your code" if not /VendorSai.o|saisdkdump/' From 0984a91169d265f1bb197083f26f45c2625f1885 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Fri, 24 May 2024 13:09:10 +0200 Subject: [PATCH 3/3] trigger