mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-10-16 11:43:46 +08:00
Implement optional printing of execution time for each test
This commit is contained in:

committed by
Shreyas Balakrishna

parent
05daf95d4e
commit
cc909efed3
@ -236,4 +236,12 @@
|
||||
/* #define UNITY_PTR_ATTRIBUTE __attribute__((far)) */
|
||||
/* #define UNITY_PTR_ATTRIBUTE near */
|
||||
|
||||
/* Print execution time of each test when executed in verbose mode
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* TEST - PASS (10 ms)
|
||||
*/
|
||||
/* #define UNITY_INCLUDE_EXEC_TIME */
|
||||
|
||||
#endif /* UNITY_CONFIG_H */
|
||||
|
@ -93,6 +93,8 @@ void UnityTestRunner(unityfunction* setup,
|
||||
UnityMalloc_StartTest();
|
||||
UnityPointer_Init();
|
||||
|
||||
UNITY_EXEC_TIME_START();
|
||||
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
setup();
|
||||
@ -418,6 +420,8 @@ void UnityConcludeFixtureTest(void)
|
||||
if (UnityFixture.Verbose)
|
||||
{
|
||||
UnityPrint(" PASS");
|
||||
UNITY_EXEC_TIME_STOP();
|
||||
UNITY_PRINT_EXEC_TIME();
|
||||
UNITY_PRINT_EOL();
|
||||
}
|
||||
}
|
||||
|
@ -370,6 +370,7 @@ void UnityConcludeTest(void)
|
||||
|
||||
Unity.CurrentTestFailed = 0;
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
UNITY_EXEC_TIME_RESET();
|
||||
UNITY_PRINT_EOL();
|
||||
UNITY_FLUSH_CALL();
|
||||
}
|
||||
@ -1351,6 +1352,7 @@ void UnityBegin(const char* filename)
|
||||
Unity.TestIgnores = 0;
|
||||
Unity.CurrentTestFailed = 0;
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
UNITY_EXEC_TIME_RESET();
|
||||
|
||||
UNITY_CLR_DETAILS();
|
||||
UNITY_OUTPUT_START();
|
||||
|
@ -32,6 +32,10 @@
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXCLUDE_TIME_H
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Guess Widths If Not Specified
|
||||
*-------------------------------------------------------*/
|
||||
@ -285,6 +289,44 @@ extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION;
|
||||
#define UNITY_OUTPUT_COMPLETE()
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXEC_TIME_RESET
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
#define UNITY_EXEC_TIME_RESET()\
|
||||
Unity.CurrentTestStartTime = 0;\
|
||||
Unity.CurrentTestStopTime = 0;
|
||||
#else
|
||||
#define UNITY_EXEC_TIME_RESET()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXEC_TIME_START
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
#define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS();
|
||||
#else
|
||||
#define UNITY_EXEC_TIME_START()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXEC_TIME_START
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
#define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS();
|
||||
#else
|
||||
#define UNITY_EXEC_TIME_STOP()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_PRINT_EXEC_TIME
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
#define UNITY_PRINT_EXEC_TIME() \
|
||||
UnityPrint(" (");\
|
||||
UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime);
|
||||
UnityPrintNumberUnsigned(execTimeMs);\
|
||||
UnityPrint(" ms)");
|
||||
#else
|
||||
#define UNITY_PRINT_EXEC_TIME()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Footprint
|
||||
*-------------------------------------------------------*/
|
||||
@ -387,6 +429,10 @@ struct UNITY_STORAGE_T
|
||||
UNITY_COUNTER_TYPE TestIgnores;
|
||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
||||
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
||||
#endif
|
||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||
jmp_buf AbortFrame;
|
||||
#endif
|
||||
@ -590,6 +636,12 @@ extern const char UnityStrErr64[];
|
||||
#define TEST_ABORT() return
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXCLUDE_TIME_H
|
||||
#define UNITY_CLOCK_MS() (UNITY_COUNTER_TYPE)((clock() * 1000) / CLOCKS_PER_SEC)
|
||||
#else
|
||||
#define UNITY_CLOCK_MS()
|
||||
#endif
|
||||
|
||||
/* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */
|
||||
#ifndef RUN_TEST
|
||||
#ifdef __STDC_VERSION__
|
||||
|
@ -99,6 +99,10 @@ void testUnitySizeInitializationReminder(void)
|
||||
UNITY_COUNTER_TYPE TestIgnores;
|
||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
||||
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
||||
#endif
|
||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||
jmp_buf AbortFrame;
|
||||
#endif
|
||||
@ -115,6 +119,10 @@ void testUnitySizeInitializationReminder(void)
|
||||
UNITY_COUNTER_TYPE TestIgnores;
|
||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
||||
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
||||
#endif
|
||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||
jmp_buf AbortFrame;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user