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