Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: tests/run_cgpt_tests.sh

Issue 5352005: Add 'prioritize' command to cgpt tool. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/common.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash -eu 1 #!/bin/bash -eu
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # Run tests for CGPT. 7 # Run tests for CGPT.
8 8
9 # Load common constants and variables. 9 # Load common constants and variables.
10 . "$(dirname "$0")/common.sh" 10 . "$(dirname "$0")/common.sh"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 $GPT add -b ${FUTURE_START} -s ${FUTURE_SIZE} -t ${FUTURE_GUID} \ 74 $GPT add -b ${FUTURE_START} -s ${FUTURE_SIZE} -t ${FUTURE_GUID} \
75 -l "${FUTURE_LABEL}" ${DEV} 75 -l "${FUTURE_LABEL}" ${DEV}
76 $GPT add -b ${RANDOM_START} -s ${RANDOM_SIZE} -t ${RANDOM_GUID} \ 76 $GPT add -b ${RANDOM_START} -s ${RANDOM_SIZE} -t ${RANDOM_GUID} \
77 -l "${RANDOM_LABEL}" ${DEV} 77 -l "${RANDOM_LABEL}" ${DEV}
78 78
79 79
80 echo "Extract the start and size of given partitions..." 80 echo "Extract the start and size of given partitions..."
81 81
82 X=$($GPT show -b -i $DATA_NUM ${DEV}) 82 X=$($GPT show -b -i $DATA_NUM ${DEV})
83 Y=$($GPT show -s -i $DATA_NUM ${DEV}) 83 Y=$($GPT show -s -i $DATA_NUM ${DEV})
84 [ "$X $Y" = "$DATA_START $DATA_SIZE" ] || error "fail at line $LINENO" 84 [ "$X $Y" = "$DATA_START $DATA_SIZE" ] || error
85 85
86 X=$($GPT show -b -i $KERN_NUM ${DEV}) 86 X=$($GPT show -b -i $KERN_NUM ${DEV})
87 Y=$($GPT show -s -i $KERN_NUM ${DEV}) 87 Y=$($GPT show -s -i $KERN_NUM ${DEV})
88 [ "$X $Y" = "$KERN_START $KERN_SIZE" ] || error "fail at line $LINENO" 88 [ "$X $Y" = "$KERN_START $KERN_SIZE" ] || error
89 89
90 X=$($GPT show -b -i $ROOTFS_NUM ${DEV}) 90 X=$($GPT show -b -i $ROOTFS_NUM ${DEV})
91 Y=$($GPT show -s -i $ROOTFS_NUM ${DEV}) 91 Y=$($GPT show -s -i $ROOTFS_NUM ${DEV})
92 [ "$X $Y" = "$ROOTFS_START $ROOTFS_SIZE" ] || error "fail at line $LINENO" 92 [ "$X $Y" = "$ROOTFS_START $ROOTFS_SIZE" ] || error
93 93
94 X=$($GPT show -b -i $ESP_NUM ${DEV}) 94 X=$($GPT show -b -i $ESP_NUM ${DEV})
95 Y=$($GPT show -s -i $ESP_NUM ${DEV}) 95 Y=$($GPT show -s -i $ESP_NUM ${DEV})
96 [ "$X $Y" = "$ESP_START $ESP_SIZE" ] || error "fail at line $LINENO" 96 [ "$X $Y" = "$ESP_START $ESP_SIZE" ] || error
97 97
98 X=$($GPT show -b -i $FUTURE_NUM ${DEV}) 98 X=$($GPT show -b -i $FUTURE_NUM ${DEV})
99 Y=$($GPT show -s -i $FUTURE_NUM ${DEV}) 99 Y=$($GPT show -s -i $FUTURE_NUM ${DEV})
100 [ "$X $Y" = "$FUTURE_START $FUTURE_SIZE" ] || error "fail at line $LINENO" 100 [ "$X $Y" = "$FUTURE_START $FUTURE_SIZE" ] || error
101 101
102 X=$($GPT show -b -i $RANDOM_NUM ${DEV}) 102 X=$($GPT show -b -i $RANDOM_NUM ${DEV})
103 Y=$($GPT show -s -i $RANDOM_NUM ${DEV}) 103 Y=$($GPT show -s -i $RANDOM_NUM ${DEV})
104 [ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error "fail at line $LINENO" 104 [ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error
105 105
106 106
107 echo "Set the boot partition.." 107 echo "Set the boot partition.."
108 $GPT boot -i ${KERN_NUM} ${DEV} >/dev/null 108 $GPT boot -i ${KERN_NUM} ${DEV} >/dev/null
109 109
110 echo "Check the PMBR's idea of the boot partition..." 110 echo "Check the PMBR's idea of the boot partition..."
111 X=$($GPT boot ${DEV}) 111 X=$($GPT boot ${DEV})
112 Y=$($GPT show -u -i $KERN_NUM $DEV) 112 Y=$($GPT show -u -i $KERN_NUM $DEV)
113 [ "$X" = "$Y" ] || error "fail at line $LINENO" 113 [ "$X" = "$Y" ] || error
114
115
116 echo "Test the cgpt prioritize command..."
117
118 # Input: sequence of priorities
119 # Output: ${DEV} has kernel partitions with the given priorities
120 make_pri() {
121 local idx=0
122 $GPT create ${DEV}
123 for pri in "$@"; do
124 idx=$((idx+1))
125 $GPT add -t kernel -l "kern$idx" -b $((100 + 2 * $idx)) -s 1 -P $pri ${DEV}
126 done
127 }
128
129 # Output: returns string containing priorities of all kernels
130 get_pri() {
131 echo $(
132 for idx in $($GPT find -t kernel ${DEV} | sed -e s@${DEV}@@); do
133 $GPT show -i $idx -P ${DEV}
134 done
135 )
136 }
137
138 # Input: list of priorities
139 # Operation: expects ${DEV} to contain those kernel priorities
140 assert_pri() {
141 local expected="$*"
142 local actual=$(get_pri)
143 [ "$actual" = "$expected" ] || \
144 error 1 "expected priority \"$expected\", actual priority \"$actual\""
145 }
146
147
148 # no kernels at all. This should do nothing.
149 $GPT create ${DEV}
150 $GPT add -t rootfs -b 100 -s 1 ${DEV}
151 $GPT prioritize ${DEV}
152 assert_pri ""
153
154 # common install/upgrade sequence
155 make_pri 2 0 0
156 $GPT prioritize -i 1 ${DEV}
157 assert_pri 1 0 0
158 $GPT prioritize -i 2 ${DEV}
159 assert_pri 1 2 0
160 $GPT prioritize -i 1 ${DEV}
161 assert_pri 2 1 0
162 $GPT prioritize -i 2 ${DEV}
163 assert_pri 1 2 0
164
165 # lots of kernels, all same starting priority, should go to priority 1
166 make_pri 8 8 8 8 8 8 8 8 8 8 8 0 0 8
167 $GPT prioritize ${DEV}
168 assert_pri 1 1 1 1 1 1 1 1 1 1 1 0 0 1
169
170 # now raise them all up again
171 $GPT prioritize -P 4 ${DEV}
172 assert_pri 4 4 4 4 4 4 4 4 4 4 4 0 0 4
173
174 # set one of them higher, should leave the rest alone
175 $GPT prioritize -P 5 -i 3 ${DEV}
176 assert_pri 4 4 5 4 4 4 4 4 4 4 4 0 0 4
177
178 # set one of them lower, should bring the rest down
179 $GPT prioritize -P 3 -i 4 ${DEV}
180 assert_pri 1 1 2 3 1 1 1 1 1 1 1 0 0 1
181
182 # raise a group by including the friends of one partition
183 $GPT prioritize -P 6 -i 1 -f ${DEV}
184 assert_pri 6 6 4 5 6 6 6 6 6 6 6 0 0 6
185
186 # resurrect one, should not affect the others
187 make_pri 0 0 0 0 0 0 0 0 0 0 0 0 0 0
188 $GPT prioritize -i 2 ${DEV}
189 assert_pri 0 1 0 0 0 0 0 0 0 0 0 0 0 0
190
191 # resurrect one and all its friends
192 make_pri 0 0 0 0 0 0 0 0 1 2 0 0 0 0
193 $GPT prioritize -P 5 -i 2 -f ${DEV}
194 assert_pri 5 5 5 5 5 5 5 5 3 4 5 5 5 5
195
196 # no options should maintain the same order
197 $GPT prioritize ${DEV}
198 assert_pri 3 3 3 3 3 3 3 3 1 2 3 3 3 3
199
200 # squish all the ranks
201 make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
202 $GPT prioritize -P 6 ${DEV}
203 assert_pri 1 1 1 1 2 2 3 3 4 4 0 5 6 6
204
205 # squish the ranks by not leaving room
206 make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
207 $GPT prioritize -P 7 -i 3 ${DEV}
208 assert_pri 1 1 7 1 2 2 3 3 4 4 0 5 6 6
209
210 # squish the ranks while bringing the friends along
211 make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
212 $GPT prioritize -P 6 -i 3 -f ${DEV}
213 assert_pri 1 1 6 6 1 1 2 2 3 3 0 4 5 5
214
215 # squish them pretty hard
216 make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
217 $GPT prioritize -P 2 ${DEV}
218 assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 2 2
219
220 # squish them really really hard (nobody gets reduced to zero, though)
221 make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
222 $GPT prioritize -P 1 -i 3 ${DEV}
223 assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 1 1
224
225 # squish if we try to go too high
226 make_pri 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0
227 $GPT prioritize -i 3 ${DEV}
228 assert_pri 14 14 15 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 0
229 $GPT prioritize -i 5 ${DEV}
230 assert_pri 13 13 14 12 15 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0
231 # but if I bring friends I don't have to squish
232 $GPT prioritize -i 1 -f ${DEV}
233 assert_pri 15 15 13 12 14 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0
114 234
115 echo "Done." 235 echo "Done."
116 236
117 happy "All tests passed." 237 happy "All tests passed."
OLDNEW
« no previous file with comments | « tests/common.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698