1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4NUM_NETIFS=1 5source devlink_lib_spectrum.sh 6 7setup_prepare() 8{ 9 devlink_sp_read_kvd_defaults 10} 11 12cleanup() 13{ 14 pre_cleanup 15 devlink_sp_size_kvd_to_default 16} 17 18trap cleanup EXIT 19 20setup_prepare 21 22profiles_test() 23{ 24 local i 25 26 log_info "Running profile tests" 27 28 for i in $KVD_PROFILES; do 29 RET=0 30 devlink_sp_resource_kvd_profile_set $i 31 log_test "'$i' profile" 32 done 33 34 # Default is explicitly tested at end to ensure it's actually applied 35 RET=0 36 devlink_sp_resource_kvd_profile_set "default" 37 log_test "'default' profile" 38} 39 40resources_min_test() 41{ 42 local size 43 local i 44 local j 45 46 log_info "Running KVD-minimum tests" 47 48 for i in $KVD_CHILDREN; do 49 RET=0 50 size=$(devlink_resource_get kvd "$i" | jq '.["size_min"]') 51 devlink_resource_size_set "$size" kvd "$i" 52 53 # In case of linear, need to minimize sub-resources as well 54 if [[ "$i" == "linear" ]]; then 55 for j in $KVDL_CHILDREN; do 56 devlink_resource_size_set 0 kvd linear "$j" 57 done 58 fi 59 60 devlink_reload 61 devlink_sp_size_kvd_to_default 62 log_test "'$i' minimize [$size]" 63 done 64} 65 66resources_max_test() 67{ 68 local min_size 69 local size 70 local i 71 local j 72 73 log_info "Running KVD-maximum tests" 74 for i in $KVD_CHILDREN; do 75 RET=0 76 devlink_sp_resource_minimize 77 78 # Calculate the maximum possible size for the given partition 79 size=$(devlink_resource_size_get kvd) 80 for j in $KVD_CHILDREN; do 81 if [ "$i" != "$j" ]; then 82 min_size=$(devlink_resource_get kvd "$j" | \ 83 jq '.["size_min"]') 84 size=$((size - min_size)) 85 fi 86 done 87 88 # Test almost maximum size 89 devlink_resource_size_set "$((size - 128))" kvd "$i" 90 devlink_reload 91 log_test "'$i' almost maximize [$((size - 128))]" 92 93 # Test above maximum size 94 devlink resource set "$DEVLINK_DEV" \ 95 path "kvd/$i" size $((size + 128)) &> /dev/null 96 check_fail $? "Set kvd/$i to size $((size + 128)) should fail" 97 log_test "'$i' Overflow rejection [$((size + 128))]" 98 99 # Test maximum size 100 if [ "$i" == "hash_single" ] || [ "$i" == "hash_double" ]; then 101 echo "SKIP: Observed problem with exact max $i" 102 continue 103 fi 104 105 devlink_resource_size_set "$size" kvd "$i" 106 devlink_reload 107 log_test "'$i' maximize [$size]" 108 109 devlink_sp_size_kvd_to_default 110 done 111} 112 113profiles_test 114resources_min_test 115resources_max_test 116 117exit "$RET" 118