- Add internal tests.
- Enable int32, stl_util and command line self tests.
Change-Id: I8546c6fa8e629da7c0a068eeffc88614f7ad1b4e
* \brief Modulo that generates the same sign as divisor and rounds toward
* negative infinity -- assuming c99 %-operator.
*/
-DE_INLINE deInt32 deInt32ModF(deInt32 n, deInt32 d)
+DE_INLINE deInt32 deInt32ModF (deInt32 n, deInt32 d)
{
deInt32 r = n%d;
if ((r > 0 && d < 0) || (r < 0 && d > 0)) r = r+d;
return r;
}
-DE_INLINE deBool deInt64InInt32Range(deInt64 x)
+DE_INLINE deBool deInt64InInt32Range (deInt64 x)
{
return ((x >= (-1ll<<31)) && (x <= ((1ll<<31)-1)));
}
+
+DE_INLINE deUint32 deBitMask32 (int leastSignificantBitNdx, int numBits)
+{
+ DE_ASSERT(deInRange32(leastSignificantBitNdx, 0, 32));
+ DE_ASSERT(deInRange32(numBits, 0, 32));
+ DE_ASSERT(deInRange32(leastSignificantBitNdx+numBits, 0, 32));
+
+ if (numBits < 32 && leastSignificantBitNdx < 32)
+ return ((1u<<numBits)-1u) << (deUint32)leastSignificantBitNdx;
+ else if (numBits == 0 && leastSignificantBitNdx == 32)
+ return 0u;
+ else
+ {
+ DE_ASSERT(numBits == 32 && leastSignificantBitNdx == 0);
+ return 0xFFFFFFFFu;
+ }
+}
+
+DE_INLINE deUint32 deUintMaxValue32 (int numBits)
+{
+ DE_ASSERT(deInRange32(numBits, 1, 32));
+ if (numBits < 32)
+ return ((1u<<numBits)-1u);
+ else
+ return 0xFFFFFFFFu;
+}
+
+DE_INLINE deInt32 deIntMaxValue32 (int numBits)
+{
+ DE_ASSERT(deInRange32(numBits, 1, 32));
+ if (numBits < 32)
+ return ((deInt32)1 << (numBits - 1)) - 1;
+ else
+ {
+ /* avoid undefined behavior of int overflow when shifting */
+ return 0x7FFFFFFF;
+ }
+}
+
+DE_INLINE deInt32 deIntMinValue32 (int numBits)
+{
+ DE_ASSERT(deInRange32(numBits, 1, 32));
+ if (numBits < 32)
+ return -((deInt32)1 << (numBits - 1));
+ else
+ {
+ /* avoid undefined behavior of int overflow when shifting */
+ return (deInt32)(-0x7FFFFFFF - 1);
+ }
+}
+
DE_END_EXTERN_C
#endif /* _DEINT32_H */
DE_TEST_ASSERT(exp == numBits);
}
}
+
+ DE_TEST_ASSERT(deBitMask32(0, 0) == 0);
+ DE_TEST_ASSERT(deBitMask32(8, 0) == 0);
+ DE_TEST_ASSERT(deBitMask32(16, 0) == 0);
+ DE_TEST_ASSERT(deBitMask32(31, 0) == 0);
+ DE_TEST_ASSERT(deBitMask32(32, 0) == 0);
+
+ DE_TEST_ASSERT(deBitMask32(0, 2) == 3);
+ DE_TEST_ASSERT(deBitMask32(0, 32) == 0xFFFFFFFFu);
+
+ DE_TEST_ASSERT(deBitMask32(16, 16) == 0xFFFF0000u);
+ DE_TEST_ASSERT(deBitMask32(31, 1) == 0x80000000u);
+ DE_TEST_ASSERT(deBitMask32(8, 4) == 0xF00u);
+
+ DE_TEST_ASSERT(deUintMaxValue32(1) == 1);
+ DE_TEST_ASSERT(deUintMaxValue32(2) == 3);
+ DE_TEST_ASSERT(deUintMaxValue32(32) == 0xFFFFFFFFu);
+
+ DE_TEST_ASSERT(deIntMaxValue32(1) == 0);
+ DE_TEST_ASSERT(deIntMaxValue32(2) == 1);
+ DE_TEST_ASSERT(deIntMaxValue32(32) == 0x7FFFFFFF);
+
+ DE_TEST_ASSERT(deIntMinValue32(1) == -1);
+ DE_TEST_ASSERT(deIntMinValue32(2) == -2);
+ DE_TEST_ASSERT(deIntMinValue32(32) == -0x7FFFFFFF - 1);
}
DE_END_EXTERN_C
deFree(cmdLine);
}
-#if defined(DE_DEBUG)
static void testParse (const char* cmdLine, const char* const* refArgs, int numArgs)
{
deCommandLine* parsedCmdLine = deCommandLine_parse(cmdLine);
testParse(cmdLine, ref, DE_LENGTH_OF_ARRAY(ref));
}
}
-#endif
deCommandLine* deCommandLine_parse (const char* cmdLine);
void deCommandLine_destroy (deCommandLine* cmdLine);
-#if defined(DE_DEBUG)
void deCommandLine_selfTest (void);
-#endif
DE_END_EXTERN_C
// deutil
#include "deTimerTest.h"
+#include "deCommandLine.h"
+
+// debase
+#include "deInt32.h"
// decpp
#include "deBlockBuffer.hpp"
#include "deArrayBuffer.hpp"
#include "deStringUtil.hpp"
#include "deSpinBarrier.hpp"
+#include "deSTLUtil.hpp"
namespace dit
{
void init (void)
{
- addChild(new SelfCheckCase(m_testCtx, "timer", "deTimer_selfTest()", deTimer_selfTest));
+ addChild(new SelfCheckCase(m_testCtx, "timer", "deTimer_selfTest()", deTimer_selfTest));
+ addChild(new SelfCheckCase(m_testCtx, "command_line", "deCommandLine_selfTest()", deCommandLine_selfTest));
+ }
+};
+
+class DebaseTests : public tcu::TestCaseGroup
+{
+public:
+ DebaseTests (tcu::TestContext& testCtx)
+ : tcu::TestCaseGroup(testCtx, "debase", "debase self-tests")
+ {
+ }
+
+ void init (void)
+ {
+ addChild(new SelfCheckCase(m_testCtx, "int32", "deInt32_selfTest()", deInt32_selfTest));
}
};
addChild(new SelfCheckCase(m_testCtx, "array_buffer", "de::ArrayBuffer_selfTest()", de::ArrayBuffer_selfTest));
addChild(new SelfCheckCase(m_testCtx, "string_util", "de::StringUtil_selfTest()", de::StringUtil_selfTest));
addChild(new SelfCheckCase(m_testCtx, "spin_barrier", "de::SpinBarrier_selfTest()", de::SpinBarrier_selfTest));
+ addChild(new SelfCheckCase(m_testCtx, "stl_util", "de::STLUtil_selfTest()", de::STLUtil_selfTest));
}
};
addChild(new DepoolTests (m_testCtx));
addChild(new DethreadTests (m_testCtx));
addChild(new DeutilTests (m_testCtx));
+ addChild(new DebaseTests (m_testCtx));
addChild(new DecppTests (m_testCtx));
}