Add compile option to disable floating point usage (#114)
This commit adds the option to disable floating point processing in
QCBOR. To disable, the USEFULBUF_DISABLE_ALL_FLOAT preprocessor macro
needs to be defined.
e.g.:
$ make CMD_LINE="-DUSEFULBUF_DISABLE_ALL_FLOAT"
This removes the capability (and the code) of decoding floating point
types. The type is still recognised, so a meaningful
QCBOR_ERR_ALL_FLOAT_DISABLED error is returned when a floating point value
is encountered in a decoded qcbor. From the encoding interface the
floating point encoding functions are removed.
Change-Id: I371769246f7d83354607de9bce1e7998b8c536a1
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/test/UsefulBuf_Tests.c b/test/UsefulBuf_Tests.c
index 264fbca..b6914d2 100644
--- a/test/UsefulBuf_Tests.c
+++ b/test/UsefulBuf_Tests.c
@@ -1,6 +1,7 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
Copyright (c) 2018-2021, Laurence Lundblade.
+ Copyright (c) 2021, Arm Limited.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -637,16 +638,20 @@
const uint64_t u64 = 1984738472938472;
const uint16_t u16 = 40000;
const uint8_t u8 = 9;
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
const float f = (float)314.15;
const double d = 2.1e10;
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
UsefulOutBuf_AppendUint32(&UOB, u32); // Also tests UsefulOutBuf_InsertUint64 and UsefulOutBuf_GetEndPosition
UsefulOutBuf_AppendUint64(&UOB, u64); // Also tests UsefulOutBuf_InsertUint32
UsefulOutBuf_AppendUint16(&UOB, u16); // Also tests UsefulOutBuf_InsertUint16
UsefulOutBuf_AppendByte(&UOB, u8);
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
UsefulOutBuf_AppendFloat(&UOB, f); // Also tests UsefulOutBuf_InsertFloat
UsefulOutBuf_AppendDouble(&UOB, d); // Also tests UsefulOutBuf_InsertDouble
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
const UsefulBufC O = UsefulOutBuf_OutUBuf(&UOB);
if(UsefulBuf_IsNULLC(O))
@@ -678,12 +683,14 @@
if(UsefulInputBuf_GetByte(&UIB) != u8) {
return "u8 out then in failed";
}
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
if(UsefulInputBuf_GetFloat(&UIB) != f) {
return "float out then in failed";
}
if(UsefulInputBuf_GetDouble(&UIB) != d) {
return "double out then in failed";
}
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
// Reset and go again for a few more tests
UsefulInputBuf_Init(&UIB, O);
@@ -696,6 +703,7 @@
return "Four compare failed";
}
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
if(UsefulInputBuf_BytesUnconsumed(&UIB) != 23){
return "Wrong number of unconsumed bytes";
}
@@ -707,6 +715,18 @@
if(UsefulInputBuf_BytesAvailable(&UIB, 24)){
return "Wrong number of bytes available II";
}
+#else /* USEFULBUF_DISABLE_ALL_FLOAT */
+ if(UsefulInputBuf_BytesUnconsumed(&UIB) != 11){
+ return "Wrong number of unconsumed bytes";
+ }
+ if(!UsefulInputBuf_BytesAvailable(&UIB, 11)){
+ return "Wrong number of bytes available I";
+ }
+
+ if(UsefulInputBuf_BytesAvailable(&UIB, 12)){
+ return "Wrong number of bytes available II";
+ }
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
UsefulInputBuf_Seek(&UIB, 0);
@@ -737,6 +757,7 @@
}
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
const char *UBUTest_CopyUtil(void)
{
if(UsefulBufUtil_CopyFloatToUint32(65536.0F) != 0x47800000) {
@@ -757,6 +778,7 @@
return NULL;
}
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
diff --git a/test/UsefulBuf_Tests.h b/test/UsefulBuf_Tests.h
index 976de62..0d06206 100644
--- a/test/UsefulBuf_Tests.h
+++ b/test/UsefulBuf_Tests.h
@@ -1,6 +1,7 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
Copyright (c) 2018, Laurence Lundblade.
+ Copyright (c) 2021, Arm Limited.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -45,6 +46,8 @@
const char * UIBTest_IntegerFormat(void);
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
const char * UBUTest_CopyUtil(void);
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
#endif
diff --git a/test/float_tests.c b/test/float_tests.c
index 12f34fd..99297c0 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -2,6 +2,7 @@
float_tests.c -- tests for float and conversion to/from half-precision
Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
@@ -648,6 +649,7 @@
0x18, 0x6A,
0xFA, 0x00, 0x00, 0x00, 0x00};
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
static const uint8_t spExpectedFloatsNoHalf[] = {
0x8B,
0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -749,6 +751,7 @@
return 0;
}
}
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
int32_t GeneralFloatDecodeTests()
@@ -766,133 +769,164 @@
return -1;
}
-#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != 0.0) {
+ if(uErr != FLOAT_ERR_CODE_NO_HALF_PREC(QCBOR_SUCCESS)
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != 0.0
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
+ ) {
return -2;
}
-#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
- uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_ERR_HALF_PRECISION_DISABLED) {
- return -3;
- }
-#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != 3.14) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != 3.14
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -4;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != 0.0) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != 0.0
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -5;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- !isnan(Item.val.dfnum)) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || !isnan(Item.val.dfnum)
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -6;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != INFINITY) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != INFINITY
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -7;
}
-#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
- // Tests for normal config
+// Tests for normal config
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != 0.0) {
+ if(uErr != FLOAT_ERR_CODE_NO_HALF_PREC(QCBOR_SUCCESS)
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != 0.0
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
+ ) {
return -8;
}
-#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
- // Tests for preferred serialization turned off
- uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_ERR_HALF_PRECISION_DISABLED) {
- return -13;
- }
-#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- CHECK_EXPECTED_DOUBLE(3.14, Item.val.dfnum)) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || CHECK_EXPECTED_DOUBLE(3.14, Item.val.dfnum)
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -9;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != 0.0) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != 0.0
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -10;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- !isnan(Item.val.dfnum)) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || !isnan(Item.val.dfnum)
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -11;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_DOUBLE ||
- Item.val.dfnum != INFINITY) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_DOUBLE
+ || Item.val.dfnum != INFINITY
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -12;
}
#else /* QCBOR_DISABLE_FLOAT_HW_USE */
// Tests for floating point HW use disabled
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_FLOAT ||
- CHECK_EXPECTED_DOUBLE(3.14, Item.val.fnum)) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_FLOAT
+ || CHECK_EXPECTED_DOUBLE(3.14, Item.val.fnum)
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -9;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_FLOAT ||
- Item.val.fnum != 0.0) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_FLOAT
+ || Item.val.fnum != 0.0
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -10;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_FLOAT ||
- !isnan(Item.val.fnum)) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_FLOAT
+ || !isnan(Item.val.fnum)
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -11;
}
uErr = QCBORDecode_GetNext(&DC, &Item);
- if(uErr != QCBOR_SUCCESS ||
- Item.uDataType != QCBOR_TYPE_FLOAT ||
- Item.val.fnum != INFINITY) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS)
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.uDataType != QCBOR_TYPE_FLOAT
+ || Item.val.fnum != INFINITY
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -12;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
+
/* Sufficent test coverage. Don't need to decode the rest */
// Now tests for spiffy decode
TestData = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedFloats);
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
double d;
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
QCBORDecode_Init(&DC, TestData, 0);
QCBORDecode_EnterArray(&DC, NULL);
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
// Spiffy decode tests for normal full float support
@@ -1135,6 +1169,7 @@
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
return 0;
}
diff --git a/test/half_to_double_from_rfc7049.c b/test/half_to_double_from_rfc7049.c
index fce90f7..d4fded6 100644
--- a/test/half_to_double_from_rfc7049.c
+++ b/test/half_to_double_from_rfc7049.c
@@ -3,6 +3,8 @@
Copyright (c) 2013 IETF Trust and the persons identified as the
document authors. All rights reserved.
+ Copyright (c) 2021, Arm Limited. All rights reserved.
+
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of
@@ -33,6 +35,7 @@
#include <math.h>
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
double decode_half(unsigned char *halfp) {
int half = (halfp[0] << 8) + halfp[1];
int exp = (half >> 10) & 0x1f;
@@ -43,3 +46,4 @@
else val = mant == 0 ? INFINITY : NAN;
return half & 0x8000 ? -val : val;
}
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
diff --git a/test/half_to_double_from_rfc7049.h b/test/half_to_double_from_rfc7049.h
index 4642f04..6318f80 100644
--- a/test/half_to_double_from_rfc7049.h
+++ b/test/half_to_double_from_rfc7049.h
@@ -2,6 +2,7 @@
half_to_double_from_rfc7049.h -- interface to IETF float conversion code.
Copyright (c) 2018-2020, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
@@ -13,6 +14,8 @@
#ifndef half_to_double_from_rfc7049_h
#define half_to_double_from_rfc7049_h
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
double decode_half(unsigned char *halfp);
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
#endif /* half_to_double_from_rfc7049_h */
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 4b20e71..aebe492 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1,6 +1,7 @@
/*==============================================================================
Copyright (c) 2016-2018, The Linux Foundation.
Copyright (c) 2018-2021, Laurence Lundblade.
+ Copyright (c) 2021, Arm Limited.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -2418,8 +2419,11 @@
return -4;
}
if(Item.uDataType != QCBOR_TYPE_DATE_EPOCH ||
- Item.val.epochDate.nSeconds != 1400000000 ||
- Item.val.epochDate.fSecondsFraction != 0 ) {
+ Item.val.epochDate.nSeconds != 1400000000
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || Item.val.epochDate.fSecondsFraction != 0
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -5;
}
@@ -2436,7 +2440,9 @@
}
if(Item.uDataType != QCBOR_TYPE_DATE_EPOCH ||
Item.val.epochDate.nSeconds != 1400000001 ||
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
Item.val.epochDate.fSecondsFraction != 0 ||
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
!QCBORDecode_IsTagged(&DCtx, &Item, CBOR_TAG_ENC_AS_B64)) {
return -8;
}
@@ -2446,14 +2452,18 @@
return -9;
}
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
// Epoch date in float format with fractional seconds
if((uError = QCBORDecode_GetNext(&DCtx, &Item))) {
return -10;
}
if(Item.uDataType != QCBOR_TYPE_DATE_EPOCH ||
- Item.val.epochDate.nSeconds != 1 ||
- CHECK_EXPECTED_DOUBLE(Item.val.epochDate.fSecondsFraction, 0.1 )) {
+ Item.val.epochDate.nSeconds != 1
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+ || CHECK_EXPECTED_DOUBLE(Item.val.epochDate.fSecondsFraction, 0.1 )
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+ ) {
return -11;
}
@@ -2526,6 +2536,7 @@
#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
return 0;
}
@@ -2655,11 +2666,11 @@
QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
uError = QCBORDecode_GetAndResetError(&DC);
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uError != QCBOR_ERR_DATE_OVERFLOW) {
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_DATE_OVERFLOW)) {
return 1111;
}
#else
- if(uError != QCBOR_ERR_FLOAT_DATE_DISABLED) {
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_FLOAT_DATE_DISABLED)) {
return 1112;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
@@ -2676,12 +2687,12 @@
uError = QCBORDecode_GetAndResetError(&DC);
#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- const QCBORError uExpectedforHalfMinusInfinity = QCBOR_ERR_DATE_OVERFLOW;
+ const QCBORError uExpectedforHalfMinusInfinity = FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_DATE_OVERFLOW);
#else /* QCBOR_DISABLE_FLOAT_HW_USE */
- const QCBORError uExpectedforHalfMinusInfinity = QCBOR_ERR_FLOAT_DATE_DISABLED;
+ const QCBORError uExpectedforHalfMinusInfinity = FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_FLOAT_DATE_DISABLED);
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
- const QCBORError uExpectedforHalfMinusInfinity = QCBOR_ERR_HALF_PRECISION_DISABLED;
+ const QCBORError uExpectedforHalfMinusInfinity = FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_HALF_PRECISION_DISABLED);
#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
if(uError != uExpectedforHalfMinusInfinity) {
return 2;
@@ -2715,7 +2726,7 @@
}
#else /* QCBOR_DISABLE_FLOAT_HW_USE */
uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != QCBOR_ERR_FLOAT_DATE_DISABLED) {
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_FLOAT_DATE_DISABLED)) {
return 102;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
@@ -2729,7 +2740,7 @@
}
#else /* QCBOR_DISABLE_FLOAT_HW_USE */
uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != QCBOR_ERR_FLOAT_DATE_DISABLED) {
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_FLOAT_DATE_DISABLED)) {
return 112;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
@@ -2743,7 +2754,7 @@
}
#else /* QCBOR_DISABLE_FLOAT_HW_USE */
uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != QCBOR_ERR_FLOAT_DATE_DISABLED) {
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_FLOAT_DATE_DISABLED)) {
return 104;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
@@ -5483,11 +5494,11 @@
QCBORDecode_GetEpochDateInMapN(&DCtx, 0x04, QCBOR_TAG_REQUIREMENT_TAG, &nInt);
uErr = QCBORDecode_GetAndResetError(&DCtx);
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uErr != QCBOR_ERR_DATE_OVERFLOW) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_DATE_OVERFLOW)) {
return 2024;
}
#else
- if(uErr != QCBOR_ERR_FLOAT_DATE_DISABLED) {
+ if(uErr != FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_FLOAT_DATE_DISABLED)) {
return 2027;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
@@ -5831,14 +5842,14 @@
{(uint8_t[]){0xfb, 0x40, 0x59, 0x13, 0x33, 0x33, 0x33, 0x33, 0x33}, 9},
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
100L,
- QCBOR_SUCCESS,
+ FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS),
100ULL,
- QCBOR_SUCCESS,
+ FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS),
#else /* QCBOR_DISABLE_FLOAT_HW_USE */
0,
- QCBOR_ERR_HW_FLOAT_DISABLED,
+ FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_HW_FLOAT_DISABLED),
0,
- QCBOR_ERR_HW_FLOAT_DISABLED,
+ FLOAT_ERR_CODE_NO_FLOAT(QCBOR_ERR_HW_FLOAT_DISABLED),
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
100.3,
QCBOR_SUCCESS
@@ -5846,50 +5857,32 @@
{
"Floating point value NaN 0xfa7fc00000",
{(uint8_t[]){0xfa, 0x7f, 0xc0, 0x00, 0x00}, 5},
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
0,
- QCBOR_ERR_FLOAT_EXCEPTION,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
0,
- QCBOR_ERR_FLOAT_EXCEPTION,
-#else /* QCBOR_DISABLE_FLOAT_HW_USE */
- 0,
- QCBOR_ERR_HW_FLOAT_DISABLED,
- 0,
- QCBOR_ERR_HW_FLOAT_DISABLED,
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
NAN,
QCBOR_SUCCESS
},
{
"half-precision Floating point value -4",
{(uint8_t[]){0xf9, 0xc4, 0x00}, 3},
-#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
// Normal case with all enabled.
-4,
- QCBOR_SUCCESS,
+ FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_SUCCESS),
0,
- QCBOR_ERR_NUMBER_SIGN_CONVERSION,
+ FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_ERR_NUMBER_SIGN_CONVERSION),
-4.0,
- QCBOR_SUCCESS
-#else /* QCBOR_DISABLE_FLOAT_HW_USE */
- // Float HW disabled
- -4,
- QCBOR_ERR_HW_FLOAT_DISABLED, // Can't convert to integer
+ FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_SUCCESS)
+#else /* USEFULBUF_DISABLE_ALL_FLOAT */
0,
- QCBOR_ERR_HW_FLOAT_DISABLED, // Can't convert to integer
- -4.0,
- QCBOR_SUCCESS // Uses ieee754.h to conver, not HW
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-#else /* QCBOR_DISABLE_PREFERRED_FLOAT */
- // Half-precision disabled
- -4,
- QCBOR_ERR_HALF_PRECISION_DISABLED,
+ QCBOR_ERR_ALL_FLOAT_DISABLED,
0,
- QCBOR_ERR_HALF_PRECISION_DISABLED,
- -4.0,
- QCBOR_ERR_HALF_PRECISION_DISABLED
-#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
+ QCBOR_ERR_ALL_FLOAT_DISABLED,
+ 0,
+ QCBOR_ERR_ALL_FLOAT_DISABLED,
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
},
{
"Decimal fraction 3/10",
@@ -5913,17 +5906,10 @@
{
"+inifinity",
{(uint8_t[]){0xfa, 0x7f, 0x80, 0x00, 0x00}, 5},
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
0,
- QCBOR_ERR_FLOAT_EXCEPTION,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
0,
- QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
-#else /* QCBOR_DISABLE_FLOAT_HW_USE */
- 0,
- QCBOR_ERR_HW_FLOAT_DISABLED,
- 0,
- QCBOR_ERR_HW_FLOAT_DISABLED,
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW),
INFINITY,
QCBOR_SUCCESS
},
@@ -7123,6 +7109,7 @@
return 4;
}
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
double uDouble;
QCBORDecode_GetDoubleConvertAllInMapSZ(&DCtx,
"label2",
@@ -7140,6 +7127,7 @@
return 7;
}
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
QCBORDecode_ExitMap(&DCtx);
diff --git a/test/run_tests.c b/test/run_tests.c
index 53d83f6..be2582f 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -2,6 +2,7 @@
run_tests.c -- test aggregator and results reporting
Copyright (c) 2018-2021, Laurence Lundblade. All rights reserved.
+ Copyright (c) 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
@@ -51,7 +52,9 @@
static test_entry2 s_tests2[] = {
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
TEST_ENTRY(UBUTest_CopyUtil),
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
TEST_ENTRY(UOBTest_NonAdversarial),
TEST_ENTRY(TestBasicSanity),
TEST_ENTRY(UOBTest_BoundaryConditionsTest),
@@ -114,7 +117,9 @@
TEST_ENTRY(DoubleAsSmallestTest),
TEST_ENTRY(HalfPrecisionAgainstRFCCodeTest),
#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
TEST_ENTRY(GeneralFloatEncodeTests),
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
TEST_ENTRY(GeneralFloatDecodeTests),
TEST_ENTRY(BstrWrapTest),
TEST_ENTRY(BstrWrapErrorTest),