os/kernelhwsrv/kerneltest/e32test/mmu/t_kblockmap.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_kblockmap.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,586 @@
     1.4 +// Copyright (c) 2006-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\mmu\t_kblockmap.cpp
    1.18 +// Unit tests for TKernBlockMap
    1.19 +// 002 Test Initialise error checking
    1.20 +// 003 Test processing of user-side block map into extent list
    1.21 +// 004 Test processing of user-side block map into extent list, block size > read unit size
    1.22 +// 005 Test Read error checking
    1.23 +// 006 Test Read
    1.24 +// 
    1.25 +//
    1.26 +
    1.27 +//! @SYMTestCaseID			KBASE-T_KBLOCKMAP-0338
    1.28 +//! @SYMTestType			UT
    1.29 +//! @SYMPREQ				PREQ1110
    1.30 +//! @SYMTestCaseDesc		Demand Paging Kernel Blockmap tests
    1.31 +//! @SYMTestActions			001 Unit tests the TKernBlockMap class
    1.32 +//! @SYMTestExpectedResults All tests should pass.
    1.33 +//! @SYMTestPriority        High
    1.34 +//! @SYMTestStatus          Implemented
    1.35 +
    1.36 +#include <e32test.h>
    1.37 +#include <e32debug.h>
    1.38 +#include <memmodel/epoc/mmubase/kblockmap.h>
    1.39 +
    1.40 +RTest test(_L("T_KBLOCKMAP"));
    1.41 +
    1.42 +#define test_noError(x) { TInt _r = (x); if (_r < 0) HandleError(_r, __LINE__); }
    1.43 +#define test_notNull(x) { TAny* _a = (TAny*)(x); if (_a == NULL) HandleNull(__LINE__); }
    1.44 +#define test_equal(e, a) { TInt _e = (e); TInt _a = (a); if (_e != _a) HandleNotEqual(_e, _a, __LINE__); }
    1.45 +
    1.46 +void HandleError(TInt aError, TInt aLine)
    1.47 +	{
    1.48 +	test.Printf(_L("Error %d\n"), aError);
    1.49 +	test.operator()(EFalse, aLine);
    1.50 +	}
    1.51 +
    1.52 +void HandleNull(TInt aLine)
    1.53 +	{
    1.54 +	test.Printf(_L("Null value\n"));
    1.55 +	test.operator()(EFalse, aLine);
    1.56 +	}
    1.57 +
    1.58 +void HandleNotEqual(TInt aExpected, TInt aActual, TInt aLine)
    1.59 +	{
    1.60 +	test.Printf(_L("Expected 0x%x but got 0x%x\n"), aExpected, aActual);
    1.61 +	test.operator()(EFalse, aLine);
    1.62 +	}
    1.63 +
    1.64 +/// An list of "pod" objects which can be initialised by passing a variable number of TUints to its
    1.65 +/// constructor
    1.66 +template <class T>
    1.67 +class CList
    1.68 +	{
    1.69 +public:
    1.70 +	CList();
    1.71 +	CList(TInt aCount, ...);
    1.72 +	virtual ~CList();
    1.73 +	inline TInt Count() const { return iCount; }
    1.74 +	const T* Entries() const { return iEntries; }
    1.75 +	const T& operator[](TInt aIndex) const;
    1.76 +protected:
    1.77 +	void Set(TInt aCount, VA_LIST aList);
    1.78 +private:
    1.79 +	const CList<T>& operator=(const CList<T>&);
    1.80 +	TInt iCount;
    1.81 +	T* iEntries;
    1.82 +	};
    1.83 +
    1.84 +template <class T>
    1.85 +CList<T>::CList()
    1.86 +	: iCount(0), iEntries(NULL)
    1.87 +	{
    1.88 +	__ASSERT_COMPILE(sizeof(T) % sizeof(TUint32) == 0);
    1.89 +	}
    1.90 +
    1.91 +template <class T>
    1.92 +CList<T>::CList(TInt aCount, ...)
    1.93 +	: iCount(aCount)
    1.94 +	{
    1.95 +	VA_LIST list;
    1.96 +	VA_START(list, aCount);
    1.97 +	Set(aCount, list);
    1.98 +	}
    1.99 +
   1.100 +template <class T>
   1.101 +CList<T>::~CList()
   1.102 +	{
   1.103 +	User::Free(iEntries);
   1.104 +	iEntries = NULL;
   1.105 +	}
   1.106 +
   1.107 +template <class T>
   1.108 +void CList<T>::Set(TInt aCount, VA_LIST aList)
   1.109 +	{
   1.110 +	iCount = aCount;
   1.111 +	test(iEntries == NULL);
   1.112 +	iEntries = (T*)User::Alloc(sizeof(T) * iCount);
   1.113 +	test_notNull(iEntries);
   1.114 +	TInt argCount = iCount * (sizeof(T) / sizeof(TUint32));
   1.115 +	for (TInt i = 0 ; i < argCount ; ++i)
   1.116 +		((TUint32*)iEntries)[i] = VA_ARG(aList, TUint32);
   1.117 +	}
   1.118 +
   1.119 +template <class T>
   1.120 +const T& CList<T>::operator[](TInt aIndex) const
   1.121 +	{
   1.122 +	test(aIndex < iCount);
   1.123 +	return iEntries[aIndex];
   1.124 +	}
   1.125 +
   1.126 +/// Holds all the data associated with the user-side representation of a block map
   1.127 +class CBlockMap : public CList<TBlockMapEntryBase>
   1.128 +	{
   1.129 +public:
   1.130 +	CBlockMap(TUint aBlockGranularity,
   1.131 +			  TUint aBlockStartOffset,
   1.132 +			  TInt64 aStartBlockAddress,
   1.133 +			  TUint aReadUnitShift,
   1.134 +			  TUint aCodeLengthInFile,
   1.135 +			  TUint aEntriesSize,
   1.136 +			  ...);
   1.137 +	inline const SBlockMapInfoBase& Info() const { return iInfo; }
   1.138 +	inline TInt ReadUnitShift() const { return iReadUnitShift; }
   1.139 +	inline TInt CodeLengthInFile() const { return iCodeLengthInFile; }
   1.140 +	inline TInt EntriesSize() const { return iEntriesSize; }
   1.141 +private:
   1.142 +	SBlockMapInfoBase iInfo;
   1.143 +	TBlockMapEntryBase* iEntries;
   1.144 +	TUint iReadUnitShift;
   1.145 +	TUint iCodeLengthInFile;
   1.146 +	TUint iEntriesSize;
   1.147 +	};
   1.148 +
   1.149 +CBlockMap::CBlockMap(TUint aBlockGranularity,
   1.150 +					 TUint aBlockStartOffset,
   1.151 +					 TInt64 aStartBlockAddress,
   1.152 +					 TUint aReadUnitShift,
   1.153 +					 TUint aCodeLengthInFile,
   1.154 +					 TUint aEntriesSize,
   1.155 +					 ...)
   1.156 +	{
   1.157 +	iInfo.iBlockGranularity = aBlockGranularity;
   1.158 +	iInfo.iBlockStartOffset = aBlockStartOffset;
   1.159 +	iInfo.iStartBlockAddress = aStartBlockAddress;
   1.160 +	// don't care about iInfo.iLocalDriveNumber for test purposes
   1.161 +	iReadUnitShift = aReadUnitShift;
   1.162 +	iCodeLengthInFile = aCodeLengthInFile;
   1.163 +	iEntriesSize = aEntriesSize;
   1.164 +	iEntries = (TBlockMapEntryBase*)User::Alloc(iEntriesSize);
   1.165 +
   1.166 +	VA_LIST list;
   1.167 +	VA_START(list, aEntriesSize);
   1.168 +	Set(iEntriesSize / sizeof(TBlockMapEntryBase), list);
   1.169 +	}
   1.170 +
   1.171 +/// A list of extents, for comparison with those generated by the kernel block map processing code
   1.172 +class CExtentList : public CList<TBlockMap::SExtent>
   1.173 +	{
   1.174 +public:
   1.175 +	typedef TBlockMap::SExtent SExtent;
   1.176 +	CExtentList(TInt aCount, ...);
   1.177 +	void Dump() const;
   1.178 +	};
   1.179 +
   1.180 +CExtentList::CExtentList(TInt aCount, ...)
   1.181 +	{
   1.182 +	VA_LIST list;
   1.183 +	VA_START(list, aCount);
   1.184 +	Set(aCount, list);
   1.185 +	}
   1.186 +
   1.187 +void CExtentList::Dump() const
   1.188 +	{
   1.189 +	RDebug::Printf("CExtentList:\n");
   1.190 +	const CExtentList& self = *this;
   1.191 +	for (TInt i = 0 ; i < Count() ; ++i)
   1.192 +		RDebug::Printf("  %d: %08x -> %08x: %08x\n", i, self[i].iDataOffset, self[i+1].iDataOffset, self[i].iBlockNumber);
   1.193 +	}
   1.194 +
   1.195 +TBool operator==(const TBlockMap::SExtent& a, const TBlockMap::SExtent& b)
   1.196 +	{
   1.197 +	return a.iDataOffset == b.iDataOffset && a.iBlockNumber == b.iBlockNumber;
   1.198 +	}
   1.199 +
   1.200 +TBool operator!=(const TBlockMap::SExtent& a, const TBlockMap::SExtent& b)
   1.201 +	{
   1.202 +	return !(a == b);
   1.203 +	}
   1.204 +
   1.205 +TBool CompareExtentsEqual(const TBlockMap& aBlockMap, const CExtentList& aExtentList)
   1.206 +	{
   1.207 +	if (aBlockMap.Count() != aExtentList.Count())
   1.208 +		return EFalse;
   1.209 +	for (TInt i = 0 ; i < aBlockMap.Count() ; ++i)
   1.210 +		{
   1.211 +		if (aBlockMap.Extent(i) != aExtentList[i])
   1.212 +			return EFalse;
   1.213 +		}
   1.214 +	return ETrue;
   1.215 +	}
   1.216 +
   1.217 +TInt MakeKernBlockMap(TBlockMap& aKbm, const CBlockMap& aUbm)
   1.218 +	{
   1.219 +	TBlockMapEntryBase* buffer = (TBlockMapEntryBase*)User::Alloc(aUbm.EntriesSize());
   1.220 +	test_notNull(buffer);
   1.221 +	Mem::Copy(buffer, aUbm.Entries(), aUbm.EntriesSize());
   1.222 +	return aKbm.Initialise(aUbm.Info(),
   1.223 +						   buffer,
   1.224 +						   aUbm.EntriesSize(),
   1.225 +						   aUbm.ReadUnitShift(),
   1.226 +						   aUbm.CodeLengthInFile());
   1.227 +}
   1.228 +
   1.229 +void MakeKernBlockMapAndTestExtents(const CBlockMap& aUbm, const CExtentList& aExpectedExtentList)
   1.230 +	{
   1.231 +	TBlockMap kbm;
   1.232 +	test_noError(MakeKernBlockMap(kbm, aUbm));
   1.233 +	TBool equal = CompareExtentsEqual(kbm, aExpectedExtentList);
   1.234 +	if (!equal)
   1.235 +		{
   1.236 +		aExpectedExtentList.Dump();
   1.237 +#ifdef _DEBUG
   1.238 +		kbm.Dump();
   1.239 +#endif
   1.240 +		}
   1.241 +	test(equal);
   1.242 +	}
   1.243 +
   1.244 +// Tests
   1.245 +
   1.246 +void TestInitialiseErrors()
   1.247 +	{
   1.248 +	test.Next(_L("Test Initialise error checking"));
   1.249 +	TBlockMap kbm;
   1.250 +
   1.251 +	// Block size must be a power of two
   1.252 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(513, 0, 0, 9, 1, 8, 1, 0)));
   1.253 +
   1.254 +	// Block size must be greater than or equal to the read unit size
   1.255 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 10, 1, 8, 1, 0)));
   1.256 +
   1.257 +	// Block start offset must be less than or equal to block size
   1.258 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 513, 0, 9, 1, 8, 1, 0)));
   1.259 +
   1.260 +	// Block zero address must be a multiple of the block size
   1.261 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 0, 1, 9, 1, 8, 1, 0)));
   1.262 +
   1.263 +	// Code length in file must be greater than zero
   1.264 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 9, 0, 8, 1, 0)));
   1.265 +
   1.266 +	// Size of entries array must be multiple of the size of one entry
   1.267 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 9, 1, 9, 1, 0)));
   1.268 +
   1.269 +	// Size of entries must be non-zero
   1.270 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 9, 1, 0)));
   1.271 +	
   1.272 +	// Size of block map must be greater or equal to size of data in file
   1.273 +	test_equal(KErrArgument, MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 9, 513, 8, 1, 0)));
   1.274 +	}
   1.275 +
   1.276 +	// blockGranularity, startOffset, blockZeroAddress, readUnitShift, codeLengthInFile, entriesSize, (numberOfBlocks, startBlock)+
   1.277 +
   1.278 +void TestExtentList()
   1.279 +	{
   1.280 +	test.Next(_L("Test processing of user-side block map into extent list"));
   1.281 +
   1.282 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.283 +	//  |=      |       |       |       |       |       |       |       |       |
   1.284 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.285 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 0, 0, 9, 1, 8, 1, 0),
   1.286 +								   CExtentList(1, 0, 0));
   1.287 +
   1.288 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.289 +	//  |       |=      |       |       |       |       |       |       |       |
   1.290 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.291 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 0, 512, 9, 1, 8, 1, 0),
   1.292 +								   CExtentList(1, 0, 1));
   1.293 +	
   1.294 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.295 +	//  |       | =     |       |       |       |       |       |       |       |
   1.296 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.297 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 1, 8, 1, 0),
   1.298 +								   CExtentList(1, -23, 1));
   1.299 +
   1.300 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.301 +	//  |       |       |       | =     |       |       |       |       |       |
   1.302 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.303 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 1, 8, 1, 2),
   1.304 +								   CExtentList(1, -23, 3));
   1.305 +
   1.306 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.307 +	//  |       |       |       | ======|       |       |       |       |       |
   1.308 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.309 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 489, 8, 1, 2),
   1.310 +								   CExtentList(1, -23, 3));
   1.311 +
   1.312 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.313 +	//  |       |       |       | ========      |       |       |       |       |
   1.314 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.315 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 600, 8, 2, 2),
   1.316 +								   CExtentList(1, -23, 3));
   1.317 +	
   1.318 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.319 +	//  |       |       |       | ==============|       |==     |       |       |
   1.320 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.321 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 1100, 16, 2, 2, 1, 5),
   1.322 +								   CExtentList(2, -23, 3, 1001, 6));
   1.323 +
   1.324 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.325 +	//  |       |       |       | ==============|       |=======|       |       |
   1.326 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.327 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 1513, 16, 2, 2, 1, 5),
   1.328 +								   CExtentList(2, -23, 3, 1001, 6));
   1.329 +	
   1.330 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.331 +	//  |       |       |       | ==============|       |=======|=      |       |
   1.332 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.333 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 9, 1540, 16, 2, 2, 2, 5),
   1.334 +								   CExtentList(2, -23, 3, 1001, 6));
   1.335 +	}
   1.336 +
   1.337 +void TestExtentListScaled()
   1.338 +	{
   1.339 +	test.Next(_L("Test processing of user-side block map into extent list, block size > read unit size"));
   1.340 +
   1.341 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.342 +	//  |=  :   |   :   |   :   |   :   |   :   |   :   |   :   |   :   |   :   |
   1.343 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.344 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 0, 0, 8, 1, 8, 1, 0),
   1.345 +								   CExtentList(1, 0, 0));
   1.346 +
   1.347 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.348 +	//  |   :   |=  :   |   :   |   :   |   :   |   :   |   :   |   :   |   :   |
   1.349 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.350 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 0, 512, 8, 1, 8, 1, 0),
   1.351 +								   CExtentList(1, 0, 2));
   1.352 +	
   1.353 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.354 +	//  |   :   | = :   |   :   |   :   |   :   |   :   |   :   |   :   |   :   |
   1.355 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.356 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 23, 512, 8, 1, 8, 1, 0),
   1.357 +								   CExtentList(1, -23, 2));
   1.358 +
   1.359 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.360 +	//  |   :   |   : = |   :   |   :   |   :   |   :   |   :   |   :   |   :   |
   1.361 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.362 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 1, 8, 1, 0),
   1.363 +								   CExtentList(1, -24, 3));
   1.364 +
   1.365 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.366 +	//  |   :   |   :   |   :   |   : = |   :   |   :   |   :   |   :   |   :   |
   1.367 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.368 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 1, 8, 1, 2),
   1.369 +								   CExtentList(1, -24, 7));
   1.370 +
   1.371 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.372 +	//  |   :   |   :   |   :   |   : ==|   :   |   :   |   :   |   :   |   :   |
   1.373 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.374 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 232, 8, 1, 2),
   1.375 +								   CExtentList(1, -24, 7));
   1.376 +
   1.377 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.378 +	//  |   :   |   :   |   :   |   : ====  :   |   :   |   :   |   :   |   :   |
   1.379 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.380 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 333, 8, 2, 2),
   1.381 +								   CExtentList(1, -24, 7));
   1.382 +
   1.383 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.384 +	//  |   :   |   :   |   :   |   : ========  |   :   |   :   |   :   |   :   |
   1.385 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.386 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 666, 8, 2, 2),
   1.387 +								   CExtentList(1, -24, 7));
   1.388 +
   1.389 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.390 +	//  |   :   |   :   |   :   |   : ==========|   :   |   :   |   :   |   :   |
   1.391 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.392 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 744, 8, 2, 2),
   1.393 +								   CExtentList(1, -24, 7));
   1.394 +
   1.395 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.396 +	//  |   :   |   :   |   :   |   : ==========|   :   |== :   |   :   |   :   |
   1.397 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.398 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 888, 16, 2, 2, 1, 5),
   1.399 +								   CExtentList(2, -24, 7, 744, 12));
   1.400 +
   1.401 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.402 +	//  |   :   |   :   |   :   |   : ==========|   :   |=======|   :   |   :   |
   1.403 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.404 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 1256, 16, 2, 2, 1, 5),
   1.405 +								   CExtentList(2, -24, 7, 744, 12));
   1.406 +
   1.407 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.408 +	//  |   :   |   :   |   :   |   : ==========|   :   |=========  :   |   :   |
   1.409 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.410 +	MakeKernBlockMapAndTestExtents(CBlockMap(512, 280, 512, 8, 1350, 16, 2, 2, 2, 5),
   1.411 +								   CExtentList(2, -24, 7, 744, 12));
   1.412 +	}
   1.413 +
   1.414 +/// Holds the expected arguments for one call to the read function
   1.415 +struct SReadEntry
   1.416 +	{
   1.417 +	TLinAddr iBuffer;
   1.418 +	TInt iBlockNumber;
   1.419 +	TInt iBlockCount;
   1.420 +	};
   1.421 +
   1.422 +/// Holds a list of expected arguments for all calls to the read function
   1.423 +class CReadInfo : public CList<SReadEntry>
   1.424 +	{
   1.425 +public:
   1.426 +	CReadInfo(TInt aReturnVal, TInt aCount, ...);
   1.427 +	const SReadEntry& Next();
   1.428 +	void Done() const;
   1.429 +	TInt ReturnVal() const { return iReturnVal; }
   1.430 +private:
   1.431 +	TInt iPos;
   1.432 +	TInt iReturnVal;
   1.433 +	};
   1.434 +
   1.435 +CReadInfo::CReadInfo(TInt aReturnVal, TInt aCount, ...)
   1.436 +	: iPos(0), iReturnVal(aReturnVal)
   1.437 +	{
   1.438 +	VA_LIST list;
   1.439 +	VA_START(list, aCount);
   1.440 +	Set(aCount, list);
   1.441 +	}
   1.442 +
   1.443 +const SReadEntry& CReadInfo::Next()
   1.444 +	{
   1.445 +	const CList<SReadEntry>& self = *this;
   1.446 +	return self[iPos++];
   1.447 +	}
   1.448 +
   1.449 +void CReadInfo::Done() const
   1.450 +	{
   1.451 +	test_equal(Count(), iPos);
   1.452 +	}
   1.453 +
   1.454 +TInt ReadFunc(TAny* aArg, TAny*, TLinAddr aBuffer, TInt aBlockNumber, TInt aBlockCount)
   1.455 +	{
   1.456 +	CReadInfo& info = *(CReadInfo*)aArg;
   1.457 +	const SReadEntry& expected = info.Next();
   1.458 +	test_equal(expected.iBuffer, aBuffer);
   1.459 +	test_equal(expected.iBlockNumber, aBlockNumber);
   1.460 +	test_equal(expected.iBlockCount, aBlockCount);
   1.461 +	return KErrNone;
   1.462 +	}
   1.463 +
   1.464 +void TestRead(const TBlockMap& aBlockMap,
   1.465 +			  TLinAddr aBuffer,
   1.466 +			  TInt aPos,
   1.467 +			  TInt aLength,
   1.468 +			  TInt aReadUnitShift,
   1.469 +			  const CReadInfo& aExpected)
   1.470 +	{
   1.471 +	test_equal(aExpected.ReturnVal(),
   1.472 +			   aBlockMap.Read(aBuffer, aPos, aLength, aReadUnitShift, ReadFunc, (TAny*)&aExpected, (TAny*)NULL));
   1.473 +	aExpected.Done();
   1.474 +	}
   1.475 +
   1.476 +void TestReadErrors()
   1.477 +	{
   1.478 +	test.Next(_L("Test Read error checking"));
   1.479 +
   1.480 +	TBlockMap kbm, kbm2;
   1.481 +	
   1.482 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.483 +	//  |=      |       |       |       |       |       |       |       |       |
   1.484 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.485 +	test_noError(MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 9, 1, 8, 1, 0)));
   1.486 +
   1.487 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.488 +	//  |   :   |   :   |   :   |   : ==========|   :   |=========  :   |   :   |
   1.489 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------	
   1.490 +	test_noError(MakeKernBlockMap(kbm2, CBlockMap(512, 280, 512, 8, 1350, 16, 2, 2, 2, 5)));
   1.491 +
   1.492 +	// Test read start position is outside block map
   1.493 +	TestRead(kbm, 0, 1, 1, 9, CReadInfo(KErrArgument, 0));
   1.494 +	TestRead(kbm2, 0, 1350, 1, 8, CReadInfo(KErrArgument, 0));
   1.495 +
   1.496 +	// Test read start position is negative
   1.497 +	TestRead(kbm, 0, -1, 1, 9, CReadInfo(KErrArgument, 0));
   1.498 +	TestRead(kbm2, 0, -1, 1, 8, CReadInfo(KErrArgument, 0));
   1.499 +
   1.500 +	// Test read length exceeds block map length 
   1.501 +	TestRead(kbm, 0, 0, 2, 9, CReadInfo(KErrArgument, 1, 0, 0, 1));
   1.502 +	TestRead(kbm2, 0, 1349, 2, 8, CReadInfo(KErrArgument, 1, 0, 14, 1));
   1.503 +	}
   1.504 +
   1.505 +void TestReads()
   1.506 +	{
   1.507 +	test.Next(_L("Test Read"));
   1.508 +
   1.509 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.510 +	//  |=======================|       |       |       |       |       |       |
   1.511 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.512 +	
   1.513 +	TBlockMap kbm2;
   1.514 +	test_noError(MakeKernBlockMap(kbm2, CBlockMap(512, 0, 0, 9, 1536, 8, 3, 0)));
   1.515 +
   1.516 +	// Test correct number of blocks read
   1.517 +	TestRead(kbm2, 0, 0, 512, 9, CReadInfo(0, 1, 0, 0, 1));
   1.518 +	TestRead(kbm2, 0, 0, 513, 9, CReadInfo(0, 1, 0, 0, 2));
   1.519 +	TestRead(kbm2, 0, 0, 1024, 9, CReadInfo(0, 1, 0, 0, 2));
   1.520 +	TestRead(kbm2, 0, 0, 1025, 9, CReadInfo(0, 1, 0, 0, 3));
   1.521 +	TestRead(kbm2, 0, 0, 1536, 9, CReadInfo(0, 1, 0, 0, 3));
   1.522 +
   1.523 +	// Test start offset not aligned to read unit
   1.524 +	TestRead(kbm2, 0, 1, 511, 9, CReadInfo(1, 1, 0, 0, 1));
   1.525 +	TestRead(kbm2, 0, 256, 256, 9, CReadInfo(256, 1, 0, 0, 1));
   1.526 +	TestRead(kbm2, 0, 511, 1, 9, CReadInfo(511, 1, 0, 0, 1));
   1.527 +	TestRead(kbm2, 0, 513, 511, 9, CReadInfo(1, 1, 0, 1, 1));
   1.528 +	TestRead(kbm2, 0, 1023, 1, 9, CReadInfo(511, 1, 0, 1, 1));
   1.529 +
   1.530 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.531 +	//  |=======|       |=======|       |=======|       |       |       |       |
   1.532 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.533 +	
   1.534 +	TBlockMap kbm;
   1.535 +	test_noError(MakeKernBlockMap(kbm, CBlockMap(512, 0, 0, 9, 1536, 24, 1, 0, 1, 3, 1, 5)));
   1.536 +
   1.537 +	// Test correct block selected for read
   1.538 +	TestRead(kbm, 0, 0, 1, 9, CReadInfo(0, 1, 0, 0, 1));
   1.539 +	TestRead(kbm, 0, 256, 1, 9, CReadInfo(256, 1, 0, 0, 1));
   1.540 +	TestRead(kbm, 0, 511, 1, 9, CReadInfo(511, 1, 0, 0, 1));
   1.541 +	TestRead(kbm, 0, 512, 1, 9, CReadInfo(0, 1, 0, 3, 1));
   1.542 +	TestRead(kbm, 0, 768, 1, 9, CReadInfo(256, 1, 0, 3, 1));
   1.543 +	TestRead(kbm, 0, 1023, 1, 9, CReadInfo(511, 1, 0, 3, 1));
   1.544 +	TestRead(kbm, 0, 1535, 1, 9, CReadInfo(511, 1, 0, 5, 1));
   1.545 +
   1.546 +	// Test reading multiple blocks
   1.547 +	TestRead(kbm, 0, 0, 513, 9, CReadInfo(0, 2, 0, 0, 1, 512, 3, 1));
   1.548 +	TestRead(kbm, 0, 0, 1024, 9, CReadInfo(0, 2, 0, 0, 1, 512, 3, 1));
   1.549 +	TestRead(kbm, 0, 0, 1025, 9, CReadInfo(0, 3, 0, 0, 1, 512, 3, 1, 1024, 5, 1));
   1.550 +	TestRead(kbm, 0, 0, 1536, 9, CReadInfo(0, 3, 0, 0, 1, 512, 3, 1, 1024, 5, 1));
   1.551 +
   1.552 +
   1.553 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.554 +	//  |   ====|       |=======|       |=======|       |       |       |       |
   1.555 +	//  +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------
   1.556 +	
   1.557 +	TBlockMap kbm3;
   1.558 +	test_noError(MakeKernBlockMap(kbm3, CBlockMap(512, 256, 0, 9, 1280, 24, 1, 0, 1, 3, 1, 5)));
   1.559 +
   1.560 +	// Test correct block selected for read
   1.561 +	TestRead(kbm3, 0, 0, 1, 9, CReadInfo(256, 1, 0, 0, 1));
   1.562 +	TestRead(kbm3, 0, 255, 1, 9, CReadInfo(511, 1, 0, 0, 1));
   1.563 +	TestRead(kbm3, 0, 256, 1, 9, CReadInfo(0, 1, 0, 3, 1));
   1.564 +	TestRead(kbm3, 0, 767, 1, 9, CReadInfo(511, 1, 0, 3, 1));
   1.565 +	TestRead(kbm3, 0, 768, 1, 9, CReadInfo(0, 1, 0, 5, 1));
   1.566 +
   1.567 +	// Test reading multiple blocks
   1.568 +	TestRead(kbm3, 0, 0, 256, 9, CReadInfo(256, 1, 0, 0, 1));
   1.569 +	TestRead(kbm3, 0, 0, 257, 9, CReadInfo(256, 2, 0, 0, 1, 512, 3, 1));
   1.570 +	TestRead(kbm3, 0, 0, 768, 9, CReadInfo(256, 2, 0, 0, 1, 512, 3, 1));
   1.571 +	TestRead(kbm3, 0, 0, 769, 9, CReadInfo(256, 3, 0, 0, 1, 512, 3, 1, 1024, 5, 1));
   1.572 +	TestRead(kbm3, 0, 0, 1280, 9, CReadInfo(256, 3, 0, 0, 1, 512, 3, 1, 1024, 5, 1));
   1.573 +	}
   1.574 +
   1.575 +TInt E32Main()
   1.576 +	{
   1.577 +	test.Title();
   1.578 +	test.Start(_L("Unit tests the TKernBlockMap class"));
   1.579 +
   1.580 +	TestInitialiseErrors();
   1.581 +	TestExtentList();
   1.582 +	TestExtentListScaled();
   1.583 +	TestReadErrors();
   1.584 +	TestReads();
   1.585 + 
   1.586 +	test.End();
   1.587 +
   1.588 +	return KErrNone;
   1.589 +	}