summaryrefslogtreecommitdiff
path: root/tests.as-root/make-patch.script
blob: de1ce172b740b1d3a26d8be3fe61d4bb62ba2818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
#
# Test making a patch between two different system images
#
# Copyright (C) 2012  Codethink Limited
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -eu

# Make a stratum that include hello and kernel chunks.
cat <<EOF > "$DATADIR/morphs-repo/hello-stratum.morph"
{
    "name": "hello-stratum",
    "kind": "stratum",
    "chunks": [
        {
            "name": "hello",
            "repo": "test:chunk-repo",
            "ref": "farrokh",
            "build-depends": []
        },
        {
            "name": "linux",
            "repo": "test:kernel-repo",
            "ref": "master",
            "build-depends": ["hello"]
        }
    ]
}
EOF
"$SRCDIR/scripts/run-git-in" "$DATADIR/morphs-repo" commit --quiet -am foo \
    > /dev/null

# Build first image. Remember the stratum.
"$SRCDIR/scripts/test-morph" build-morphology \
    test:morphs-repo master hello-system
img1=$(find "$DATADIR/cache/artifacts" -maxdepth 1 -name '*.system.*-rootfs')

# Modify the chunk, in a new branch.
"$SRCDIR/scripts/run-git-in" "$DATADIR/chunk-repo" checkout --quiet farrokh
"$SRCDIR/scripts/run-git-in" "$DATADIR/chunk-repo" checkout --quiet -b alfred
sed -i s/hello/goodbye/ "$DATADIR/chunk-repo/hello.c"
"$SRCDIR/scripts/run-git-in" "$DATADIR/chunk-repo" commit -am goodbye \
    > /dev/null
    
# Modify the morphs repo to use the new chunk branch, creating a new 
# branch for the morphs repo.
"$SRCDIR/scripts/run-git-in" "$DATADIR/morphs-repo" checkout --quiet -b alfred
sed -i 's/farrokh/alfred/' "$DATADIR/morphs-repo/hello-stratum.morph"
sed -i 's/master/alfred/' "$DATADIR/morphs-repo/hello-system.morph"
"$SRCDIR/scripts/run-git-in" "$DATADIR/morphs-repo" commit -am goodbye \
    > /dev/null

# Build second image.
"$SRCDIR/scripts/test-morph" build-morphology \
    test:morphs-repo alfred hello-system
img2=$(find "$DATADIR/cache/artifacts" -maxdepth 1 -name '*.system.*' \
            ! -name $(basename "$img1"))

# Make the patch.
patch="$DATADIR/patch"
"$SRCDIR/scripts/test-morph" make-patch "$patch" \
    test:morphs-repo master hello-system.morph \
    test:morphs-repo alfred hello-system.morph

# find out the offset of the partition in the disk image
# udevadm settle is used to wait until devices have appeared
loop=$(losetup -f --show "$img1")
udevadm settle
offset=$(sfdisk -d "$loop" |
             sed -n '/start=/s/^.*start=\s*\([0-9]\+\)[^0-9].*$/\1/p' |
             head -n 1)
ssz=`cat "/sys/devices/virtual/block/$(basename "$loop")/queue/hw_sector_size"`
losetup -d "$loop"
udevadm settle

# mount the disk
mkdir "$DATADIR/unpacked"
# this has to be done by losetup then mount, because busybox mount doesn't
# accept the -o offset= option
loop=$(losetup -o "$(expr "$offset" '*' "$ssz")" -f --show "$img1")
udevadm settle
trap 'losetup -d "$loop"' INT TERM EXIT
mount -o subvol=factory-run -t btrfs "$loop" "$DATADIR/unpacked"
trap 'umount "$DATADIR/unpacked"; losetup -d "$loop"' INT TERM EXIT

cd "$DATADIR/unpacked"
echo "old version:"
./bin/hello

# Apply patch, run program again. We should get updated output.
tbdiff-deploy "$patch" 2>/dev/null
echo "new version:"
./bin/hello

# Done.
echo "Done."
# chdir out of mounted folder, so it can be unmounted
cd /