From 776264ce36dbdfe6197b8fcc2d9bd2ff839e1158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Mi=C5=A1i=C4=87?= Date: Tue, 2 Apr 2024 13:35:33 +0200 Subject: [PATCH] Print unit test execution time --- Makefile | 6 ++++-- Tests/unity_config.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Tests/unity_config.h diff --git a/Makefile b/Makefile index c0f70f5..cd4db59 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ endif UNITY_ROOT=Tests/Unity -CFLAGS=-std=c99 +CFLAGS=-std=c99 -std=gnu99 CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Wpointer-arith @@ -148,12 +148,14 @@ INC_DIRS_CODE= \ -IInc/crc/crc16_variants \ -IInc/crc/crc32_variants \ -IInc/crypto \ - -IInc/sort + -IInc/sort \ + -ITests/ INC_DIRS=$(INC_DIRS_CODE) -I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src SYMBOLS = -DUNITY_FIXTURE_NO_EXTRAS SYMBOLS += -DUNITY_INCLUDE_DOUBLE SYMBOLS += -DUNITY_DOUBLE_PRECISION=1e-12 +SYMBOLS += -DUNITY_INCLUDE_CONFIG_H ####################################### # Astyle diff --git a/Tests/unity_config.h b/Tests/unity_config.h new file mode 100644 index 0000000..76b5d1c --- /dev/null +++ b/Tests/unity_config.h @@ -0,0 +1,34 @@ +#ifndef TESTS_UNITY_UNITY_CONFIG_H_ +#define TESTS_UNITY_UNITY_CONFIG_H_ + +#define UNITY_INCLUDE_EXEC_TIME +#define UNITY_CLOCK_MS + +#if defined(_WIN32) +#include +#define UNITY_TIME_TYPE clock_t +#define UNITY_GET_TIME(t) t = (clock_t)((clock() * 1000) / CLOCKS_PER_SEC) +#define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) +#define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) +#define UNITY_PRINT_EXEC_TIME() { \ + UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ + UnityPrint(" ("); \ + UnityPrintNumberUnsigned(execTimeMs); \ + UnityPrint(" ms)"); \ + } +#elif defined(__unix__) || defined(__APPLE__) +#include +#define UNITY_TIME_TYPE struct timespec +#define UNITY_GET_TIME(t) clock_gettime(CLOCK_MONOTONIC, &t) +#define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) +#define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) +#define UNITY_PRINT_EXEC_TIME() { \ + UNITY_UINT execTimeNs = ((Unity.CurrentTestStopTime.tv_sec - Unity.CurrentTestStartTime.tv_sec) * 1000L); \ + execTimeNs += (Unity.CurrentTestStopTime.tv_nsec - Unity.CurrentTestStartTime.tv_nsec); \ + UnityPrint(" ("); \ + UnityPrintNumberUnsigned(execTimeNs); \ + UnityPrint(" ns)"); \ + } +#endif + +#endif /* TESTS_UNITY_UNITY_CONFIG_H_ */