From 89cc2ef4325f0c7a7afba521506a39986b8d3d2c Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sat, 12 Dec 2020 11:05:21 -0800 Subject: [PATCH] [test] add 'otPlatEntropyGet()' using TRNG for unit test (#5945) --- tests/unit/test_platform.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index f4392b5e6..99f156b5f 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -28,6 +28,7 @@ #include "test_platform.h" +#include #include bool g_testPlatAlarmSet = false; @@ -380,10 +381,29 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) VerifyOrExit(aOutput, error = OT_ERROR_INVALID_ARGS); +#if __SANITIZE_ADDRESS__ == 0 + { + FILE * file = nullptr; + size_t readLength; + + file = fopen("/dev/urandom", "rb"); + VerifyOrExit(file != nullptr, error = OT_ERROR_FAILED); + + readLength = fread(aOutput, 1, aOutputLength, file); + + if (readLength != aOutputLength) + { + error = OT_ERROR_FAILED; + } + + fclose(file); + } +#else for (uint16_t length = 0; length < aOutputLength; length++) { aOutput[length] = (uint8_t)rand(); } +#endif exit: return error;