diff options
author | Yifan Hong <elsk@google.com> | 2016-08-18 15:09:28 -0700 |
---|---|---|
committer | Iliyan Malchev <malchev@google.com> | 2016-08-30 23:15:05 -0700 |
commit | a401680f6e98350a97ee69041e78d4d4207510ba (patch) | |
tree | 5acdaacb639e1e08f74ba3e0870134f924c19eed /tests/expression | |
parent | 092d4cdfa01b1a3b856e5414ff3f91305e4fbc71 (diff) | |
download | platform_hardware_interfaces-a401680f6e98350a97ee69041e78d4d4207510ba.tar.gz platform_hardware_interfaces-a401680f6e98350a97ee69041e78d4d4207510ba.tar.bz2 platform_hardware_interfaces-a401680f6e98350a97ee69041e78d4d4207510ba.zip |
add test for constant expression evaluation output
Simply run:
# hidl_gen converts .hal to .h correctly
make hidl_gen_test
# converted .h can compile
make android.hardware.tests.expression@1.0
to run the tests.
b/30951879: int8_t is same as char, and when emitting output the
character corresponding to that number is emitted instead of
the number itself.
Change-Id: Icacba6b6262cc0026a94f64527b80e2c0e35e72e
Diffstat (limited to 'tests/expression')
-rw-r--r-- | tests/expression/1.0/IExpression.hal | 138 |
1 files changed, 118 insertions, 20 deletions
diff --git a/tests/expression/1.0/IExpression.hal b/tests/expression/1.0/IExpression.hal index 4523505829..3dea9a489f 100644 --- a/tests/expression/1.0/IExpression.hal +++ b/tests/expression/1.0/IExpression.hal @@ -15,35 +15,133 @@ */ package android.hardware.tests.expression@1.0; - @hal_type(type="LIGHT") - interface IExpression { - enum int_literals : int32_t { + enum UInt64LiteralTypeGuessing : uint64_t { + noSuffixDec1 = 0, + noSuffixDec2 = 1, + noSuffixDec3 = -1, + noSuffixDec4 = ~0, + noSuffixDec5 = 2147483647, + noSuffixDec6 = -2147483648, + noSuffixDec7 = 2147483648, + noSuffixDec8 = -2147483649, + noSuffixDec9 = ~(-1), + noSuffixHex1 = 0x7fffffff, + noSuffixHex2 = 0x80000000, + noSuffixHex3 = 0xffffffff, + longHex1 = 0xffffffffl, + longHex2 = 0xfffffffff, + longHex3 = 0x7fffffffffffffff, + longHex4 = 0x8000000000000000, + longHex5 = 0xFFFFFFFFFFFFFFFF, + }; + + enum SuffixedLiteralTypeGuessing : int32_t { + // Should be all true / ones. + // dec literals are either int32_t or int64_t + decInt32_1 = (~(-1)) == 0, + decInt32_2 = -(1 << 31) == (1 << 31), + decInt64_1 = (~(-1l)) == 0, + decInt64_2 = (~4294967295) != 0, + decInt64_3 = (~4294967295l) != 0, + decInt64_4 = -(1l << 63) == (1l << 63), + // hex literals could be (u)int32_t or (u)int64_t + // 0x7fffffff is int32_t, hence can be negated + hexInt32_1 = -0x7fffffff < 0, + // 0x80000000 is uint32_t; if it were int32_t then -(int32_t)0x80000000 == (int32_t)0x80000000 > 0 + hexUInt32_1 = -0x80000000 > 0, + // 0xFFFFFFFF is uint32_t, not int64_t; if it were int64_t then ~(int64_t)0xFFFFFFFF != 0 + hexUInt32_2 = ~0xFFFFFFFF == 0, + // 0x7FFFFFFFFFFFFFFF is int64_t, hence can be negated + hexInt64_1 = -0x7FFFFFFFFFFFFFFF < 0, + // 0x8000000000000000 is uint64_t + hexUInt64_1 = -0x8000000000000000 > 0, + }; + + enum Int64LiteralTypeGuessing : int64_t { + // both treated int32_t, sum = (int64_t)(int32_t)0x80000000 = (int64_t)(-2147483648) + noSuffixDec11 = 1 + 0x7fffffff, + // 0x80000000 is uint32_t, sum = (int64_t)(uint32_t)0x7fffffff = (int64_t)(2147483647) + noSuffixDec12 = 0x80000000 - 1, + }; + + enum Int32BitShifting : int32_t { + // Shifting for more than 31 bits are undefined. Not tested. + int32BitShift1 = 1 << 31, + }; + + enum UInt32BitShifting : uint32_t { + uint32BitShift1 = 1 << 31, + }; + + enum Int64BitShifting : int64_t { + int64BitShift1 = 1l << 63, + }; + + enum UInt64BitShifting : uint64_t { + uint64BitShift1 = 1l << 63, + }; + + enum Precedence : int32_t { literal = 4, + neg = -4, literalL = -4L, + hex = 0xffffffff, + hexLong = 0xffffffffl, + hexLong2 = 0xfffffffff, simpleArithmetic = 4 + 1, - simpleIdentifier = literalL, - simpleIdentifier2 = literalL + simpleArithmetic, + simpleArithmetic2 = 2 + 3 - 4, + simpleBoolExpr = 1 == 4, + simpleLogical = 1 && 1, + simpleComp = 1 < 2, + boolExpr1 = !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0), boolExpr = 1 == 7 && !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0), + simpleBitShift = 1 << 2, + simpleBitShift2 = 4 >> 1, + simpleBitShiftNeg = 4 << -1, + simpleArithmeticRightShift = 1 << 31 >> 31, + simpleBitExpr = 1 | 16 >> 2, bitExpr = ~42 & (1 << 3 | 16 >> 2) ^ 7, arithmeticExpr = 2 + 3 - 4 * -7 / (10 % 3), - messyExpr = 2 + (-3&4 / 7), + messyExpr = 2 + (-3&4 / 7), paranExpr = (((((1 + 1))))), ternary = 1?2:3, ternary2 = 1&&2?3:4, - complicatedTernary2 = 1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3 - }; - // const float SIMPLE_FLOAT1 = 1e20; - // const float SIMPLE_FLOAT2 = 1e-10L; - // const float SIMPLE_FLOAT3 = 1.; - // const float SIMPLE_FLOAT4 = 1.e-2; - // const float SIMPLE_FLOAT5 = 3.1416; - // const float SIMPLE_FLOAT6 = .5f; - // const float SIMPLE_FLOAT7 = 0.5e-3L; - // struct expressionist_t { - // uint8_t[1 << 10] buffer; - // }; - // @param(name = "mask", normal = 1 << 5) - // setExpression(expressionist_t state, int32_t mask) generates (int32_t ret); + complicatedTernary2 = 1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3, + }; + + enum OperatorSanityCheck : int32_t { + // Should be all true / ones. + plus = (1 + 2) == 3, + minus = (8 - 9) == -1, + product = (9 * 9) == 81, + division = (29 / 3) == 9, + mod = (29 % 3) == 2, + bit_or = (0xC0010000 | 0xF00D) == (0xC001F00D), + bit_or2 = (10 | 6) == 14, + bit_and = (10 & 6) == 2, + bit_xor = (10 ^ 6) == 12, + lt1 = 6 < 10, + lt2 = (10 < 10) == 0, + gt1 = (6 > 10) == 0, + gt2 = (10 > 10) == 0, + gte1 = 19 >= 10, + gte2 = 10 >= 10, + lte1 = 5 <= 10, + lte2 = (19 <= 10) == 0, + ne1 = 19 != 10, + ne2 = (10 != 10) == 0, + lshift = (22 << 1) == 44, + rshift = (11 >> 1) == 5, + logor1 = (1 || 0) == 1, + logor2 = (1 || 1) == 1, + logor3 = (0 || 0) == 0, + logor4 = (0 || 1) == 1, + logand1 = (1 && 0) == 0, + logand2 = (1 && 1) == 1, + logand3 = (0 && 0) == 0, + logand4 = (0 && 1) == 0, + }; + }; |