os/kernelhwsrv/kerneltest/e32test/cppexceptions/t_unmap2.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/cppexceptions/t_unmap2.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,99 @@
     1.4 +// Copyright (c) 2004-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\cppexceptions\t_unmap2.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32std_private.h>
    1.23 +#include <e32base.h>
    1.24 +#include <e32base_private.h>
    1.25 +#include <e32test.h>
    1.26 +#include "d_unmap.h"
    1.27 +
    1.28 +_LIT(KTestName, "t_unmap2");
    1.29 +RTest test(KTestName);
    1.30 +RSemaphore WaitSemaphore;
    1.31 +RSemaphore SignalSemaphore;
    1.32 +
    1.33 +void TestLibraryCleanup();
    1.34 +
    1.35 +TInt E32Main()
    1.36 +   	{
    1.37 +	test.Start(_L("Check code seg unmapping over User::Leave()/C++ exceptions."));
    1.38 +
    1.39 +	__UHEAP_MARK;
    1.40 +   	CTrapCleanup* cleanup = CTrapCleanup::New();
    1.41 +   	TInt r = KErrNoMemory;
    1.42 +   	if (cleanup)
    1.43 +   		{
    1.44 +		test.Printf(_L("Opening semaphores for barrier with other process\n"));
    1.45 +		test(WaitSemaphore.Open(1)==KErrNone);
    1.46 +		test(SignalSemaphore.Open(2)==KErrNone);
    1.47 +		TRAP(r, TestLibraryCleanup());
    1.48 +		test.Printf(_L("Returned %d, expected %d\n"), r, KErrGeneral);
    1.49 +		test(r == KErrGeneral);
    1.50 +		WaitSemaphore.Close();
    1.51 +		SignalSemaphore.Close();
    1.52 +		r = KErrNone;
    1.53 +   		}
    1.54 +
    1.55 +	delete cleanup;
    1.56 + 	__UHEAP_MARKEND;
    1.57 +
    1.58 +	test.End();
    1.59 +   	return r;
    1.60 +   	}
    1.61 +
    1.62 +void Checkpoint(TAny*)
    1.63 +	{
    1.64 +	test.Printf(_L("Checkpointing...\n"));
    1.65 +	SignalSemaphore.Signal();
    1.66 +	WaitSemaphore.Wait();
    1.67 +	}
    1.68 +
    1.69 +void TestLibraryCleanup()
    1.70 +	{
    1.71 +    test.Printf(_L("Loading DLL.\n"));
    1.72 +	RLibrary library;
    1.73 +	test(library.Load(KLeavingDll2) == KErrNone);
    1.74 +
    1.75 +    test.Printf(_L("Pushing cleanup item to synchronise after closing library handle.\n"));
    1.76 +	CleanupStack::PushL(TCleanupItem(&Checkpoint, NULL));
    1.77 +
    1.78 +    test.Printf(_L("Pushing handle to dynamically loaded DLL onto the cleanup stack.\n"));
    1.79 +	CleanupClosePushL(library);
    1.80 +
    1.81 +	test.Printf(_L("Pushing cleanup item to synchronise during leave\n"));
    1.82 +	CleanupStack::PushL(TCleanupItem(&Checkpoint, NULL));
    1.83 +
    1.84 +    test.Printf(_L("Looking up leaving function.\n"));
    1.85 +	TLibraryFunction leaving = library.Lookup(1);
    1.86 +	test(leaving != NULL);
    1.87 +
    1.88 +	test.Printf(_L("Check-point whilst holding the open library handle.\n"));
    1.89 +	Checkpoint(NULL);
    1.90 +
    1.91 +	test.Printf(_L("Calling leaving function.\n"));
    1.92 +	(*leaving)();
    1.93 +
    1.94 +	test.Printf(_L("Cleaning up checkpoint operation.\n"));
    1.95 +	CleanupStack::Pop(); // pause leave op
    1.96 +
    1.97 +	test.Printf(_L("Cleaning up DLL handle.\n"));
    1.98 +	CleanupStack::PopAndDestroy();
    1.99 +
   1.100 +	test.Printf(_L("Cleaning up checkpoint operation.\n"));
   1.101 +	CleanupStack::Pop(); // pause leave op
   1.102 +	}