mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-22 01:47:26 +08:00
Merge pull request #377 from elliot-gawthrop/execution-time-embedded
Execution time improvements
This commit is contained in:
@ -300,6 +300,7 @@ class UnityTestRunnerGenerator
|
|||||||
output.puts(' Unity.CurrentTestLineNumber = TestLineNum; \\')
|
output.puts(' Unity.CurrentTestLineNumber = TestLineNum; \\')
|
||||||
output.puts(' if (UnityTestMatches()) { \\') if @options[:cmdline_args]
|
output.puts(' if (UnityTestMatches()) { \\') if @options[:cmdline_args]
|
||||||
output.puts(' Unity.NumberOfTests++; \\')
|
output.puts(' Unity.NumberOfTests++; \\')
|
||||||
|
output.puts(' UNITY_EXEC_TIME_START(); \\')
|
||||||
output.puts(' CMock_Init(); \\') unless used_mocks.empty?
|
output.puts(' CMock_Init(); \\') unless used_mocks.empty?
|
||||||
output.puts(' UNITY_CLR_DETAILS(); \\') unless used_mocks.empty?
|
output.puts(' UNITY_CLR_DETAILS(); \\') unless used_mocks.empty?
|
||||||
output.puts(' if (TEST_PROTECT()) \\')
|
output.puts(' if (TEST_PROTECT()) \\')
|
||||||
@ -316,6 +317,7 @@ class UnityTestRunnerGenerator
|
|||||||
output.puts(' CMock_Verify(); \\') unless used_mocks.empty?
|
output.puts(' CMock_Verify(); \\') unless used_mocks.empty?
|
||||||
output.puts(' } \\')
|
output.puts(' } \\')
|
||||||
output.puts(' CMock_Destroy(); \\') unless used_mocks.empty?
|
output.puts(' CMock_Destroy(); \\') unless used_mocks.empty?
|
||||||
|
output.puts(' UNITY_EXEC_TIME_STOP(); \\')
|
||||||
output.puts(' UnityConcludeTest(); \\')
|
output.puts(' UnityConcludeTest(); \\')
|
||||||
output.puts(' } \\') if @options[:cmdline_args]
|
output.puts(' } \\') if @options[:cmdline_args]
|
||||||
output.puts("}\n")
|
output.puts("}\n")
|
||||||
|
@ -599,7 +599,7 @@ void UnityConcludeTest(void)
|
|||||||
|
|
||||||
Unity.CurrentTestFailed = 0;
|
Unity.CurrentTestFailed = 0;
|
||||||
Unity.CurrentTestIgnored = 0;
|
Unity.CurrentTestIgnored = 0;
|
||||||
UNITY_EXEC_TIME_RESET();
|
UNITY_PRINT_EXEC_TIME();
|
||||||
UNITY_PRINT_EOL();
|
UNITY_PRINT_EOL();
|
||||||
UNITY_FLUSH_CALL();
|
UNITY_FLUSH_CALL();
|
||||||
}
|
}
|
||||||
@ -1712,6 +1712,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
|
|||||||
Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
|
Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
|
||||||
Unity.NumberOfTests++;
|
Unity.NumberOfTests++;
|
||||||
UNITY_CLR_DETAILS();
|
UNITY_CLR_DETAILS();
|
||||||
|
UNITY_EXEC_TIME_START();
|
||||||
if (TEST_PROTECT())
|
if (TEST_PROTECT())
|
||||||
{
|
{
|
||||||
setUp();
|
setUp();
|
||||||
@ -1721,6 +1722,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
|
|||||||
{
|
{
|
||||||
tearDown();
|
tearDown();
|
||||||
}
|
}
|
||||||
|
UNITY_EXEC_TIME_STOP();
|
||||||
UnityConcludeTest();
|
UnityConcludeTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1735,7 +1737,6 @@ 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();
|
||||||
|
@ -40,10 +40,6 @@
|
|||||||
#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
|
||||||
*-------------------------------------------------------*/
|
*-------------------------------------------------------*/
|
||||||
@ -299,42 +295,67 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
|
|||||||
#define UNITY_OUTPUT_COMPLETE()
|
#define UNITY_OUTPUT_COMPLETE()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_EXEC_TIME_RESET
|
|
||||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||||
#define UNITY_EXEC_TIME_RESET()\
|
#if !defined(UNITY_EXEC_TIME_START) && \
|
||||||
Unity.CurrentTestStartTime = 0;\
|
!defined(UNITY_EXEC_TIME_STOP) && \
|
||||||
Unity.CurrentTestStopTime = 0;
|
!defined(UNITY_PRINT_EXEC_TIME) && \
|
||||||
#else
|
!defined(UNITY_TIME_TYPE)
|
||||||
#define UNITY_EXEC_TIME_RESET()
|
/* If none any of these macros are defined then try to provide a default implementation */
|
||||||
#endif
|
|
||||||
|
#if defined(UNITY_CLOCK_MS)
|
||||||
|
/* This is a simple way to get a default implementation on platforms that support getting a millisecond counter */
|
||||||
|
#define UNITY_TIME_TYPE UNITY_UINT
|
||||||
|
#define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS()
|
||||||
|
#define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS()
|
||||||
|
#define UNITY_PRINT_EXEC_TIME() { \
|
||||||
|
UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \
|
||||||
|
UnityPrint(" ("); \
|
||||||
|
UnityPrintNumberUnsigned(execTimeMs); \
|
||||||
|
UnityPrint(" ms)"); \
|
||||||
|
}
|
||||||
|
#elif 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__)
|
||||||
|
#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 execTimeMs = ((Unity.CurrentTestStopTime.tv_sec - Unity.CurrentTestStartTime.tv_sec) * 1000L); \
|
||||||
|
execTimeMs += ((Unity.CurrentTestStopTime.tv_nsec - Unity.CurrentTestStartTime.tv_nsec) / 1000000L); \
|
||||||
|
UnityPrint(" ("); \
|
||||||
|
UnityPrintNumberUnsigned(execTimeMs); \
|
||||||
|
UnityPrint(" ms)"); \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_EXEC_TIME_START
|
#ifndef UNITY_EXEC_TIME_START
|
||||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
#define UNITY_EXEC_TIME_START() do{}while(0)
|
||||||
#define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS();
|
|
||||||
#else
|
|
||||||
#define UNITY_EXEC_TIME_START()
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_EXEC_TIME_STOP
|
#ifndef UNITY_EXEC_TIME_STOP
|
||||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
#define UNITY_EXEC_TIME_STOP() do{}while(0)
|
||||||
#define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS();
|
|
||||||
#else
|
|
||||||
#define UNITY_EXEC_TIME_STOP()
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNITY_TIME_TYPE
|
||||||
|
#define UNITY_TIME_TYPE UNITY_UINT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_PRINT_EXEC_TIME
|
#ifndef UNITY_PRINT_EXEC_TIME
|
||||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
#define UNITY_PRINT_EXEC_TIME() do{}while(0)
|
||||||
#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
|
#endif
|
||||||
|
|
||||||
/*-------------------------------------------------------
|
/*-------------------------------------------------------
|
||||||
@ -451,8 +472,8 @@ struct UNITY_STORAGE_T
|
|||||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||||
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
UNITY_TIME_TYPE CurrentTestStartTime;
|
||||||
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
UNITY_TIME_TYPE CurrentTestStopTime;
|
||||||
#endif
|
#endif
|
||||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
jmp_buf AbortFrame;
|
jmp_buf AbortFrame;
|
||||||
@ -671,12 +692,6 @@ 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__
|
||||||
|
@ -104,8 +104,8 @@ void testUnitySizeInitializationReminder(void)
|
|||||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||||
#ifdef UNITY_INCLUDE_EXEC_TIME
|
#ifdef UNITY_INCLUDE_EXEC_TIME
|
||||||
UNITY_COUNTER_TYPE CurrentTestStartTime;
|
UNITY_TIME_TYPE CurrentTestStartTime;
|
||||||
UNITY_COUNTER_TYPE CurrentTestStopTime;
|
UNITY_TIME_TYPE CurrentTestStopTime;
|
||||||
#endif
|
#endif
|
||||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
jmp_buf AbortFrame;
|
jmp_buf AbortFrame;
|
||||||
|
Reference in New Issue
Block a user