os/kernelhwsrv/kerneltest/e32test/nkern/t_nktrace.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/nkern/t_nktrace.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,202 @@
     1.4 +// Copyright (c) 2005-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\nkern\t_nktrace.cpp
    1.18 +// Overview:
    1.19 +// Test the KTRACE macros and debug mask related functions.
    1.20 +// API Information:
    1.21 +// UserSvr::DebugMask(), User::SetDebugMask, KDebugMask(), KDebugNum()
    1.22 +// Details:	
    1.23 +// Set debug masks and verify they are as expected. Test using 
    1.24 +// UserSvr::DebugMask() & User::SetDebugMask().
    1.25 +// In a kernel level LDD, test the kernel functions using 
    1.26 +// KDebugMask() & KDebugNum().
    1.27 +// 
    1.28 +//
    1.29 +
    1.30 +#include <e32test.h>
    1.31 +#include <e32svr.h>
    1.32 +#include "nk_trace.h"
    1.33 +#include "d_nktrace.h"
    1.34 +
    1.35 +LOCAL_D RTest test(_L("T_NKTRACE"));
    1.36 +
    1.37 +void Wait(TInt aSeconds)
    1.38 +	{
    1.39 +	while (aSeconds>0)
    1.40 +		{
    1.41 +		--aSeconds;
    1.42 +		User::After(1000000);
    1.43 +		test.Printf(_L("."));
    1.44 +		}
    1.45 +	}
    1.46 +
    1.47 +GLDEF_C TInt E32Main()
    1.48 +    {
    1.49 +	test.Title();
    1.50 +
    1.51 +	test.Start(_L("Load LDD"));
    1.52 +	TInt r=User::LoadLogicalDevice(_L("D_NKTRACE"));
    1.53 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.54 +	test.Next(_L("Open channel"));
    1.55 +	RNKTraceTest traceSys;
    1.56 +	r=traceSys.Open();
    1.57 +	test(r==KErrNone);
    1.58 +
    1.59 +	// verify access to debug mask 0, with and without argument
    1.60 +	TUint32 initial[8];
    1.61 +	TInt i;
    1.62 +	
    1.63 +	for (i=0; i<8; i++)
    1.64 +		   initial[i]= UserSvr::DebugMask(i);
    1.65 +
    1.66 +	test.Printf(_L("initial DebugMask value = 0x%08x\n"), initial[0]);
    1.67 +	TUint32 m = UserSvr::DebugMask();
    1.68 +	test(m==initial[0]);
    1.69 +	User::SetDebugMask(~m);
    1.70 +	m = UserSvr::DebugMask(0);
    1.71 +	test(m!=initial[0]);
    1.72 +	test(m==~initial[0]);
    1.73 +
    1.74 +	// set and verify each of the 8 debug masks
    1.75 +	User::SetDebugMask(0x12340000, 0);
    1.76 +	User::SetDebugMask(0x12341111, 1);
    1.77 +	User::SetDebugMask(0x12342222, 2);
    1.78 +	User::SetDebugMask(0x12343333, 3);
    1.79 +	User::SetDebugMask(0x12344444, 4);
    1.80 +	User::SetDebugMask(0x12345555, 5);
    1.81 +	User::SetDebugMask(0x12346666, 6);
    1.82 +	User::SetDebugMask(0x12347777, 7);
    1.83 +
    1.84 +	m = UserSvr::DebugMask(0);
    1.85 +	test(m==0x12340000);
    1.86 +	m = UserSvr::DebugMask(1);
    1.87 +	test(m==0x12341111);
    1.88 +	m = UserSvr::DebugMask(2);
    1.89 +	test(m==0x12342222);
    1.90 +	m = UserSvr::DebugMask(3);
    1.91 +	test(m==0x12343333);
    1.92 +	m = UserSvr::DebugMask(4);
    1.93 +	test(m==0x12344444);
    1.94 +	m = UserSvr::DebugMask(5);
    1.95 +	test(m==0x12345555);
    1.96 +	m = UserSvr::DebugMask(6);
    1.97 +	test(m==0x12346666);
    1.98 +	m = UserSvr::DebugMask(7);
    1.99 +	test(m==0x12347777);
   1.100 +
   1.101 +	// verify correct results when no index argument is given
   1.102 +	User::SetDebugMask(0xC0000000);
   1.103 +	m = UserSvr::DebugMask();
   1.104 +	test.Printf(_L("UserSvr::DebugMask = 0x%08x\n"), m);
   1.105 +	test(m==0xC0000000);
   1.106 +
   1.107 +	User::SetDebugMask(0x80000000);
   1.108 +	m = UserSvr::DebugMask();
   1.109 +	test.Printf(_L("UserSvr::DebugMask = 0x%08x\n"), m);
   1.110 +	test(m==0x80000000);
   1.111 +
   1.112 +	test.Next(_L("Test the Kernel level code..."));
   1.113 +	User::SetDebugMask(0xC0000000, 0);    // set bits 30 & 31
   1.114 +	User::SetDebugMask(0x00000008, 1);    // set bit 35
   1.115 +	User::SetDebugMask(0x00000010, 2);    // set bit 68
   1.116 +	User::SetDebugMask(0x00000020, 3);    // set bit 101
   1.117 +	User::SetDebugMask(0x00000100, 4);    // set bit 136
   1.118 +	User::SetDebugMask(0x00001000, 5);    // set bit 172
   1.119 +	User::SetDebugMask(0x00000001, 6);    // set bit 192
   1.120 +	User::SetDebugMask(0x00000040, 7);    // set bit 230
   1.121 +
   1.122 +	// test the KTRACE_OPT macros in server code
   1.123 +	r=traceSys.KTrace(RNKTraceTest::ETestKTrace);
   1.124 +
   1.125 +	// test the KDebugMask() and KDebugNum() functions in server code
   1.126 +	r=traceSys.KDebug(RNKTraceTest::ETestKTrace);
   1.127 +
   1.128 +    test.Printf(_L("Kern::Printf() output goes\n"));
   1.129 +	test.Printf(_L("to the serial port or the \n"));
   1.130 +	test.Printf(_L("file epocwind.out when \n"));
   1.131 +	test.Printf(_L("tested on the emulator. \n"));
   1.132 +    test.Printf(_L("The following results\n"));
   1.133 +    test.Printf(_L("should be displayed:\n"));
   1.134 +
   1.135 +   	test.Printf(_L("Test __KTRACE_OPT macros\n"));
   1.136 +    test.Printf(_L("KALWAYS\n"));
   1.137 +    test.Printf(_L("KPANIC\n"));
   1.138 +    test.Printf(_L("KSCRATCH\n"));
   1.139 +    test.Printf(_L("Debug bit 35 is set\n"));
   1.140 +    test.Printf(_L("Debug bit 68 is set\n"));
   1.141 +    test.Printf(_L("Debug bit 101 is set\n"));
   1.142 +    test.Printf(_L("Debug bit 136 is set\n"));
   1.143 +    test.Printf(_L("Debug bit 172 is set\n"));
   1.144 +    test.Printf(_L("Debug bit 192 is set\n"));
   1.145 +    test.Printf(_L("Debug bit 230 is set\n"));    
   1.146 +    test.Printf(_L("KTRACE_ALL returned true\n"));    
   1.147 +
   1.148 +	// Wait for a while, or for a key press
   1.149 +	test.Printf(_L("Press a key to continue..."));
   1.150 +	TRequestStatus keyStat;
   1.151 +	test.Console()->Read(keyStat);
   1.152 +	RTimer timer;
   1.153 +	test(timer.CreateLocal()==KErrNone);
   1.154 +	TRequestStatus timerStat;
   1.155 +	timer.After(timerStat,10*1000000);
   1.156 +	User::WaitForRequest(timerStat,keyStat);
   1.157 +	TInt key;
   1.158 +	if(keyStat!=KRequestPending)
   1.159 +		key = test.Console()->KeyCode();
   1.160 +	timer.Cancel();
   1.161 +	test.Console()->ReadCancel();
   1.162 +	User::WaitForAnyRequest();
   1.163 +
   1.164 +	test.Printf(_L("\n"));
   1.165 +    test.Printf(_L("KDebug tests (0)\n"));
   1.166 +    test.Printf(_L("KDebugMask() = 0xc0000000\n"));
   1.167 +    test.Printf(_L("KDebugNum(30) = 1\n"));
   1.168 +    test.Printf(_L("KDebugNum(31) = 1\n"));
   1.169 +    test.Printf(_L("KDebugNum(3) = 0\n"));
   1.170 +    test.Printf(_L("KDebugNum(9) = 0\n"));
   1.171 +    test.Printf(_L("KDebugNum(10000) = 0\n"));
   1.172 +    test.Printf(_L("KDebugNum(-1) = 1\n"));
   1.173 +    test.Printf(_L("KDebugNum(-2) = 0\n"));
   1.174 +    test.Printf(_L("KDebugNum(35) = 1\n"));
   1.175 +    test.Printf(_L("KDebugNum(36) = 0\n"));
   1.176 +    test.Printf(_L("KDebugNum(101) = 1\n"));
   1.177 +    test.Printf(_L("KDebugNum(192) = 1\n"));
   1.178 +    test.Printf(_L("KDebugNum(230) = 1\n"));
   1.179 +
   1.180 +	// set the debug masks back to the original state
   1.181 +	for (i=0; i<8; i++)
   1.182 +		User::SetDebugMask(initial[i], i);
   1.183 +
   1.184 +	m = UserSvr::DebugMask(0);
   1.185 +	test(m==initial[0]);
   1.186 +	m = UserSvr::DebugMask(1);
   1.187 +	test(m==initial[1]);
   1.188 +	m = UserSvr::DebugMask(2);
   1.189 +	test(m==initial[2]);
   1.190 +	m = UserSvr::DebugMask(3);
   1.191 +	test(m==initial[3]);
   1.192 +	m = UserSvr::DebugMask(4);
   1.193 +	test(m==initial[4]);
   1.194 +	m = UserSvr::DebugMask(5);
   1.195 +	test(m==initial[5]);
   1.196 +	m = UserSvr::DebugMask(6);
   1.197 +	test(m==initial[6]);
   1.198 +	m = UserSvr::DebugMask(7);
   1.199 +	test(m==initial[7]);
   1.200 +
   1.201 +	test.End();
   1.202 +
   1.203 +	return(0);
   1.204 +    }
   1.205 +