-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (126 loc) · 4.76 KB
/
Copy pathtest-device.yml
File metadata and controls
162 lines (126 loc) · 4.76 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
name: Test on block devices
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test-loopback:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.13', '3.14']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Install dependencies
run: |
uv sync
- name: Create loopback devices
run: |
# Create sparse files for loopback devices (10 MB each)
truncate -s 10M /tmp/loop_src.img
truncate -s 10M /tmp/loop_dst.img
# Set up loopback devices
sudo losetup -f /tmp/loop_src.img
sudo losetup -f /tmp/loop_dst.img
# Get the device names
SRC_DEVICE=$(losetup -j /tmp/loop_src.img | cut -d: -f1)
DST_DEVICE=$(losetup -j /tmp/loop_dst.img | cut -d: -f1)
echo "SRC_DEVICE=$SRC_DEVICE" >> $GITHUB_ENV
echo "DST_DEVICE=$DST_DEVICE" >> $GITHUB_ENV
echo "Source device: $SRC_DEVICE"
echo "Destination device: $DST_DEVICE"
# Show loopback devices
losetup -l
- name: Write test data to source device
run: |
# Write random data to source device
sudo dd if=/dev/urandom of=$SRC_DEVICE bs=1M count=10 status=progress
# Verify the data was written
echo "Source device checksum:"
sudo md5sum $SRC_DEVICE
- name: Test blockcopy on loopback devices
run: |
# Make devices readable/writable by current user for testing
sudo chmod 666 $SRC_DEVICE $DST_DEVICE
echo "=== Testing blockcopy copy from device to device ==="
# Run blockcopy: checksum | retrieve | save pipeline
uv run blockcopy checksum $DST_DEVICE | \
uv run blockcopy retrieve $SRC_DEVICE | \
uv run blockcopy save $DST_DEVICE
echo "=== Verifying copied data ==="
SRC_MD5=$(md5sum $SRC_DEVICE | cut -d' ' -f1)
DST_MD5=$(md5sum $DST_DEVICE | cut -d' ' -f1)
echo "Source MD5: $SRC_MD5"
echo "Destination MD5: $DST_MD5"
if [ "$SRC_MD5" = "$DST_MD5" ]; then
echo "SUCCESS: Device copy verified!"
else
echo "FAILURE: MD5 checksums do not match!"
exit 1
fi
- name: Test incremental copy (no changes)
run: |
echo "=== Testing incremental copy when devices are identical ==="
# Run blockcopy again - should transfer minimal data
uv run blockcopy checksum $DST_DEVICE 2>&1 | tee /tmp/checksum_output.bin | \
uv run blockcopy retrieve $SRC_DEVICE 2>&1 | tee /tmp/retrieve_output.bin | \
uv run blockcopy save $DST_DEVICE
# Check that retrieve output contains no 'data' blocks (only meta and done)
if grep -q 'data' /tmp/retrieve_output.bin; then
echo "Note: Some data blocks were transferred (this may be expected for block alignment)"
else
echo "SUCCESS: No data blocks transferred for identical content!"
fi
# Verify data integrity
SRC_MD5=$(md5sum $SRC_DEVICE | cut -d' ' -f1)
DST_MD5=$(md5sum $DST_DEVICE | cut -d' ' -f1)
if [ "$SRC_MD5" = "$DST_MD5" ]; then
echo "SUCCESS: Data integrity maintained!"
else
echo "FAILURE: MD5 checksums do not match!"
exit 1
fi
- name: Test partial modification copy
run: |
echo "=== Testing copy after partial modification ==="
# Modify a small portion of the source device
echo "Modified content at offset 5MB" | sudo dd of=$SRC_DEVICE bs=1 seek=5242880 conv=notrunc
# Run blockcopy
uv run blockcopy --verbose checksum $DST_DEVICE | \
uv run blockcopy --verbose retrieve $SRC_DEVICE | \
uv run blockcopy --verbose save $DST_DEVICE
# Verify
SRC_MD5=$(md5sum $SRC_DEVICE | cut -d' ' -f1)
DST_MD5=$(md5sum $DST_DEVICE | cut -d' ' -f1)
echo "Source MD5: $SRC_MD5"
echo "Destination MD5: $DST_MD5"
if [ "$SRC_MD5" = "$DST_MD5" ]; then
echo "SUCCESS: Partial modification copy verified!"
else
echo "FAILURE: MD5 checksums do not match!"
exit 1
fi
- name: Cleanup loopback devices
if: always()
run: |
# Detach loopback devices
if [ -n "$SRC_DEVICE" ]; then
sudo losetup -d $SRC_DEVICE || true
fi
if [ -n "$DST_DEVICE" ]; then
sudo losetup -d $DST_DEVICE || true
fi
# Remove image files
rm -f /tmp/loop_src.img /tmp/loop_dst.img
echo "Cleanup complete"