1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/math/t_gen32.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,313 @@
1.4 +// Copyright (c) 1996-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 +// f32test\math\t_gen32.cpp
1.18 +// Generates files to be used in testing whether arithmetic in TReal32 gives
1.19 +// exactly the same results using the MSDEV complier as on the rack.
1.20 +//
1.21 +//
1.22 +
1.23 +#include <f32file.h>
1.24 +#include <e32svr.h>
1.25 +#include "t_math.h"
1.26 +#include "../server/t_server.h"
1.27 +
1.28 +#if defined(__VC32__)
1.29 +//
1.30 +// Some symbols generated by the VC++ compiler for floating point stuff.
1.31 +//
1.32 +extern "C" {
1.33 +GLDEF_D TInt _adj_fdiv_m32;
1.34 +}
1.35 +#endif
1.36 +
1.37 +GLDEF_D RTest test(_L("T_GEN32"));
1.38 +
1.39 +LOCAL_D RFile f;
1.40 +LOCAL_D const TFileName fileName32 = _L("T_REAL32.H");
1.41 +
1.42 +LOCAL_D const TFileName pathName = _L("C:\\E32-MATH\\");
1.43 +LOCAL_D TBuf<0x100> buf;
1.44 +LOCAL_D TBuf8<0x100> buf8;
1.45 +
1.46 +// Data for tests from T_R32DTA.cpp
1.47 +GLREF_D TReal32 addInput[];
1.48 +GLREF_D TReal32 subInput[];
1.49 +GLREF_D TReal32 multInput[];
1.50 +GLREF_D TReal32 divInput[];
1.51 +//GLREF_D TApprox32 subApprox[];
1.52 +GLREF_D TReal32 unaryInput[];
1.53 +GLREF_D TReal32 incDecInput[];
1.54 +GLREF_D TInt sizeAdd;
1.55 +GLREF_D TInt sizeSub;
1.56 +GLREF_D TInt sizeMult;
1.57 +GLREF_D TInt sizeDiv;
1.58 +//GLREF_D TInt sizeSubApprox;
1.59 +GLREF_D TInt sizeUnary;
1.60 +GLREF_D TInt sizeIncDec;
1.61 +
1.62 +LOCAL_C void appendStart()
1.63 + {
1.64 + f.Write(_L8("// Generated by \\E32\\TMATH\\T_GEN32.MAK\n\n"));
1.65 + f.Write(_L8("#include <e32std.h>\n\n"));
1.66 + f.Write(_L8("#if defined(__WINS__)\n#include \"t_vals.hwg\"\n"));
1.67 + f.Write(_L8("#else\n#include \"t_vals.hag\"\n#endif\n"));
1.68 + }
1.69 +
1.70 +LOCAL_C void appendArrayName32(TPtrC aName)
1.71 + {
1.72 + buf=_L("");
1.73 + buf.AppendFormat(_L("const TInt32x %S[] = \n{\n"),&aName);
1.74 + buf8.Copy(buf);
1.75 + f.Write(buf8);
1.76 + }
1.77 +
1.78 +LOCAL_C void appendValue32(TReal32* aVal)
1.79 + {
1.80 + buf=_L("");
1.81 + buf.AppendFormat(_L(" TInt32x(0x%x),\n"),*(TUint32*)aVal);
1.82 + buf8.Copy(buf);
1.83 + f.Write(buf8);
1.84 + }
1.85 +
1.86 +LOCAL_C void appendArrayTerm()
1.87 + {
1.88 + buf8=_L8("};\n\n");
1.89 + f.Write(buf8);
1.90 + }
1.91 +
1.92 +LOCAL_C void createAddArray()
1.93 +//
1.94 +// Writes an array of results of additions to the header file
1.95 +//
1.96 + {
1.97 + TInt ii;
1.98 + TReal32 ff;
1.99 +
1.100 + appendArrayName32(_L("addArray"));
1.101 + for (ii=0; ii<sizeAdd-1; ii++)
1.102 + {
1.103 + ff=addInput[ii]+addInput[ii+1];
1.104 + appendValue32(&ff);
1.105 + }
1.106 + appendArrayTerm();
1.107 + }
1.108 +
1.109 +LOCAL_C void createSubArray()
1.110 +//
1.111 +// Writes an array of results of subtractions to the header file
1.112 +//
1.113 + {
1.114 + TInt ii;
1.115 + TReal32 ff;
1.116 +
1.117 + appendArrayName32(_L("subArray"));
1.118 + for (ii=0; ii<sizeSub-1; ii++)
1.119 + {
1.120 + ff=subInput[ii]-subInput[ii+1];
1.121 + appendValue32(&ff);
1.122 + }
1.123 + appendArrayTerm();
1.124 +
1.125 + /*
1.126 + appendArrayName32(_L("subApproxArray"));
1.127 + for (ii=0; ii<sizeSubApprox; ii++)
1.128 + {
1.129 + ff=subApprox[ii].f-subApprox[ii].g;
1.130 + appendValue32(&ff);
1.131 + }
1.132 + appendArrayTerm();
1.133 + */
1.134 + }
1.135 +
1.136 +LOCAL_C void createMultArray()
1.137 +//
1.138 +// Writes an array of results of multiplications to the header file
1.139 +//
1.140 + {
1.141 + TInt ii;
1.142 + TReal32 ff;
1.143 +
1.144 + appendArrayName32(_L("multArray"));
1.145 + for (ii=0; ii<sizeMult-1; ii++)
1.146 + {
1.147 + ff=multInput[ii]*multInput[ii+1];
1.148 + appendValue32(&ff);
1.149 + }
1.150 + appendArrayTerm();
1.151 + }
1.152 +
1.153 +LOCAL_C void createDivArray()
1.154 +//
1.155 +// Writes an array of results of divisions to the header file
1.156 +//
1.157 + {
1.158 + TInt ii;
1.159 + TReal32 ff;
1.160 +
1.161 + appendArrayName32(_L("divArray"));
1.162 + for (ii=0; ii<sizeDiv-1; ii++)
1.163 + {
1.164 + if (divInput[ii+1]!=0)
1.165 + {
1.166 + ff=divInput[ii]/divInput[ii+1];
1.167 + appendValue32(&ff);
1.168 + }
1.169 + }
1.170 + appendArrayTerm();
1.171 + }
1.172 +
1.173 +LOCAL_C void createUnaryArray()
1.174 +//
1.175 +// Writes an array of results of unary operations to the header file
1.176 +//
1.177 + {
1.178 + TReal32 f;
1.179 +
1.180 + appendArrayName32(_L("unaryArray"));
1.181 + for (TInt ii=0; ii<sizeUnary; ii++)
1.182 + {
1.183 + f=-unaryInput[ii];
1.184 + appendValue32(&f);
1.185 + }
1.186 + appendArrayTerm();
1.187 + }
1.188 +
1.189 +LOCAL_C void createIncDecArrays()
1.190 +//
1.191 +// Writes an array of results of pre and post increment and decrement operations to the
1.192 +// header file
1.193 +//
1.194 + {
1.195 + TInt ii;
1.196 + TReal32 f;
1.197 +
1.198 + appendArrayName32(_L("preIncArray1"));
1.199 + for (ii=0; ii<sizeIncDec; ii++)
1.200 + {
1.201 + f=incDecInput[ii];
1.202 + ++f;
1.203 + appendValue32(&f);
1.204 + }
1.205 + appendArrayTerm();
1.206 +
1.207 + appendArrayName32(_L("preIncArray2"));
1.208 + for (ii=0; ii<sizeIncDec; ii++)
1.209 + {
1.210 + f=incDecInput[ii];
1.211 + ++f;
1.212 + ++f;
1.213 + appendValue32(&f);
1.214 + }
1.215 + appendArrayTerm();
1.216 +
1.217 + appendArrayName32(_L("preDecArray1"));
1.218 + for (ii=0; ii<sizeIncDec; ii++)
1.219 + {
1.220 + f=incDecInput[ii];
1.221 + --f;
1.222 + appendValue32(&f);
1.223 + }
1.224 + appendArrayTerm();
1.225 +
1.226 + appendArrayName32(_L("preDecArray2"));
1.227 + for (ii=0; ii<sizeIncDec; ii++)
1.228 + {
1.229 + f=incDecInput[ii];
1.230 + --f;
1.231 + --f;
1.232 + appendValue32(&f);
1.233 + }
1.234 + appendArrayTerm();
1.235 +
1.236 + appendArrayName32(_L("postIncArray1"));
1.237 + for (ii=0; ii<sizeIncDec; ii++)
1.238 + {
1.239 + f=incDecInput[ii];
1.240 + f++;
1.241 + appendValue32(&f);
1.242 + }
1.243 + appendArrayTerm();
1.244 +
1.245 + appendArrayName32(_L("postIncArray2"));
1.246 + for (ii=0; ii<sizeIncDec; ii++)
1.247 + {
1.248 + f=incDecInput[ii];
1.249 + f++;
1.250 + f++;
1.251 + appendValue32(&f);
1.252 + }
1.253 + appendArrayTerm();
1.254 +
1.255 + appendArrayName32(_L("postDecArray1"));
1.256 + for (ii=0; ii<sizeIncDec; ii++)
1.257 + {
1.258 + f=incDecInput[ii];
1.259 + f--;
1.260 + appendValue32(&f);
1.261 + }
1.262 + appendArrayTerm();
1.263 +
1.264 + appendArrayName32(_L("postDecArray2"));
1.265 + for (ii=0; ii<sizeIncDec; ii++)
1.266 + {
1.267 + f=incDecInput[ii];
1.268 + f--;
1.269 + f--;
1.270 + appendValue32(&f);
1.271 + }
1.272 + appendArrayTerm();
1.273 + }
1.274 +
1.275 +LOCAL_C void createArrays()
1.276 +//
1.277 +// Create and append to header file all arrays required for T_R32.CPP tests
1.278 +//
1.279 + {
1.280 + createAddArray();
1.281 + createSubArray();
1.282 + createMultArray();
1.283 + createDivArray();
1.284 + createUnaryArray();
1.285 + createIncDecArrays();
1.286 + }
1.287 +
1.288 +GLDEF_C void CallTestsL(void)
1.289 +//
1.290 +// Generate TReal32s (and special values if required) and write to header files
1.291 +//
1.292 + {
1.293 +
1.294 + test.Title();
1.295 +
1.296 + TFileName msg;
1.297 + msg=_L("Generating Maths constants to header files:\n ");
1.298 + msg+=pathName;
1.299 + msg+=fileName32;
1.300 + test.Start(msg);
1.301 +
1.302 + test.Next(_L("Making directory"));
1.303 + TInt r=TheFs.MkDirAll(pathName);
1.304 + test(r==KErrNone || r==KErrAlreadyExists);
1.305 + test(TheFs.SetSessionPath(pathName)==KErrNone);
1.306 +
1.307 + test(f.Replace(TheFs,fileName32,EFileWrite)==KErrNone);
1.308 + test.Next(_L("Generating TReal32s"));
1.309 + appendStart();
1.310 + createArrays();
1.311 + f.Close();
1.312 +
1.313 + test.End();
1.314 +
1.315 + return;
1.316 + }