Skip to content

Commit

Permalink
unity: add linux port
Browse files Browse the repository at this point in the history
This allows using unity fixture in Linux host tests
  • Loading branch information
igrr committed Aug 15, 2022
1 parent f8bcec0 commit 1ac3fc7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/unity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if(NOT "${target}" STREQUAL "linux")
list(APPEND srcs "unity_port_esp32.c")
list(APPEND srcs "port/esp/unity_utils_memory_esp.c")
else()
list(APPEND srcs "unity_port_linux.c")
list(APPEND srcs "port/linux/unity_utils_memory_linux.c")
endif()

Expand All @@ -43,10 +44,8 @@ if(CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER)
idf_component_optional_requires(PRIVATE spi_flash)
endif()

if(NOT "${target}" STREQUAL "linux")
target_compile_definitions(${COMPONENT_LIB} PUBLIC
-DUNITY_INCLUDE_CONFIG_H
)
endif()
target_compile_definitions(${COMPONENT_LIB} PUBLIC
-DUNITY_INCLUDE_CONFIG_H
)

target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-const-variable)
42 changes: 42 additions & 0 deletions components/unity/unity_port_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include "unity.h"
#include "sdkconfig.h"


static struct timeval s_test_start, s_test_stop;

void unity_putc(int c)
{
putc(c, stdout);
}

void unity_flush(void)
{
fflush(stdout);
fsync(fileno(stdout));
}

void unity_exec_time_start(void)
{
gettimeofday(&s_test_start, NULL);
}

void unity_exec_time_stop(void)
{
gettimeofday(&s_test_stop, NULL);
}

uint32_t unity_exec_time_get_ms(void)
{
return (uint32_t) (((s_test_stop.tv_sec * 1000000ULL + s_test_stop.tv_usec) -
(s_test_start.tv_sec * 1000000ULL + s_test_start.tv_usec)) / 1000);
}

0 comments on commit 1ac3fc7

Please sign in to comment.