• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) 2009 FUJITSU LIMITED                                         ##
6##  Author: Shi Weihua <shiwh@cn.fujitsu.com>                                 ##
7## Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>                          ##
8## Copyright (c) 2015-2016 Cyril Hrubis <chrubis@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
26TCID="cgroup_fj_stress"
27TST_TOTAL=1
28
29. cgroup_fj_common.sh
30
31subsystem="$1"
32subgroup_num="$2"
33subgroup_depth="$3"
34attach_operation="$4"
35
36usage_and_exit()
37{
38    echo "usage of cgroup_fj_stress.sh: "
39    echo "  ./cgroup_fj_stress.sh subsystem subgroup_num subgroup_depth attach_operation"
40    echo "    subgroup_num"
41    echo "      number of subgroups created in group"
42    echo "    subgroup_depth"
43    echo "      depth of the created tree"
44    echo "    attach_operation"
45    echo "      none - do not attach anything"
46    echo "      one  - move one processe around"
47    echo "      each - attach process to each subgroup"
48    echo "example: ./cgroup_fj_stress.sh cpuset 1 1 one"
49    echo
50    tst_brkm TBROK "$1"
51}
52
53if [ "$#" -ne "4" ]; then
54    usage_and_exit "Wrong number of parameters, expected 4"
55fi
56
57case $subgroup_num in
58    ''|*[!0-9]*) usage_and_exit "Number of subgroups must be possitive integer";;
59    *) ;;
60esac
61
62case $subgroup_depth in
63    ''|*[!0-9]*) usage_and_exit "Depth of the subgroup tree must be possitive integer";;
64    *) ;;
65esac
66
67case $attach_operation in
68    'none'|'one'|'each');;
69    *) usage_and_exit "Invalid attach operation: $attach_operation";;
70esac
71
72setup
73
74export TMPFILE=./tmp_tasks.$$
75
76count=0
77collected_pids=
78
79build_subgroups()
80{
81    local cur_path="$1"
82    local cur_depth="$2"
83    local i
84
85    if [ "$cur_depth" -gt "$subgroup_depth" ]; then
86        return
87    fi
88
89    create_subgroup "$cur_path"
90    count=$((count+1))
91
92    for i in $(seq 1 $subgroup_num); do
93         build_subgroups "$cur_path/$i" $((cur_depth+1))
94    done
95}
96
97attach_task()
98{
99    local cur_path="$1"
100    local cur_depth="$2"
101    local ppid="$3"
102    local i
103
104    if [ "$cur_depth" -gt "$subgroup_depth" ]; then
105        return
106    fi
107
108    if [ -z "$ppid" ]; then
109        cgroup_fj_proc&
110        pid=$!
111        collected_pids="$collected_pids $pid"
112    else
113        pid="$ppid"
114    fi
115
116    if ! attach_and_check "$pid" "$cur_path"; then
117            fail=1
118    fi
119
120    for i in $(seq 1 $subgroup_num); do
121         local new_path="$cur_path/$i"
122         attach_task "$new_path" $((cur_depth+1)) "$ppid"
123    done
124
125    if [ -n "$ppid" ]; then
126        if ! attach_and_check "$pid" "$cur_path"; then
127            fail=1
128        fi
129    fi
130}
131
132start_path="$mount_point/ltp"
133
134tst_resm TINFO "Creating subgroups ..."
135
136build_subgroups "$start_path" 0
137
138tst_resm TINFO "... mkdired $count times"
139
140case $attach_operation in
141"one" )
142    cgroup_fj_proc &
143    pid=$!
144
145    tst_resm TINFO "Moving one task around"
146    attach_task "$start_path" 0 "$pid"
147    ROD kill -9 "$pid"
148    wait "$pid"
149    ;;
150"each" )
151    tst_resm TINFO "Attaching task to each subgroup"
152    attach_task "$start_path" 0
153    for pid in $collected_pids; do
154        ROD kill -9 "$pid"
155        wait "$pid"
156    done
157    ;;
158*  )
159    ;;
160esac
161
162if [ -n "$fail" ]; then
163    tst_resm TFAIL "Attaching tasks failed!"
164else
165    tst_resm TPASS "All done!"
166fi
167
168tst_exit
169