Skip to content

Commit 43514bd

Browse files
committed
vhd-tool: Add cram tests for read_headers
This is just an easy way to make sure the semantics are preserved in any future refactorings, without having to run full VHD exports. Signed-off-by: Andrii Sultanov <andriy.sultanov@vates.tech>
1 parent 98413b2 commit 43514bd

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

ocaml/vhd-tool/cli/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@
7171
(section libexec_root)
7272
(files (get_vhd_vsize.exe as xapi/get_vhd_vsize) (sparse_dd.exe as xapi/sparse_dd))
7373
)
74+
75+
(cram
76+
(package vhd-tool)
77+
(deps main.exe))

ocaml/vhd-tool/cli/read_headers.t

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Create a sparse raw file
2+
$ dd if=/dev/random of=test.raw bs=2097152 count=16 > /dev/null 2>&1
3+
$ dd if=/dev/zero of=test.raw bs=2097152 count=10 seek=3 conv=notrunc > /dev/null 2>&1
4+
5+
Convert to .vhd
6+
$ qemu-img convert -f raw -O vpc test.raw test.vhd
7+
8+
Check if the right clusters are found to be allocated (legacy JSON format)
9+
$ ./main.exe read_headers test.vhd
10+
{"virtual_size":33562624,"cluster_bits":21,"data_clusters":[0,1,2,13,14,15]}
11+
12+
Check fully allocated file
13+
$ dd if=/dev/random of=test.raw bs=2097152 count=16 > /dev/null 2>&1
14+
$ qemu-img convert -f raw -O vpc test.raw test.vhd
15+
$ ./main.exe read_headers test.vhd
16+
{"virtual_size":33562624,"cluster_bits":21,"data_clusters":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]}
17+
18+
Check empty file
19+
$ dd if=/dev/zero of=test.raw bs=2097152 count=16 > /dev/null 2>&1
20+
$ qemu-img convert -f raw -O vpc test.raw test.vhd
21+
$ ./main.exe read_headers test.vhd
22+
{"virtual_size":33562624,"cluster_bits":21,"data_clusters":[]}

0 commit comments

Comments
 (0)