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