blob: 239b98459e25f84cd5e20a25d57be64faafe1a46 [file] [log] [blame]
Gilad Arnold553b0ec2013-01-26 01:00:39 -08001#!/bin/bash
2#
Amin Hassanif94b6432018-01-26 17:39:47 -08003# Copyright (C) 2013 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Gilad Arnold553b0ec2013-01-26 01:00:39 -080017
18# A test script for paycheck.py and the update_payload.py library.
19#
20# This script requires three payload files, along with a metadata signature for
21# each, and a public key for verifying signatures. Payload include:
22#
23# - A full payload for release X (old_full_payload)
24#
25# - A full payload for release Y (new_full_payload), where Y > X
26#
27# - A delta payload from X to Y (delta_payload)
28#
29# The test performs the following:
30#
31# - It verifies each payload against its metadata signature, also asserting the
32# payload type. Another artifact is a human-readable payload report, which
33# is output to stdout to be inspected by the user.
34#
Gilad Arnold553b0ec2013-01-26 01:00:39 -080035# - It applies old_full_payload to yield old kernel (old_kern.part) and rootfs
36# (old_root.part) partitions.
37#
38# - It applies delta_payload to old_{kern,root}.part to yield new kernel
39# (new_delta_kern.part) and rootfs (new_delta_root.part) partitions.
40#
41# - It applies new_full_payload to yield reference new kernel
42# (new_full_kern.part) and rootfs (new_full_root.part) partitions.
43#
44# - It compares new_{delta,full}_kern.part and new_{delta,full}_root.part to
45# ensure that they are binary identical.
46#
47# If all steps have completed successfully we know with high certainty that
Amin Hassania5489022018-01-26 11:23:26 -080048# paycheck.py (and hence update_payload.py) correctly parses both full and delta
49# payloads, and applies them to yield the expected result. Finally, each
50# paycheck.py execution is timed.
Gilad Arnold553b0ec2013-01-26 01:00:39 -080051
52
Gilad Arnold9157a1a2013-04-30 15:40:01 -070053# Stop on errors, unset variables.
54set -e
55set -u
56
57# Temporary image files.
Gilad Arnold553b0ec2013-01-26 01:00:39 -080058OLD_KERN_PART=old_kern.part
59OLD_ROOT_PART=old_root.part
60NEW_DELTA_KERN_PART=new_delta_kern.part
61NEW_DELTA_ROOT_PART=new_delta_root.part
62NEW_FULL_KERN_PART=new_full_kern.part
63NEW_FULL_ROOT_PART=new_full_root.part
Tudor Brindus5c8c6272018-06-20 14:35:57 -070064CROS_PARTS="kernel root"
Gilad Arnold553b0ec2013-01-26 01:00:39 -080065
Gilad Arnold553b0ec2013-01-26 01:00:39 -080066
67log() {
68 echo "$@" >&2
69}
70
71die() {
72 log "$@"
73 exit 1
74}
75
76usage_and_exit() {
77 cat >&2 <<EOF
Gilad Arnoldd0130282013-05-13 08:12:39 -070078Usage: ${0##*/} old_full_payload delta_payload new_full_payload
Gilad Arnold553b0ec2013-01-26 01:00:39 -080079EOF
80 exit
81}
82
83check_payload() {
84 payload_file=$1
Gilad Arnoldd0130282013-05-13 08:12:39 -070085 payload_type=$2
Gilad Arnold553b0ec2013-01-26 01:00:39 -080086
Gilad Arnoldd0130282013-05-13 08:12:39 -070087 time ${paycheck} -t ${payload_type} ${payload_file}
Gilad Arnold553b0ec2013-01-26 01:00:39 -080088}
89
Gilad Arnold553b0ec2013-01-26 01:00:39 -080090apply_full_payload() {
91 payload_file=$1
Amin Hassanie20eb912018-02-21 12:39:42 -080092 out_dst_kern_part="$2/$3"
93 out_dst_root_part="$2/$4"
Gilad Arnold553b0ec2013-01-26 01:00:39 -080094
Amin Hassani52b60392017-12-19 10:53:24 -080095 time ${paycheck} ${payload_file} \
Tudor Brindus5c8c6272018-06-20 14:35:57 -070096 --part_names ${CROS_PARTS} \
97 --out_dst_part_paths ${out_dst_kern_part} ${out_dst_root_part}
Gilad Arnold553b0ec2013-01-26 01:00:39 -080098}
99
100apply_delta_payload() {
101 payload_file=$1
Amin Hassanie20eb912018-02-21 12:39:42 -0800102 out_dst_kern_part="$2/$3"
103 out_dst_root_part="$2/$4"
104 dst_kern_part="$2/$5"
105 dst_root_part="$2/$6"
106 src_kern_part="$2/$7"
107 src_root_part="$2/$8"
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800108
Amin Hassani52b60392017-12-19 10:53:24 -0800109 time ${paycheck} ${payload_file} \
Tudor Brindus5c8c6272018-06-20 14:35:57 -0700110 --part_names ${CROS_PARTS} \
111 --out_dst_part_paths ${out_dst_kern_part} ${out_dst_root_part} \
112 --dst_part_paths ${dst_kern_part} ${dst_root_part} \
113 --src_part_paths ${src_kern_part} ${src_root_part}
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800114}
115
116main() {
117 # Read command-line arguments.
118 if [ $# == 1 ] && [ "$1" == "-h" ]; then
119 usage_and_exit
Gilad Arnoldd0130282013-05-13 08:12:39 -0700120 elif [ $# != 3 ]; then
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800121 die "Error: unexpected number of arguments"
122 fi
Gilad Arnoldd0130282013-05-13 08:12:39 -0700123 old_full_payload="$1"
124 delta_payload="$2"
125 new_full_payload="$3"
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800126
127 # Find paycheck.py
128 paycheck=${0%/*}/paycheck.py
129 if [ -z "${paycheck}" ] || [ ! -x ${paycheck} ]; then
Gilad Arnold2ca9f142013-05-13 12:29:58 -0700130 die "cannot find ${paycheck} or file is not executable"
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800131 fi
132
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700133 # Check the payloads statically.
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800134 log "Checking payloads..."
Gilad Arnoldd0130282013-05-13 08:12:39 -0700135 check_payload "${old_full_payload}" full
136 check_payload "${new_full_payload}" full
137 check_payload "${delta_payload}" delta
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800138 log "Done"
139
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700140 # Apply full/delta payloads and verify results are identical.
141 tmpdir="$(mktemp -d --tmpdir test_paycheck.XXXXXXXX)"
142 log "Initiating application of payloads at $tmpdir"
143
144 log "Applying old full payload..."
145 apply_full_payload "${old_full_payload}" "${tmpdir}" "${OLD_KERN_PART}" \
146 "${OLD_ROOT_PART}"
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800147 log "Done"
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700148
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700149 log "Applying new full payload..."
150 apply_full_payload "${new_full_payload}" "${tmpdir}" "${NEW_FULL_KERN_PART}" \
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800151 "${NEW_FULL_ROOT_PART}"
152 log "Done"
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700153
Amin Hassanie20eb912018-02-21 12:39:42 -0800154 log "Applying delta payload to old partitions..."
155 apply_delta_payload "${delta_payload}" "${tmpdir}" "${NEW_DELTA_KERN_PART}" \
156 "${NEW_DELTA_ROOT_PART}" "${NEW_FULL_KERN_PART}" \
157 "${NEW_FULL_ROOT_PART}" "${OLD_KERN_PART}" "${OLD_ROOT_PART}"
158 log "Done"
159
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800160 log "Comparing results of delta and new full updates..."
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700161 diff "${tmpdir}/${NEW_FULL_KERN_PART}" "${tmpdir}/${NEW_DELTA_KERN_PART}"
162 diff "${tmpdir}/${NEW_FULL_ROOT_PART}" "${tmpdir}/${NEW_DELTA_ROOT_PART}"
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800163 log "Done"
Gilad Arnold9157a1a2013-04-30 15:40:01 -0700164
165 log "Cleaning up"
166 rm -fr "${tmpdir}"
Gilad Arnold553b0ec2013-01-26 01:00:39 -0800167}
168
169main "$@"