mirror of
https://github.com/espressif/openthread.git
synced 2026-07-26 22:09:05 +00:00
[unit-test] add a common function to dump buffer content (#4367)
This commit updates `test_utils.hpp/cpp` to include a common helper function `DumpBuffer` to print the content of a buffer (as hex and char string) to screen. It also removes unused helper functions and use of STL header files and types.
This commit is contained in:
committed by
Jonathan Hui
parent
91e8903699
commit
eaf2e7b9f7
@@ -26,13 +26,11 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "ncp/spinel_encoder.hpp"
|
||||
|
||||
#include "test_util.h"
|
||||
#include "test_util.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Ncp {
|
||||
@@ -42,47 +40,6 @@ enum
|
||||
kTestBufferSize = 800,
|
||||
};
|
||||
|
||||
// Dump the buffer content to screen.
|
||||
void DumpBuffer(const char *aTextMessage, uint8_t *aBuffer, uint16_t aBufferLength)
|
||||
{
|
||||
enum
|
||||
{
|
||||
kBytesPerLine = 32, // Number of bytes per line.
|
||||
};
|
||||
|
||||
char charBuff[kBytesPerLine + 1];
|
||||
uint16_t counter;
|
||||
uint8_t byte;
|
||||
|
||||
printf("\n%s - len = %u\n ", aTextMessage, aBufferLength);
|
||||
|
||||
counter = 0;
|
||||
|
||||
while (aBufferLength--)
|
||||
{
|
||||
byte = *aBuffer++;
|
||||
printf("%02X ", byte);
|
||||
charBuff[counter] = isprint(byte) ? static_cast<char>(byte) : '.';
|
||||
counter++;
|
||||
|
||||
if (counter == kBytesPerLine)
|
||||
{
|
||||
charBuff[counter] = 0;
|
||||
printf(" %s\n ", charBuff);
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
charBuff[counter] = 0;
|
||||
|
||||
while (counter++ < kBytesPerLine)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
printf(" %s\n", charBuff);
|
||||
}
|
||||
|
||||
otError ReadFrame(NcpFrameBuffer &aNcpBuffer, uint8_t *aFrame, uint16_t &aFrameLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
Reference in New Issue
Block a user