os/kernelhwsrv/kerneltest/e32test/examples/defrag/t_defrag_ref.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/defrag/t_defrag_ref.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,106 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\defrag\t_defrag_ref.cpp
    1.18 +// Overview:
    1.19 +// Test application that uses the reference defragmantation driver to invoke
    1.20 +// the top-level defragmentation operations.
    1.21 +// API Information:
    1.22 +// RBusLogicalChannel
    1.23 +// Details:
    1.24 +// - Load and open the logical device driver ("D_DEFRAG_REF.LDD"). Verify
    1.25 +// results.
    1.26 +// - Request that the driver attempt to trigger various defragmentation
    1.27 +// operations. Verify that they complete successfully.
    1.28 +// Platforms/Drives/Compatibility:
    1.29 +// Hardware only. No defrag support on emulator.
    1.30 +// Assumptions/Requirement/Pre-requisites:
    1.31 +// Failures and causes:
    1.32 +// Base Port information:
    1.33 +// 
    1.34 +//
    1.35 +
    1.36 +#define __E32TEST_EXTENSION__
    1.37 +#include <e32test.h>
    1.38 +#include "d_defrag_ref.h"
    1.39 +#include "..\..\mmu\mmudetect.h"
    1.40 +
    1.41 +LOCAL_D RTest test(_L("T_DEFRAG_REF"));
    1.42 +
    1.43 +const TPtrC KLddFileName=_L("d_defrag_ref.ldd");
    1.44 +
    1.45 +GLDEF_C TInt E32Main()
    1.46 +    {
    1.47 +	test.Title();
    1.48 +	if (!HaveMMU())
    1.49 +		{
    1.50 +		test.Printf(_L("This test requires an MMU\n"));
    1.51 +		return KErrNone;
    1.52 +		}
    1.53 +
    1.54 +	test.Start(_L("Load test LDD"));
    1.55 +	TInt r=User::LoadLogicalDevice(KLddFileName);
    1.56 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.57 +
    1.58 +	RDefragChannel defrag;
    1.59 +	TRequestStatus req;
    1.60 +	test.Next(_L("Open test LDD"));
    1.61 +	r = defrag.Open();
    1.62 +	if (r == KErrNotSupported)
    1.63 +		{// This system has no defrag support so can't continue
    1.64 +		goto exit;
    1.65 +		}
    1.66 +	test_KErrNone(r);		
    1.67 +
    1.68 +	test.Next(_L("Test calls to GeneralDefragRam DFC"));
    1.69 +	test_KErrNone(defrag.GeneralDefragDfc(&req));
    1.70 +
    1.71 +	test.Next(_L("Only one defrag operation can be active per channel"));
    1.72 +	test_Equal(KErrInUse, defrag.GeneralDefrag());
    1.73 +
    1.74 +	test.Next(_L("Wait for defrag request to complete"));
    1.75 +	User::WaitForRequest(req);
    1.76 +	test_KErrNone(defrag.GeneralDefragDfcComplete());
    1.77 +	
    1.78 +	test.Next(_L("Test calls to GeneralDefragRam"));
    1.79 +	test_KErrNone(defrag.GeneralDefrag());
    1.80 +
    1.81 +	test.Next(_L("Test calls to GeneralDefragRamSem"));
    1.82 +	test_KErrNone(defrag.GeneralDefragSem());
    1.83 +
    1.84 +	test.Next(_L("Test allocating into the least preferable zone"));
    1.85 +	r = defrag.AllocLowestZone();
    1.86 +	test(r == KErrNone || r == KErrNoMemory);
    1.87 +	if (r == KErrNone)
    1.88 +		{
    1.89 +		test.Next(_L("Test closing the chunk mapped to the least preferable zone"));
    1.90 +		test_KErrNone(defrag.CloseChunk());
    1.91 +		}
    1.92 +
    1.93 +	test.Next(_L("Test claiming the least preferable zone"));
    1.94 +	r = defrag.ClaimLowestZone();
    1.95 +	test(r == KErrNone || r == KErrNoMemory);
    1.96 +	if (r == KErrNone)
    1.97 +		{
    1.98 +		test.Next(_L("Test closing the chunk mapped to the least preferable zone"));
    1.99 +		test_KErrNone(defrag.CloseChunk());
   1.100 +		}
   1.101 +
   1.102 +exit:
   1.103 +	test.Next(_L("Close test LDD"));
   1.104 +	defrag.Close();
   1.105 +	User::FreeLogicalDevice(KLddFileName);
   1.106 +
   1.107 +	test.End();
   1.108 +	return(KErrNone);
   1.109 +    }