Update contrib.
1 // Copyright (c) 1996-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\device\t_prom.cpp
23 GLDEF_D RDevE2Prom prom;
24 GLDEF_D RTest test(_L("E2PROM tests"));
26 #if !defined(__WINS__)
27 LOCAL_C TInt CheckProm(TInt aVal)
29 // Write aVal to every location in prom and verify...
35 test(prom.WriteAll(aVal)==KErrNone);
36 test(prom.ReadData(buf)==KErrNone);
40 for(len=0;len<16;len++)
47 GLDEF_C TInt E32Main()
49 // Test E2 PROM handling.
54 test.Start(_L("This test is valid under EPOC platforms only"));
60 test.Start(_L("Loading E2PROM LDD"));
61 TInt r=User::LoadLogicalDevice(_L("E2PROM"));
62 test(r==KErrNone || r==KErrAlreadyExists);
63 test.Next(_L("Opening device driver"));
64 test(prom.Open()==KErrNone);
65 test.Next(_L("Copying current contents of PROM"));
66 TInt currentProtectValue=prom.ProtectRead();
67 TBuf16<16> currentContents;
69 /* Random hacky code */
72 RProcess().CommandLine(buf);
82 test.Printf(_L("Setting to value %08x"), val);
84 currentContents.SetLength(16);
85 Mem::FillZ((TUint8 *)currentContents.Ptr(), 32);
86 test(prom.ReadData(currentContents)==KErrNone);
87 currentContents[4]=val;
92 s^=((TUint8*)currentContents.Ptr())[i];
95 ((TUint8*)currentContents.Ptr())[0]=s;
96 test(prom.WriteData(currentContents)==KErrNone);
97 test.Next(_L("Reading back"));
98 test(prom.ReadData(currentContents)==KErrNone);
99 test.Next(_L("Check checksum"));
103 s^=((TUint8 *)currentContents.Ptr())[i];
105 test.Printf(_L("checksum=%08x"), s);
107 User::FreeLogicalDevice(_L("E2PROM"));
113 test(prom.ReadData(currentContents)==KErrNone);
120 test.Next(_L("Clearing protect register"));
122 test(prom.ProtectClear()==KErrNone);
123 test(prom.ProtectRead()==63);
125 test.Next(_L("Writing all"));
127 test(CheckProm(0)==KErrNone);
128 test(CheckProm(0x0008)==KErrNone);
129 test(CheckProm(0x0080)==KErrNone);
130 test(CheckProm(0x0800)==KErrNone);
131 test(CheckProm(0x8000)==KErrNone);
132 test(CheckProm(0xffff)==KErrNone);
133 test(CheckProm(0xf0f0)==KErrNone);
134 test(CheckProm(0xf00f)==KErrNone);
136 test.Next(_L("Writing data"));
142 for(len=0;len<16;len++)
143 buf1[len]=(TInt16)len;
145 test(prom.WriteData(buf1)==KErrNone);
146 test.Next(_L("Reading and verifying"));
147 test(prom.ReadData(buf2)==KErrNone);
150 test.Next(_L("Testing protection"));
151 test(prom.ProtectSet(6)==KErrNone);
152 test(prom.ProtectRead()==6);
153 test(prom.WriteAll(0)==KErrNone);
154 test(prom.ReadData(buf2)==KErrNone);
157 for(len=0;len<16;len++)
158 buf1[len]=(TInt16)(len+0x8570);
160 test(prom.WriteData(buf1)==KErrNone);
161 test(prom.ReadData(buf2)==KErrNone);
164 for(len=6;len<16;len++)
165 buf1[len]=(TInt16)len;
168 test.Next(_L("Writing back original contents"));
169 test(prom.ProtectClear()==KErrNone);
170 test(prom.WriteData(currentContents)==KErrNone);
171 test(prom.ProtectSet(currentProtectValue)==KErrNone);