test_cpuset_v1_hp.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Test the special cpuset v1 hotplug case where a cpuset become empty of
  5. # CPUs will force migration of tasks out to an ancestor.
  6. #
  7. skip_test() {
  8. echo "$1"
  9. echo "Test SKIPPED"
  10. exit 4 # ksft_skip
  11. }
  12. [[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!"
  13. # Find cpuset v1 mount point
  14. CPUSET=$(mount -t cgroup | grep cpuset | head -1 | awk -e '{print $3}')
  15. [[ -n "$CPUSET" ]] || skip_test "cpuset v1 mount point not found!"
  16. #
  17. # Create a test cpuset, put a CPU and a task there and offline that CPU
  18. #
  19. TDIR=test$$
  20. [[ -d $CPUSET/$TDIR ]] || mkdir $CPUSET/$TDIR
  21. echo 1 > $CPUSET/$TDIR/cpuset.cpus
  22. echo 0 > $CPUSET/$TDIR/cpuset.mems
  23. sleep 10&
  24. TASK=$!
  25. echo $TASK > $CPUSET/$TDIR/tasks
  26. NEWCS=$(cat /proc/$TASK/cpuset)
  27. [[ $NEWCS != "/$TDIR" ]] && {
  28. echo "Unexpected cpuset $NEWCS, test FAILED!"
  29. exit 1
  30. }
  31. echo 0 > /sys/devices/system/cpu/cpu1/online
  32. sleep 0.5
  33. echo 1 > /sys/devices/system/cpu/cpu1/online
  34. NEWCS=$(cat /proc/$TASK/cpuset)
  35. rmdir $CPUSET/$TDIR
  36. [[ $NEWCS != "/" ]] && {
  37. echo "cpuset $NEWCS, test FAILED!"
  38. exit 1
  39. }
  40. echo "Test PASSED"
  41. exit 0