Skip to content

Commit

Permalink
Print unit test execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Misic authored and jciberlin committed Apr 2, 2024
1 parent 95e6a0e commit b25639c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endif

UNITY_ROOT=Tests/Unity

CFLAGS=-std=c99
CFLAGS=-std=c99 -std=gnu99
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Wpointer-arith
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions Tests/unity_config.h
Original file line number Diff line number Diff line change
@@ -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 <time.h>
#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 <time.h>
#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_ */

0 comments on commit b25639c

Please sign in to comment.