nsprpub/pr/tests/lltest.c

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 ** testll.c -- test suite for 64bit integer (longlong) operations
michael@0 8 **
michael@0 9 ** Summary: testll [-d] | [-h]
michael@0 10 **
michael@0 11 ** Where:
michael@0 12 ** -d set debug mode on; displays individual test failures
michael@0 13 ** -v verbose mode; displays progress in test, plus -d
michael@0 14 ** -h gives usage message.
michael@0 15 **
michael@0 16 ** Description:
michael@0 17 ** lltest.c tests the functions defined in NSPR 2.0's prlong.h.
michael@0 18 **
michael@0 19 ** Successive tests begin to depend on other LL functions working
michael@0 20 ** correctly. So, ... Do not change the order of the tests as run
michael@0 21 ** from main().
michael@0 22 **
michael@0 23 ** Caveats:
michael@0 24 ** Do not even begin to think that this is an exhaustive test!
michael@0 25 **
michael@0 26 ** These tests try a little of everything, but not all boundary
michael@0 27 ** conditions and limits are tested.
michael@0 28 ** You want better coverage? ... Add it.
michael@0 29 **
michael@0 30 ** ---
michael@0 31 ** Author: Lawrence Hardiman <larryh@netscape.com>.
michael@0 32 ** ---
michael@0 33 ** Revision History:
michael@0 34 ** 01-Oct-1997. Original implementation.
michael@0 35 **
michael@0 36 */
michael@0 37
michael@0 38 #include "nspr.h"
michael@0 39 #include "plgetopt.h"
michael@0 40
michael@0 41 /* --- Local Definitions --- */
michael@0 42 #define ReportProgress(m) if (verboseMode) PR_fprintf(output, (m));
michael@0 43
michael@0 44
michael@0 45 /* --- Global variables --- */
michael@0 46 static PRIntn failedAlready = 0;
michael@0 47 static PRFileDesc* output = NULL;
michael@0 48 static PRBool debugMode = PR_FALSE;
michael@0 49 static PRBool verboseMode = PR_FALSE;
michael@0 50
michael@0 51 /*
michael@0 52 ** Constants used in tests.
michael@0 53 */
michael@0 54 const PRInt64 bigZero = LL_INIT( 0, 0 );
michael@0 55 const PRInt64 bigOne = LL_INIT( 0, 1 );
michael@0 56 const PRInt64 bigTwo = LL_INIT( 0, 2 );
michael@0 57 const PRInt64 bigSixTeen = LL_INIT( 0, 16 );
michael@0 58 const PRInt64 bigThirtyTwo = LL_INIT( 0, 32 );
michael@0 59 const PRInt64 bigMinusOne = LL_INIT( 0xffffffff, 0xffffffff );
michael@0 60 const PRInt64 bigMinusTwo = LL_INIT( 0xffffffff, 0xfffffffe );
michael@0 61 const PRInt64 bigNumber = LL_INIT( 0x7fffffff, 0xffffffff );
michael@0 62 const PRInt64 bigMinusNumber = LL_INIT( 0x80000000, 0x00000001 );
michael@0 63 const PRInt64 bigMaxInt32 = LL_INIT( 0x00000000, 0x7fffffff );
michael@0 64 const PRInt64 big2To31 = LL_INIT( 0x00000000, 0x80000000 );
michael@0 65 const PRUint64 bigZeroFox = LL_INIT( 0x00000000, 0xffffffff );
michael@0 66 const PRUint64 bigFoxFox = LL_INIT( 0xffffffff, 0xffffffff );
michael@0 67 const PRUint64 bigFoxZero = LL_INIT( 0xffffffff, 0x00000000 );
michael@0 68 const PRUint64 bigEightZero = LL_INIT( 0x80000000, 0x00000000 );
michael@0 69 const PRUint64 big64K = LL_INIT( 0x00000000, 0x00010000 );
michael@0 70 const PRInt64 bigInt0 = LL_INIT( 0x01a00000, 0x00001000 );
michael@0 71 const PRInt64 bigInt1 = LL_INIT( 0x01a00000, 0x00001100 );
michael@0 72 const PRInt64 bigInt2 = LL_INIT( 0x01a00000, 0x00000100 );
michael@0 73 const PRInt64 bigInt3 = LL_INIT( 0x01a00001, 0x00001000 );
michael@0 74 const PRInt64 bigInt4 = LL_INIT( 0x01a00001, 0x00001100 );
michael@0 75 const PRInt64 bigInt5 = LL_INIT( 0x01a00001, 0x00000100 );
michael@0 76 const PRInt64 bigInt6 = LL_INIT( 0xb1a00000, 0x00001000 );
michael@0 77 const PRInt64 bigInt7 = LL_INIT( 0xb1a00000, 0x00001100 );
michael@0 78 const PRInt64 bigInt8 = LL_INIT( 0xb1a00000, 0x00000100 );
michael@0 79 const PRInt64 bigInt9 = LL_INIT( 0xb1a00001, 0x00001000 );
michael@0 80 const PRInt64 bigInt10 = LL_INIT( 0xb1a00001, 0x00001100 );
michael@0 81 const PRInt64 bigInt11 = LL_INIT( 0xb1a00001, 0x00000100 );
michael@0 82 const PRInt32 one = 1l;
michael@0 83 const PRInt32 minusOne = -1l;
michael@0 84 const PRInt32 sixteen = 16l;
michael@0 85 const PRInt32 thirtyTwo = 32l;
michael@0 86 const PRInt32 sixtyThree = 63l;
michael@0 87
michael@0 88 /*
michael@0 89 ** SetFailed() -- Report individual test failure
michael@0 90 **
michael@0 91 */
michael@0 92 static void
michael@0 93 SetFailed( char *what, char *how )
michael@0 94 {
michael@0 95 failedAlready = 1;
michael@0 96 if ( debugMode )
michael@0 97 PR_fprintf(output, "%s: failed: %s\n", what, how );
michael@0 98 return;
michael@0 99 }
michael@0 100
michael@0 101 static void
michael@0 102 ResultFailed( char *what, char *how, PRInt64 expected, PRInt64 got)
michael@0 103 {
michael@0 104 if ( debugMode)
michael@0 105 {
michael@0 106 SetFailed( what, how );
michael@0 107 PR_fprintf(output, "Expected: 0x%llx Got: 0x%llx\n", expected, got );
michael@0 108 }
michael@0 109 return;
michael@0 110 }
michael@0 111
michael@0 112
michael@0 113 /*
michael@0 114 ** TestAssignment() -- Test the assignment
michael@0 115 */
michael@0 116 static void TestAssignment( void )
michael@0 117 {
michael@0 118 PRInt64 zero = LL_Zero();
michael@0 119 PRInt64 min = LL_MinInt();
michael@0 120 PRInt64 max = LL_MaxInt();
michael@0 121 if (!LL_EQ(zero, bigZero))
michael@0 122 SetFailed("LL_EQ(zero, bigZero)", "!=");
michael@0 123 if (!LL_CMP(max, >, min))
michael@0 124 SetFailed("LL_CMP(max, >, min)", "!>");
michael@0 125 }
michael@0 126
michael@0 127 /*
michael@0 128 ** TestComparisons() -- Test the longlong comparison operations
michael@0 129 */
michael@0 130 static void
michael@0 131 TestComparisons( void )
michael@0 132 {
michael@0 133 ReportProgress("Testing Comparisons Operations\n");
michael@0 134
michael@0 135 /* test for zero */
michael@0 136 if ( !LL_IS_ZERO( bigZero ))
michael@0 137 SetFailed( "LL_IS_ZERO", "Zero is not zero" );
michael@0 138
michael@0 139 if ( LL_IS_ZERO( bigOne ))
michael@0 140 SetFailed( "LL_IS_ZERO", "One tests as zero" );
michael@0 141
michael@0 142 if ( LL_IS_ZERO( bigMinusOne ))
michael@0 143 SetFailed( "LL_IS_ZERO", "Minus One tests as zero" );
michael@0 144
michael@0 145 /* test equal */
michael@0 146 if ( !LL_EQ( bigZero, bigZero ))
michael@0 147 SetFailed( "LL_EQ", "zero EQ zero");
michael@0 148
michael@0 149 if ( !LL_EQ( bigOne, bigOne ))
michael@0 150 SetFailed( "LL_EQ", "one EQ one" );
michael@0 151
michael@0 152 if ( !LL_EQ( bigNumber, bigNumber ))
michael@0 153 SetFailed( "LL_EQ", "bigNumber EQ bigNumber" );
michael@0 154
michael@0 155 if ( !LL_EQ( bigMinusOne, bigMinusOne ))
michael@0 156 SetFailed( "LL_EQ", "minus one EQ minus one");
michael@0 157
michael@0 158 if ( LL_EQ( bigZero, bigOne ))
michael@0 159 SetFailed( "LL_EQ", "zero EQ one");
michael@0 160
michael@0 161 if ( LL_EQ( bigOne, bigZero ))
michael@0 162 SetFailed( "LL_EQ", "one EQ zero" );
michael@0 163
michael@0 164 if ( LL_EQ( bigMinusOne, bigOne ))
michael@0 165 SetFailed( "LL_EQ", "minus one EQ one");
michael@0 166
michael@0 167 if ( LL_EQ( bigNumber, bigOne ))
michael@0 168 SetFailed( "LL_EQ", "bigNumber EQ one");
michael@0 169
michael@0 170 /* test not equal */
michael@0 171 if ( LL_NE( bigZero, bigZero ))
michael@0 172 SetFailed( "LL_NE", "0 NE 0");
michael@0 173
michael@0 174 if ( LL_NE( bigOne, bigOne ))
michael@0 175 SetFailed( "LL_NE", "1 NE 1");
michael@0 176
michael@0 177 if ( LL_NE( bigMinusOne, bigMinusOne ))
michael@0 178 SetFailed( "LL_NE", "-1 NE -1");
michael@0 179
michael@0 180 if ( LL_NE( bigNumber, bigNumber ))
michael@0 181 SetFailed( "LL_NE", "n NE n");
michael@0 182
michael@0 183 if ( LL_NE( bigMinusNumber, bigMinusNumber ))
michael@0 184 SetFailed( "LL_NE", "-n NE -n");
michael@0 185
michael@0 186 if ( !LL_NE( bigZero, bigOne))
michael@0 187 SetFailed( "LL_NE", "0 NE 1");
michael@0 188
michael@0 189 if ( !LL_NE( bigOne, bigMinusNumber))
michael@0 190 SetFailed( "LL_NE", "1 NE -n");
michael@0 191
michael@0 192 /* Greater than or equal to zero */
michael@0 193 if ( !LL_GE_ZERO( bigZero ))
michael@0 194 SetFailed( "LL_GE_ZERO", "0");
michael@0 195
michael@0 196 if ( !LL_GE_ZERO( bigOne ))
michael@0 197 SetFailed( "LL_GE_ZERO", "1");
michael@0 198
michael@0 199 if ( !LL_GE_ZERO( bigNumber ))
michael@0 200 SetFailed( "LL_GE_ZERO", "n");
michael@0 201
michael@0 202 if ( LL_GE_ZERO( bigMinusOne ))
michael@0 203 SetFailed( "LL_GE_ZERO", "-1");
michael@0 204
michael@0 205 if ( LL_GE_ZERO( bigMinusNumber ))
michael@0 206 SetFailed( "LL_GE_ZERO", "-n");
michael@0 207
michael@0 208 /* Algebraic Compare two values */
michael@0 209 if ( !LL_CMP( bigZero, ==, bigZero ))
michael@0 210 SetFailed( "LL_CMP", "0 == 0");
michael@0 211
michael@0 212 if ( LL_CMP( bigZero, >, bigZero ))
michael@0 213 SetFailed( "LL_CMP", "0 > 0");
michael@0 214
michael@0 215 if ( LL_CMP( bigZero, <, bigZero ))
michael@0 216 SetFailed( "LL_CMP", "0 < 0");
michael@0 217
michael@0 218 if ( LL_CMP( bigNumber, <, bigOne ))
michael@0 219 SetFailed( "LL_CMP", "n < 1");
michael@0 220
michael@0 221 if ( !LL_CMP( bigNumber, >, bigOne ))
michael@0 222 SetFailed( "LL_CMP", "n <= 1");
michael@0 223
michael@0 224 if ( LL_CMP( bigOne, >, bigNumber ))
michael@0 225 SetFailed( "LL_CMP", "1 > n");
michael@0 226
michael@0 227 if ( LL_CMP( bigMinusNumber, >, bigNumber ))
michael@0 228 SetFailed( "LL_CMP", "-n > n");
michael@0 229
michael@0 230 if ( LL_CMP( bigNumber, !=, bigNumber))
michael@0 231 SetFailed( "LL_CMP", "n != n");
michael@0 232
michael@0 233 if ( !LL_CMP( bigMinusOne, >, bigMinusTwo ))
michael@0 234 SetFailed( "LL_CMP", "-1 <= -2");
michael@0 235
michael@0 236 if ( !LL_CMP( bigMaxInt32, <, big2To31 ))
michael@0 237 SetFailed( "LL_CMP", "Max 32-bit signed int >= 2^31");
michael@0 238
michael@0 239 /* Two positive numbers */
michael@0 240 if ( !LL_CMP( bigInt0, <=, bigInt0 ))
michael@0 241 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 242
michael@0 243 if ( !LL_CMP( bigInt0, <=, bigInt1 ))
michael@0 244 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 245
michael@0 246 if ( LL_CMP( bigInt0, <=, bigInt2 ))
michael@0 247 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 248
michael@0 249 if ( !LL_CMP( bigInt0, <=, bigInt3 ))
michael@0 250 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 251
michael@0 252 if ( !LL_CMP( bigInt0, <=, bigInt4 ))
michael@0 253 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 254
michael@0 255 if ( !LL_CMP( bigInt0, <=, bigInt5 ))
michael@0 256 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 257
michael@0 258 /* Two negative numbers */
michael@0 259 if ( !LL_CMP( bigInt6, <=, bigInt6 ))
michael@0 260 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 261
michael@0 262 if ( !LL_CMP( bigInt6, <=, bigInt7 ))
michael@0 263 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 264
michael@0 265 if ( LL_CMP( bigInt6, <=, bigInt8 ))
michael@0 266 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 267
michael@0 268 if ( !LL_CMP( bigInt6, <=, bigInt9 ))
michael@0 269 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 270
michael@0 271 if ( !LL_CMP( bigInt6, <=, bigInt10 ))
michael@0 272 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 273
michael@0 274 if ( !LL_CMP( bigInt6, <=, bigInt11 ))
michael@0 275 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 276
michael@0 277 /* One positive, one negative */
michael@0 278 if ( LL_CMP( bigInt0, <=, bigInt6 ))
michael@0 279 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 280
michael@0 281 if ( LL_CMP( bigInt0, <=, bigInt7 ))
michael@0 282 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 283
michael@0 284 if ( LL_CMP( bigInt0, <=, bigInt8 ))
michael@0 285 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
michael@0 286
michael@0 287 /* Bitwise Compare two numbers */
michael@0 288 if ( !LL_UCMP( bigZero, ==, bigZero ))
michael@0 289 SetFailed( "LL_UCMP", "0 == 0");
michael@0 290
michael@0 291 if ( LL_UCMP( bigZero, >, bigZero ))
michael@0 292 SetFailed( "LL_UCMP", "0 > 0");
michael@0 293
michael@0 294 if ( LL_UCMP( bigZero, <, bigZero ))
michael@0 295 SetFailed( "LL_UCMP", "0 < 0");
michael@0 296
michael@0 297 if ( LL_UCMP( bigNumber, <, bigOne ))
michael@0 298 SetFailed( "LL_UCMP", "n < 1");
michael@0 299
michael@0 300 if ( !LL_UCMP( bigNumber, >, bigOne ))
michael@0 301 SetFailed( "LL_UCMP", "n < 1");
michael@0 302
michael@0 303 if ( LL_UCMP( bigOne, >, bigNumber ))
michael@0 304 SetFailed( "LL_UCMP", "1 > n");
michael@0 305
michael@0 306 if ( LL_UCMP( bigMinusNumber, <, bigNumber ))
michael@0 307 SetFailed( "LL_UCMP", "-n < n");
michael@0 308
michael@0 309 /* Two positive numbers */
michael@0 310 if ( !LL_UCMP( bigInt0, <=, bigInt0 ))
michael@0 311 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 312
michael@0 313 if ( !LL_UCMP( bigInt0, <=, bigInt1 ))
michael@0 314 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 315
michael@0 316 if ( LL_UCMP( bigInt0, <=, bigInt2 ))
michael@0 317 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 318
michael@0 319 if ( !LL_UCMP( bigInt0, <=, bigInt3 ))
michael@0 320 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 321
michael@0 322 if ( !LL_UCMP( bigInt0, <=, bigInt4 ))
michael@0 323 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 324
michael@0 325 if ( !LL_UCMP( bigInt0, <=, bigInt5 ))
michael@0 326 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 327
michael@0 328 /* Two negative numbers */
michael@0 329 if ( !LL_UCMP( bigInt6, <=, bigInt6 ))
michael@0 330 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 331
michael@0 332 if ( !LL_UCMP( bigInt6, <=, bigInt7 ))
michael@0 333 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 334
michael@0 335 if ( LL_UCMP( bigInt6, <=, bigInt8 ))
michael@0 336 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 337
michael@0 338 if ( !LL_UCMP( bigInt6, <=, bigInt9 ))
michael@0 339 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 340
michael@0 341 if ( !LL_UCMP( bigInt6, <=, bigInt10 ))
michael@0 342 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 343
michael@0 344 if ( !LL_UCMP( bigInt6, <=, bigInt11 ))
michael@0 345 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 346
michael@0 347 /* One positive, one negative */
michael@0 348 if ( !LL_UCMP( bigInt0, <=, bigInt6 ))
michael@0 349 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 350
michael@0 351 if ( !LL_UCMP( bigInt0, <=, bigInt7 ))
michael@0 352 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 353
michael@0 354 if ( !LL_UCMP( bigInt0, <=, bigInt8 ))
michael@0 355 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
michael@0 356
michael@0 357 return;
michael@0 358 }
michael@0 359
michael@0 360 /*
michael@0 361 ** TestLogicalOperations() -- Tests for AND, OR, ...
michael@0 362 **
michael@0 363 */
michael@0 364 static void
michael@0 365 TestLogicalOperations( void )
michael@0 366 {
michael@0 367 PRUint64 result, result2;
michael@0 368
michael@0 369 ReportProgress("Testing Logical Operations\n");
michael@0 370
michael@0 371 /* Test AND */
michael@0 372 LL_AND( result, bigZero, bigZero );
michael@0 373 if ( !LL_IS_ZERO( result ))
michael@0 374 ResultFailed( "LL_AND", "0 & 0", bigZero, result );
michael@0 375
michael@0 376 LL_AND( result, bigOne, bigOne );
michael@0 377 if ( LL_IS_ZERO( result ))
michael@0 378 ResultFailed( "LL_AND", "1 & 1", bigOne, result );
michael@0 379
michael@0 380 LL_AND( result, bigZero, bigOne );
michael@0 381 if ( !LL_IS_ZERO( result ))
michael@0 382 ResultFailed( "LL_AND", "1 & 1", bigZero, result );
michael@0 383
michael@0 384 LL_AND( result, bigMinusOne, bigMinusOne );
michael@0 385 if ( !LL_UCMP( result, ==, bigMinusOne ))
michael@0 386 ResultFailed( "LL_AND", "-1 & -1", bigMinusOne, result );
michael@0 387
michael@0 388 /* test OR */
michael@0 389 LL_OR( result, bigZero, bigZero );
michael@0 390 if ( !LL_IS_ZERO( result ))
michael@0 391 ResultFailed( "LL_OR", "0 | 1", bigZero, result);
michael@0 392
michael@0 393 LL_OR( result, bigZero, bigOne );
michael@0 394 if ( LL_IS_ZERO( result ))
michael@0 395 ResultFailed( "LL_OR", "0 | 1", bigOne, result );
michael@0 396
michael@0 397 LL_OR( result, bigZero, bigMinusNumber );
michael@0 398 if ( !LL_UCMP( result, ==, bigMinusNumber ))
michael@0 399 ResultFailed( "LL_OR", "0 | -n", bigMinusNumber, result);
michael@0 400
michael@0 401 LL_OR( result, bigMinusNumber, bigZero );
michael@0 402 if ( !LL_UCMP( result, ==, bigMinusNumber ))
michael@0 403 ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result );
michael@0 404
michael@0 405 /* test XOR */
michael@0 406 LL_XOR( result, bigZero, bigZero );
michael@0 407 if ( LL_UCMP( result, !=, bigZero ))
michael@0 408 ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result);
michael@0 409
michael@0 410 LL_XOR( result, bigOne, bigZero );
michael@0 411 if ( LL_UCMP( result, !=, bigOne ))
michael@0 412 ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result );
michael@0 413
michael@0 414 LL_XOR( result, bigMinusNumber, bigZero );
michael@0 415 if ( LL_UCMP( result, !=, bigMinusNumber ))
michael@0 416 ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result );
michael@0 417
michael@0 418 LL_XOR( result, bigMinusNumber, bigMinusNumber );
michael@0 419 if ( LL_UCMP( result, !=, bigZero ))
michael@0 420 ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result);
michael@0 421
michael@0 422 /* test OR2. */
michael@0 423 result = bigZero;
michael@0 424 LL_OR2( result, bigOne );
michael@0 425 if ( LL_UCMP( result, !=, bigOne ))
michael@0 426 ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result);
michael@0 427
michael@0 428 result = bigOne;
michael@0 429 LL_OR2( result, bigNumber );
michael@0 430 if ( LL_UCMP( result, !=, bigNumber ))
michael@0 431 ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result);
michael@0 432
michael@0 433 result = bigMinusNumber;
michael@0 434 LL_OR2( result, bigMinusNumber );
michael@0 435 if ( LL_UCMP( result, !=, bigMinusNumber ))
michael@0 436 ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result);
michael@0 437
michael@0 438 /* test NOT */
michael@0 439 LL_NOT( result, bigMinusNumber);
michael@0 440 LL_NOT( result2, result);
michael@0 441 if ( LL_UCMP( result2, !=, bigMinusNumber ))
michael@0 442 ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result);
michael@0 443
michael@0 444 /* test Negation */
michael@0 445 LL_NEG( result, bigMinusNumber );
michael@0 446 LL_NEG( result2, result );
michael@0 447 if ( LL_CMP( result2, !=, bigMinusNumber ))
michael@0 448 ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result);
michael@0 449
michael@0 450 return;
michael@0 451 }
michael@0 452
michael@0 453
michael@0 454
michael@0 455 /*
michael@0 456 ** TestConversion() -- Test Conversion Operations
michael@0 457 **
michael@0 458 */
michael@0 459 static void
michael@0 460 TestConversion( void )
michael@0 461 {
michael@0 462 PRInt64 result;
michael@0 463 PRInt64 resultU;
michael@0 464 PRInt32 result32;
michael@0 465 PRUint32 resultU32;
michael@0 466 float resultF;
michael@0 467 PRFloat64 resultD;
michael@0 468
michael@0 469 ReportProgress("Testing Conversion Operations\n");
michael@0 470
michael@0 471 /* LL_L2I -- Convert to signed 32bit */
michael@0 472 LL_L2I(result32, bigOne );
michael@0 473 if ( result32 != one )
michael@0 474 SetFailed( "LL_L2I", "r != 1");
michael@0 475
michael@0 476 LL_L2I(result32, bigMinusOne );
michael@0 477 if ( result32 != minusOne )
michael@0 478 SetFailed( "LL_L2I", "r != -1");
michael@0 479
michael@0 480 /* LL_L2UI -- Convert 64bit to unsigned 32bit */
michael@0 481 LL_L2UI( resultU32, bigMinusOne );
michael@0 482 if ( resultU32 != (PRUint32) minusOne )
michael@0 483 SetFailed( "LL_L2UI", "r != -1");
michael@0 484
michael@0 485 LL_L2UI( resultU32, bigOne );
michael@0 486 if ( resultU32 != (PRUint32) one )
michael@0 487 SetFailed( "LL_L2UI", "r != 1");
michael@0 488
michael@0 489 /* LL_L2F -- Convert to 32bit floating point */
michael@0 490 LL_L2F( resultF, bigOne );
michael@0 491 if ( resultF != 1.0 )
michael@0 492 SetFailed( "LL_L2F", "r != 1.0");
michael@0 493
michael@0 494 LL_L2F( resultF, bigMinusOne );
michael@0 495 if ( resultF != -1.0 )
michael@0 496 SetFailed( "LL_L2F", "r != 1.0");
michael@0 497
michael@0 498 /* LL_L2D -- Convert to 64bit floating point */
michael@0 499 LL_L2D( resultD, bigOne );
michael@0 500 if ( resultD != 1.0L )
michael@0 501 SetFailed( "LL_L2D", "r != 1.0");
michael@0 502
michael@0 503 LL_L2D( resultD, bigMinusOne );
michael@0 504 if ( resultD != -1.0L )
michael@0 505 SetFailed( "LL_L2D", "r != -1.0");
michael@0 506
michael@0 507 /* LL_I2L -- Convert 32bit signed to 64bit signed */
michael@0 508 LL_I2L( result, one );
michael@0 509 if ( LL_CMP(result, !=, bigOne ))
michael@0 510 SetFailed( "LL_I2L", "r != 1");
michael@0 511
michael@0 512 LL_I2L( result, minusOne );
michael@0 513 if ( LL_CMP(result, !=, bigMinusOne ))
michael@0 514 SetFailed( "LL_I2L", "r != -1");
michael@0 515
michael@0 516 /* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */
michael@0 517 LL_UI2L( resultU, (PRUint32) one );
michael@0 518 if ( LL_CMP(resultU, !=, bigOne ))
michael@0 519 SetFailed( "LL_UI2L", "r != 1");
michael@0 520
michael@0 521 /* [lth.] This did not behave as expected, but it is correct
michael@0 522 */
michael@0 523 LL_UI2L( resultU, (PRUint32) minusOne );
michael@0 524 if ( LL_CMP(resultU, !=, bigZeroFox ))
michael@0 525 ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU);
michael@0 526
michael@0 527 /* LL_F2L -- Convert 32bit float to 64bit signed */
michael@0 528 LL_F2L( result, 1.0 );
michael@0 529 if ( LL_CMP(result, !=, bigOne ))
michael@0 530 SetFailed( "LL_F2L", "r != 1");
michael@0 531
michael@0 532 LL_F2L( result, -1.0 );
michael@0 533 if ( LL_CMP(result, !=, bigMinusOne ))
michael@0 534 SetFailed( "LL_F2L", "r != -1");
michael@0 535
michael@0 536 /* LL_D2L -- Convert 64bit Float to 64bit signed */
michael@0 537 LL_D2L( result, 1.0L );
michael@0 538 if ( LL_CMP(result, !=, bigOne ))
michael@0 539 SetFailed( "LL_D2L", "r != 1");
michael@0 540
michael@0 541 LL_D2L( result, -1.0L );
michael@0 542 if ( LL_CMP(result, !=, bigMinusOne ))
michael@0 543 SetFailed( "LL_D2L", "r != -1");
michael@0 544
michael@0 545 return;
michael@0 546 }
michael@0 547
michael@0 548 static void ShiftCompileOnly()
michael@0 549 {
michael@0 550 /*
michael@0 551 ** This function is only compiled, never called.
michael@0 552 ** The real test is to see if it compiles w/o
michael@0 553 ** warnings. This is no small feat, by the way.
michael@0 554 */
michael@0 555 PRInt64 ia, ib;
michael@0 556 PRUint64 ua, ub;
michael@0 557 LL_SHR(ia, ib, 32);
michael@0 558 LL_SHL(ia, ib, 32);
michael@0 559
michael@0 560 LL_USHR(ua, ub, 32);
michael@0 561 LL_ISHL(ia, 49, 32);
michael@0 562
michael@0 563 } /* ShiftCompileOnly */
michael@0 564
michael@0 565
michael@0 566 /*
michael@0 567 ** TestShift() -- Test Shifting Operations
michael@0 568 **
michael@0 569 */
michael@0 570 static void
michael@0 571 TestShift( void )
michael@0 572 {
michael@0 573 static const PRInt64 largeTwoZero = LL_INIT( 0x00000002, 0x00000000 );
michael@0 574 PRInt64 result;
michael@0 575 PRUint64 resultU;
michael@0 576
michael@0 577 ReportProgress("Testing Shifting Operations\n");
michael@0 578
michael@0 579 /* LL_SHL -- Shift left algebraic */
michael@0 580 LL_SHL( result, bigOne, one );
michael@0 581 if ( LL_CMP( result, !=, bigTwo ))
michael@0 582 ResultFailed( "LL_SHL", "r != 2", bigOne, result );
michael@0 583
michael@0 584 LL_SHL( result, bigTwo, thirtyTwo );
michael@0 585 if ( LL_CMP( result, !=, largeTwoZero ))
michael@0 586 ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result);
michael@0 587
michael@0 588 /* LL_SHR -- Shift right algebraic */
michael@0 589 LL_SHR( result, bigFoxZero, thirtyTwo );
michael@0 590 if ( LL_CMP( result, !=, bigMinusOne ))
michael@0 591 ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result);
michael@0 592
michael@0 593 LL_SHR( result, bigTwo, one );
michael@0 594 if ( LL_CMP( result, !=, bigOne ))
michael@0 595 ResultFailed( "LL_SHR", "r != 1", bigOne, result);
michael@0 596
michael@0 597 LL_SHR( result, bigFoxFox, thirtyTwo );
michael@0 598 if ( LL_CMP( result, !=, bigMinusOne ))
michael@0 599 ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result);
michael@0 600
michael@0 601 /* LL_USHR -- Logical shift right */
michael@0 602 LL_USHR( resultU, bigZeroFox, thirtyTwo );
michael@0 603 if ( LL_UCMP( resultU, !=, bigZero ))
michael@0 604 ResultFailed( "LL_USHR", "r != 0 ", bigZero, result);
michael@0 605
michael@0 606 LL_USHR( resultU, bigFoxFox, thirtyTwo );
michael@0 607 if ( LL_UCMP( resultU, !=, bigZeroFox ))
michael@0 608 ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result);
michael@0 609
michael@0 610 /* LL_ISHL -- Shift a 32bit integer into a 64bit result */
michael@0 611 LL_ISHL( resultU, minusOne, thirtyTwo );
michael@0 612 if ( LL_UCMP( resultU, !=, bigFoxZero ))
michael@0 613 ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result);
michael@0 614
michael@0 615 LL_ISHL( resultU, one, sixtyThree );
michael@0 616 if ( LL_UCMP( resultU, !=, bigEightZero ))
michael@0 617 ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result);
michael@0 618
michael@0 619 LL_ISHL( resultU, one, sixteen );
michael@0 620 if ( LL_UCMP( resultU, !=, big64K ))
michael@0 621 ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU);
michael@0 622
michael@0 623 return;
michael@0 624 }
michael@0 625
michael@0 626
michael@0 627 /*
michael@0 628 ** TestArithmetic() -- Test arithmetic operations.
michael@0 629 **
michael@0 630 */
michael@0 631 static void
michael@0 632 TestArithmetic( void )
michael@0 633 {
michael@0 634 PRInt64 largeVal = LL_INIT( 0x00000001, 0xffffffff );
michael@0 635 PRInt64 largeValPlusOne = LL_INIT( 0x00000002, 0x00000000 );
michael@0 636 PRInt64 largeValTimesTwo = LL_INIT( 0x00000003, 0xfffffffe );
michael@0 637 PRInt64 largeMultCand = LL_INIT( 0x00000000, 0x7fffffff );
michael@0 638 PRInt64 largeMinusMultCand = LL_INIT( 0xffffffff, 0x10000001 );
michael@0 639 PRInt64 largeMultCandx64K = LL_INIT( 0x00007fff, 0xffff0000 );
michael@0 640 PRInt64 largeNumSHL5 = LL_INIT( 0x0000001f, 0xffffffe0 );
michael@0 641 PRInt64 result, result2;
michael@0 642
michael@0 643 /* Addition */
michael@0 644 LL_ADD( result, bigOne, bigOne );
michael@0 645 if ( LL_CMP( result, !=, bigTwo ))
michael@0 646 ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result);
michael@0 647
michael@0 648 LL_ADD( result, bigMinusOne, bigOne );
michael@0 649 if ( LL_CMP( result, !=, bigZero ))
michael@0 650 ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result);
michael@0 651
michael@0 652 LL_ADD( result, largeVal, bigOne );
michael@0 653 if ( LL_CMP( result, !=, largeValPlusOne ))
michael@0 654 ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result);
michael@0 655
michael@0 656 /* Subtraction */
michael@0 657 LL_SUB( result, bigOne, bigOne );
michael@0 658 if ( LL_CMP( result, !=, bigZero ))
michael@0 659 ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result);
michael@0 660
michael@0 661 LL_SUB( result, bigTwo, bigOne );
michael@0 662 if ( LL_CMP( result, !=, bigOne ))
michael@0 663 ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result);
michael@0 664
michael@0 665 LL_SUB( result, largeValPlusOne, bigOne );
michael@0 666 if ( LL_CMP( result, !=, largeVal ))
michael@0 667 ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result);
michael@0 668
michael@0 669
michael@0 670 /* Multiply */
michael@0 671 LL_MUL( result, largeVal, bigTwo );
michael@0 672 if ( LL_CMP( result, !=, largeValTimesTwo ))
michael@0 673 ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result);
michael@0 674
michael@0 675 LL_MUL( result, largeMultCand, big64K );
michael@0 676 if ( LL_CMP( result, !=, largeMultCandx64K ))
michael@0 677 ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result);
michael@0 678
michael@0 679 LL_NEG( result2, largeMultCand );
michael@0 680 LL_MUL( result, largeMultCand, bigMinusOne );
michael@0 681 if ( LL_CMP( result, !=, result2 ))
michael@0 682 ResultFailed( "LL_MUL", "r != -lMC", result2, result);
michael@0 683
michael@0 684 LL_SHL( result2, bigZeroFox, 5);
michael@0 685 LL_MUL( result, bigZeroFox, bigThirtyTwo );
michael@0 686 if ( LL_CMP( result, !=, largeNumSHL5 ))
michael@0 687 ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result );
michael@0 688
michael@0 689
michael@0 690
michael@0 691 /* LL_DIV() Division */
michael@0 692 LL_DIV( result, bigOne, bigOne);
michael@0 693 if ( LL_CMP( result, !=, bigOne ))
michael@0 694 ResultFailed( "LL_DIV", "1 != 1", bigOne, result);
michael@0 695
michael@0 696 LL_DIV( result, bigNumber, bigOne );
michael@0 697 if ( LL_CMP( result, !=, bigNumber ))
michael@0 698 ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result);
michael@0 699
michael@0 700 LL_DIV( result, bigNumber, bigMinusOne );
michael@0 701 if ( LL_CMP( result, !=, bigMinusNumber ))
michael@0 702 ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result);
michael@0 703
michael@0 704 LL_DIV( result, bigMinusNumber, bigMinusOne );
michael@0 705 if ( LL_CMP( result, !=, bigNumber ))
michael@0 706 ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result);
michael@0 707
michael@0 708 LL_SHL( result2, bigZeroFox, 5 );
michael@0 709 LL_DIV( result, result2, bigOne );
michael@0 710 if ( LL_CMP( result, !=, result2 ))
michael@0 711 ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result);
michael@0 712
michael@0 713 LL_SHL( result2, bigZeroFox, 5 );
michael@0 714 LL_NEG( result2, result2 );
michael@0 715 LL_DIV( result, result2, bigOne );
michael@0 716 if ( LL_CMP( result, !=, result2 ))
michael@0 717 ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result);
michael@0 718
michael@0 719 LL_SHL( result2, bigZeroFox, 17 );
michael@0 720 LL_DIV( result, result2, bigMinusOne );
michael@0 721 LL_NEG( result2, result2 );
michael@0 722 if ( LL_CMP( result, !=, result2 ))
michael@0 723 ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result);
michael@0 724
michael@0 725
michael@0 726 /* LL_MOD() Modulo Division */
michael@0 727 LL_ADD( result2, bigThirtyTwo, bigOne );
michael@0 728 LL_MOD( result, result2, bigSixTeen );
michael@0 729 if ( LL_CMP( result, !=, bigOne ))
michael@0 730 ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result);
michael@0 731
michael@0 732
michael@0 733 LL_MUL( result2, bigZeroFox, bigThirtyTwo );
michael@0 734 LL_ADD( result2, result2, bigSixTeen);
michael@0 735 LL_MOD( result, result2, bigThirtyTwo );
michael@0 736 if ( LL_CMP( result, !=, bigSixTeen ))
michael@0 737 ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result);
michael@0 738
michael@0 739 /* LL_UDIVMOD */
michael@0 740 LL_DIV( result, bigOne, bigOne);
michael@0 741 if ( LL_CMP( result, !=, bigOne ))
michael@0 742 ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result);
michael@0 743
michael@0 744
michael@0 745 return;
michael@0 746 }
michael@0 747
michael@0 748 static void TestWellknowns(void)
michael@0 749 {
michael@0 750 PRInt64 max = LL_MAXINT, min = LL_MININT, zero = LL_ZERO;
michael@0 751 PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero();
michael@0 752 if (LL_NE(max, mmax))
michael@0 753 ResultFailed( "max, mmax", "max != mmax", max, mmax);
michael@0 754 if (LL_NE(min, mmin))
michael@0 755 ResultFailed( "min, mmin", "min != mmin", max, mmin);
michael@0 756 if (LL_NE(zero, mzero))
michael@0 757 ResultFailed( "zero, mzero", "zero != mzero", zero, mzero);
michael@0 758 } /* TestWellknowns */
michael@0 759
michael@0 760 /*
michael@0 761 ** Initialize() -- Initialize the test case
michael@0 762 **
michael@0 763 ** Parse command line options
michael@0 764 **
michael@0 765 */
michael@0 766 static PRIntn
michael@0 767 Initialize( PRIntn argc, char **argv )
michael@0 768 {
michael@0 769 PLOptState *opt = PL_CreateOptState(argc, argv, "dvh");
michael@0 770 PLOptStatus os;
michael@0 771
michael@0 772 /*
michael@0 773 ** Parse command line options
michael@0 774 */
michael@0 775 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
michael@0 776 {
michael@0 777 if (PL_OPT_BAD == os) continue;
michael@0 778 switch (opt->option)
michael@0 779 {
michael@0 780 case 'd': /* set debug mode */
michael@0 781 debugMode = PR_TRUE;
michael@0 782 break;
michael@0 783
michael@0 784 case 'v': /* set verbose mode */
michael@0 785 verboseMode = PR_TRUE;
michael@0 786 debugMode = PR_TRUE;
michael@0 787 break;
michael@0 788
michael@0 789 case 'h': /* user wants some guidance */
michael@0 790 default:
michael@0 791 PR_fprintf(output, "You get help.\n");
michael@0 792 return(1);
michael@0 793 }
michael@0 794 }
michael@0 795 PL_DestroyOptState(opt);
michael@0 796 return(0);
michael@0 797 }
michael@0 798
michael@0 799 int main(int argc, char **argv)
michael@0 800 {
michael@0 801 PR_STDIO_INIT();
michael@0 802 output = PR_GetSpecialFD(PR_StandardError);
michael@0 803
michael@0 804 if ( Initialize( argc, argv ))
michael@0 805 return(1);
michael@0 806
michael@0 807 TestAssignment();
michael@0 808 TestComparisons();
michael@0 809 TestLogicalOperations();
michael@0 810 TestConversion();
michael@0 811 TestShift();
michael@0 812 TestArithmetic();
michael@0 813 TestWellknowns();
michael@0 814
michael@0 815 /*
michael@0 816 ** That's all folks!
michael@0 817 */
michael@0 818 if ( failedAlready )
michael@0 819 {
michael@0 820 PR_fprintf(output, "FAIL\n");\
michael@0 821 }
michael@0 822 else
michael@0 823 {
michael@0 824 PR_fprintf(output, "PASS\n");\
michael@0 825 }
michael@0 826 return failedAlready;
michael@0 827 } /* end main() */

mercurial