diff -r 000000000000 -r a41df078684a kerneltest/e32test/nkernsa/tiedevents.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32test/nkernsa/tiedevents.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,235 @@ +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32test\nkernsa\tiedevents.cpp +// +// + +#include + +//--------------------------------------------------------------------------------------------------------------------- +//! @SYMTestCaseID KBASE-tiedevents-2448 +//! @SYMTestType UT +//! @SYMTestCaseDesc Verifying tied events +//! @SYMPREQ PREQ2094 +//! @SYMTestPriority High +//! @SYMTestActions +//! 1. TiedEventTest: run a reader thread (or several in a group) accessing a +//! common data block. A timer, IDFC, or interrupt handler writes to the +//! data block concurrently - first incrementing all data from 0 to 1 then +//! decrementing it again. +//! +//! @SYMTestExpectedResults +//! 1. When the timer/IDFC/interrupt is tied to the thread/group, then the +//! execution of the event should prevent the thread/group from running on +//! any processor, and thus readers should never be able to observe the +//! data being 1. When the event is not tied, the reader should observe +//! the data as being 1 at least some of the time. +//--------------------------------------------------------------------------------------------------------------------- + +#ifdef __SMP__ + +extern "C" void HijackSystemTimer(NSchedulable* aTieTo); + +const TInt FlagCount = 2048; +const TInt LoopCount = 100; + +volatile TUint32 Flags[FlagCount]; +volatile TBool Done; +volatile TUint32 FlagsSet; +NTimer* Timer; +TDfc* IDfc; +NThreadGroup TG; +NFastSemaphore* DoneSem; + +enum TTiedMode + { + ETimer, + EInterrupt, + EIDFC + }; + +// Used directly as the IDFC, also called by the timer function +void FiddleFlags(TAny*) + { + TInt i; + for (i=0; iOneShot(10); + } + +// Used for IDFC case as the timer function +void IDfcQFn(TAny*) + { + IDfc->Add(); + if (!__e32_atomic_load_acq32(&Done)) + Timer->OneShot(10); + } + +// Test thread, just looks for flags being set +void TiedEventThread(TAny*) + { + TInt cpu, i, j; + TUint32 set=0; + + for_each_cpu(cpu) + { + NKern::ThreadSetCpuAffinity(NKern::CurrentThread(), cpu); + + for (i=0; i 0, "Flag wasn't set, test broken?"); + } +#endif + +void TestTiedEvents() + { +#ifdef __SMP__ + TiedEventTest(EFalse, 1, ETimer); + TiedEventTest(ETrue, 1, ETimer); + TiedEventTest(EFalse, 2, ETimer); + TiedEventTest(ETrue, 2, ETimer); + +#ifndef __X86__ + TiedEventTest(EFalse, 1, EInterrupt); + TiedEventTest(ETrue, 1, EInterrupt); + TiedEventTest(EFalse, 2, EInterrupt); + TiedEventTest(ETrue, 2, EInterrupt); +#endif + + TiedEventTest(EFalse, 1, EIDFC); + TiedEventTest(ETrue, 1, EIDFC); + TiedEventTest(EFalse, 2, EIDFC); + TiedEventTest(ETrue, 2, EIDFC); +#endif + }