os/kernelhwsrv/kerneltest/e32test/property/t_race.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/property/t_race.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,176 @@
     1.4 +// Copyright (c) 2002-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 +//
    1.18 +
    1.19 +#include "t_property.h"
    1.20 +
    1.21 +_LIT(KPropSetGetRaceName, "RProperty::Set/Get() Race");
    1.22 + 
    1.23 +CPropSetGetRace::CPropSetGetRace(TUid aCategory, TUint aKey) : 
    1.24 +	  CTestProgram(KPropSetGetRaceName), iCategory(aCategory), iKey(aKey), 
    1.25 +		  iBuf1(RProperty::KMaxPropertySize), iBuf2(RProperty::KMaxPropertySize)
    1.26 +	{
    1.27 +	}
    1.28 +
    1.29 +void CPropSetGetRace::Trublemaker(TDes8& aBuf)
    1.30 +	{
    1.31 +	RProperty prop;	
    1.32 +	TInt r = prop.Attach(iCategory, iKey, EOwnerThread);
    1.33 +	TF_ERROR(r, r == KErrNone);
    1.34 +	TBool attached = ETrue;
    1.35 +	for(;;)
    1.36 +		{
    1.37 +		TBuf8<RProperty::KMaxPropertySize> buf;
    1.38 +		if (attached)
    1.39 +			{
    1.40 +			r = prop.Set(aBuf);
    1.41 +			TF_ERROR(r, r == KErrNone);
    1.42 +			r = prop.Get(buf);
    1.43 +			TF_ERROR(r, r == KErrNone);
    1.44 +			}
    1.45 +		else 
    1.46 +			{
    1.47 +			r = prop.Set(iCategory, iKey, aBuf);
    1.48 +			TF_ERROR(r, r == KErrNone);
    1.49 +			r = prop.Get(iCategory, iKey, buf);
    1.50 +			TF_ERROR(r, r == KErrNone);
    1.51 +			}
    1.52 +		TF_ERROR(KErrGeneral, !(buf.Compare(iBuf1) && buf.Compare(iBuf2)));
    1.53 +		User::After(1);
    1.54 +		attached = !attached;
    1.55 +		}
    1.56 +	}
    1.57 +
    1.58 +TInt CPropSetGetRace::TrublemakerThreadEntry(TAny* ptr)
    1.59 +	{
    1.60 +	CPropSetGetRace* prog = (CPropSetGetRace*) ptr;
    1.61 +	prog->Trublemaker(prog->iBuf2);
    1.62 +	return KErrNone;
    1.63 +	}
    1.64 +
    1.65 +void CPropSetGetRace::Run(TUint aCount)
    1.66 +	{
    1.67 +	RProperty prop;	
    1.68 +
    1.69 +	TInt r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy);
    1.70 +	TF_ERROR(r, r == KErrNone);
    1.71 +	r = prop.Attach(iCategory,iKey);
    1.72 +	TF_ERROR(r, r == KErrNone);
    1.73 +
    1.74 +	TUint i;
    1.75 +	for(i = 0; i < RProperty::KMaxPropertySize; ++i)
    1.76 +		{
    1.77 +		iBuf1[i] = '1';
    1.78 +		iBuf2[i] = '2';
    1.79 +		}
    1.80 +
    1.81 +	TRequestStatus status;
    1.82 +	RThread thr;
    1.83 +	r = thr.Create(KNullDesC, TrublemakerThreadEntry, 0x2000, NULL, this);
    1.84 +	TF_ERROR(r, r == KErrNone);
    1.85 +	thr.Logon(status);
    1.86 +	thr.SetPriority(EPriorityMore);
    1.87 +	thr.Resume();
    1.88 +
    1.89 +	TBool attached = ETrue;
    1.90 +	for (i = 0; i < aCount; ++i)
    1.91 +		{
    1.92 +		TBuf8<RProperty::KMaxPropertySize> buf;
    1.93 +		if (attached)
    1.94 +			{
    1.95 +			r = prop.Set(iBuf1);
    1.96 +			TF_ERROR(r, r == KErrNone);
    1.97 +			r = prop.Get(buf);
    1.98 +			TF_ERROR(r, r == KErrNone);
    1.99 +			}
   1.100 +		else 
   1.101 +			{
   1.102 +			r = prop.Set(iCategory, iKey, iBuf1);
   1.103 +			TF_ERROR(r, r == KErrNone);
   1.104 +			r = prop.Get(iCategory, iKey, buf);
   1.105 +			TF_ERROR(r, r == KErrNone);
   1.106 +			}
   1.107 +		TF_ERROR(KErrGeneral, !(buf.Compare(iBuf1) && buf.Compare(iBuf2)));
   1.108 +		attached = !attached;
   1.109 +		}
   1.110 +
   1.111 +	thr.Kill(EExitKill);
   1.112 +	thr.Close();
   1.113 +
   1.114 +	User::WaitForRequest(status);
   1.115 +	TF_ERROR(status.Int(), status.Int() == EExitKill);
   1.116 +
   1.117 +	prop.Delete(iCategory, iKey);
   1.118 +	prop.Close();
   1.119 +	}
   1.120 +
   1.121 +
   1.122 +_LIT(KPropCancelRaceName, "RProperty::Cancel() Race");
   1.123 + 
   1.124 +CPropCancelRace::CPropCancelRace(TUid aCategory, TUint aKey) : 
   1.125 +	  CTestProgram(KPropCancelRaceName), iCategory(aCategory), iKey(aKey) 
   1.126 +	{
   1.127 +	}
   1.128 +
   1.129 +void CPropCancelRace::Trublemaker()
   1.130 +	{
   1.131 +	for(;;)
   1.132 +		{
   1.133 +		iProp.Cancel();
   1.134 +		User::After(1);
   1.135 +		}
   1.136 +	}
   1.137 +
   1.138 +TInt CPropCancelRace::TrublemakerThreadEntry(TAny* ptr)
   1.139 +	{
   1.140 +	CPropCancelRace* prog = (CPropCancelRace*) ptr;
   1.141 +	prog->Trublemaker();
   1.142 +	return KErrNone;
   1.143 +	}
   1.144 +
   1.145 +void CPropCancelRace::Run(TUint aCount)
   1.146 +	{
   1.147 +	TInt r = iProp.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy);
   1.148 +	TF_ERROR(r, r == KErrNone);
   1.149 +	r = iProp.Attach(iCategory,iKey);
   1.150 +	TF_ERROR(r, r == KErrNone);
   1.151 +
   1.152 +	TRequestStatus thrStatus;
   1.153 +	RThread thr;
   1.154 +	r = thr.Create(KNullDesC, TrublemakerThreadEntry, 0x2000, NULL, this);
   1.155 +	TF_ERROR(r, r == KErrNone);
   1.156 +	thr.Logon(thrStatus);
   1.157 +	thr.SetPriority(EPriorityMore);
   1.158 +	thr.Resume();
   1.159 +
   1.160 +	for (TUint i = 0; i < aCount; ++i)
   1.161 +		{
   1.162 +		TRequestStatus status;
   1.163 +		iProp.Subscribe(status);
   1.164 +		TInt st = status.Int();
   1.165 +		TF_ERROR(st, (st == KRequestPending) || (st == KErrCancel));
   1.166 +		iProp.Set(1);
   1.167 +		User::WaitForRequest(status);
   1.168 +		st = status.Int();
   1.169 +		TF_ERROR(st, (st == KErrNone) || (st == KErrCancel));
   1.170 +		}
   1.171 +
   1.172 +	thr.Kill(EExitKill);
   1.173 +	User::WaitForRequest(thrStatus);
   1.174 +	TF_ERROR(thrStatus.Int(), thrStatus.Int() == EExitKill);
   1.175 +	thr.Close();
   1.176 +
   1.177 +	iProp.Delete(iCategory, iKey);
   1.178 +	iProp.Close();
   1.179 +	}