summaryrefslogtreecommitdiffstats
path: root/src/VBox/Storage/testcase/tstVDCopy.vd
blob: efddb802e41f564660a464f65dac1742dfb56ec3 (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
/* $Id: tstVDCopy.vd $ */
/**
 * Storage: Testcase for VDCopy with snapshots and optimizations.
 */

/*
 * Copyright (C) 2011-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * 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, in version 3 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, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

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

    /* Create source disk and fill data. */
    print("Creating Source Disk");
    createdisk("source", false);
    create("source", "base", "source_base.vdi", "dynamic", "VDI", 1G, false, false);
    io("source", false, 1, "rnd", 64K, 0, 512M, 256M, 100, "none");

    print("Creating first diff");
    create("source", "diff", "source_diff1.vdi", "dynamic", "VDI", 1G, false, false);
    io("source", false, 1, "rnd", 64K, 512M, 1G, 256M, 50, "none");

    print("Creating second diff");
    create("source", "diff", "source_diff2.vdi", "dynamic", "VDI", 1G, false, false);
    io("source", false, 1, "rnd", 1M, 0, 1G, 45M, 100, "none");

    print("Creating third diff");
    create("source", "diff", "source_diff3.vdi", "dynamic", "VDI", 1G, false, false);
    io("source", false, 1, "rnd", 1M, 0, 1G, 45M, 100, "none");

    print("Creating fourth diff");
    create("source", "diff", "source_diff4.vdi", "dynamic", "VDI", 1G, false, false);
    io("source", false, 1, "rnd", 1M, 0, 1G, 45M, 100, "none");

    print("Creating destination disk");
    createdisk("dest", false);

    print("Copying base image");
    copy("source", "dest", 0, "VDI", "dest_base.vdi", false, 0, 0xffffffff, 0xffffffff); /* Image content unknown */

    print("Copying first diff optimized");
    copy("source", "dest", 1, "VDI", "dest_diff1.vdi", false, 0, 0, 0);

    print("Copying other diffs optimized");
    copy("source", "dest", 2, "VDI", "dest_diff2.vdi", false, 0, 1, 1);
    copy("source", "dest", 3, "VDI", "dest_diff3.vdi", false, 0, 2, 2);
    copy("source", "dest", 4, "VDI", "dest_diff4.vdi", false, 0, 3, 3);

    print("Comparing disks");
    comparedisks("source", "dest");

    printfilesize("source", 0);
    printfilesize("source", 1);
    printfilesize("source", 2);
    printfilesize("source", 3);
    printfilesize("source", 4);

    printfilesize("dest", 0);
    printfilesize("dest", 1);
    printfilesize("dest", 2);
    printfilesize("dest", 3);
    printfilesize("dest", 4);

    print("Cleaning up");
    close("dest", "single", true);
    close("dest", "single", true);
    close("dest", "single", true);
    close("dest", "single", true);
    close("dest", "single", true);

    close("source", "single", true);
    close("source", "single", true);
    close("source", "single", true);
    close("source", "single", true);
    close("source", "single", true);
    destroydisk("source");
    destroydisk("dest");

    iorngdestroy();
}