1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/prime/t_kern.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,175 @@
1.4 +// Copyright (c) 1994-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\prime\t_kern.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +
1.23 +LOCAL_D RTest test(_L("T_KERN"));
1.24 +LOCAL_D TFindProcess fProc;
1.25 +LOCAL_D TFindThread fThread;
1.26 +LOCAL_D TFindSemaphore fSem;
1.27 +LOCAL_D TFindMutex fMutex;
1.28 +LOCAL_D TFindChunk fChunk;
1.29 +LOCAL_D TFindLogicalDevice fLdd;
1.30 +LOCAL_D TFindPhysicalDevice fPdd;
1.31 +LOCAL_D TFindServer fServ;
1.32 +LOCAL_D TFindLibrary fLib;
1.33 +
1.34 +LOCAL_C void testFindHandles()
1.35 +//
1.36 +// Test the various find handles.
1.37 +//
1.38 + {
1.39 +
1.40 + test.Start(_L("Processes"));
1.41 + TFullName n;
1.42 + while (fProc.Next(n)==KErrNone)
1.43 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fProc.Handle());
1.44 + test.Next(_L("Threads"));
1.45 + while (fThread.Next(n)==KErrNone)
1.46 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fThread.Handle());
1.47 + test.Next(_L("Semaphores"));
1.48 + while (fSem.Next(n)==KErrNone)
1.49 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fSem.Handle());
1.50 + test.Next(_L("Mutexes"));
1.51 + while (fMutex.Next(n)==KErrNone)
1.52 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fMutex.Handle());
1.53 + test.Next(_L("Chunks"));
1.54 + while (fChunk.Next(n)==KErrNone)
1.55 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fChunk.Handle());
1.56 + test.Next(_L("LogicalDevice"));
1.57 + while (fLdd.Next(n)==KErrNone)
1.58 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fLdd.Handle());
1.59 + test.Next(_L("PhysicalDevice"));
1.60 + while (fPdd.Next(n)==KErrNone)
1.61 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fPdd.Handle());
1.62 + test.Next(_L("Server"));
1.63 + while (fServ.Next(n)==KErrNone)
1.64 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fServ.Handle());
1.65 + test.Next(_L("Library"));
1.66 + while (fLib.Next(n)==KErrNone)
1.67 + test.Printf(_L(" %- 50s %d\n"),n.PtrZ(),fLib.Handle());
1.68 + test.End();
1.69 + }
1.70 +
1.71 +LOCAL_C void testCurrentProcessAndThread()
1.72 +//
1.73 +// Test the handles for the current process and thread.
1.74 +//
1.75 + {
1.76 +
1.77 + test.Start(_L("Process"));
1.78 + RProcess p;
1.79 + TFullName pFullName = p.FullName();
1.80 + test.Printf(_L(" %S\n"),&pFullName);
1.81 + TName pName = p.Name();
1.82 + test.Printf(_L(" %S\n"),&pName);
1.83 +//
1.84 + test.Next(_L("Thread"));
1.85 + RThread t;
1.86 + TFullName tFullName = t.FullName();
1.87 + test.Printf(_L(" %S\n"),&tFullName);
1.88 + TName tName = t.Name();
1.89 + test.Printf(_L(" %S\n"),&tName);
1.90 +//
1.91 + test.End();
1.92 + }
1.93 +
1.94 +LOCAL_C TInt ThreadBeepFunction(TAny*)
1.95 +//
1.96 +// Thread which beeps and stops before the beep completes
1.97 +//
1.98 + {
1.99 +
1.100 + User::Beep(440,1000000);
1.101 + return KErrNone;
1.102 + }
1.103 +
1.104 +LOCAL_C void testBeep()
1.105 +//
1.106 +// Test the beep function.
1.107 +//
1.108 + {
1.109 +
1.110 + test.Start(_L("220Hz dur=10"));
1.111 + User::Beep(220,1000000);
1.112 + User::After(2000000);
1.113 + test.Next(_L("330Hz dur=10"));
1.114 + User::Beep(330,1000000);
1.115 + User::After(2000000);
1.116 + test.Next(_L("440Hz dur=10"));
1.117 + User::Beep(440,1000000);
1.118 + User::After(2000000);
1.119 + test.Next(_L("880Hz dur=10"));
1.120 + User::Beep(880,1000000);
1.121 + User::After(2000000);
1.122 + test.Next(_L("1760Hz dur=10"));
1.123 + User::Beep(1760,1000000);
1.124 + User::After(2000000);
1.125 +
1.126 + test.Next(_L("Listen to check that the first beep is interrupted after 2 secs"));
1.127 + User::Beep(330,10000000);
1.128 + User::After(2000000);
1.129 + User::Beep(660,1000000);
1.130 + User::After(1000000);
1.131 +
1.132 + test.Next(_L("Listen to check that a negative value does not interrupt"));
1.133 + User::Beep(330,5000000);
1.134 + User::After(2000000);
1.135 + TInt r=User::Beep(660,-1000000);
1.136 + test.Next(_L("Check the 2nd beep returned KErrGeneral"));
1.137 + test(r==KErrGeneral);
1.138 + User::After(3000000);
1.139 +
1.140 + test.Next(_L("Beep survives when thread terminates"));
1.141 + RThread thread;
1.142 + thread.Create(_L("Beep Test Thread"),ThreadBeepFunction,0x1000,0x1000,0x1000,NULL);
1.143 + TRequestStatus stat;
1.144 + thread.Logon(stat);
1.145 + thread.Resume();
1.146 + User::WaitForRequest(stat);
1.147 + RTimer timer;
1.148 + timer.CreateLocal();
1.149 + thread.Close();
1.150 + timer.After(stat,TTimeIntervalMicroSeconds32(2000000)); //2secs
1.151 + User::WaitForRequest(stat);
1.152 + CLOSE_AND_WAIT(thread);
1.153 + test.End();
1.154 + }
1.155 +
1.156 +GLDEF_C TInt E32Main()
1.157 +//
1.158 +// Test the various kernel types.
1.159 +//
1.160 + {
1.161 +
1.162 + test.Title();
1.163 +//
1.164 + test.Start(_L("TFindHandles"));
1.165 + testFindHandles();
1.166 +//
1.167 + test.Next(_L("Current process and thread"));
1.168 + testCurrentProcessAndThread();
1.169 +//
1.170 + test.Next(_L("Test beeper"));
1.171 + testBeep();
1.172 +//
1.173 + test.End();
1.174 + return(KErrNone);
1.175 + }
1.176 +
1.177 +
1.178 +