os/kernelhwsrv/kerneltest/f32test/math/t_gen32.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) 1996-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
// f32test\math\t_gen32.cpp
sl@0
    15
// Generates files to be used in testing whether arithmetic in TReal32 gives
sl@0
    16
// exactly the same results using the MSDEV complier as on the rack.
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <e32svr.h>
sl@0
    22
#include "t_math.h"
sl@0
    23
#include "../server/t_server.h"
sl@0
    24
sl@0
    25
#if defined(__VC32__)
sl@0
    26
//
sl@0
    27
// Some symbols generated by the VC++ compiler for floating point stuff.
sl@0
    28
//
sl@0
    29
extern "C" {
sl@0
    30
GLDEF_D TInt _adj_fdiv_m32;
sl@0
    31
}
sl@0
    32
#endif
sl@0
    33
sl@0
    34
GLDEF_D RTest test(_L("T_GEN32"));
sl@0
    35
sl@0
    36
LOCAL_D	RFile f;
sl@0
    37
LOCAL_D const TFileName fileName32 = _L("T_REAL32.H");
sl@0
    38
sl@0
    39
LOCAL_D const TFileName pathName = _L("C:\\E32-MATH\\");
sl@0
    40
LOCAL_D	TBuf<0x100> buf;
sl@0
    41
LOCAL_D TBuf8<0x100> buf8;
sl@0
    42
sl@0
    43
// Data for tests from T_R32DTA.cpp 
sl@0
    44
GLREF_D TReal32 addInput[];
sl@0
    45
GLREF_D TReal32 subInput[];
sl@0
    46
GLREF_D TReal32 multInput[];
sl@0
    47
GLREF_D TReal32 divInput[];
sl@0
    48
//GLREF_D TApprox32 subApprox[];
sl@0
    49
GLREF_D TReal32 unaryInput[];
sl@0
    50
GLREF_D TReal32 incDecInput[];
sl@0
    51
GLREF_D TInt sizeAdd;
sl@0
    52
GLREF_D TInt sizeSub;
sl@0
    53
GLREF_D TInt sizeMult;
sl@0
    54
GLREF_D TInt sizeDiv;
sl@0
    55
//GLREF_D TInt sizeSubApprox;
sl@0
    56
GLREF_D TInt sizeUnary;
sl@0
    57
GLREF_D TInt sizeIncDec;
sl@0
    58
sl@0
    59
LOCAL_C void appendStart()
sl@0
    60
	{
sl@0
    61
	f.Write(_L8("// Generated by \\E32\\TMATH\\T_GEN32.MAK\n\n"));
sl@0
    62
	f.Write(_L8("#include <e32std.h>\n\n"));
sl@0
    63
	f.Write(_L8("#if defined(__WINS__)\n#include \"t_vals.hwg\"\n"));
sl@0
    64
	f.Write(_L8("#else\n#include \"t_vals.hag\"\n#endif\n"));
sl@0
    65
	}
sl@0
    66
sl@0
    67
LOCAL_C void appendArrayName32(TPtrC aName)
sl@0
    68
	{
sl@0
    69
	buf=_L("");
sl@0
    70
	buf.AppendFormat(_L("const TInt32x %S[] = \n{\n"),&aName);
sl@0
    71
	buf8.Copy(buf);
sl@0
    72
	f.Write(buf8);
sl@0
    73
	}
sl@0
    74
sl@0
    75
LOCAL_C void appendValue32(TReal32* aVal)
sl@0
    76
	{
sl@0
    77
	buf=_L("");
sl@0
    78
	buf.AppendFormat(_L("	TInt32x(0x%x),\n"),*(TUint32*)aVal);
sl@0
    79
	buf8.Copy(buf);
sl@0
    80
	f.Write(buf8);
sl@0
    81
	}
sl@0
    82
sl@0
    83
LOCAL_C void appendArrayTerm()
sl@0
    84
	{
sl@0
    85
	buf8=_L8("};\n\n");
sl@0
    86
	f.Write(buf8);
sl@0
    87
	}
sl@0
    88
sl@0
    89
LOCAL_C void createAddArray()
sl@0
    90
//
sl@0
    91
// Writes an array of results of additions to the header file
sl@0
    92
//
sl@0
    93
	{
sl@0
    94
	TInt ii;
sl@0
    95
	TReal32 ff;
sl@0
    96
sl@0
    97
	appendArrayName32(_L("addArray"));
sl@0
    98
	for (ii=0; ii<sizeAdd-1; ii++)
sl@0
    99
		{
sl@0
   100
		ff=addInput[ii]+addInput[ii+1];
sl@0
   101
		appendValue32(&ff);
sl@0
   102
		}
sl@0
   103
	appendArrayTerm();
sl@0
   104
	}
sl@0
   105
sl@0
   106
LOCAL_C void createSubArray()
sl@0
   107
//
sl@0
   108
// Writes an array of results of subtractions to the header file
sl@0
   109
//
sl@0
   110
	{
sl@0
   111
	TInt ii;
sl@0
   112
	TReal32 ff;
sl@0
   113
sl@0
   114
	appendArrayName32(_L("subArray"));
sl@0
   115
	for (ii=0; ii<sizeSub-1; ii++)
sl@0
   116
		{
sl@0
   117
		ff=subInput[ii]-subInput[ii+1];
sl@0
   118
		appendValue32(&ff);
sl@0
   119
		}
sl@0
   120
	appendArrayTerm();
sl@0
   121
sl@0
   122
	/*
sl@0
   123
	appendArrayName32(_L("subApproxArray"));
sl@0
   124
	for (ii=0; ii<sizeSubApprox; ii++)
sl@0
   125
		{
sl@0
   126
		ff=subApprox[ii].f-subApprox[ii].g;
sl@0
   127
		appendValue32(&ff);
sl@0
   128
		}
sl@0
   129
	appendArrayTerm();
sl@0
   130
	*/
sl@0
   131
	} 
sl@0
   132
sl@0
   133
LOCAL_C void createMultArray()
sl@0
   134
//
sl@0
   135
// Writes an array of results of multiplications to the header file
sl@0
   136
//
sl@0
   137
	{
sl@0
   138
	TInt ii;
sl@0
   139
	TReal32 ff;
sl@0
   140
sl@0
   141
	appendArrayName32(_L("multArray"));
sl@0
   142
	for (ii=0; ii<sizeMult-1; ii++)
sl@0
   143
		{
sl@0
   144
		ff=multInput[ii]*multInput[ii+1];
sl@0
   145
		appendValue32(&ff);
sl@0
   146
		}
sl@0
   147
	appendArrayTerm();
sl@0
   148
	} 
sl@0
   149
sl@0
   150
LOCAL_C void createDivArray()
sl@0
   151
//
sl@0
   152
// Writes an array of results of divisions to the header file
sl@0
   153
//
sl@0
   154
	{
sl@0
   155
	TInt ii;
sl@0
   156
	TReal32 ff;
sl@0
   157
sl@0
   158
	appendArrayName32(_L("divArray"));
sl@0
   159
	for (ii=0; ii<sizeDiv-1; ii++)
sl@0
   160
		{
sl@0
   161
		if (divInput[ii+1]!=0)
sl@0
   162
			{
sl@0
   163
			ff=divInput[ii]/divInput[ii+1];
sl@0
   164
			appendValue32(&ff);
sl@0
   165
			}
sl@0
   166
		}
sl@0
   167
	appendArrayTerm();
sl@0
   168
	} 
sl@0
   169
sl@0
   170
LOCAL_C void createUnaryArray()
sl@0
   171
//
sl@0
   172
// Writes an array of results of unary operations to the header file
sl@0
   173
//
sl@0
   174
	{
sl@0
   175
	TReal32 f;
sl@0
   176
sl@0
   177
	appendArrayName32(_L("unaryArray"));
sl@0
   178
	for (TInt ii=0; ii<sizeUnary; ii++)
sl@0
   179
		{
sl@0
   180
		f=-unaryInput[ii];
sl@0
   181
		appendValue32(&f);
sl@0
   182
		}
sl@0
   183
	appendArrayTerm();
sl@0
   184
	} 
sl@0
   185
sl@0
   186
LOCAL_C void createIncDecArrays()
sl@0
   187
//
sl@0
   188
// Writes an array of results of pre and post increment and decrement operations to the
sl@0
   189
// header file
sl@0
   190
//
sl@0
   191
	{
sl@0
   192
	TInt ii;
sl@0
   193
	TReal32 f;
sl@0
   194
sl@0
   195
	appendArrayName32(_L("preIncArray1"));
sl@0
   196
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   197
		{
sl@0
   198
		f=incDecInput[ii];
sl@0
   199
		++f;
sl@0
   200
		appendValue32(&f);
sl@0
   201
		}
sl@0
   202
	appendArrayTerm();
sl@0
   203
sl@0
   204
	appendArrayName32(_L("preIncArray2"));
sl@0
   205
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   206
		{
sl@0
   207
		f=incDecInput[ii];
sl@0
   208
		++f;
sl@0
   209
		++f;
sl@0
   210
		appendValue32(&f);
sl@0
   211
		}
sl@0
   212
	appendArrayTerm();
sl@0
   213
sl@0
   214
	appendArrayName32(_L("preDecArray1"));
sl@0
   215
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   216
		{
sl@0
   217
		f=incDecInput[ii];
sl@0
   218
		--f;
sl@0
   219
		appendValue32(&f);
sl@0
   220
		}
sl@0
   221
	appendArrayTerm();
sl@0
   222
sl@0
   223
	appendArrayName32(_L("preDecArray2"));
sl@0
   224
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   225
		{
sl@0
   226
		f=incDecInput[ii];
sl@0
   227
		--f;
sl@0
   228
		--f;
sl@0
   229
		appendValue32(&f);
sl@0
   230
		}
sl@0
   231
	appendArrayTerm();
sl@0
   232
sl@0
   233
	appendArrayName32(_L("postIncArray1"));
sl@0
   234
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   235
		{
sl@0
   236
		f=incDecInput[ii];
sl@0
   237
		f++;
sl@0
   238
		appendValue32(&f);
sl@0
   239
		}
sl@0
   240
	appendArrayTerm();
sl@0
   241
sl@0
   242
	appendArrayName32(_L("postIncArray2"));
sl@0
   243
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   244
		{
sl@0
   245
		f=incDecInput[ii];
sl@0
   246
		f++;
sl@0
   247
		f++;
sl@0
   248
		appendValue32(&f);
sl@0
   249
		}
sl@0
   250
	appendArrayTerm();
sl@0
   251
sl@0
   252
	appendArrayName32(_L("postDecArray1"));
sl@0
   253
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   254
		{
sl@0
   255
		f=incDecInput[ii];
sl@0
   256
		f--;
sl@0
   257
		appendValue32(&f);
sl@0
   258
		}
sl@0
   259
	appendArrayTerm();
sl@0
   260
	
sl@0
   261
	appendArrayName32(_L("postDecArray2"));
sl@0
   262
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   263
		{
sl@0
   264
		f=incDecInput[ii];
sl@0
   265
		f--;
sl@0
   266
		f--;
sl@0
   267
		appendValue32(&f);
sl@0
   268
		}
sl@0
   269
	appendArrayTerm();
sl@0
   270
	} 
sl@0
   271
sl@0
   272
LOCAL_C void createArrays()
sl@0
   273
//
sl@0
   274
// Create and append to header file all arrays required for T_R32.CPP tests
sl@0
   275
//
sl@0
   276
	{
sl@0
   277
	createAddArray();
sl@0
   278
	createSubArray();
sl@0
   279
	createMultArray();
sl@0
   280
	createDivArray();
sl@0
   281
	createUnaryArray();
sl@0
   282
	createIncDecArrays();
sl@0
   283
	}
sl@0
   284
sl@0
   285
GLDEF_C void CallTestsL(void)
sl@0
   286
//
sl@0
   287
// Generate TReal32s (and special values if required) and write to header files
sl@0
   288
//
sl@0
   289
    {
sl@0
   290
sl@0
   291
	test.Title();
sl@0
   292
sl@0
   293
	TFileName msg;
sl@0
   294
	msg=_L("Generating Maths constants to header files:\n ");
sl@0
   295
	msg+=pathName;
sl@0
   296
	msg+=fileName32;
sl@0
   297
	test.Start(msg);
sl@0
   298
sl@0
   299
	test.Next(_L("Making directory"));
sl@0
   300
	TInt r=TheFs.MkDirAll(pathName);
sl@0
   301
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   302
	test(TheFs.SetSessionPath(pathName)==KErrNone);
sl@0
   303
sl@0
   304
	test(f.Replace(TheFs,fileName32,EFileWrite)==KErrNone);
sl@0
   305
	test.Next(_L("Generating TReal32s"));
sl@0
   306
	appendStart();
sl@0
   307
	createArrays();
sl@0
   308
	f.Close();
sl@0
   309
sl@0
   310
	test.End();
sl@0
   311
sl@0
   312
	return;
sl@0
   313
    }