269 const TDmacTestCaps KDmacTestCapsV2(KTestCapSet, 2); |
292 const TDmacTestCaps KDmacTestCapsV2(KTestCapSet, 2); |
270 |
293 |
271 void TDmaCapability::SelfTest() |
294 void TDmaCapability::SelfTest() |
272 { |
295 { |
273 test.Start(_L("Unit test_Value of TDmaCapability::CompareToDmaCaps\n")); |
296 test.Start(_L("Unit test_Value of TDmaCapability::CompareToDmaCaps\n")); |
274 |
|
275 { |
|
276 test.Next(_L("ENone\n")); |
|
277 TResult t = none.CompareToDmaCaps(KTestCapSet); |
|
278 test_Value(t, t == ERun); |
|
279 } |
|
280 |
|
281 { |
|
282 test.Next(_L("EChannelPauseAndResume - wanted\n")); |
|
283 TResult t = pauseRequired.CompareToDmaCaps(KTestCapSet); |
|
284 test_Value(t, t == EFail); |
|
285 } |
|
286 { |
|
287 test.Next(_L("EChannelPauseAndResume - wanted - Allow skip\n")); |
|
288 TResult t = pauseRequired_skip.CompareToDmaCaps(KTestCapSet); |
|
289 test_Value(t, t == ESkip); |
|
290 } |
|
291 { |
|
292 test.Next(_L("EChannelPauseAndResume - not wanted\n")); |
|
293 TResult t = pauseNotWanted.CompareToDmaCaps(KTestCapSet); |
|
294 test_Value(t, t == ERun); |
|
295 } |
|
296 |
|
297 { |
|
298 test.Next(_L("EHwDescriptors - not wanted\n")); |
|
299 TResult t = hwDesNotWanted.CompareToDmaCaps(KTestCapSet); |
|
300 test_Value(t, t == EFail); |
|
301 } |
|
302 |
|
303 { |
|
304 test.Next(_L("EHwDescriptors - not wanted - Allow skip\n")); |
|
305 TResult t = hwDesNotWanted_skip.CompareToDmaCaps(KTestCapSet); |
|
306 test_Value(t, t == ESkip); |
|
307 } |
|
308 |
|
309 { |
|
310 test.Next(_L("EHwDescriptors - wanted\n")); |
|
311 TResult t = hwDesWanted.CompareToDmaCaps(KTestCapSet); |
|
312 test_Value(t, t == ERun); |
|
313 } |
|
314 |
|
315 |
|
316 //TODO use this macro for the above tests |
|
317 |
|
318 // Note: The construction of the test description message |
297 // Note: The construction of the test description message |
319 // is horribly confusing. The _L macro will make the |
298 // is horribly confusing. The _L macro will make the |
320 // *first* string token wide, but not the next two. |
299 // *first* string token wide, but not the next two. |
321 // Therefore these must be made wide or compilier |
300 // Therefore these must be made wide or compilier |
322 // will complain about concatination of narrow and wide string |
301 // will complain about concatination of narrow and wide string |
343 test.End(); |
329 test.End(); |
344 } |
330 } |
345 |
331 |
346 void TTestCase::SelfTest() |
332 void TTestCase::SelfTest() |
347 { |
333 { |
348 //TODO should use macros for these tests |
|
349 test.Start(_L("Unit test of TTestCase::TestCaseValid\n")); |
334 test.Start(_L("Unit test of TTestCase::TestCaseValid\n")); |
350 |
335 |
351 TTestCase testCase(NULL, EFalse, pauseRequired, hwDesNotWanted); |
336 // Create a TTestCase with paramaters CAP1 and CAP2 |
352 test.Next(_L("pauseRequired, hwDesNotWanted\n")); |
337 // call TTestCase::TestCaseValid against CAPSET |
353 TResult t = testCase.TestCaseValid(KTestCapSet); |
338 // Expected result is EXPCT |
354 test_Value(t, t == EFail); |
339 #define TEST_TEST_CASE(CAP1, CAP2, CAPSET, EXPCT)\ |
355 |
340 {\ |
356 test.Next(_L("pauseRequired_skip, hwDesNotWanted\n")); |
341 test.Next(_L(#CAP1 L", " L ## #CAP2 L" -- Against: " L ## #CAPSET L", Expect: " L ## #EXPCT));\ |
357 testCase.iChannelCaps[0] = pauseRequired_skip; |
342 TTestCase testCase(NULL, EFalse, CAP1, CAP2);\ |
358 t = testCase.TestCaseValid(KTestCapSet); |
343 testCase.iChannelCaps[0] = (CAP1);\ |
359 test_Value(t, t == EFail); |
344 TResult t = testCase.TestCaseValid(CAPSET);\ |
360 |
345 test_Equal(EXPCT, t);\ |
361 test.Next(_L("pauseRequired_skip, hwDesNotWanted_skip\n")); |
346 } |
362 testCase.iChannelCaps[1] = hwDesNotWanted_skip; |
347 |
363 t = testCase.TestCaseValid(KTestCapSet); |
348 TEST_TEST_CASE(pauseRequired, hwDesNotWanted, KTestCapSet, EFail); |
364 test_Value(t, t == ESkip); |
349 TEST_TEST_CASE(pauseRequired_skip, hwDesNotWanted, KTestCapSet, EFail); |
365 |
350 TEST_TEST_CASE(pauseRequired_skip, hwDesNotWanted_skip, KTestCapSet, ESkip); |
366 test.Next(_L("pauseNotWanted, hwDesNotWanted_skip\n")); |
351 TEST_TEST_CASE(pauseNotWanted, hwDesNotWanted_skip, KTestCapSet, ESkip); |
367 testCase.iChannelCaps[0] = pauseNotWanted; |
352 TEST_TEST_CASE(pauseNotWanted, hwDesWanted, KTestCapSet, ERun); |
368 t = testCase.TestCaseValid(KTestCapSet); |
353 TEST_TEST_CASE(pauseNotWanted, none, KTestCapSet, ERun); |
369 test_Value(t, t == ESkip); |
354 |
370 |
355 TEST_TEST_CASE(pauseNotWanted, capAboveV1, KDmacTestCapsV1, ESkip); |
371 test.Next(_L("pauseNotWanted, hwDesWanted\n")); |
356 TEST_TEST_CASE(pauseNotWanted, capAboveV1, KDmacTestCapsV2, ERun); |
372 testCase.iChannelCaps[1] = hwDesWanted; |
357 |
373 t = testCase.TestCaseValid(KTestCapSet); |
358 TEST_TEST_CASE(pauseNotWanted, capBelowV2, KDmacTestCapsV1, ERun); |
374 test_Value(t, t == ERun); |
359 TEST_TEST_CASE(pauseNotWanted, capBelowV2, KDmacTestCapsV2, ESkip); |
375 |
360 |
376 test.Next(_L("pauseNotWanted\n")); |
361 // contradictory requirements |
377 testCase.iChannelCaps[1] = none; |
362 TEST_TEST_CASE(capAboveV1, capBelowV2, KDmacTestCapsV2, ESkip); |
378 t = testCase.TestCaseValid(KTestCapSet); |
363 TEST_TEST_CASE(capBelowV2, capAboveV1, KDmacTestCapsV2, ESkip); |
379 test_Value(t, t == ERun); |
364 |
380 |
365 TEST_TEST_CASE(capAboveV1, capBelowV2, KDmacTestCapsV1, ESkip); |
381 test.Next(_L("pauseNotWanted + V1 PIL required\n")); |
366 TEST_TEST_CASE(capBelowV2, capAboveV1, KDmacTestCapsV1, ESkip); |
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); |
|
388 test_Equal(ERun, t); |
|
389 |
|
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); |
|
394 test_Equal(ERun, t); |
|
395 test.Next(_L("Against KDmacTestCapsV2")); |
|
396 t = testCase.TestCaseValid(KDmacTestCapsV2); |
|
397 test_Equal(ESkip, t); |
|
398 |
367 |
399 test.End(); |
368 test.End(); |
400 test.Close(); |
369 test.Close(); |
401 } |
370 } |
402 |
371 |
645 const TAddressParms pD(0, 128, 64); |
627 const TAddressParms pD(0, 128, 64); |
646 test(pD.Overlaps(pA)); |
628 test(pD.Overlaps(pA)); |
647 test(pD.Overlaps(pB)); |
629 test(pD.Overlaps(pB)); |
648 test(pD.Overlaps(pC)); |
630 test(pD.Overlaps(pC)); |
649 test.End(); |
631 test.End(); |
|
632 } |
|
633 |
|
634 void TIsrRequeArgsSet::SelfTest() |
|
635 { |
|
636 test.Start(_L("Selftest of TIsrRequeArgsSet")); |
|
637 |
|
638 TUint size = 0x1000; |
|
639 TDmaTransferArgs tferArgs(0, 1*size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr); |
|
640 |
|
641 TIsrRequeArgs requeArgArray[] = { |
|
642 TIsrRequeArgs(), // Repeat |
|
643 TIsrRequeArgs(KPhysAddrInvalidUser, 2*size, 0), // Change destination |
|
644 TIsrRequeArgs(), // Repeat |
|
645 TIsrRequeArgs(3*size, KPhysAddrInvalidUser, 0), // Change source |
|
646 TIsrRequeArgs(), // Repeat |
|
647 }; |
|
648 TIsrRequeArgsSet argSet(requeArgArray, ARRAY_LENGTH(requeArgArray)); |
|
649 |
|
650 test.Next(_L("Test that Substitute updates transfer args in order")); |
|
651 argSet.Substitute(tferArgs); |
|
652 |
|
653 TAddressParms expectedFinal(3*size, 2*size, size); |
|
654 if(!(expectedFinal == argSet.iRequeArgs[4])) |
|
655 { |
|
656 TBuf<0x100> out; |
|
657 |
|
658 out += _L("substitue: "); |
|
659 GetAddrParms(tferArgs).AppendString(out); |
|
660 test.Printf(out); |
|
661 |
|
662 out.Zero(); |
|
663 out += _L("\nexpected final: "); |
|
664 expectedFinal.AppendString(out); |
|
665 test.Printf(out); |
|
666 |
|
667 out.Zero(); |
|
668 out += _L("\nactual: "); |
|
669 argSet.iRequeArgs[4].AppendString(out); |
|
670 test.Printf(out); |
|
671 |
|
672 test(EFalse); |
|
673 } |
|
674 |
|
675 TIsrRequeArgs requeArgArray2[] = { |
|
676 TIsrRequeArgs(), // Repeat |
|
677 TIsrRequeArgs(KPhysAddrInvalidUser, 2*size, 0), // Change destination |
|
678 TIsrRequeArgs(KPhysAddrInvalidUser, 1*size, 0), // Change destination back |
|
679 }; |
|
680 argSet = TIsrRequeArgsSet(requeArgArray2, ARRAY_LENGTH(requeArgArray2)); |
|
681 |
|
682 test.Next(_L("CheckRange(), negative")); |
|
683 |
|
684 test(!argSet.CheckRange(0, (2 * size) - 1, tferArgs)); |
|
685 test(!argSet.CheckRange(0, (2 * size) + 1, tferArgs)); |
|
686 test(!argSet.CheckRange(0, (2 * size), tferArgs)); |
|
687 |
|
688 test(!argSet.CheckRange(1 ,(3 * size), tferArgs)); |
|
689 test(!argSet.CheckRange(1 ,(3 * size) + 1, tferArgs)); |
|
690 |
|
691 test(!argSet.CheckRange(1 * size , 2 * size, tferArgs)); |
|
692 |
|
693 test.Next(_L("CheckRange(), positive")); |
|
694 test(argSet.CheckRange(0, 3 * size, tferArgs)); |
|
695 test(argSet.CheckRange(0, 3 * size+1, tferArgs)); |
|
696 test(argSet.CheckRange(0, 4 * size, tferArgs)); |
|
697 |
|
698 |
|
699 test.End(); |
|
700 } |
|
701 |
|
702 void RArrayCopyTestL() |
|
703 { |
|
704 test.Start(_L("Selftest of RArray CopyL")); |
|
705 |
|
706 RArray<TInt> orig; |
|
707 TInt i; // VC++ |
|
708 for(i=0; i<10; i++) |
|
709 { |
|
710 orig.AppendL(i); |
|
711 } |
|
712 |
|
713 RArray<TInt> newArray; |
|
714 CopyL(orig, newArray); |
|
715 |
|
716 test_Equal(10, newArray.Count()); |
|
717 |
|
718 for(i=0; i<10; i++) |
|
719 { |
|
720 test_Equal(orig[i], newArray[i]) |
|
721 } |
|
722 |
|
723 orig.Close(); |
|
724 newArray.Close(); |
|
725 test.End(); |
|
726 } |
|
727 |
|
728 void RArrayInsertLTest() |
|
729 { |
|
730 test.Start(_L("Selftest of RArray InsertL")); |
|
731 |
|
732 RArray<TInt> array; |
|
733 TInt numbers[10] = {0,1,2,3,4,5,6,7,8,9}; |
|
734 ArrayAppendL(array, &numbers[0], numbers + ARRAY_LENGTH(numbers)); |
|
735 |
|
736 test_Equal(10, array.Count()); |
|
737 for(TInt i=0; i<10; i++) |
|
738 { |
|
739 test_Equal(numbers[i], array[i]) |
|
740 } |
|
741 |
|
742 array.Close(); |
|
743 test.End(); |
|
744 } |
|
745 |
|
746 /** |
|
747 Run check buffers on the supplied TAddressParms array |
|
748 */ |
|
749 TBool DoTferParmTestL(const TAddressParms* aParms, TInt aCount, TBool aAllowRepeat, TBool aPositive) |
|
750 { |
|
751 _LIT(KPositive, "positive"); |
|
752 _LIT(KNegative, "negative"); |
|
753 test.Printf(_L("CheckBuffers %S test: %d args, repeats allowed %d\n"), |
|
754 (aPositive ? &KPositive : &KNegative), aCount, aAllowRepeat); |
|
755 RArray<const TAddressParms> array; |
|
756 ArrayAppendL(array, aParms, aParms + aCount); |
|
757 TPreTransferIncrBytes preTran; |
|
758 TBool r = preTran.CheckBuffers(array, aAllowRepeat); |
|
759 array.Close(); |
|
760 return r; |
|
761 } |
|
762 |
|
763 void TPreTransferIncrBytes::SelfTest() |
|
764 { |
|
765 // Test that TPreTransferIncrBytes::CheckBuffers can identify |
|
766 // overlapping buffers |
|
767 test.Start(_L("Selftest of TPreTransferIncrBytes")); |
|
768 |
|
769 // Macro generates test for 2 element array |
|
770 #define TPARM_TEST2(EXPECT, ALLOW_REPEAT, EL0, EL1)\ |
|
771 {\ |
|
772 TAddressParms set[2] = {EL0, EL1}; \ |
|
773 const TBool r = DoTferParmTestL(set, 2, ALLOW_REPEAT, EXPECT);\ |
|
774 test_Equal(EXPECT, r);\ |
|
775 } |
|
776 |
|
777 // Generate positive 2 element test |
|
778 #define TPARM_TEST2_POSITIVE(ALLOW_REPEAT, EL0, EL1) TPARM_TEST2(ETrue, ALLOW_REPEAT, EL0, EL1) |
|
779 // Generate negative 2 element test |
|
780 #define TPARM_TEST2_NEG(ALLOW_REPEAT, EL0, EL1) TPARM_TEST2(EFalse, ALLOW_REPEAT, EL0, EL1) |
|
781 |
|
782 // Macro generates test for 3 element array |
|
783 #define TPARM_TEST3(EXPECT, ALLOW_REPEAT, EL0, EL1, EL2)\ |
|
784 {\ |
|
785 TAddressParms set[3] = {EL0, EL1, EL2}; \ |
|
786 const TBool r = DoTferParmTestL(set, 3, ALLOW_REPEAT, EXPECT);\ |
|
787 test_Equal(EXPECT, r);\ |
|
788 } |
|
789 |
|
790 // Generate positive 3 element test |
|
791 #define TPARM_TEST3_POSITIVE(ALLOW_REPEAT, EL0, EL1, EL2) TPARM_TEST3(ETrue, ALLOW_REPEAT, EL0, EL1, EL2) |
|
792 // Generate negative 3 element test |
|
793 #define TPARM_TEST3_NEG(ALLOW_REPEAT, EL0, EL1, EL2) TPARM_TEST3(EFalse, ALLOW_REPEAT, EL0, EL1, EL2) |
|
794 |
|
795 TPARM_TEST2_POSITIVE(EFalse, TAddressParms(0,16,16), TAddressParms(32, 48, 16)); |
|
796 TPARM_TEST2_POSITIVE(ETrue, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // both overlap (repeat allowed) |
|
797 |
|
798 TPARM_TEST2_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(24, 40, 16)); // second source depends on first destination |
|
799 TPARM_TEST2_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(16, 0, 16)); // second dest overwrites first source |
|
800 TPARM_TEST2_NEG(EFalse, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // both overlap (repeat not allowed) |
|
801 TPARM_TEST2_NEG(ETrue, TAddressParms(0, 16, 16), TAddressParms(0, 20, 16)); // exact repeat allowed, but overlap is only partial |
|
802 TPARM_TEST2_NEG(ETrue, TAddressParms(0, 16, 16), TAddressParms(32, 16, 16)); // exact repeat allowed, but 2nd overwrites first dest |
|
803 |
|
804 |
|
805 TPARM_TEST3_POSITIVE(EFalse, TAddressParms(0,16,16), TAddressParms(32, 48, 16), TAddressParms(64, 128, 64)); // no overlaps |
|
806 TPARM_TEST3_POSITIVE(ETrue, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // all overlap (repeat allowed) |
|
807 TPARM_TEST3_POSITIVE(EFalse, TAddressParms(0,16,16), TAddressParms(0, 32, 16), TAddressParms(0, 48, 16)); // no overlaps (1 src to 3 dsts) |
|
808 |
|
809 TPARM_TEST3_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(128, 256, 128), TAddressParms(24, 40, 16)); // 3rd source depends on first destination |
|
810 TPARM_TEST3_NEG(EFalse, TAddressParms(0,16,16), TAddressParms(128, 256, 128), TAddressParms(16, 0, 16)); // 3rd dest overwrites first source |
|
811 TPARM_TEST3_NEG(EFalse, TAddressParms(0, 16, 16), TAddressParms(0, 16, 16), TAddressParms(0, 16, 16)); // all overlap (repeat not allowed) |
|
812 test.Next(_L("CheckBuffers(RArray<TAddressParms>)")); |
650 } |
813 } |
651 |
814 |
652 void SelfTests() |
815 void SelfTests() |
653 { |
816 { |
654 test.Next(_L("Running framework unit tests")); |
817 test.Next(_L("Running framework unit tests")); |