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 __attribute__((far)) */
|
||||||
/* #define UNITY_PTR_ATTRIBUTE near */
|
/* #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 */
|
#endif /* UNITY_CONFIG_H */
|
||||||
|
@ -93,6 +93,8 @@ void UnityTestRunner(unityfunction* setup,
|
|||||||
UnityMalloc_StartTest();
|
UnityMalloc_StartTest();
|
||||||
UnityPointer_Init();
|
UnityPointer_Init();
|
||||||
|
|
||||||
|
UNITY_EXEC_TIME_START();
|
||||||
|
|
||||||
if (TEST_PROTECT())
|
if (TEST_PROTECT())
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
@ -418,6 +420,8 @@ void UnityConcludeFixtureTest(void)
|
|||||||
if (UnityFixture.Verbose)
|
if (UnityFixture.Verbose)
|
||||||
{
|
{
|
||||||
UnityPrint(" PASS");
|
UnityPrint(" PASS");
|
||||||
|
UNITY_EXEC_TIME_STOP();
|
||||||
|
UNITY_PRINT_EXEC_TIME();
|
||||||
UNITY_PRINT_EOL();
|
UNITY_PRINT_EOL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,6 +370,7 @@ void UnityConcludeTest(void)
|
|||||||
|
|
||||||
Unity.CurrentTestFailed = 0;
|
Unity.CurrentTestFailed = 0;
|
||||||
Unity.CurrentTestIgnored = 0;
|
Unity.CurrentTestIgnored = 0;
|
||||||
|
UNITY_EXEC_TIME_RESET();
|
||||||
UNITY_PRINT_EOL();
|
UNITY_PRINT_EOL();
|
||||||
UNITY_FLUSH_CALL();
|
UNITY_FLUSH_CALL();
|
||||||
}
|
}
|
||||||
@ -958,7 +959,7 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta,
|
|||||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||||
{
|
{
|
||||||
if (actual > expected)
|
if (actual > expected)
|
||||||
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
|
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
|
||||||
else
|
else
|
||||||
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta);
|
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta);
|
||||||
}
|
}
|
||||||
@ -1351,6 +1352,7 @@ void UnityBegin(const char* filename)
|
|||||||
Unity.TestIgnores = 0;
|
Unity.TestIgnores = 0;
|
||||||
Unity.CurrentTestFailed = 0;
|
Unity.CurrentTestFailed = 0;
|
||||||
Unity.CurrentTestIgnored = 0;
|
Unity.CurrentTestIgnored = 0;
|
||||||
|
UNITY_EXEC_TIME_RESET();
|
||||||
|
|
||||||
UNITY_CLR_DETAILS();
|
UNITY_CLR_DETAILS();
|
||||||
UNITY_OUTPUT_START();
|
UNITY_OUTPUT_START();
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNITY_EXCLUDE_TIME_H
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*-------------------------------------------------------
|
/*-------------------------------------------------------
|
||||||
* Guess Widths If Not Specified
|
* Guess Widths If Not Specified
|
||||||
*-------------------------------------------------------*/
|
*-------------------------------------------------------*/
|
||||||
@ -285,6 +289,44 @@ extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION;
|
|||||||
#define UNITY_OUTPUT_COMPLETE()
|
#define UNITY_OUTPUT_COMPLETE()
|
||||||
#endif
|
#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
|
* Footprint
|
||||||
*-------------------------------------------------------*/
|
*-------------------------------------------------------*/
|
||||||
@ -387,6 +429,10 @@ struct UNITY_STORAGE_T
|
|||||||
UNITY_COUNTER_TYPE TestIgnores;
|
UNITY_COUNTER_TYPE TestIgnores;
|
||||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||||
|
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||||
|
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
||||||
|
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
||||||
|
#endif
|
||||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
jmp_buf AbortFrame;
|
jmp_buf AbortFrame;
|
||||||
#endif
|
#endif
|
||||||
@ -590,6 +636,12 @@ extern const char UnityStrErr64[];
|
|||||||
#define TEST_ABORT() return
|
#define TEST_ABORT() return
|
||||||
#endif
|
#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__) */
|
/* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */
|
||||||
#ifndef RUN_TEST
|
#ifndef RUN_TEST
|
||||||
#ifdef __STDC_VERSION__
|
#ifdef __STDC_VERSION__
|
||||||
|
@ -99,6 +99,10 @@ void testUnitySizeInitializationReminder(void)
|
|||||||
UNITY_COUNTER_TYPE TestIgnores;
|
UNITY_COUNTER_TYPE TestIgnores;
|
||||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||||
|
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||||
|
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
||||||
|
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
||||||
|
#endif
|
||||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
jmp_buf AbortFrame;
|
jmp_buf AbortFrame;
|
||||||
#endif
|
#endif
|
||||||
@ -115,6 +119,10 @@ void testUnitySizeInitializationReminder(void)
|
|||||||
UNITY_COUNTER_TYPE TestIgnores;
|
UNITY_COUNTER_TYPE TestIgnores;
|
||||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||||
|
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||||
|
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
||||||
|
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
||||||
|
#endif
|
||||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
jmp_buf AbortFrame;
|
jmp_buf AbortFrame;
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user