cgroup_fj_function.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) 2009 FUJITSU LIMITED ##
  5. ## Author: Shi Weihua <shiwh@cn.fujitsu.com> ##
  6. ## Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com> ##
  7. ## Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz> ##
  8. ## ##
  9. ## This program is free software; you can redistribute it and#or modify ##
  10. ## it under the terms of the GNU General Public License as published by ##
  11. ## the Free Software Foundation; either version 2 of the License, or ##
  12. ## (at your option) any later version. ##
  13. ## ##
  14. ## This program is distributed in the hope that it will be useful, but ##
  15. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  16. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  17. ## for more details. ##
  18. ## ##
  19. ## You should have received a copy of the GNU General Public License ##
  20. ## along with this program; if not, write to the Free Software Foundation, ##
  21. ## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  22. ## ##
  23. ################################################################################
  24. TCID="cgroup_fj_function2"
  25. TST_TOTAL=7
  26. . cgroup_fj_common.sh
  27. subsystem=$1
  28. usage_and_exit()
  29. {
  30. echo "usage of cgroup_fj_function2.sh: "
  31. echo " ./cgroup_fj_function2.sh subsystem"
  32. echo "example: ./cgroup_fj_function2.sh cpuset"
  33. tst_brkm TBROK "$1"
  34. }
  35. if [ "$#" -ne "1" ]; then
  36. usage_and_exit "Invalid number of parameters"
  37. fi
  38. # Move a task from group to group
  39. test1()
  40. {
  41. if ! attach_and_check "$pid" "$start_path/ltp_1"; then
  42. tst_resm TFAIL "Failed to attach task"
  43. return
  44. fi
  45. if ! attach_and_check "$pid" "$start_path"; then
  46. tst_resm TFAIL "Failed to attach task"
  47. return
  48. fi
  49. tst_resm TPASS "Task attached succesfully"
  50. }
  51. # Group can be renamed with mv
  52. test2()
  53. {
  54. create_subgroup "$start_path/ltp_2"
  55. if ! mv "$start_path/ltp_2" "$start_path/ltp_3"; then
  56. tst_resm TFAIL "Failed to move $start_path/ltp_2 to $start_path/ltp_3"
  57. rmdir "$start_path/ltp_2"
  58. return
  59. fi
  60. if ! rmdir "$start_path/ltp_3"; then
  61. tst_resm TFAIL "Failed to remove $start_path/ltp_3"
  62. return
  63. fi
  64. tst_resm TPASS "Successfully moved $start_path/ltp_2 to $start_path/ltp_3"
  65. }
  66. # Group can be renamed with mv unless the target name exists
  67. test3()
  68. {
  69. create_subgroup "$start_path/ltp_2"
  70. if mv "$start_path/ltp_2" "$start_path/ltp_1" > /dev/null 2>&1; then
  71. tst_resm TFAIL "Moved $start_path/ltp_2 over existing $start_path/ltp_1"
  72. return
  73. fi
  74. tst_resm TPASS "Failed to move $start_path/ltp_2 over existing $start_path/ltp_1"
  75. ROD rmdir "$start_path/ltp_2"
  76. }
  77. # Group with attached task cannot be removed
  78. test4()
  79. {
  80. if ! attach_and_check "$pid" "$start_path/ltp_1"; then
  81. tst_resm TFAIL "Failed to attach $pid to $start_path/ltp_1"
  82. return
  83. fi
  84. if rmdir "$start_path/ltp_1" > /dev/null 2>&1; then
  85. tst_resm TFAIL "Removed $start_path/ltp_1 which contains task $pid"
  86. create_subgroup "$start_path/ltp_1"
  87. return
  88. fi
  89. tst_resm TPASS "Group $start_path/ltp_1 with task $pid cannot be removed"
  90. }
  91. # Group with a subgroup cannot be removed
  92. test5()
  93. {
  94. create_subgroup "$start_path/ltp_1/a"
  95. if rmdir "$start_path/ltp_1" > /dev/null 2>&1; then
  96. tst_resm TFAIL "Removed $start_path/ltp_1 which contains subdir 'a'"
  97. return
  98. fi
  99. tst_resm TPASS "Dir $start_path/ltp_1 with subdir 'a' cannot be removed"
  100. ROD rmdir "$start_path/ltp_1/a"
  101. ROD echo "$pid" \> "$start_path/tasks"
  102. }
  103. # Group cannot be moved outside of hierarchy
  104. test6()
  105. {
  106. if mv "$start_path/ltp_1" "$PWD/ltp" > /dev/null 2>&1; then
  107. tst_resm TFAIL "Subgroup $start_path/ltp_1 outside hierarchy to $PWD/ltp"
  108. return
  109. fi
  110. tst_resm TPASS "Subgroup $start_path/ltp_1 cannot be moved to $PWD/ltp"
  111. }
  112. # Tasks file cannot be removed
  113. test7()
  114. {
  115. if rm "$start_path/ltp_1/tasks" > /dev/null 2>&1; then
  116. tst_resm TFAIL "Tasks file $start_path/ltp_1/tasks could be removed"
  117. return
  118. fi
  119. tst_resm TPASS "Tasks file $start_path/ltp_1/tasks cannot be removed"
  120. }
  121. # Test notify_on_release with invalid inputs
  122. test8()
  123. {
  124. if echo "-1" > "$start_path/ltp_1/notify_on_release" 2>/dev/null; then
  125. tst_resm TFAIL "Can write -1 to $start_path/ltp_1/notify_on_release"
  126. return
  127. fi
  128. if echo "ltp" > "$start_path/ltp_1/notify_on_release" 2>/dev/null; then
  129. tst_resm TFAIL "Can write ltp to $start_path/ltp_1/notify_on_release"
  130. return
  131. fi
  132. tst_resm TPASS "Cannot write invalid values to $start_path/ltp_1/notify_on_release"
  133. }
  134. # Test that notify_on_release can be changed
  135. test9()
  136. {
  137. local notify=$(ROD cat "$start_path/ltp_1/notify_on_release")
  138. local value
  139. if [ "$notify" -eq 0 ]; then
  140. value=1
  141. else
  142. value=0
  143. fi
  144. if ! echo "$value" > "$start_path/ltp_1/notify_on_release"; then
  145. tst_resm TFAIL "Failed to set $start_path/ltp_1/notify_on_release to $value"
  146. return
  147. fi
  148. ROD echo "$notify" \> "$start_path/ltp_1/notify_on_release"
  149. tst_resm TPASS "Set $start_path/ltp_1/notify_on_release to $value"
  150. }
  151. setup
  152. cgroup_fj_proc&
  153. pid=$!
  154. start_path="$mount_point/ltp"
  155. create_subgroup "$start_path"
  156. create_subgroup "$start_path/ltp_1"
  157. test1
  158. test2
  159. test3
  160. test4
  161. test5
  162. test6
  163. test7
  164. test8
  165. test9
  166. ROD kill -9 $pid
  167. wait $pid
  168. ROD rmdir "$start_path/ltp_1"
  169. tst_exit