os/kernelhwsrv/kerneltest/e32test/misc/kill.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1997-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\misc\kill.cpp
    15 // 
    16 //
    17 
    18 #include <e32test.h>
    19 
    20 _LIT(KPanicCat,"Test");
    21 
    22 LOCAL_D RTest test(_L("Kill"));
    23 
    24 GLDEF_C TInt E32Main()
    25 	{
    26 	test.Title();
    27 	TBuf<256> cmd;
    28 	TFullName fn;
    29 	User::CommandLine(cmd);
    30 	TLex lex(cmd);
    31 	TPtrC threadSpec(lex.NextToken());
    32 	TFindThread ft(threadSpec);
    33 	TExitType exitType=EExitKill;
    34 	TInt exitCode=0;
    35 	if (!lex.Eos())
    36 		{
    37 		TPtrC xtSpec(lex.NextToken());
    38 		TPtrC xc(xtSpec);
    39 		TChar xt0=xtSpec[0];
    40 		if (xt0.IsAlpha())
    41 			{
    42 			xt0.LowerCase();
    43 			if (xt0==TChar('t'))
    44 				exitType=EExitTerminate;
    45 			else if (xt0==TChar('p'))
    46 				exitType=EExitPanic;
    47 			new(&xc) TPtrC(lex.NextToken());
    48 			}
    49 		if (xc.Length())
    50 			{
    51 			TLex lex2(xc);
    52 			lex2.Val(exitCode);
    53 			}
    54 		}
    55 	while (ft.Next(fn)==KErrNone)
    56 		{
    57 		test.Printf(_L("Killing %S\n"),&fn);
    58 		RThread t;
    59 		TInt r=t.Open(ft);
    60 		if (r==KErrNone)
    61 			{
    62 			// FIXME: SHOULD REMOVE CRITICALNESS - WOULD NEED DEVICE DRIVER
    63 			switch (exitType)
    64 				{
    65 				case EExitKill:	t.Kill(exitCode); break;
    66 				case EExitTerminate: t.Terminate(exitCode); break;
    67 				case EExitPanic: t.Panic(KPanicCat,exitCode); break;
    68 				default: break;
    69 				}
    70 			t.Close();
    71 			}
    72 		}
    73 	return 0;
    74 	}