Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: ifs: verify test image loading functionality

Scan test image files have to be loaded before starting IFS test.

Verify that In Field scan driver is able to load valid test image files.

Also check if loading an invalid test image file fails.

Reviewed-by: Jithu Joseph <jithu.joseph@intel.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Co-developed-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Pengfei Xu <pengfei.xu@intel.com>
Acked-by: Jithu Joseph <jithu.joseph@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Pengfei Xu and committed by
Shuah Khan
20cef303 8e51106d

+120 -1
+120 -1
tools/testing/selftests/drivers/platform/x86/intel/ifs/test_ifs.sh
··· 10 10 readonly KSFT_XFAIL=2 11 11 readonly KSFT_SKIP=4 12 12 13 + readonly IMG_PATH="/lib/firmware/intel/ifs_0" 13 14 readonly IFS_SCAN_MODE="0" 14 15 readonly IFS_PATH="/sys/devices/virtual/misc/intel_ifs" 15 16 readonly IFS_SCAN_SYSFS_PATH="${IFS_PATH}_${IFS_SCAN_MODE}" ··· 30 29 31 30 FML="" 32 31 MODEL="" 33 - 32 + STEPPING="" 33 + CPU_FMS="" 34 34 TRUE="true" 35 35 FALSE="false" 36 36 RESULT=$KSFT_PASS 37 + IMAGE_NAME="" 37 38 export INTERVAL_TIME=1 38 39 # For IFS cleanup tags 39 40 ORIGIN_IFS_LOADED="" 41 + IFS_IMAGE_NEED_RESTORE=$FALSE 40 42 IFS_LOG="/tmp/ifs_logs.$$" 43 + DEFAULT_IMG_ID="" 41 44 42 45 append_log() 43 46 { ··· 73 68 74 69 ifs_cleanup() 75 70 { 71 + echo "[$INFO] Restore environment after IFS test" 72 + 73 + # Restore ifs origin image if origin image backup step is needed 74 + [[ "$IFS_IMAGE_NEED_RESTORE" == "$TRUE" ]] && { 75 + mv -f "$IMG_PATH"/"$IMAGE_NAME"_origin "$IMG_PATH"/"$IMAGE_NAME" 76 + } 77 + 76 78 lsmod | grep -q "$IFS_NAME" && [[ "$ORIGIN_IFS_LOADED" == "$FALSE" ]] && { 77 79 echo "[$INFO] modprobe -r $IFS_NAME" 78 80 modprobe -r "$IFS_NAME" ··· 90 78 91 79 echo "[RESULT] IFS test exit with $RESULT" 92 80 exit "$RESULT" 81 + } 82 + 83 + do_cmd() 84 + { 85 + local cmd=$* 86 + local ret="" 87 + 88 + append_log "[$INFO] $cmd" 89 + eval "$cmd" 90 + ret=$? 91 + if [[ $ret -ne 0 ]]; then 92 + append_log "[$FAIL] $cmd failed. Return code is $ret" 93 + RESULT=$KSFT_XFAIL 94 + ifs_cleanup 95 + fi 93 96 } 94 97 95 98 test_exit() ··· 126 99 { 127 100 FML=$(grep -m 1 "family" /proc/cpuinfo | awk -F ":" '{printf "%02x",$2;}') 128 101 MODEL=$(grep -m 1 "model" /proc/cpuinfo | awk -F ":" '{printf "%02x",$2;}') 102 + STEPPING=$(grep -m 1 "stepping" /proc/cpuinfo | awk -F ":" '{printf "%02x",$2;}') 103 + CPU_FMS="${FML}-${MODEL}-${STEPPING}" 129 104 } 130 105 131 106 check_cpu_ifs_support_interval_time() ··· 191 162 fi 192 163 } 193 164 165 + load_image() 166 + { 167 + local image_id=$1 168 + local image_info="" 169 + local ret="" 170 + 171 + check_ifs_loaded 172 + if [[ -e "${IMG_PATH}/${IMAGE_NAME}" ]]; then 173 + append_log "[$INFO] echo 0x$image_id > ${IFS_SCAN_SYSFS_PATH}/current_batch" 174 + echo "0x$image_id" > "$IFS_SCAN_SYSFS_PATH"/current_batch 2>/dev/null 175 + ret=$? 176 + [[ "$ret" -eq 0 ]] || { 177 + append_log "[$FAIL] Load ifs image $image_id failed with ret:$ret\n" 178 + return "$ret" 179 + } 180 + image_info=$(cat ${IFS_SCAN_SYSFS_PATH}/current_batch) 181 + if [[ "$image_info" == 0x"$image_id" ]]; then 182 + append_log "[$PASS] load IFS current_batch:$image_info" 183 + else 184 + append_log "[$FAIL] current_batch:$image_info is not expected:$image_id" 185 + return "$KSFT_FAIL" 186 + fi 187 + else 188 + append_log "[$FAIL] No IFS image file ${IMG_PATH}/${IMAGE_NAME}"\ 189 + return "$KSFT_FAIL" 190 + fi 191 + return 0 192 + } 193 + 194 + test_load_origin_ifs_image() 195 + { 196 + local image_id=$1 197 + 198 + IMAGE_NAME="${CPU_FMS}-${image_id}.scan" 199 + 200 + load_image "$image_id" || return $? 201 + return 0 202 + } 203 + 204 + test_load_bad_ifs_image() 205 + { 206 + local image_id=$1 207 + 208 + IMAGE_NAME="${CPU_FMS}-${image_id}.scan" 209 + 210 + do_cmd "mv -f ${IMG_PATH}/${IMAGE_NAME} ${IMG_PATH}/${IMAGE_NAME}_origin" 211 + 212 + # Set IFS_IMAGE_NEED_RESTORE to true before corrupt the origin ifs image file 213 + IFS_IMAGE_NEED_RESTORE=$TRUE 214 + do_cmd "dd if=/dev/urandom of=${IMG_PATH}/${IMAGE_NAME} bs=1K count=6 2>/dev/null" 215 + 216 + # Use the specified judgment for negative testing 217 + append_log "[$INFO] echo 0x$image_id > ${IFS_SCAN_SYSFS_PATH}/current_batch" 218 + echo "0x$image_id" > "$IFS_SCAN_SYSFS_PATH"/current_batch 2>/dev/null 219 + ret=$? 220 + if [[ "$ret" -ne 0 ]]; then 221 + append_log "[$PASS] Load invalid ifs image failed with ret:$ret not 0 as expected" 222 + else 223 + append_log "[$FAIL] Load invalid ifs image ret:$ret unexpectedly" 224 + fi 225 + 226 + do_cmd "mv -f ${IMG_PATH}/${IMAGE_NAME}_origin ${IMG_PATH}/${IMAGE_NAME}" 227 + IFS_IMAGE_NEED_RESTORE=$FALSE 228 + } 229 + 230 + test_bad_and_origin_ifs_image() 231 + { 232 + local image_id=$1 233 + 234 + append_log "[$INFO] Test loading bad and then loading original IFS image:" 235 + test_load_origin_ifs_image "$image_id" || return $? 236 + test_load_bad_ifs_image "$image_id" 237 + # Load origin image again and make sure it's worked 238 + test_load_origin_ifs_image "$image_id" || return $? 239 + append_log "[$INFO] Loading invalid IFS image and then loading initial image passed.\n" 240 + } 241 + 194 242 prepare_ifs_test_env() 195 243 { 196 244 check_cpu_ifs_support_interval_time 245 + 246 + DEFAULT_IMG_ID=$(find $IMG_PATH -maxdepth 1 -name "${CPU_FMS}-[0-9a-fA-F][0-9a-fA-F].scan" \ 247 + 2>/dev/null \ 248 + | sort \ 249 + | head -n 1 \ 250 + | awk -F "-" '{print $NF}' \ 251 + | cut -d "." -f 1) 197 252 } 198 253 199 254 test_ifs() ··· 285 172 prepare_ifs_test_env 286 173 287 174 test_ifs_scan_entry 175 + 176 + if [[ -z "$DEFAULT_IMG_ID" ]]; then 177 + append_log "[$SKIP] No proper ${IMG_PATH}/${CPU_FMS}-*.scan, skip ifs_0 scan" 178 + else 179 + test_bad_and_origin_ifs_image "$DEFAULT_IMG_ID" 180 + fi 288 181 } 289 182 290 183 trap ifs_cleanup SIGTERM SIGINT