michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** testll.c -- test suite for 64bit integer (longlong) operations michael@0: ** michael@0: ** Summary: testll [-d] | [-h] michael@0: ** michael@0: ** Where: michael@0: ** -d set debug mode on; displays individual test failures michael@0: ** -v verbose mode; displays progress in test, plus -d michael@0: ** -h gives usage message. michael@0: ** michael@0: ** Description: michael@0: ** lltest.c tests the functions defined in NSPR 2.0's prlong.h. michael@0: ** michael@0: ** Successive tests begin to depend on other LL functions working michael@0: ** correctly. So, ... Do not change the order of the tests as run michael@0: ** from main(). michael@0: ** michael@0: ** Caveats: michael@0: ** Do not even begin to think that this is an exhaustive test! michael@0: ** michael@0: ** These tests try a little of everything, but not all boundary michael@0: ** conditions and limits are tested. michael@0: ** You want better coverage? ... Add it. michael@0: ** michael@0: ** --- michael@0: ** Author: Lawrence Hardiman . michael@0: ** --- michael@0: ** Revision History: michael@0: ** 01-Oct-1997. Original implementation. michael@0: ** michael@0: */ michael@0: michael@0: #include "nspr.h" michael@0: #include "plgetopt.h" michael@0: michael@0: /* --- Local Definitions --- */ michael@0: #define ReportProgress(m) if (verboseMode) PR_fprintf(output, (m)); michael@0: michael@0: michael@0: /* --- Global variables --- */ michael@0: static PRIntn failedAlready = 0; michael@0: static PRFileDesc* output = NULL; michael@0: static PRBool debugMode = PR_FALSE; michael@0: static PRBool verboseMode = PR_FALSE; michael@0: michael@0: /* michael@0: ** Constants used in tests. michael@0: */ michael@0: const PRInt64 bigZero = LL_INIT( 0, 0 ); michael@0: const PRInt64 bigOne = LL_INIT( 0, 1 ); michael@0: const PRInt64 bigTwo = LL_INIT( 0, 2 ); michael@0: const PRInt64 bigSixTeen = LL_INIT( 0, 16 ); michael@0: const PRInt64 bigThirtyTwo = LL_INIT( 0, 32 ); michael@0: const PRInt64 bigMinusOne = LL_INIT( 0xffffffff, 0xffffffff ); michael@0: const PRInt64 bigMinusTwo = LL_INIT( 0xffffffff, 0xfffffffe ); michael@0: const PRInt64 bigNumber = LL_INIT( 0x7fffffff, 0xffffffff ); michael@0: const PRInt64 bigMinusNumber = LL_INIT( 0x80000000, 0x00000001 ); michael@0: const PRInt64 bigMaxInt32 = LL_INIT( 0x00000000, 0x7fffffff ); michael@0: const PRInt64 big2To31 = LL_INIT( 0x00000000, 0x80000000 ); michael@0: const PRUint64 bigZeroFox = LL_INIT( 0x00000000, 0xffffffff ); michael@0: const PRUint64 bigFoxFox = LL_INIT( 0xffffffff, 0xffffffff ); michael@0: const PRUint64 bigFoxZero = LL_INIT( 0xffffffff, 0x00000000 ); michael@0: const PRUint64 bigEightZero = LL_INIT( 0x80000000, 0x00000000 ); michael@0: const PRUint64 big64K = LL_INIT( 0x00000000, 0x00010000 ); michael@0: const PRInt64 bigInt0 = LL_INIT( 0x01a00000, 0x00001000 ); michael@0: const PRInt64 bigInt1 = LL_INIT( 0x01a00000, 0x00001100 ); michael@0: const PRInt64 bigInt2 = LL_INIT( 0x01a00000, 0x00000100 ); michael@0: const PRInt64 bigInt3 = LL_INIT( 0x01a00001, 0x00001000 ); michael@0: const PRInt64 bigInt4 = LL_INIT( 0x01a00001, 0x00001100 ); michael@0: const PRInt64 bigInt5 = LL_INIT( 0x01a00001, 0x00000100 ); michael@0: const PRInt64 bigInt6 = LL_INIT( 0xb1a00000, 0x00001000 ); michael@0: const PRInt64 bigInt7 = LL_INIT( 0xb1a00000, 0x00001100 ); michael@0: const PRInt64 bigInt8 = LL_INIT( 0xb1a00000, 0x00000100 ); michael@0: const PRInt64 bigInt9 = LL_INIT( 0xb1a00001, 0x00001000 ); michael@0: const PRInt64 bigInt10 = LL_INIT( 0xb1a00001, 0x00001100 ); michael@0: const PRInt64 bigInt11 = LL_INIT( 0xb1a00001, 0x00000100 ); michael@0: const PRInt32 one = 1l; michael@0: const PRInt32 minusOne = -1l; michael@0: const PRInt32 sixteen = 16l; michael@0: const PRInt32 thirtyTwo = 32l; michael@0: const PRInt32 sixtyThree = 63l; michael@0: michael@0: /* michael@0: ** SetFailed() -- Report individual test failure michael@0: ** michael@0: */ michael@0: static void michael@0: SetFailed( char *what, char *how ) michael@0: { michael@0: failedAlready = 1; michael@0: if ( debugMode ) michael@0: PR_fprintf(output, "%s: failed: %s\n", what, how ); michael@0: return; michael@0: } michael@0: michael@0: static void michael@0: ResultFailed( char *what, char *how, PRInt64 expected, PRInt64 got) michael@0: { michael@0: if ( debugMode) michael@0: { michael@0: SetFailed( what, how ); michael@0: PR_fprintf(output, "Expected: 0x%llx Got: 0x%llx\n", expected, got ); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: michael@0: /* michael@0: ** TestAssignment() -- Test the assignment michael@0: */ michael@0: static void TestAssignment( void ) michael@0: { michael@0: PRInt64 zero = LL_Zero(); michael@0: PRInt64 min = LL_MinInt(); michael@0: PRInt64 max = LL_MaxInt(); michael@0: if (!LL_EQ(zero, bigZero)) michael@0: SetFailed("LL_EQ(zero, bigZero)", "!="); michael@0: if (!LL_CMP(max, >, min)) michael@0: SetFailed("LL_CMP(max, >, min)", "!>"); michael@0: } michael@0: michael@0: /* michael@0: ** TestComparisons() -- Test the longlong comparison operations michael@0: */ michael@0: static void michael@0: TestComparisons( void ) michael@0: { michael@0: ReportProgress("Testing Comparisons Operations\n"); michael@0: michael@0: /* test for zero */ michael@0: if ( !LL_IS_ZERO( bigZero )) michael@0: SetFailed( "LL_IS_ZERO", "Zero is not zero" ); michael@0: michael@0: if ( LL_IS_ZERO( bigOne )) michael@0: SetFailed( "LL_IS_ZERO", "One tests as zero" ); michael@0: michael@0: if ( LL_IS_ZERO( bigMinusOne )) michael@0: SetFailed( "LL_IS_ZERO", "Minus One tests as zero" ); michael@0: michael@0: /* test equal */ michael@0: if ( !LL_EQ( bigZero, bigZero )) michael@0: SetFailed( "LL_EQ", "zero EQ zero"); michael@0: michael@0: if ( !LL_EQ( bigOne, bigOne )) michael@0: SetFailed( "LL_EQ", "one EQ one" ); michael@0: michael@0: if ( !LL_EQ( bigNumber, bigNumber )) michael@0: SetFailed( "LL_EQ", "bigNumber EQ bigNumber" ); michael@0: michael@0: if ( !LL_EQ( bigMinusOne, bigMinusOne )) michael@0: SetFailed( "LL_EQ", "minus one EQ minus one"); michael@0: michael@0: if ( LL_EQ( bigZero, bigOne )) michael@0: SetFailed( "LL_EQ", "zero EQ one"); michael@0: michael@0: if ( LL_EQ( bigOne, bigZero )) michael@0: SetFailed( "LL_EQ", "one EQ zero" ); michael@0: michael@0: if ( LL_EQ( bigMinusOne, bigOne )) michael@0: SetFailed( "LL_EQ", "minus one EQ one"); michael@0: michael@0: if ( LL_EQ( bigNumber, bigOne )) michael@0: SetFailed( "LL_EQ", "bigNumber EQ one"); michael@0: michael@0: /* test not equal */ michael@0: if ( LL_NE( bigZero, bigZero )) michael@0: SetFailed( "LL_NE", "0 NE 0"); michael@0: michael@0: if ( LL_NE( bigOne, bigOne )) michael@0: SetFailed( "LL_NE", "1 NE 1"); michael@0: michael@0: if ( LL_NE( bigMinusOne, bigMinusOne )) michael@0: SetFailed( "LL_NE", "-1 NE -1"); michael@0: michael@0: if ( LL_NE( bigNumber, bigNumber )) michael@0: SetFailed( "LL_NE", "n NE n"); michael@0: michael@0: if ( LL_NE( bigMinusNumber, bigMinusNumber )) michael@0: SetFailed( "LL_NE", "-n NE -n"); michael@0: michael@0: if ( !LL_NE( bigZero, bigOne)) michael@0: SetFailed( "LL_NE", "0 NE 1"); michael@0: michael@0: if ( !LL_NE( bigOne, bigMinusNumber)) michael@0: SetFailed( "LL_NE", "1 NE -n"); michael@0: michael@0: /* Greater than or equal to zero */ michael@0: if ( !LL_GE_ZERO( bigZero )) michael@0: SetFailed( "LL_GE_ZERO", "0"); michael@0: michael@0: if ( !LL_GE_ZERO( bigOne )) michael@0: SetFailed( "LL_GE_ZERO", "1"); michael@0: michael@0: if ( !LL_GE_ZERO( bigNumber )) michael@0: SetFailed( "LL_GE_ZERO", "n"); michael@0: michael@0: if ( LL_GE_ZERO( bigMinusOne )) michael@0: SetFailed( "LL_GE_ZERO", "-1"); michael@0: michael@0: if ( LL_GE_ZERO( bigMinusNumber )) michael@0: SetFailed( "LL_GE_ZERO", "-n"); michael@0: michael@0: /* Algebraic Compare two values */ michael@0: if ( !LL_CMP( bigZero, ==, bigZero )) michael@0: SetFailed( "LL_CMP", "0 == 0"); michael@0: michael@0: if ( LL_CMP( bigZero, >, bigZero )) michael@0: SetFailed( "LL_CMP", "0 > 0"); michael@0: michael@0: if ( LL_CMP( bigZero, <, bigZero )) michael@0: SetFailed( "LL_CMP", "0 < 0"); michael@0: michael@0: if ( LL_CMP( bigNumber, <, bigOne )) michael@0: SetFailed( "LL_CMP", "n < 1"); michael@0: michael@0: if ( !LL_CMP( bigNumber, >, bigOne )) michael@0: SetFailed( "LL_CMP", "n <= 1"); michael@0: michael@0: if ( LL_CMP( bigOne, >, bigNumber )) michael@0: SetFailed( "LL_CMP", "1 > n"); michael@0: michael@0: if ( LL_CMP( bigMinusNumber, >, bigNumber )) michael@0: SetFailed( "LL_CMP", "-n > n"); michael@0: michael@0: if ( LL_CMP( bigNumber, !=, bigNumber)) michael@0: SetFailed( "LL_CMP", "n != n"); michael@0: michael@0: if ( !LL_CMP( bigMinusOne, >, bigMinusTwo )) michael@0: SetFailed( "LL_CMP", "-1 <= -2"); michael@0: michael@0: if ( !LL_CMP( bigMaxInt32, <, big2To31 )) michael@0: SetFailed( "LL_CMP", "Max 32-bit signed int >= 2^31"); michael@0: michael@0: /* Two positive numbers */ michael@0: if ( !LL_CMP( bigInt0, <=, bigInt0 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt0, <=, bigInt1 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( LL_CMP( bigInt0, <=, bigInt2 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt0, <=, bigInt3 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt0, <=, bigInt4 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt0, <=, bigInt5 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: /* Two negative numbers */ michael@0: if ( !LL_CMP( bigInt6, <=, bigInt6 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt6, <=, bigInt7 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( LL_CMP( bigInt6, <=, bigInt8 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt6, <=, bigInt9 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt6, <=, bigInt10 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( !LL_CMP( bigInt6, <=, bigInt11 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: /* One positive, one negative */ michael@0: if ( LL_CMP( bigInt0, <=, bigInt6 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( LL_CMP( bigInt0, <=, bigInt7 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: if ( LL_CMP( bigInt0, <=, bigInt8 )) michael@0: SetFailed( "LL_CMP", "LL_CMP(<=) failed"); michael@0: michael@0: /* Bitwise Compare two numbers */ michael@0: if ( !LL_UCMP( bigZero, ==, bigZero )) michael@0: SetFailed( "LL_UCMP", "0 == 0"); michael@0: michael@0: if ( LL_UCMP( bigZero, >, bigZero )) michael@0: SetFailed( "LL_UCMP", "0 > 0"); michael@0: michael@0: if ( LL_UCMP( bigZero, <, bigZero )) michael@0: SetFailed( "LL_UCMP", "0 < 0"); michael@0: michael@0: if ( LL_UCMP( bigNumber, <, bigOne )) michael@0: SetFailed( "LL_UCMP", "n < 1"); michael@0: michael@0: if ( !LL_UCMP( bigNumber, >, bigOne )) michael@0: SetFailed( "LL_UCMP", "n < 1"); michael@0: michael@0: if ( LL_UCMP( bigOne, >, bigNumber )) michael@0: SetFailed( "LL_UCMP", "1 > n"); michael@0: michael@0: if ( LL_UCMP( bigMinusNumber, <, bigNumber )) michael@0: SetFailed( "LL_UCMP", "-n < n"); michael@0: michael@0: /* Two positive numbers */ michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt0 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt1 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( LL_UCMP( bigInt0, <=, bigInt2 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt3 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt4 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt5 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: /* Two negative numbers */ michael@0: if ( !LL_UCMP( bigInt6, <=, bigInt6 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt6, <=, bigInt7 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( LL_UCMP( bigInt6, <=, bigInt8 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt6, <=, bigInt9 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt6, <=, bigInt10 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt6, <=, bigInt11 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: /* One positive, one negative */ michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt6 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt7 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: if ( !LL_UCMP( bigInt0, <=, bigInt8 )) michael@0: SetFailed( "LL_UCMP", "LL_UCMP(<=) failed"); michael@0: michael@0: return; michael@0: } michael@0: michael@0: /* michael@0: ** TestLogicalOperations() -- Tests for AND, OR, ... michael@0: ** michael@0: */ michael@0: static void michael@0: TestLogicalOperations( void ) michael@0: { michael@0: PRUint64 result, result2; michael@0: michael@0: ReportProgress("Testing Logical Operations\n"); michael@0: michael@0: /* Test AND */ michael@0: LL_AND( result, bigZero, bigZero ); michael@0: if ( !LL_IS_ZERO( result )) michael@0: ResultFailed( "LL_AND", "0 & 0", bigZero, result ); michael@0: michael@0: LL_AND( result, bigOne, bigOne ); michael@0: if ( LL_IS_ZERO( result )) michael@0: ResultFailed( "LL_AND", "1 & 1", bigOne, result ); michael@0: michael@0: LL_AND( result, bigZero, bigOne ); michael@0: if ( !LL_IS_ZERO( result )) michael@0: ResultFailed( "LL_AND", "1 & 1", bigZero, result ); michael@0: michael@0: LL_AND( result, bigMinusOne, bigMinusOne ); michael@0: if ( !LL_UCMP( result, ==, bigMinusOne )) michael@0: ResultFailed( "LL_AND", "-1 & -1", bigMinusOne, result ); michael@0: michael@0: /* test OR */ michael@0: LL_OR( result, bigZero, bigZero ); michael@0: if ( !LL_IS_ZERO( result )) michael@0: ResultFailed( "LL_OR", "0 | 1", bigZero, result); michael@0: michael@0: LL_OR( result, bigZero, bigOne ); michael@0: if ( LL_IS_ZERO( result )) michael@0: ResultFailed( "LL_OR", "0 | 1", bigOne, result ); michael@0: michael@0: LL_OR( result, bigZero, bigMinusNumber ); michael@0: if ( !LL_UCMP( result, ==, bigMinusNumber )) michael@0: ResultFailed( "LL_OR", "0 | -n", bigMinusNumber, result); michael@0: michael@0: LL_OR( result, bigMinusNumber, bigZero ); michael@0: if ( !LL_UCMP( result, ==, bigMinusNumber )) michael@0: ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result ); michael@0: michael@0: /* test XOR */ michael@0: LL_XOR( result, bigZero, bigZero ); michael@0: if ( LL_UCMP( result, !=, bigZero )) michael@0: ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result); michael@0: michael@0: LL_XOR( result, bigOne, bigZero ); michael@0: if ( LL_UCMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result ); michael@0: michael@0: LL_XOR( result, bigMinusNumber, bigZero ); michael@0: if ( LL_UCMP( result, !=, bigMinusNumber )) michael@0: ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result ); michael@0: michael@0: LL_XOR( result, bigMinusNumber, bigMinusNumber ); michael@0: if ( LL_UCMP( result, !=, bigZero )) michael@0: ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result); michael@0: michael@0: /* test OR2. */ michael@0: result = bigZero; michael@0: LL_OR2( result, bigOne ); michael@0: if ( LL_UCMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result); michael@0: michael@0: result = bigOne; michael@0: LL_OR2( result, bigNumber ); michael@0: if ( LL_UCMP( result, !=, bigNumber )) michael@0: ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result); michael@0: michael@0: result = bigMinusNumber; michael@0: LL_OR2( result, bigMinusNumber ); michael@0: if ( LL_UCMP( result, !=, bigMinusNumber )) michael@0: ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result); michael@0: michael@0: /* test NOT */ michael@0: LL_NOT( result, bigMinusNumber); michael@0: LL_NOT( result2, result); michael@0: if ( LL_UCMP( result2, !=, bigMinusNumber )) michael@0: ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result); michael@0: michael@0: /* test Negation */ michael@0: LL_NEG( result, bigMinusNumber ); michael@0: LL_NEG( result2, result ); michael@0: if ( LL_CMP( result2, !=, bigMinusNumber )) michael@0: ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result); michael@0: michael@0: return; michael@0: } michael@0: michael@0: michael@0: michael@0: /* michael@0: ** TestConversion() -- Test Conversion Operations michael@0: ** michael@0: */ michael@0: static void michael@0: TestConversion( void ) michael@0: { michael@0: PRInt64 result; michael@0: PRInt64 resultU; michael@0: PRInt32 result32; michael@0: PRUint32 resultU32; michael@0: float resultF; michael@0: PRFloat64 resultD; michael@0: michael@0: ReportProgress("Testing Conversion Operations\n"); michael@0: michael@0: /* LL_L2I -- Convert to signed 32bit */ michael@0: LL_L2I(result32, bigOne ); michael@0: if ( result32 != one ) michael@0: SetFailed( "LL_L2I", "r != 1"); michael@0: michael@0: LL_L2I(result32, bigMinusOne ); michael@0: if ( result32 != minusOne ) michael@0: SetFailed( "LL_L2I", "r != -1"); michael@0: michael@0: /* LL_L2UI -- Convert 64bit to unsigned 32bit */ michael@0: LL_L2UI( resultU32, bigMinusOne ); michael@0: if ( resultU32 != (PRUint32) minusOne ) michael@0: SetFailed( "LL_L2UI", "r != -1"); michael@0: michael@0: LL_L2UI( resultU32, bigOne ); michael@0: if ( resultU32 != (PRUint32) one ) michael@0: SetFailed( "LL_L2UI", "r != 1"); michael@0: michael@0: /* LL_L2F -- Convert to 32bit floating point */ michael@0: LL_L2F( resultF, bigOne ); michael@0: if ( resultF != 1.0 ) michael@0: SetFailed( "LL_L2F", "r != 1.0"); michael@0: michael@0: LL_L2F( resultF, bigMinusOne ); michael@0: if ( resultF != -1.0 ) michael@0: SetFailed( "LL_L2F", "r != 1.0"); michael@0: michael@0: /* LL_L2D -- Convert to 64bit floating point */ michael@0: LL_L2D( resultD, bigOne ); michael@0: if ( resultD != 1.0L ) michael@0: SetFailed( "LL_L2D", "r != 1.0"); michael@0: michael@0: LL_L2D( resultD, bigMinusOne ); michael@0: if ( resultD != -1.0L ) michael@0: SetFailed( "LL_L2D", "r != -1.0"); michael@0: michael@0: /* LL_I2L -- Convert 32bit signed to 64bit signed */ michael@0: LL_I2L( result, one ); michael@0: if ( LL_CMP(result, !=, bigOne )) michael@0: SetFailed( "LL_I2L", "r != 1"); michael@0: michael@0: LL_I2L( result, minusOne ); michael@0: if ( LL_CMP(result, !=, bigMinusOne )) michael@0: SetFailed( "LL_I2L", "r != -1"); michael@0: michael@0: /* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */ michael@0: LL_UI2L( resultU, (PRUint32) one ); michael@0: if ( LL_CMP(resultU, !=, bigOne )) michael@0: SetFailed( "LL_UI2L", "r != 1"); michael@0: michael@0: /* [lth.] This did not behave as expected, but it is correct michael@0: */ michael@0: LL_UI2L( resultU, (PRUint32) minusOne ); michael@0: if ( LL_CMP(resultU, !=, bigZeroFox )) michael@0: ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU); michael@0: michael@0: /* LL_F2L -- Convert 32bit float to 64bit signed */ michael@0: LL_F2L( result, 1.0 ); michael@0: if ( LL_CMP(result, !=, bigOne )) michael@0: SetFailed( "LL_F2L", "r != 1"); michael@0: michael@0: LL_F2L( result, -1.0 ); michael@0: if ( LL_CMP(result, !=, bigMinusOne )) michael@0: SetFailed( "LL_F2L", "r != -1"); michael@0: michael@0: /* LL_D2L -- Convert 64bit Float to 64bit signed */ michael@0: LL_D2L( result, 1.0L ); michael@0: if ( LL_CMP(result, !=, bigOne )) michael@0: SetFailed( "LL_D2L", "r != 1"); michael@0: michael@0: LL_D2L( result, -1.0L ); michael@0: if ( LL_CMP(result, !=, bigMinusOne )) michael@0: SetFailed( "LL_D2L", "r != -1"); michael@0: michael@0: return; michael@0: } michael@0: michael@0: static void ShiftCompileOnly() michael@0: { michael@0: /* michael@0: ** This function is only compiled, never called. michael@0: ** The real test is to see if it compiles w/o michael@0: ** warnings. This is no small feat, by the way. michael@0: */ michael@0: PRInt64 ia, ib; michael@0: PRUint64 ua, ub; michael@0: LL_SHR(ia, ib, 32); michael@0: LL_SHL(ia, ib, 32); michael@0: michael@0: LL_USHR(ua, ub, 32); michael@0: LL_ISHL(ia, 49, 32); michael@0: michael@0: } /* ShiftCompileOnly */ michael@0: michael@0: michael@0: /* michael@0: ** TestShift() -- Test Shifting Operations michael@0: ** michael@0: */ michael@0: static void michael@0: TestShift( void ) michael@0: { michael@0: static const PRInt64 largeTwoZero = LL_INIT( 0x00000002, 0x00000000 ); michael@0: PRInt64 result; michael@0: PRUint64 resultU; michael@0: michael@0: ReportProgress("Testing Shifting Operations\n"); michael@0: michael@0: /* LL_SHL -- Shift left algebraic */ michael@0: LL_SHL( result, bigOne, one ); michael@0: if ( LL_CMP( result, !=, bigTwo )) michael@0: ResultFailed( "LL_SHL", "r != 2", bigOne, result ); michael@0: michael@0: LL_SHL( result, bigTwo, thirtyTwo ); michael@0: if ( LL_CMP( result, !=, largeTwoZero )) michael@0: ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result); michael@0: michael@0: /* LL_SHR -- Shift right algebraic */ michael@0: LL_SHR( result, bigFoxZero, thirtyTwo ); michael@0: if ( LL_CMP( result, !=, bigMinusOne )) michael@0: ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result); michael@0: michael@0: LL_SHR( result, bigTwo, one ); michael@0: if ( LL_CMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_SHR", "r != 1", bigOne, result); michael@0: michael@0: LL_SHR( result, bigFoxFox, thirtyTwo ); michael@0: if ( LL_CMP( result, !=, bigMinusOne )) michael@0: ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result); michael@0: michael@0: /* LL_USHR -- Logical shift right */ michael@0: LL_USHR( resultU, bigZeroFox, thirtyTwo ); michael@0: if ( LL_UCMP( resultU, !=, bigZero )) michael@0: ResultFailed( "LL_USHR", "r != 0 ", bigZero, result); michael@0: michael@0: LL_USHR( resultU, bigFoxFox, thirtyTwo ); michael@0: if ( LL_UCMP( resultU, !=, bigZeroFox )) michael@0: ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result); michael@0: michael@0: /* LL_ISHL -- Shift a 32bit integer into a 64bit result */ michael@0: LL_ISHL( resultU, minusOne, thirtyTwo ); michael@0: if ( LL_UCMP( resultU, !=, bigFoxZero )) michael@0: ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result); michael@0: michael@0: LL_ISHL( resultU, one, sixtyThree ); michael@0: if ( LL_UCMP( resultU, !=, bigEightZero )) michael@0: ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result); michael@0: michael@0: LL_ISHL( resultU, one, sixteen ); michael@0: if ( LL_UCMP( resultU, !=, big64K )) michael@0: ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU); michael@0: michael@0: return; michael@0: } michael@0: michael@0: michael@0: /* michael@0: ** TestArithmetic() -- Test arithmetic operations. michael@0: ** michael@0: */ michael@0: static void michael@0: TestArithmetic( void ) michael@0: { michael@0: PRInt64 largeVal = LL_INIT( 0x00000001, 0xffffffff ); michael@0: PRInt64 largeValPlusOne = LL_INIT( 0x00000002, 0x00000000 ); michael@0: PRInt64 largeValTimesTwo = LL_INIT( 0x00000003, 0xfffffffe ); michael@0: PRInt64 largeMultCand = LL_INIT( 0x00000000, 0x7fffffff ); michael@0: PRInt64 largeMinusMultCand = LL_INIT( 0xffffffff, 0x10000001 ); michael@0: PRInt64 largeMultCandx64K = LL_INIT( 0x00007fff, 0xffff0000 ); michael@0: PRInt64 largeNumSHL5 = LL_INIT( 0x0000001f, 0xffffffe0 ); michael@0: PRInt64 result, result2; michael@0: michael@0: /* Addition */ michael@0: LL_ADD( result, bigOne, bigOne ); michael@0: if ( LL_CMP( result, !=, bigTwo )) michael@0: ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result); michael@0: michael@0: LL_ADD( result, bigMinusOne, bigOne ); michael@0: if ( LL_CMP( result, !=, bigZero )) michael@0: ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result); michael@0: michael@0: LL_ADD( result, largeVal, bigOne ); michael@0: if ( LL_CMP( result, !=, largeValPlusOne )) michael@0: ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result); michael@0: michael@0: /* Subtraction */ michael@0: LL_SUB( result, bigOne, bigOne ); michael@0: if ( LL_CMP( result, !=, bigZero )) michael@0: ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result); michael@0: michael@0: LL_SUB( result, bigTwo, bigOne ); michael@0: if ( LL_CMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result); michael@0: michael@0: LL_SUB( result, largeValPlusOne, bigOne ); michael@0: if ( LL_CMP( result, !=, largeVal )) michael@0: ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result); michael@0: michael@0: michael@0: /* Multiply */ michael@0: LL_MUL( result, largeVal, bigTwo ); michael@0: if ( LL_CMP( result, !=, largeValTimesTwo )) michael@0: ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result); michael@0: michael@0: LL_MUL( result, largeMultCand, big64K ); michael@0: if ( LL_CMP( result, !=, largeMultCandx64K )) michael@0: ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result); michael@0: michael@0: LL_NEG( result2, largeMultCand ); michael@0: LL_MUL( result, largeMultCand, bigMinusOne ); michael@0: if ( LL_CMP( result, !=, result2 )) michael@0: ResultFailed( "LL_MUL", "r != -lMC", result2, result); michael@0: michael@0: LL_SHL( result2, bigZeroFox, 5); michael@0: LL_MUL( result, bigZeroFox, bigThirtyTwo ); michael@0: if ( LL_CMP( result, !=, largeNumSHL5 )) michael@0: ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result ); michael@0: michael@0: michael@0: michael@0: /* LL_DIV() Division */ michael@0: LL_DIV( result, bigOne, bigOne); michael@0: if ( LL_CMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_DIV", "1 != 1", bigOne, result); michael@0: michael@0: LL_DIV( result, bigNumber, bigOne ); michael@0: if ( LL_CMP( result, !=, bigNumber )) michael@0: ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result); michael@0: michael@0: LL_DIV( result, bigNumber, bigMinusOne ); michael@0: if ( LL_CMP( result, !=, bigMinusNumber )) michael@0: ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result); michael@0: michael@0: LL_DIV( result, bigMinusNumber, bigMinusOne ); michael@0: if ( LL_CMP( result, !=, bigNumber )) michael@0: ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result); michael@0: michael@0: LL_SHL( result2, bigZeroFox, 5 ); michael@0: LL_DIV( result, result2, bigOne ); michael@0: if ( LL_CMP( result, !=, result2 )) michael@0: ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result); michael@0: michael@0: LL_SHL( result2, bigZeroFox, 5 ); michael@0: LL_NEG( result2, result2 ); michael@0: LL_DIV( result, result2, bigOne ); michael@0: if ( LL_CMP( result, !=, result2 )) michael@0: ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result); michael@0: michael@0: LL_SHL( result2, bigZeroFox, 17 ); michael@0: LL_DIV( result, result2, bigMinusOne ); michael@0: LL_NEG( result2, result2 ); michael@0: if ( LL_CMP( result, !=, result2 )) michael@0: ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result); michael@0: michael@0: michael@0: /* LL_MOD() Modulo Division */ michael@0: LL_ADD( result2, bigThirtyTwo, bigOne ); michael@0: LL_MOD( result, result2, bigSixTeen ); michael@0: if ( LL_CMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result); michael@0: michael@0: michael@0: LL_MUL( result2, bigZeroFox, bigThirtyTwo ); michael@0: LL_ADD( result2, result2, bigSixTeen); michael@0: LL_MOD( result, result2, bigThirtyTwo ); michael@0: if ( LL_CMP( result, !=, bigSixTeen )) michael@0: ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result); michael@0: michael@0: /* LL_UDIVMOD */ michael@0: LL_DIV( result, bigOne, bigOne); michael@0: if ( LL_CMP( result, !=, bigOne )) michael@0: ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result); michael@0: michael@0: michael@0: return; michael@0: } michael@0: michael@0: static void TestWellknowns(void) michael@0: { michael@0: PRInt64 max = LL_MAXINT, min = LL_MININT, zero = LL_ZERO; michael@0: PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero(); michael@0: if (LL_NE(max, mmax)) michael@0: ResultFailed( "max, mmax", "max != mmax", max, mmax); michael@0: if (LL_NE(min, mmin)) michael@0: ResultFailed( "min, mmin", "min != mmin", max, mmin); michael@0: if (LL_NE(zero, mzero)) michael@0: ResultFailed( "zero, mzero", "zero != mzero", zero, mzero); michael@0: } /* TestWellknowns */ michael@0: michael@0: /* michael@0: ** Initialize() -- Initialize the test case michael@0: ** michael@0: ** Parse command line options michael@0: ** michael@0: */ michael@0: static PRIntn michael@0: Initialize( PRIntn argc, char **argv ) michael@0: { michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "dvh"); michael@0: PLOptStatus os; michael@0: michael@0: /* michael@0: ** Parse command line options michael@0: */ michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 'd': /* set debug mode */ michael@0: debugMode = PR_TRUE; michael@0: break; michael@0: michael@0: case 'v': /* set verbose mode */ michael@0: verboseMode = PR_TRUE; michael@0: debugMode = PR_TRUE; michael@0: break; michael@0: michael@0: case 'h': /* user wants some guidance */ michael@0: default: michael@0: PR_fprintf(output, "You get help.\n"); michael@0: return(1); michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: return(0); michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PR_STDIO_INIT(); michael@0: output = PR_GetSpecialFD(PR_StandardError); michael@0: michael@0: if ( Initialize( argc, argv )) michael@0: return(1); michael@0: michael@0: TestAssignment(); michael@0: TestComparisons(); michael@0: TestLogicalOperations(); michael@0: TestConversion(); michael@0: TestShift(); michael@0: TestArithmetic(); michael@0: TestWellknowns(); michael@0: michael@0: /* michael@0: ** That's all folks! michael@0: */ michael@0: if ( failedAlready ) michael@0: { michael@0: PR_fprintf(output, "FAIL\n");\ michael@0: } michael@0: else michael@0: { michael@0: PR_fprintf(output, "PASS\n");\ michael@0: } michael@0: return failedAlready; michael@0: } /* end main() */