summaryrefslogtreecommitdiffstats
path: root/src/VBox/Storage/testcase/tstVDCompact.vd
blob: e2d114b39c58e11eedc9fcfb9db9d4b5afd9ea24 (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
/* $Id: tstVDCompact.vd $ */
/**
 * Storage: Testcase for compacting disks.
 */

/*
 * Copyright (C) 2011-2020 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

void tstCompact(string strMsg, string strBackend)
{
    print(strMsg);

    /* Create disk containers, read verification is on. */
    createdisk("disk", true);
    create("disk", "base", "tstCompact.disk", "dynamic", strBackend, 200M, false, false);

    /* Fill the disk with random data. */
    io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 100, "none");
    /* Read the data to verify it once. */
    io("disk", false, 1, "seq", 64K, 0, 200M, 200M,   0, "none");
    /* Fill a part with 0's. */
    io("disk", false, 1, "seq", 64K, 100M, 150M, 50M, 100, "zero");

    /* Now compact. */
    compact("disk", 0);
    /* Read again to verify that the content hasn't changed. */
    io("disk", false, 1, "seq", 64K, 0, 200M, 200M,   0, "none");
    /* Fill everything with 0. */
    io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 100, "zero");
    /* Now compact again. */
    compact("disk", 0);
    /* Read again to verify that the content hasn't changed. */
    io("disk", false, 1, "seq", 64K, 0, 200M, 200M,   0, "none");

    close("disk", "single", true);
    destroydisk("disk");
}

void tstSnapshotCompact(string strMsg, string strBackend)
{
    print(strMsg);

    /* Create disk containers, read verification is on. */
    createdisk("disk", true);
    create("disk", "base", "tstCompact.disk", "dynamic", strBackend, 200M, false, false);

    /* Fill the disk with random data. */
    io("disk", false, 1, "seq", 64K, 0, 100M, 100M, 100, "none");

    create("test", "diff", "tst2.disk", "dynamic", strBackend, 200M, false /* fIgnoreFlush */, true /* fHonorSame */);

    io("disk", false, 1, "seq", 64K, 100M, 200M, 100M, 100, "none");
    io("disk", false, 1, "seq", 64K, 100M, 150M, 50M, 100, "zero");

    create("disk", "diff", "tst3.disk", "dynamic", strBackend, 200M, false /* fIgnoreFlush */, true /* fHonorSame */);
    merge("disk", 1, 2);

    compact("disk", 1);

    close("disk", "single", true);
    close("disk", "single", true);
    close("disk", "single", true);
    destroydisk("disk");
}

void main()
{
    /* Init I/O RNG for generating random data for writes. */
    iorngcreate(10M, "manual", 1234567890);

    /* Create zero pattern */
    iopatterncreatefromnumber("zero", 1M, 0);

    tstCompact("Testing VDI", "VDI");
    tstCompact("Testing VHD", "VHD");

    tstSnapshotCompact("Testing Snapshot VDI", "VDI");
    tstSnapshotCompact("Testing Snapshot VHD", "VHD");

    /* Destroy RNG and pattern */
    iopatterndestroy("zero");
    iorngdestroy();
}