os/kernelhwsrv/kerneltest/e32test/property/t_race.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) 2002-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
//
sl@0
    15
sl@0
    16
#include "t_property.h"
sl@0
    17
sl@0
    18
_LIT(KPropSetGetRaceName, "RProperty::Set/Get() Race");
sl@0
    19
 
sl@0
    20
CPropSetGetRace::CPropSetGetRace(TUid aCategory, TUint aKey) : 
sl@0
    21
	  CTestProgram(KPropSetGetRaceName), iCategory(aCategory), iKey(aKey), 
sl@0
    22
		  iBuf1(RProperty::KMaxPropertySize), iBuf2(RProperty::KMaxPropertySize)
sl@0
    23
	{
sl@0
    24
	}
sl@0
    25
sl@0
    26
void CPropSetGetRace::Trublemaker(TDes8& aBuf)
sl@0
    27
	{
sl@0
    28
	RProperty prop;	
sl@0
    29
	TInt r = prop.Attach(iCategory, iKey, EOwnerThread);
sl@0
    30
	TF_ERROR(r, r == KErrNone);
sl@0
    31
	TBool attached = ETrue;
sl@0
    32
	for(;;)
sl@0
    33
		{
sl@0
    34
		TBuf8<RProperty::KMaxPropertySize> buf;
sl@0
    35
		if (attached)
sl@0
    36
			{
sl@0
    37
			r = prop.Set(aBuf);
sl@0
    38
			TF_ERROR(r, r == KErrNone);
sl@0
    39
			r = prop.Get(buf);
sl@0
    40
			TF_ERROR(r, r == KErrNone);
sl@0
    41
			}
sl@0
    42
		else 
sl@0
    43
			{
sl@0
    44
			r = prop.Set(iCategory, iKey, aBuf);
sl@0
    45
			TF_ERROR(r, r == KErrNone);
sl@0
    46
			r = prop.Get(iCategory, iKey, buf);
sl@0
    47
			TF_ERROR(r, r == KErrNone);
sl@0
    48
			}
sl@0
    49
		TF_ERROR(KErrGeneral, !(buf.Compare(iBuf1) && buf.Compare(iBuf2)));
sl@0
    50
		User::After(1);
sl@0
    51
		attached = !attached;
sl@0
    52
		}
sl@0
    53
	}
sl@0
    54
sl@0
    55
TInt CPropSetGetRace::TrublemakerThreadEntry(TAny* ptr)
sl@0
    56
	{
sl@0
    57
	CPropSetGetRace* prog = (CPropSetGetRace*) ptr;
sl@0
    58
	prog->Trublemaker(prog->iBuf2);
sl@0
    59
	return KErrNone;
sl@0
    60
	}
sl@0
    61
sl@0
    62
void CPropSetGetRace::Run(TUint aCount)
sl@0
    63
	{
sl@0
    64
	RProperty prop;	
sl@0
    65
sl@0
    66
	TInt r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy);
sl@0
    67
	TF_ERROR(r, r == KErrNone);
sl@0
    68
	r = prop.Attach(iCategory,iKey);
sl@0
    69
	TF_ERROR(r, r == KErrNone);
sl@0
    70
sl@0
    71
	TUint i;
sl@0
    72
	for(i = 0; i < RProperty::KMaxPropertySize; ++i)
sl@0
    73
		{
sl@0
    74
		iBuf1[i] = '1';
sl@0
    75
		iBuf2[i] = '2';
sl@0
    76
		}
sl@0
    77
sl@0
    78
	TRequestStatus status;
sl@0
    79
	RThread thr;
sl@0
    80
	r = thr.Create(KNullDesC, TrublemakerThreadEntry, 0x2000, NULL, this);
sl@0
    81
	TF_ERROR(r, r == KErrNone);
sl@0
    82
	thr.Logon(status);
sl@0
    83
	thr.SetPriority(EPriorityMore);
sl@0
    84
	thr.Resume();
sl@0
    85
sl@0
    86
	TBool attached = ETrue;
sl@0
    87
	for (i = 0; i < aCount; ++i)
sl@0
    88
		{
sl@0
    89
		TBuf8<RProperty::KMaxPropertySize> buf;
sl@0
    90
		if (attached)
sl@0
    91
			{
sl@0
    92
			r = prop.Set(iBuf1);
sl@0
    93
			TF_ERROR(r, r == KErrNone);
sl@0
    94
			r = prop.Get(buf);
sl@0
    95
			TF_ERROR(r, r == KErrNone);
sl@0
    96
			}
sl@0
    97
		else 
sl@0
    98
			{
sl@0
    99
			r = prop.Set(iCategory, iKey, iBuf1);
sl@0
   100
			TF_ERROR(r, r == KErrNone);
sl@0
   101
			r = prop.Get(iCategory, iKey, buf);
sl@0
   102
			TF_ERROR(r, r == KErrNone);
sl@0
   103
			}
sl@0
   104
		TF_ERROR(KErrGeneral, !(buf.Compare(iBuf1) && buf.Compare(iBuf2)));
sl@0
   105
		attached = !attached;
sl@0
   106
		}
sl@0
   107
sl@0
   108
	thr.Kill(EExitKill);
sl@0
   109
	thr.Close();
sl@0
   110
sl@0
   111
	User::WaitForRequest(status);
sl@0
   112
	TF_ERROR(status.Int(), status.Int() == EExitKill);
sl@0
   113
sl@0
   114
	prop.Delete(iCategory, iKey);
sl@0
   115
	prop.Close();
sl@0
   116
	}
sl@0
   117
sl@0
   118
sl@0
   119
_LIT(KPropCancelRaceName, "RProperty::Cancel() Race");
sl@0
   120
 
sl@0
   121
CPropCancelRace::CPropCancelRace(TUid aCategory, TUint aKey) : 
sl@0
   122
	  CTestProgram(KPropCancelRaceName), iCategory(aCategory), iKey(aKey) 
sl@0
   123
	{
sl@0
   124
	}
sl@0
   125
sl@0
   126
void CPropCancelRace::Trublemaker()
sl@0
   127
	{
sl@0
   128
	for(;;)
sl@0
   129
		{
sl@0
   130
		iProp.Cancel();
sl@0
   131
		User::After(1);
sl@0
   132
		}
sl@0
   133
	}
sl@0
   134
sl@0
   135
TInt CPropCancelRace::TrublemakerThreadEntry(TAny* ptr)
sl@0
   136
	{
sl@0
   137
	CPropCancelRace* prog = (CPropCancelRace*) ptr;
sl@0
   138
	prog->Trublemaker();
sl@0
   139
	return KErrNone;
sl@0
   140
	}
sl@0
   141
sl@0
   142
void CPropCancelRace::Run(TUint aCount)
sl@0
   143
	{
sl@0
   144
	TInt r = iProp.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy);
sl@0
   145
	TF_ERROR(r, r == KErrNone);
sl@0
   146
	r = iProp.Attach(iCategory,iKey);
sl@0
   147
	TF_ERROR(r, r == KErrNone);
sl@0
   148
sl@0
   149
	TRequestStatus thrStatus;
sl@0
   150
	RThread thr;
sl@0
   151
	r = thr.Create(KNullDesC, TrublemakerThreadEntry, 0x2000, NULL, this);
sl@0
   152
	TF_ERROR(r, r == KErrNone);
sl@0
   153
	thr.Logon(thrStatus);
sl@0
   154
	thr.SetPriority(EPriorityMore);
sl@0
   155
	thr.Resume();
sl@0
   156
sl@0
   157
	for (TUint i = 0; i < aCount; ++i)
sl@0
   158
		{
sl@0
   159
		TRequestStatus status;
sl@0
   160
		iProp.Subscribe(status);
sl@0
   161
		TInt st = status.Int();
sl@0
   162
		TF_ERROR(st, (st == KRequestPending) || (st == KErrCancel));
sl@0
   163
		iProp.Set(1);
sl@0
   164
		User::WaitForRequest(status);
sl@0
   165
		st = status.Int();
sl@0
   166
		TF_ERROR(st, (st == KErrNone) || (st == KErrCancel));
sl@0
   167
		}
sl@0
   168
sl@0
   169
	thr.Kill(EExitKill);
sl@0
   170
	User::WaitForRequest(thrStatus);
sl@0
   171
	TF_ERROR(thrStatus.Int(), thrStatus.Int() == EExitKill);
sl@0
   172
	thr.Close();
sl@0
   173
sl@0
   174
	iProp.Delete(iCategory, iKey);
sl@0
   175
	iProp.Close();
sl@0
   176
	}