tstVDCompact.vd revision 1839eb6c2f3526b276ac2dcf3deae74f6ef8af44
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync/* $Id$ */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync/**
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * Storage: Testcase for compacting disks.
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync */
48a15610b4cfea625302a67f21b3f46215c59aa4vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync/*
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * Copyright (C) 2011 Oracle Corporation
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync *
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * available from http://www.virtualbox.org. This file is free software;
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * General Public License (GPL) as published by the Free Software
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync */
48a15610b4cfea625302a67f21b3f46215c59aa4vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsyncvoid tstCompact(string strMsg, string strBackend)
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync{
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync print(strMsg);
48a15610b4cfea625302a67f21b3f46215c59aa4vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Create disk containers, read verification is on. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync createdisk("disk", true);
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync create("disk", "base", "tstCompact.disk", "dynamic", strBackend, 200M, false);
48a15610b4cfea625302a67f21b3f46215c59aa4vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Fill the disk with random data. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 100, "none");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Read the data to verify it once. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 0, "none");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Fill a part with 0's. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync io("disk", false, 1, "seq", 64K, 100M, 150M, 50M, 100, "zero");
48a15610b4cfea625302a67f21b3f46215c59aa4vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Now compact. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync compact("disk", 0);
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Read again to verify that the content hasn't changed. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 0, "none");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Fill everything with 0. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 100, "zero");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Now compact again. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync compact("disk", 0);
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Read again to verify that the content hasn't changed. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync io("disk", false, 1, "seq", 64K, 0, 200M, 200M, 0, "none");
a1ad00e8ddb3bcb94b3fada7cb1ea310d1b31243vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync close("disk", "single", true);
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync destroydisk("disk");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync}
48a15610b4cfea625302a67f21b3f46215c59aa4vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsyncvoid main()
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync{
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Init I/O RNG for generating random data for writes. */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync iorngcreate(10M, "manual", 1234567890);
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Create zero pattern */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync iopatterncreatefromnumber("zero", 1M, 0);
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync tstCompact("Testing VDI", "VDI");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync tstCompact("Testing VHD", "VHD");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync /* Destroy RNG and pattern */
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync iopatterndestroy("zero");
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync iorngdestroy();
1839eb6c2f3526b276ac2dcf3deae74f6ef8af44vboxsync}