kerneltest/e32test/prime/t_kern.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\prime\t_kern.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 
       
    20 LOCAL_D RTest test(_L("T_KERN"));
       
    21 LOCAL_D TFindProcess fProc;
       
    22 LOCAL_D TFindThread fThread;
       
    23 LOCAL_D TFindSemaphore fSem;
       
    24 LOCAL_D TFindMutex fMutex;
       
    25 LOCAL_D TFindChunk fChunk;
       
    26 LOCAL_D TFindLogicalDevice fLdd;
       
    27 LOCAL_D TFindPhysicalDevice fPdd;
       
    28 LOCAL_D TFindServer fServ;
       
    29 LOCAL_D TFindLibrary fLib;
       
    30 
       
    31 LOCAL_C void testFindHandles()
       
    32 //
       
    33 // Test the various find handles.
       
    34 //
       
    35 	{
       
    36 
       
    37 	test.Start(_L("Processes"));
       
    38 	TFullName n;
       
    39 	while (fProc.Next(n)==KErrNone)
       
    40 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fProc.Handle());
       
    41 	test.Next(_L("Threads"));
       
    42 	while (fThread.Next(n)==KErrNone)
       
    43 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fThread.Handle());
       
    44 	test.Next(_L("Semaphores"));
       
    45 	while (fSem.Next(n)==KErrNone)
       
    46 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fSem.Handle());
       
    47 	test.Next(_L("Mutexes"));
       
    48 	while (fMutex.Next(n)==KErrNone)
       
    49 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fMutex.Handle());
       
    50 	test.Next(_L("Chunks"));
       
    51 	while (fChunk.Next(n)==KErrNone)
       
    52 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fChunk.Handle());
       
    53 	test.Next(_L("LogicalDevice"));
       
    54 	while (fLdd.Next(n)==KErrNone)
       
    55 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fLdd.Handle());
       
    56 	test.Next(_L("PhysicalDevice"));
       
    57 	while (fPdd.Next(n)==KErrNone)
       
    58 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fPdd.Handle());
       
    59 	test.Next(_L("Server"));
       
    60 	while (fServ.Next(n)==KErrNone)
       
    61 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fServ.Handle());
       
    62 	test.Next(_L("Library"));
       
    63 	while (fLib.Next(n)==KErrNone)
       
    64 		test.Printf(_L("  %- 50s %d\n"),n.PtrZ(),fLib.Handle());
       
    65 	test.End();
       
    66 	}
       
    67 
       
    68 LOCAL_C void testCurrentProcessAndThread()
       
    69 //
       
    70 // Test the handles for the current process and thread.
       
    71 //
       
    72 	{
       
    73 
       
    74 	test.Start(_L("Process"));
       
    75 	RProcess p;
       
    76 	TFullName pFullName = p.FullName();
       
    77 	test.Printf(_L("  %S\n"),&pFullName);
       
    78 	TName pName = p.Name();
       
    79 	test.Printf(_L("  %S\n"),&pName);
       
    80 //
       
    81 	test.Next(_L("Thread"));
       
    82 	RThread t;
       
    83 	TFullName tFullName = t.FullName();
       
    84 	test.Printf(_L("  %S\n"),&tFullName);
       
    85 	TName tName = t.Name();
       
    86 	test.Printf(_L("  %S\n"),&tName);
       
    87 //
       
    88 	test.End();
       
    89 	}
       
    90 
       
    91 LOCAL_C TInt ThreadBeepFunction(TAny*)
       
    92 //
       
    93 // Thread which beeps and stops before the beep completes
       
    94 //
       
    95 	{
       
    96 
       
    97 	User::Beep(440,1000000);
       
    98 	return KErrNone;
       
    99 	}
       
   100 
       
   101 LOCAL_C void testBeep()
       
   102 //
       
   103 // Test the beep function.
       
   104 //
       
   105 	{
       
   106 
       
   107 	test.Start(_L("220Hz dur=10"));
       
   108 	User::Beep(220,1000000);
       
   109 	User::After(2000000);
       
   110 	test.Next(_L("330Hz dur=10"));
       
   111 	User::Beep(330,1000000);
       
   112 	User::After(2000000);
       
   113 	test.Next(_L("440Hz dur=10"));
       
   114 	User::Beep(440,1000000);
       
   115 	User::After(2000000);
       
   116 	test.Next(_L("880Hz dur=10"));
       
   117 	User::Beep(880,1000000);
       
   118 	User::After(2000000);
       
   119 	test.Next(_L("1760Hz dur=10"));
       
   120 	User::Beep(1760,1000000);
       
   121 	User::After(2000000);
       
   122 
       
   123 	test.Next(_L("Listen to check that the first beep is interrupted after 2 secs"));
       
   124 	User::Beep(330,10000000);
       
   125 	User::After(2000000);
       
   126 	User::Beep(660,1000000);
       
   127 	User::After(1000000);
       
   128 
       
   129 	test.Next(_L("Listen to check that a negative value does not interrupt"));
       
   130 	User::Beep(330,5000000);
       
   131 	User::After(2000000);
       
   132 	TInt r=User::Beep(660,-1000000);
       
   133 	test.Next(_L("Check the 2nd beep returned KErrGeneral"));
       
   134 	test(r==KErrGeneral);
       
   135 	User::After(3000000);
       
   136 
       
   137 	test.Next(_L("Beep survives when thread terminates"));
       
   138 	RThread thread;
       
   139 	thread.Create(_L("Beep Test Thread"),ThreadBeepFunction,0x1000,0x1000,0x1000,NULL);
       
   140 	TRequestStatus stat;
       
   141 	thread.Logon(stat);
       
   142 	thread.Resume();
       
   143 	User::WaitForRequest(stat);
       
   144 	RTimer timer;
       
   145 	timer.CreateLocal();
       
   146 	thread.Close();
       
   147 	timer.After(stat,TTimeIntervalMicroSeconds32(2000000)); //2secs
       
   148 	User::WaitForRequest(stat);
       
   149 	CLOSE_AND_WAIT(thread);
       
   150 	test.End();
       
   151 	}
       
   152 
       
   153 GLDEF_C TInt E32Main()
       
   154 //
       
   155 // Test the various kernel types.
       
   156 //
       
   157     {
       
   158 
       
   159 	test.Title();
       
   160 //
       
   161 	test.Start(_L("TFindHandles"));
       
   162 	testFindHandles();
       
   163 //
       
   164 	test.Next(_L("Current process and thread"));
       
   165 	testCurrentProcessAndThread();
       
   166 //
       
   167 	test.Next(_L("Test beeper"));
       
   168 	testBeep();
       
   169 //
       
   170 	test.End();
       
   171 	return(KErrNone);
       
   172     }
       
   173 
       
   174 
       
   175