From e5bb8b788966ee4407900ee92e0e38d55bd4d06c Mon Sep 17 00:00:00 2001 From: kcudnik Date: Mon, 28 Jun 2021 12:34:28 +0200 Subject: [PATCH] [meta] Add check for enum const values This check will make sure that enum values are constant from this point on all future commits. --- meta/Makefile | 1 + meta/checkenumlock.sh | 38 ++++++++++++++++++++++++++++++++++++++ meta/checkheaders.pl | 27 ++++++++++++++++++++++++++- meta/saisanitycheck.c | 12 ++++++------ 4 files changed, 71 insertions(+), 7 deletions(-) create mode 100755 meta/checkenumlock.sh diff --git a/meta/Makefile b/meta/Makefile index a64f3e655..af2dfd35f 100644 --- a/meta/Makefile +++ b/meta/Makefile @@ -77,6 +77,7 @@ SYMBOLS = $(OBJ:=.symbols) all: toolsversions saisanitycheck saimetadatatest saiserializetest saidepgraph.svg $(SYMBOLS) ./checkheaders.pl ../inc ../inc + ./checkenumlock.sh ./saimetadatatest >/dev/null ./saiserializetest >/dev/null ./saisanitycheck diff --git a/meta/checkenumlock.sh b/meta/checkenumlock.sh new file mode 100755 index 000000000..f143b3609 --- /dev/null +++ b/meta/checkenumlock.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright (c) 2014 Microsoft Open Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT +# LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS +# FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. +# +# Microsoft would like to thank the following companies for their review and +# assistance with these files: Intel Corporation, Mellanox Technologies Ltd, +# Dell Products, L.P., Facebook, Inc., Marvell International Ltd. +# +# @file checkenumlock.sh +# +# @brief This module defines SAI enum values integration check for 2 header directories +# + +set -e + +rm -rf temp + +mkdir temp + +git --work-tree=temp/ checkout origin/master inc + +echo "Checking for possible enum values shift (current branch vs origin/master) ..." + +./checkheaders.pl -s ../inc/ temp/inc/ + +rm -rf temp diff --git a/meta/checkheaders.pl b/meta/checkheaders.pl index e7ce93f3e..16138d279 100755 --- a/meta/checkheaders.pl +++ b/meta/checkheaders.pl @@ -31,6 +31,12 @@ use File::Temp qw/ tempfile /; use Data::Dumper; +use Getopt::Std; + +my %options = (); +getopts("s", \%options); + +my $optionSkipSingleDefined = 1 if defined $options{s}; use utils; @@ -176,9 +182,28 @@ sub CheckHash for my $key (sort keys %A) { + if (defined $optionSkipSingleDefined) + { + # ignore attributes end, since those will shift + next if $key =~ /^SAI_\w+_ATTR_END$/; + + next if $key eq "SAI_ACL_TABLE_ATTR_FIELD_END"; + next if $key eq "SAI_ACL_ENTRY_ATTR_FIELD_END"; + next if $key eq "SAI_ACL_ENTRY_ATTR_ACTION_END"; + + # NOTE: some other attributes/enum with END range could be added + } + if (not defined $B{$key}) { - LogError "enum $key only defined in $A{$key}{path}:$A{$key}{nr}"; + if (not defined $optionSkipSingleDefined) + { + LogError "enum $key only defined in $A{$key}{path}:$A{$key}{nr}" + } + else + { + LogInfo "enum $key only defined in $A{$key}{path}:$A{$key}{nr}" + } next; } diff --git a/meta/saisanitycheck.c b/meta/saisanitycheck.c index 5b90a7cff..bb69610ee 100644 --- a/meta/saisanitycheck.c +++ b/meta/saisanitycheck.c @@ -4615,7 +4615,7 @@ void check_get_attr_metadata() void check_acl_user_defined_field() { - SAI_META_LOG_ENTER(); + META_LOG_ENTER(); META_ASSERT_TRUE(SAI_ACL_USER_DEFINED_FIELD_ATTR_ID_RANGE > 0, "should be positive"); @@ -4628,14 +4628,14 @@ void check_acl_user_defined_field() void check_label_size() { - SAI_META_LOG_ENTER(); + META_LOG_ENTER(); META_ASSERT_TRUE(sizeof(sai_label_id_t) == sizeof(uint32_t), "label is expected to be 32 bit"); } void check_switch_notify_list() { - SAI_META_LOG_ENTER(); + META_LOG_ENTER(); size_t i; @@ -4651,7 +4651,7 @@ void check_switch_notify_list() void check_switch_pointers_list() { - SAI_META_LOG_ENTER(); + META_LOG_ENTER(); size_t i; @@ -4667,7 +4667,7 @@ void check_switch_pointers_list() void check_defines() { - SAI_META_LOG_ENTER(); + META_LOG_ENTER(); /* * Check if defines are equal to their static values. @@ -4679,7 +4679,7 @@ void check_defines() void check_object_type_attributes() { - SAI_META_LOG_ENTER(); + META_LOG_ENTER(); size_t i = 0;