1*3f9319c6SChen Ridong#!/bin/bash 2*3f9319c6SChen Ridong# SPDX-License-Identifier: GPL-2.0 3*3f9319c6SChen Ridong# 4*3f9319c6SChen Ridong# Basc test for cpuset v1 interfaces write/read 5*3f9319c6SChen Ridong# 6*3f9319c6SChen Ridong 7*3f9319c6SChen Ridongskip_test() { 8*3f9319c6SChen Ridong echo "$1" 9*3f9319c6SChen Ridong echo "Test SKIPPED" 10*3f9319c6SChen Ridong exit 4 # ksft_skip 11*3f9319c6SChen Ridong} 12*3f9319c6SChen Ridong 13*3f9319c6SChen Ridongwrite_test() { 14*3f9319c6SChen Ridong dir=$1 15*3f9319c6SChen Ridong interface=$2 16*3f9319c6SChen Ridong value=$3 17*3f9319c6SChen Ridong original=$(cat $dir/$interface) 18*3f9319c6SChen Ridong echo "testing $interface $value" 19*3f9319c6SChen Ridong echo $value > $dir/$interface 20*3f9319c6SChen Ridong new=$(cat $dir/$interface) 21*3f9319c6SChen Ridong [[ $value -ne $(cat $dir/$interface) ]] && { 22*3f9319c6SChen Ridong echo "$interface write $value failed: new:$new" 23*3f9319c6SChen Ridong exit 1 24*3f9319c6SChen Ridong } 25*3f9319c6SChen Ridong} 26*3f9319c6SChen Ridong 27*3f9319c6SChen Ridong[[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!" 28*3f9319c6SChen Ridong 29*3f9319c6SChen Ridong# Find cpuset v1 mount point 30*3f9319c6SChen RidongCPUSET=$(mount -t cgroup | grep cpuset | head -1 | awk '{print $3}') 31*3f9319c6SChen Ridong[[ -n "$CPUSET" ]] || skip_test "cpuset v1 mount point not found!" 32*3f9319c6SChen Ridong 33*3f9319c6SChen Ridong# 34*3f9319c6SChen Ridong# Create a test cpuset, read write test 35*3f9319c6SChen Ridong# 36*3f9319c6SChen RidongTDIR=test$$ 37*3f9319c6SChen Ridong[[ -d $CPUSET/$TDIR ]] || mkdir $CPUSET/$TDIR 38*3f9319c6SChen Ridong 39*3f9319c6SChen RidongITF_MATRIX=( 40*3f9319c6SChen Ridong #interface value expect root_only 41*3f9319c6SChen Ridong 'cpuset.cpus 0-1 0-1 0' 42*3f9319c6SChen Ridong 'cpuset.mem_exclusive 1 1 0' 43*3f9319c6SChen Ridong 'cpuset.mem_exclusive 0 0 0' 44*3f9319c6SChen Ridong 'cpuset.mem_hardwall 1 1 0' 45*3f9319c6SChen Ridong 'cpuset.mem_hardwall 0 0 0' 46*3f9319c6SChen Ridong 'cpuset.memory_migrate 1 1 0' 47*3f9319c6SChen Ridong 'cpuset.memory_migrate 0 0 0' 48*3f9319c6SChen Ridong 'cpuset.memory_spread_page 1 1 0' 49*3f9319c6SChen Ridong 'cpuset.memory_spread_page 0 0 0' 50*3f9319c6SChen Ridong 'cpuset.memory_spread_slab 1 1 0' 51*3f9319c6SChen Ridong 'cpuset.memory_spread_slab 0 0 0' 52*3f9319c6SChen Ridong 'cpuset.mems 0 0 0' 53*3f9319c6SChen Ridong 'cpuset.sched_load_balance 1 1 0' 54*3f9319c6SChen Ridong 'cpuset.sched_load_balance 0 0 0' 55*3f9319c6SChen Ridong 'cpuset.sched_relax_domain_level 2 2 0' 56*3f9319c6SChen Ridong 'cpuset.memory_pressure_enabled 1 1 1' 57*3f9319c6SChen Ridong 'cpuset.memory_pressure_enabled 0 0 1' 58*3f9319c6SChen Ridong) 59*3f9319c6SChen Ridong 60*3f9319c6SChen Ridongrun_test() 61*3f9319c6SChen Ridong{ 62*3f9319c6SChen Ridong cnt="${ITF_MATRIX[@]}" 63*3f9319c6SChen Ridong for i in "${ITF_MATRIX[@]}" ; do 64*3f9319c6SChen Ridong args=($i) 65*3f9319c6SChen Ridong root_only=${args[3]} 66*3f9319c6SChen Ridong [[ $root_only -eq 1 ]] && { 67*3f9319c6SChen Ridong write_test "$CPUSET" "${args[0]}" "${args[1]}" "${args[2]}" 68*3f9319c6SChen Ridong continue 69*3f9319c6SChen Ridong } 70*3f9319c6SChen Ridong write_test "$CPUSET/$TDIR" "${args[0]}" "${args[1]}" "${args[2]}" 71*3f9319c6SChen Ridong done 72*3f9319c6SChen Ridong} 73*3f9319c6SChen Ridong 74*3f9319c6SChen Ridongrun_test 75*3f9319c6SChen Ridongrmdir $CPUSET/$TDIR 76*3f9319c6SChen Ridongecho "Test PASSED" 77*3f9319c6SChen Ridongexit 0 78