-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_test.sh
More file actions
executable file
·197 lines (173 loc) · 5.36 KB
/
run_test.sh
File metadata and controls
executable file
·197 lines (173 loc) · 5.36 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
set -xe
TEMPDIR=$(mktemp -d)
DEV=""
mkdir $TEMPDIR/mnt
cleanup() {
# Ignore errors in cleanup.
set +e
umount -l -q $TEMPDIR/mnt
[ -z "$DEV" ] || losetup -d $DEV
rm -rf $TEMPDIR
# Kill descendants, but not itself.
trap '' SIGTERM
kill -- -$(ps -o pgid= $$ | tr -d ' ')
trap - SIGTERM
}
trap cleanup EXIT
cp -rv $1 $TEMPDIR
cp test_config.yaml $TEMPDIR/storage/config.yaml
cat >$TEMPDIR/storage/registered.json <<EOF
[
{
"mac": [82, 84, 0, 18, 52, 86],
"group": 0,
"row": 1,
"col": 1,
"curr_action": null,
"curr_progress": null,
"next_action": "shutdown",
"image": "contestant"
},
{
"mac": [82, 84, 0, 18, 52, 87],
"group": 10,
"row": 9,
"col": 1,
"curr_action": null,
"curr_progress": null,
"next_action": "shutdown",
"image": "contestant"
}
]
EOF
if ! ip link show br-pixie; then
ip link add br-pixie type bridge
ip link set dev br-pixie up
ip addr add 10.0.0.1/16 dev br-pixie
fi
if ! ip link show br-pixie1; then
ip link add br-pixie1 type bridge
ip link set dev br-pixie1 up
ip addr add 10.10.0.1/16 dev br-pixie1
fi
RUST_BACKTRACE=short RUST_LOG=debug RUST_LOG_STYLE=always LLVM_PROFILE_FILE=prof-out/pixie-server-%m-%p.profraw ./pixie-server/target/debug/pixie-server -s $TEMPDIR/storage &
run_qemu() {
OVMF=/usr/share/OVMF/OVMF_CODE_4M.fd
if ! [ -e $OVMF ]; then
OVMF=/usr/share/edk2/x64/OVMF_CODE.4m.fd
fi
FILE=prof-out/pixie-uefi-$RANDOM.profraw
truncate -s 500M $FILE
qemu-system-x86_64 \
-nographic \
-chardev stdio,id=char0,logfile=$1,signal=off \
-serial chardev:char0 \
-monitor none \
-enable-kvm \
-cpu host -smp cores=2 \
-m 1G \
-drive if=pflash,format=raw,file=$OVMF \
-drive file=$TEMPDIR/disk.img,if=none,id=nvm,format=raw \
-drive file=$FILE,format=raw \
-device nvme,serial=deadbeef,drive=nvm \
-nic bridge,mac=52:54:00:12:34:56,br=br-pixie,model=e1000
}
run_qemu1() {
OVMF=/usr/share/OVMF/OVMF_CODE_4M.fd
if ! [ -e $OVMF ]; then
OVMF=/usr/share/edk2/x64/OVMF_CODE.4m.fd
fi
FILE=prof-out/pixie-uefi-$RANDOM.profraw
truncate -s 500M $FILE
qemu-system-x86_64 \
-nographic \
-chardev stdio,id=char0,logfile=$1,signal=off \
-serial chardev:char0 \
-monitor none \
-enable-kvm \
-cpu host -smp cores=2 \
-m 1G \
-drive if=pflash,format=raw,file=$OVMF \
-drive file=$TEMPDIR/disk1.img,if=none,id=nvm,format=raw \
-drive file=$FILE,format=raw \
-device nvme,serial=deadbeef,drive=nvm \
-nic bridge,mac=52:54:00:12:34:57,br=br-pixie1,model=e1000
}
truncate -s 8G $TEMPDIR/disk.img
truncate -s 8G $TEMPDIR/disk1.img
echo -e "label: gpt\n- 1GiB - -\n- 1GiB - -\n- - L -" | sfdisk $TEMPDIR/disk.img
DEV=$(losetup --partscan --show --find $TEMPDIR/disk.img)
mkswap ${DEV}p1
mkfs.ntfs -f ${DEV}p2
mkfs.ext4 ${DEV}p3
for PART in ${DEV}p{2..3}; do
mount $PART $TEMPDIR/mnt
cp ./pixie-server/target/debug/pixie-server $TEMPDIR/mnt
umount $TEMPDIR/mnt
done
losetup -d $DEV
curl 'http://localhost:8080/admin/curr_action/52:54:00:12:34:56/store'
run_qemu $TEMPDIR/store.log
# Check that we restore the original disk image.
rm -f $TEMPDIR/disk.img
truncate -s 8G $TEMPDIR/disk.img
curl 'http://localhost:8080/admin/curr_action/all/flash'
run_qemu $TEMPDIR/flash-1.log
run_qemu1 $TEMPDIR/flash1-1.log
DEV=$(losetup --partscan --show --find --read-only $TEMPDIR/disk.img)
fsck -n ${DEV}p*
for PART in ${DEV}p{2..3}; do
mount -o ro $PART $TEMPDIR/mnt
if [ "$(md5sum $TEMPDIR/mnt/pixie-server | cut -f 1 -d ' ')" != "$(md5sum ./pixie-server/target/debug/pixie-server | cut -f 1 -d ' ')" ]; then
echo "pixie-server does not contain the expected content"
exit 1
fi
umount $TEMPDIR/mnt
done
losetup -d $DEV
DEV=$(losetup --partscan --show --find --read-only $TEMPDIR/disk1.img)
fsck -n ${DEV}p*
for PART in ${DEV}p{2..3}; do
mount -o ro $PART $TEMPDIR/mnt
if [ "$(md5sum $TEMPDIR/mnt/pixie-server | cut -f 1 -d ' ')" != "$(md5sum ./pixie-server/target/debug/pixie-server | cut -f 1 -d ' ')" ]; then
echo "pixie-server does not contain the expected content"
exit 1
fi
umount $TEMPDIR/mnt
done
losetup -d $DEV
# Check that we don't fetch any data if the disk contents have not changed.
curl 'http://localhost:8080/admin/curr_action/all/flash'
run_qemu $TEMPDIR/flash-2.log
run_qemu1 $TEMPDIR/flash1-2.log
DEV=$(losetup --partscan --show --find --read-only $TEMPDIR/disk.img)
fsck -n ${DEV}p*
for PART in ${DEV}p{2..3}; do
mount -o ro $PART $TEMPDIR/mnt
if [ "$(md5sum $TEMPDIR/mnt/pixie-server | cut -f 1 -d ' ')" != "$(md5sum ./pixie-server/target/debug/pixie-server | cut -f 1 -d ' ')" ]; then
echo "pixie-server does not contain the expected content"
exit 1
fi
umount $TEMPDIR/mnt
done
losetup -d $DEV
DEV=$(losetup --partscan --show --find --read-only $TEMPDIR/disk1.img)
fsck -n ${DEV}p*
for PART in ${DEV}p{2..3}; do
mount -o ro $PART $TEMPDIR/mnt
if [ "$(md5sum $TEMPDIR/mnt/pixie-server | cut -f 1 -d ' ')" != "$(md5sum ./pixie-server/target/debug/pixie-server | cut -f 1 -d ' ')" ]; then
echo "pixie-server does not contain the expected content"
exit 1
fi
umount $TEMPDIR/mnt
done
losetup -d $DEV
if ! grep "Disk scanned; 0 chunks to fetch" $TEMPDIR/flash-2.log &>/dev/null; then
echo "Data was re-fetched"
exit 1
fi
if ! grep "Disk scanned; 0 chunks to fetch" $TEMPDIR/flash1-2.log &>/dev/null; then
echo "Data was re-fetched"
exit 1
fi