Skip to content

Commit 20cef30

Browse files
Pengfei Xushuahkh
authored andcommitted
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 <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Co-developed-by: Ashok Raj <[email protected]> Signed-off-by: Ashok Raj <[email protected]> Signed-off-by: Pengfei Xu <[email protected]> Acked-by: Jithu Joseph <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 8e51106 commit 20cef30

File tree

1 file changed

+120
-1
lines changed
  • tools/testing/selftests/drivers/platform/x86/intel/ifs

1 file changed

+120
-1
lines changed

tools/testing/selftests/drivers/platform/x86/intel/ifs/test_ifs.sh

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ readonly KSFT_FAIL=1
1010
readonly KSFT_XFAIL=2
1111
readonly KSFT_SKIP=4
1212

13+
readonly IMG_PATH="/lib/firmware/intel/ifs_0"
1314
readonly IFS_SCAN_MODE="0"
1415
readonly IFS_PATH="/sys/devices/virtual/misc/intel_ifs"
1516
readonly IFS_SCAN_SYSFS_PATH="${IFS_PATH}_${IFS_SCAN_MODE}"
@@ -29,14 +30,18 @@ readonly INTEL_FAM6="06"
2930

3031
FML=""
3132
MODEL=""
32-
33+
STEPPING=""
34+
CPU_FMS=""
3335
TRUE="true"
3436
FALSE="false"
3537
RESULT=$KSFT_PASS
38+
IMAGE_NAME=""
3639
export INTERVAL_TIME=1
3740
# For IFS cleanup tags
3841
ORIGIN_IFS_LOADED=""
42+
IFS_IMAGE_NEED_RESTORE=$FALSE
3943
IFS_LOG="/tmp/ifs_logs.$$"
44+
DEFAULT_IMG_ID=""
4045

4146
append_log()
4247
{
@@ -68,6 +73,13 @@ ifs_scan_result_summary()
6873

6974
ifs_cleanup()
7075
{
76+
echo "[$INFO] Restore environment after IFS test"
77+
78+
# Restore ifs origin image if origin image backup step is needed
79+
[[ "$IFS_IMAGE_NEED_RESTORE" == "$TRUE" ]] && {
80+
mv -f "$IMG_PATH"/"$IMAGE_NAME"_origin "$IMG_PATH"/"$IMAGE_NAME"
81+
}
82+
7183
lsmod | grep -q "$IFS_NAME" && [[ "$ORIGIN_IFS_LOADED" == "$FALSE" ]] && {
7284
echo "[$INFO] modprobe -r $IFS_NAME"
7385
modprobe -r "$IFS_NAME"
@@ -80,6 +92,21 @@ ifs_cleanup()
8092
exit "$RESULT"
8193
}
8294

95+
do_cmd()
96+
{
97+
local cmd=$*
98+
local ret=""
99+
100+
append_log "[$INFO] $cmd"
101+
eval "$cmd"
102+
ret=$?
103+
if [[ $ret -ne 0 ]]; then
104+
append_log "[$FAIL] $cmd failed. Return code is $ret"
105+
RESULT=$KSFT_XFAIL
106+
ifs_cleanup
107+
fi
108+
}
109+
83110
test_exit()
84111
{
85112
local info=$1
@@ -99,6 +126,8 @@ get_cpu_fms()
99126
{
100127
FML=$(grep -m 1 "family" /proc/cpuinfo | awk -F ":" '{printf "%02x",$2;}')
101128
MODEL=$(grep -m 1 "model" /proc/cpuinfo | awk -F ":" '{printf "%02x",$2;}')
129+
STEPPING=$(grep -m 1 "stepping" /proc/cpuinfo | awk -F ":" '{printf "%02x",$2;}')
130+
CPU_FMS="${FML}-${MODEL}-${STEPPING}"
102131
}
103132

104133
check_cpu_ifs_support_interval_time()
@@ -162,16 +191,106 @@ test_ifs_scan_entry()
162191
fi
163192
}
164193

194+
load_image()
195+
{
196+
local image_id=$1
197+
local image_info=""
198+
local ret=""
199+
200+
check_ifs_loaded
201+
if [[ -e "${IMG_PATH}/${IMAGE_NAME}" ]]; then
202+
append_log "[$INFO] echo 0x$image_id > ${IFS_SCAN_SYSFS_PATH}/current_batch"
203+
echo "0x$image_id" > "$IFS_SCAN_SYSFS_PATH"/current_batch 2>/dev/null
204+
ret=$?
205+
[[ "$ret" -eq 0 ]] || {
206+
append_log "[$FAIL] Load ifs image $image_id failed with ret:$ret\n"
207+
return "$ret"
208+
}
209+
image_info=$(cat ${IFS_SCAN_SYSFS_PATH}/current_batch)
210+
if [[ "$image_info" == 0x"$image_id" ]]; then
211+
append_log "[$PASS] load IFS current_batch:$image_info"
212+
else
213+
append_log "[$FAIL] current_batch:$image_info is not expected:$image_id"
214+
return "$KSFT_FAIL"
215+
fi
216+
else
217+
append_log "[$FAIL] No IFS image file ${IMG_PATH}/${IMAGE_NAME}"\
218+
return "$KSFT_FAIL"
219+
fi
220+
return 0
221+
}
222+
223+
test_load_origin_ifs_image()
224+
{
225+
local image_id=$1
226+
227+
IMAGE_NAME="${CPU_FMS}-${image_id}.scan"
228+
229+
load_image "$image_id" || return $?
230+
return 0
231+
}
232+
233+
test_load_bad_ifs_image()
234+
{
235+
local image_id=$1
236+
237+
IMAGE_NAME="${CPU_FMS}-${image_id}.scan"
238+
239+
do_cmd "mv -f ${IMG_PATH}/${IMAGE_NAME} ${IMG_PATH}/${IMAGE_NAME}_origin"
240+
241+
# Set IFS_IMAGE_NEED_RESTORE to true before corrupt the origin ifs image file
242+
IFS_IMAGE_NEED_RESTORE=$TRUE
243+
do_cmd "dd if=/dev/urandom of=${IMG_PATH}/${IMAGE_NAME} bs=1K count=6 2>/dev/null"
244+
245+
# Use the specified judgment for negative testing
246+
append_log "[$INFO] echo 0x$image_id > ${IFS_SCAN_SYSFS_PATH}/current_batch"
247+
echo "0x$image_id" > "$IFS_SCAN_SYSFS_PATH"/current_batch 2>/dev/null
248+
ret=$?
249+
if [[ "$ret" -ne 0 ]]; then
250+
append_log "[$PASS] Load invalid ifs image failed with ret:$ret not 0 as expected"
251+
else
252+
append_log "[$FAIL] Load invalid ifs image ret:$ret unexpectedly"
253+
fi
254+
255+
do_cmd "mv -f ${IMG_PATH}/${IMAGE_NAME}_origin ${IMG_PATH}/${IMAGE_NAME}"
256+
IFS_IMAGE_NEED_RESTORE=$FALSE
257+
}
258+
259+
test_bad_and_origin_ifs_image()
260+
{
261+
local image_id=$1
262+
263+
append_log "[$INFO] Test loading bad and then loading original IFS image:"
264+
test_load_origin_ifs_image "$image_id" || return $?
265+
test_load_bad_ifs_image "$image_id"
266+
# Load origin image again and make sure it's worked
267+
test_load_origin_ifs_image "$image_id" || return $?
268+
append_log "[$INFO] Loading invalid IFS image and then loading initial image passed.\n"
269+
}
270+
165271
prepare_ifs_test_env()
166272
{
167273
check_cpu_ifs_support_interval_time
274+
275+
DEFAULT_IMG_ID=$(find $IMG_PATH -maxdepth 1 -name "${CPU_FMS}-[0-9a-fA-F][0-9a-fA-F].scan" \
276+
2>/dev/null \
277+
| sort \
278+
| head -n 1 \
279+
| awk -F "-" '{print $NF}' \
280+
| cut -d "." -f 1)
168281
}
169282

170283
test_ifs()
171284
{
172285
prepare_ifs_test_env
173286

174287
test_ifs_scan_entry
288+
289+
if [[ -z "$DEFAULT_IMG_ID" ]]; then
290+
append_log "[$SKIP] No proper ${IMG_PATH}/${CPU_FMS}-*.scan, skip ifs_0 scan"
291+
else
292+
test_bad_and_origin_ifs_image "$DEFAULT_IMG_ID"
293+
fi
175294
}
176295

177296
trap ifs_cleanup SIGTERM SIGINT

0 commit comments

Comments
 (0)