Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * This file contains unit tests for the test framework itself.
16 * They should be run if changes have been made to
17 * to the user side test framework code ie. anything in the dmav2
18 * directory other than the d_* driver code, or test_cases.cpp
27 #define __E32TEST_EXTENSION__
32 static RTest test(_L("t_dma2 test framework tests"));
34 void RDmaSession::SelfTest()
36 test.Start(_L("Simple transfer test"));
37 test.Next(_L("Open session"));
39 TInt r = session.Open();
42 test.Next(_L("Get test info"));
43 TDmaV2TestInfo testInfo;
44 r = session.GetTestInfo(testInfo);
52 test.Next(_L("Channel open"));
53 TUint channelCookie=0;
54 r = session.ChannelOpen(16, channelCookie);
55 test.Printf(_L("cookie recived = 0x%08x\n"), channelCookie);
58 test.Next(_L("Get Channel caps"));
59 SDmacCaps channelCaps;
60 r = session.ChannelCaps(channelCookie, channelCaps);
64 PRINT(channelCaps.iChannelPriorities);
65 PRINT(channelCaps.iChannelPauseAndResume);
66 PRINT(channelCaps.iAddrAlignedToElementSize);
67 PRINT(channelCaps.i1DIndexAddressing);
68 PRINT(channelCaps.i2DIndexAddressing);
69 PRINT(channelCaps.iSynchronizationTypes);
70 PRINT(channelCaps.iBurstTransactions);
71 PRINT(channelCaps.iDescriptorInterrupt);
72 PRINT(channelCaps.iFrameInterrupt);
73 PRINT(channelCaps.iLinkedListPausedInterrupt);
74 PRINT(channelCaps.iEndiannessConversion);
75 PRINT(channelCaps.iGraphicsOps);
76 PRINT(channelCaps.iRepeatingTransfers);
77 PRINT(channelCaps.iChannelLinking);
78 PRINT(channelCaps.iHwDescriptors);
79 PRINT(channelCaps.iSrcDstAsymmetry);
80 PRINT(channelCaps.iAsymHwDescriptors);
81 PRINT(channelCaps.iBalancedAsymSegments);
82 PRINT(channelCaps.iAsymCompletionInterrupt);
83 PRINT(channelCaps.iAsymDescriptorInterrupt);
84 PRINT(channelCaps.iAsymFrameInterrupt);
85 PRINT(channelCaps.iReserved[0]);
86 PRINT(channelCaps.iReserved[1]);
87 PRINT(channelCaps.iReserved[2]);
88 PRINT(channelCaps.iReserved[3]);
89 PRINT(channelCaps.iReserved[4]);
92 test.Next(_L("Get extended Channel caps (TDmacTestCaps)"));
93 TDmacTestCaps extChannelCaps;
94 r = session.ChannelCaps(channelCookie, extChannelCaps);
96 test.Printf(_L("PIL version = %d\n"), extChannelCaps.iPILVersion);
98 const TBool newPil = (extChannelCaps.iPILVersion > 1);
100 test.Next(_L("Create Dma request - max fragment size 32K"));
102 r = session.RequestCreate(channelCookie, reqCookie, 32 * KKilo);
103 test.Printf(_L("cookie recived = 0x%08x\n"), reqCookie);
108 test.Next(_L("Create Dma request (with new-style callback)"));
109 TUint reqCookieNewStyle=0;
110 r = session.RequestCreateNew(channelCookie, reqCookieNewStyle);
111 test.Printf(_L("cookie recived = 0x%08x\n"), reqCookieNewStyle );
114 test.Next(_L("Fragment for ISR callback"));
115 const TInt size = 128 * KKilo;
116 TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
117 r = session.FragmentRequest(reqCookieNewStyle, transferArgs);
121 test.Next(_L("Queue ISR callback - with default re-queue"));
122 r = session.QueueRequestWithRequeue(reqCookieNewStyle, &reque, 1);
125 test.Next(_L("Destroy new-style Dma request"));
126 r = session.RequestDestroy(reqCookieNewStyle);
129 test.Next(_L("Attempt to destroy request again "));
130 r = session.RequestDestroy(reqCookieNewStyle);
131 test_Equal(KErrNotFound, r);
134 test.Next(_L("Open chunk handle"));
136 r = session.OpenSharedChunk(chunk);
140 test.Printf(_L("chunk base = 0x%08x\n"), chunk.Base());
141 test.Printf(_L("chunk size = %d\n"), chunk.Size());
143 test(chunk.IsWritable());
144 test(chunk.IsReadable());
146 test.Next(_L("Fragment(old style)"));
147 const TInt size = 128 * KKilo;
149 for(i = 0; i<10; i++)
152 TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
153 r = session.FragmentRequestOld(reqCookie, transferArgs, &time);
157 test.Printf(_L("%lu us\n"), time);
161 test.Next(_L("Queue"));
162 TRequestStatus status;
164 for(i = 0; i<10; i++)
167 r = session.QueueRequest(reqCookie, status, 0, &time);
168 User::WaitForRequest(status);
172 test.Printf(_L("%lu us\n"), time);
178 test.Next(_L("Fragment(new style)"));
179 TDmaTransferArgs transferArgs;
180 transferArgs.iSrcConfig.iAddr = 0;
181 transferArgs.iDstConfig.iAddr = size;
182 transferArgs.iSrcConfig.iFlags = KDmaMemAddr;
183 transferArgs.iDstConfig.iFlags = KDmaMemAddr;
184 transferArgs.iTransferCount = size;
186 for(i = 0; i<10; i++)
189 r = session.FragmentRequest(reqCookie, transferArgs, &time);
193 test.Printf(_L("%lu us\n"), time);
198 test.Next(_L("Queue"));
199 TCallbackRecord record;
200 r = session.QueueRequest(reqCookie, &record);
203 test.Next(_L("check TCallbackRecord record"));
208 const TCallbackRecord expected(TCallbackRecord::EThread, 1);
209 if(!(record == expected))
211 test.Printf(_L("TCallbackRecords did not match"));
214 test.Printf(_L("expected:"));
220 test.Next(_L("Destroy Dma request"));
221 r = session.RequestDestroy(reqCookie);
224 test.Next(_L("Close chunk handle"));
227 test.Next(_L("Channel close"));
228 r = session.ChannelClose(channelCookie);
231 test.Next(_L("Channel close (same again)"));
232 r = session.ChannelClose(channelCookie);
233 test_Equal(KErrNotFound, r);
235 test.Next(_L("Close session"));
236 RTest::CloseHandleAndWaitForDestruction(session);
242 const SDmacCaps KTestCapSet =
243 {6, // TInt iChannelPriorities;
244 EFalse, // TBool iChannelPauseAndResume;
245 ETrue, // TBool iAddrAlignedToElementSize;
246 EFalse, // TBool i1DIndexAddressing;
247 EFalse, // TBool i2DIndexAddressing;
248 KDmaSyncSizeElement | KDmaSyncSizeFrame |
249 KDmaSyncSizeBlock, // TUint iSynchronizationTypes;
250 KDmaBurstSize4 | KDmaBurstSize8, // TUint iBurstTransactions;
251 EFalse, // TBool iDescriptorInterrupt;
252 EFalse, // TBool iFrameInterrupt;
253 EFalse, // TBool iLinkedListPausedInterrupt;
254 EFalse, // TBool iEndiannessConversion;
255 0, // TUint iGraphicsOps;
256 ETrue, // TBool iRepeatingTransfers;
257 EFalse, // TBool iChannelLinking;
258 ETrue, // TBool iHwDescriptors;
259 EFalse, // TBool iSrcDstAsymmetry;
260 EFalse, // TBool iAsymHwDescriptors;
261 EFalse, // TBool iBalancedAsymSegments;
262 EFalse, // TBool iAsymCompletionInterrupt;
263 EFalse, // TBool iAsymDescriptorInterrupt;
264 EFalse, // TBool iAsymFrameInterrupt;
265 {0, 0, 0, 0, 0} // TUint32 iReserved[5];
268 const TDmacTestCaps KDmacTestCapsV1(KTestCapSet, 1);
269 const TDmacTestCaps KDmacTestCapsV2(KTestCapSet, 2);
271 void TDmaCapability::SelfTest()
273 test.Start(_L("Unit test_Value of TDmaCapability::CompareToDmaCaps\n"));
276 test.Next(_L("ENone\n"));
277 TResult t = none.CompareToDmaCaps(KTestCapSet);
278 test_Value(t, t == ERun);
282 test.Next(_L("EChannelPauseAndResume - wanted\n"));
283 TResult t = pauseRequired.CompareToDmaCaps(KTestCapSet);
284 test_Value(t, t == EFail);
287 test.Next(_L("EChannelPauseAndResume - wanted - Allow skip\n"));
288 TResult t = pauseRequired_skip.CompareToDmaCaps(KTestCapSet);
289 test_Value(t, t == ESkip);
292 test.Next(_L("EChannelPauseAndResume - not wanted\n"));
293 TResult t = pauseNotWanted.CompareToDmaCaps(KTestCapSet);
294 test_Value(t, t == ERun);
298 test.Next(_L("EHwDescriptors - not wanted\n"));
299 TResult t = hwDesNotWanted.CompareToDmaCaps(KTestCapSet);
300 test_Value(t, t == EFail);
304 test.Next(_L("EHwDescriptors - not wanted - Allow skip\n"));
305 TResult t = hwDesNotWanted_skip.CompareToDmaCaps(KTestCapSet);
306 test_Value(t, t == ESkip);
310 test.Next(_L("EHwDescriptors - wanted\n"));
311 TResult t = hwDesWanted.CompareToDmaCaps(KTestCapSet);
312 test_Value(t, t == ERun);
316 //TODO use this macro for the above tests
318 // Note: The construction of the test description message
319 // is horribly confusing. The _L macro will make the
320 // *first* string token wide, but not the next two.
321 // Therefore these must be made wide or compilier
322 // will complain about concatination of narrow and wide string
324 #define CAP_TEST(CAP, CAPSET, EXPCT)\
326 test.Next(_L(#CAP L" against " L ## #CAPSET));\
327 TResult t = (CAP).CompareToDmaCaps(CAPSET);\
328 test_Equal(EXPCT, t);\
332 CAP_TEST(capEqualV1, KDmacTestCapsV1, ERun);
333 CAP_TEST(capEqualV2, KDmacTestCapsV2, ERun);
334 CAP_TEST(capEqualV1, KDmacTestCapsV2, ESkip);
335 CAP_TEST(capEqualV2, KDmacTestCapsV1, ESkip);
336 CAP_TEST(capEqualV2Fatal, KDmacTestCapsV1, EFail);
338 CAP_TEST(capAboveV1, KDmacTestCapsV2, ERun);
339 CAP_TEST(capBelowV2, KDmacTestCapsV1, ERun);
340 CAP_TEST(capAboveV1, KDmacTestCapsV1, ESkip);
341 CAP_TEST(capBelowV2, KDmacTestCapsV2, ESkip);
346 void TTestCase::SelfTest()
348 //TODO should use macros for these tests
349 test.Start(_L("Unit test of TTestCase::TestCaseValid\n"));
351 TTestCase testCase(NULL, EFalse, pauseRequired, hwDesNotWanted);
352 test.Next(_L("pauseRequired, hwDesNotWanted\n"));
353 TResult t = testCase.TestCaseValid(KTestCapSet);
354 test_Value(t, t == EFail);
356 test.Next(_L("pauseRequired_skip, hwDesNotWanted\n"));
357 testCase.iChannelCaps[0] = pauseRequired_skip;
358 t = testCase.TestCaseValid(KTestCapSet);
359 test_Value(t, t == EFail);
361 test.Next(_L("pauseRequired_skip, hwDesNotWanted_skip\n"));
362 testCase.iChannelCaps[1] = hwDesNotWanted_skip;
363 t = testCase.TestCaseValid(KTestCapSet);
364 test_Value(t, t == ESkip);
366 test.Next(_L("pauseNotWanted, hwDesNotWanted_skip\n"));
367 testCase.iChannelCaps[0] = pauseNotWanted;
368 t = testCase.TestCaseValid(KTestCapSet);
369 test_Value(t, t == ESkip);
371 test.Next(_L("pauseNotWanted, hwDesWanted\n"));
372 testCase.iChannelCaps[1] = hwDesWanted;
373 t = testCase.TestCaseValid(KTestCapSet);
374 test_Value(t, t == ERun);
376 test.Next(_L("pauseNotWanted\n"));
377 testCase.iChannelCaps[1] = none;
378 t = testCase.TestCaseValid(KTestCapSet);
379 test_Value(t, t == ERun);
381 test.Next(_L("pauseNotWanted + V1 PIL required\n"));
382 testCase.iChannelCaps[1] = capAboveV1;
383 test.Next(_L("Against KDmacTestCapsV1"));
384 t = testCase.TestCaseValid(KDmacTestCapsV1);
385 test_Equal(ESkip, t);
386 test.Next(_L("Against KDmacTestCapsV2"));
387 t = testCase.TestCaseValid(KDmacTestCapsV2);
390 test.Next(_L("pauseNotWanted + >V1 PIL required\n"));
391 testCase.iChannelCaps[1] = capBelowV2;
392 test.Next(_L("Against KDmacTestCapsV1"));
393 t = testCase.TestCaseValid(KDmacTestCapsV1);
395 test.Next(_L("Against KDmacTestCapsV2"));
396 t = testCase.TestCaseValid(KDmacTestCapsV2);
397 test_Equal(ESkip, t);
404 void TTransferIter::SelfTest()
406 test.Start(_L("No skip"));
408 const TUint8 src[9] = {
414 const TUint32 addr = (TUint32)src;
415 const TUint elementSize = 1;
416 const TUint elementSkip = 0;
417 const TUint elementsPerFrame = 3;
418 const TUint frameSkip = 0;
419 const TUint framesPerTransfer = 3;
420 TDmaTransferConfig cfg(addr, elementSize, elementsPerFrame, framesPerTransfer,
421 elementSkip, frameSkip, KDmaMemAddr
424 TTransferIter iter(cfg, 0);
427 for(i = 0; i<9; i++, ++iter)
429 test_Equal(src[i],*iter);
433 test.Next(_L("90 degree rotation"));
434 // Now imagine that we wanted to perform a rotation
435 // as we write, so that we wrote out the following
437 const TUint8 expected[9] = {
444 TDmaTransferConfig dst_cfg(cfg);
445 dst_cfg.iAddr = (TUint32)&dst[2];
446 dst_cfg.iElementSkip = 2;
447 dst_cfg.iFrameSkip = -8;
449 TTransferIter dst_iter(dst_cfg, 0);
450 for(i=0; dst_iter != end; i++, ++dst_iter)
458 test_Equal(expected[i],dst[i]);
462 void TCallbackRecord::SelfTest()
464 test.Start(_L("SeltTest of TCallbackRecord"));
466 test.Next(_L("create default TCallbackRecord record, record2"));
467 TCallbackRecord record;
468 const TCallbackRecord record2;
471 test.Next(_L("Print record"));
475 test.Next(_L("test (record == record2)"));
476 if(!(record == record2))
485 //A series of callback masks
486 //Note these combinations do not necessarily represent
487 //possible callback combinations
490 EDmaCallbackDescriptorCompletion,
491 EDmaCallbackDescriptorCompletion,
492 EDmaCallbackDescriptorCompletion,
493 EDmaCallbackDescriptorCompletion,
494 EDmaCallbackFrameCompletion_Src,
495 EDmaCallbackFrameCompletion_Dst,
496 EDmaCallbackDescriptorCompletion_Src | EDmaCallbackDescriptorCompletion_Dst,
497 EDmaCallbackDescriptorCompletion_Src | EDmaCallbackFrameCompletion_Src | EDmaCallbackLinkedListPaused_Dst,
498 EDmaCallbackRequestCompletion | EDmaCallbackRequestCompletion_Src,
499 EDmaCallbackDescriptorCompletion_Dst
501 test.Next(_L("Feed a series of callback masks in to record"));
502 const TInt length = ARRAY_LENGTH(callbacks);
503 for(TInt i = 0; i < length; i++)
505 record.ProcessCallback(callbacks[i], EDmaResultOK);
510 test.Next(_L("Print record"));
514 test.Next(_L("test GetCount"));
515 test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion));
516 test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion_Src));
517 test_Equal(0, record.GetCount(EDmaCallbackRequestCompletion_Dst));
518 test_Equal(4, record.GetCount(EDmaCallbackDescriptorCompletion));
519 test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Src));
520 test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Dst));
521 test_Equal(0, record.GetCount(EDmaCallbackFrameCompletion));
522 test_Equal(2, record.GetCount(EDmaCallbackFrameCompletion_Src));
523 test_Equal(1, record.GetCount(EDmaCallbackFrameCompletion_Dst));
524 test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused));
525 test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused_Src));
526 test_Equal(1, record.GetCount(EDmaCallbackLinkedListPaused_Dst));
528 test.Next(_L("test expected == record"));
529 const TCallbackRecord expected(TCallbackRecord::EThread, 1, 1, 0, 4, 2, 2, 0, 2, 1, 0, 0, 1);
530 if(!(expected == record))
539 test.Next(_L("modify record: test expected != record"));
540 record.SetCount(EDmaCallbackFrameCompletion, 10);
541 if(expected == record)
550 test.Next(_L("test Reset()"));
552 test(record == record2);
557 void CDmaBenchmark::SelfTest()
559 test.Start(_L("SelfTest of CDmaBenchmark"));
560 test.Next(_L("MeanResult()"));
562 TUint64 results[] = {8, 12, 1, 19, 3, 17, 10};
563 const TInt count = ARRAY_LENGTH(results);
565 CDmaBmFragmentation fragTest(_L("SelfTest"), count, TDmaTransferArgs(), 0);
567 for(TInt i = 0; i < count; i++)
569 fragTest.iResultArray.Append(results[i]);
571 test_Equal(10, fragTest.MeanResult());
576 void TAddrRange::SelfTest()
578 test.Start(_L("SelfTest of TAddrRange"));
582 test_Equal(7, a.End());
583 test_Equal(15, b.End());
585 test(!a.Overlaps(b));
586 test(!b.Overlaps(a));
591 test_Equal(8, c.End());
608 test(!a.Contains(d));
611 test(!b.Contains(d));
613 test(!a.Contains(b));
614 test(!b.Contains(a));
618 void TAddressParms::SelfTest()
620 test.Start(_L("SelfTest of TAddressParms"));
621 const TAddressParms pA(0, 32, 8);
623 test(pA.Overlaps(pA));
625 const TAddrRange rA(4, 8);
626 const TAddrRange rB(16, 8);
627 const TAddrRange rC(28, 8);
628 const TAddrRange rD(4, 32);
630 test(pA.Overlaps(rA));
631 test(!pA.Overlaps(rB));
632 test(pA.Overlaps(rC));
633 test(pA.Overlaps(rD));
635 const TAddressParms pB(8, 16, 8);
638 test(!pA.Overlaps(pB));
639 test(!pB.Overlaps(pA));
641 const TAddressParms pC(8, 28, 8);
642 test(pC.Overlaps(pA));
643 test(pC.Overlaps(pB));
645 const TAddressParms pD(0, 128, 64);
646 test(pD.Overlaps(pA));
647 test(pD.Overlaps(pB));
648 test(pD.Overlaps(pC));
654 test.Next(_L("Running framework unit tests"));
655 RDmaSession::SelfTest();
656 TDmaCapability::SelfTest();
657 TTestCase::SelfTest();
658 TTransferIter::SelfTest();
659 TCallbackRecord::SelfTest();
660 CDmaBmFragmentation::SelfTest();
661 TAddrRange::SelfTest();
662 TAddressParms::SelfTest();