Skip to content

Commit

Permalink
Use SAI_STATUS_ITEM_NOT_FOUND when key not found (#1224)
Browse files Browse the repository at this point in the history
* Use SAI_STATUS_ITEM_NOT_FOUND when key not found
* Add unit tests for Meta SAI validation
* generate coverage info for Meta.cpp

Signed-off-by: Lawrence Lee <[email protected]>
  • Loading branch information
theasianpianist authored Apr 19, 2023
1 parent e311587 commit dc93d4c
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 20 deletions.
9 changes: 8 additions & 1 deletion .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,14 @@ jobs:
make check
gcovr --version
find SAI/meta -name "*.gc*" | xargs rm -vf
gcovr -r ./ -e ".*/SAI/.*" -e ".+/json.hpp" -e "swss/.+" -e ".*/.libs/.*" -e ".*/debian/.*" --exclude-unreachable-branches -x --xml-pretty -o coverage.xml
gcov_dirs=$(find . -path "*.libs*gcda" | xargs dirname | sort -u | cut -c"3-")
for dir in ${gcov_dirs}; do
source_dir=$(dirname $dir)
output_file="coverage-$source_dir.json"
gcovr --exclude-unreachable-branches --json-pretty -o $output_file --object-directory $source_dir $dir
done
gcovr -r ./ -e ".*/SAI/.*" -e ".+/json.hpp" -e "swss/.+" -e ".*/.libs/.*" -e ".*/debian/.*" --exclude-unreachable-branches --json-pretty -o coverage-all.json
gcovr -a "coverage-*.json" -x --xml-pretty -o coverage.xml
displayName: "Run sonic sairedis unit tests"
- publish: $(System.DefaultWorkingDirectory)/
artifact: ${{ parameters.artifact_name }}
Expand Down
36 changes: 18 additions & 18 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3258,7 +3258,7 @@ sai_status_t Meta::meta_generic_validation_remove(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

auto info = sai_metadata_get_object_type_info(meta_key.objecttype);
Expand Down Expand Up @@ -3540,7 +3540,7 @@ sai_status_t Meta::meta_sai_validate_oid(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_oid).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -3883,7 +3883,7 @@ sai_status_t Meta::meta_sai_validate_mcast_fdb_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_bv).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// check if fdb entry exists
Expand All @@ -3910,7 +3910,7 @@ sai_status_t Meta::meta_sai_validate_mcast_fdb_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_fdb).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// fdb entry is valid
Expand Down Expand Up @@ -3980,7 +3980,7 @@ sai_status_t Meta::meta_sai_validate_neighbor_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_rif).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

sai_object_meta_key_t meta_key_neighbor = { .objecttype = SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, .objectkey = { .key = { .neighbor_entry = *neighbor_entry } } };
Expand All @@ -4005,7 +4005,7 @@ sai_status_t Meta::meta_sai_validate_neighbor_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_neighbor).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// neighbor entry is valid
Expand Down Expand Up @@ -4087,7 +4087,7 @@ sai_status_t Meta::meta_sai_validate_route_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_vr).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// check if route entry exists
Expand All @@ -4114,7 +4114,7 @@ sai_status_t Meta::meta_sai_validate_route_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_route).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -4210,7 +4210,7 @@ sai_status_t Meta::meta_sai_validate_l2mc_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_bv).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// check if l2mc entry exists
Expand All @@ -4237,7 +4237,7 @@ sai_status_t Meta::meta_sai_validate_l2mc_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_route).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -4333,7 +4333,7 @@ sai_status_t Meta::meta_sai_validate_ipmc_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_bv).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// check if ipmc entry exists
Expand All @@ -4360,7 +4360,7 @@ sai_status_t Meta::meta_sai_validate_ipmc_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_route).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -4416,7 +4416,7 @@ sai_status_t Meta::meta_sai_validate_nat_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_vr).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// check if NAT entry exists
Expand All @@ -4441,7 +4441,7 @@ sai_status_t Meta::meta_sai_validate_nat_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_nat).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -4515,7 +4515,7 @@ sai_status_t Meta::meta_sai_validate_my_sid_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_vr).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// check if my_sid_entry exists
Expand All @@ -4540,7 +4540,7 @@ sai_status_t Meta::meta_sai_validate_my_sid_entry(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key_my_sid_entry).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -5722,7 +5722,7 @@ sai_status_t Meta::meta_generic_validation_set(
META_LOG_ERROR(md, "object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

// object exists in DB so we can do "set" operation
Expand Down Expand Up @@ -6034,7 +6034,7 @@ sai_status_t Meta::meta_generic_validation_get(
SWSS_LOG_ERROR("object key %s doesn't exist",
sai_serialize_object_meta_key(meta_key).c_str());

return SAI_STATUS_INVALID_PARAMETER;
return SAI_STATUS_ITEM_NOT_FOUND;
}

auto info = sai_metadata_get_object_type_info(meta_key.objecttype);
Expand Down
Loading

0 comments on commit dc93d4c

Please sign in to comment.