提交 cc909efe 编写于 作者: B balaksh 提交者: Shreyas Balakrishna

Implement optional printing of execution time for each test

上级 05daf95d
......@@ -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();
}
......@@ -958,7 +959,7 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta,
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
else
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta);
}
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册