From c8a662eca881c8c5c0f0092c1983d10f4511f303 Mon Sep 17 00:00:00 2001 From: Evgeny Litvinenko Date: Fri, 24 Jul 2020 00:01:36 +0300 Subject: [PATCH 1/6] Make function type and pointer to the function consistent --- include/CppUTest/PlatformSpecificFunctions.h | 4 ++-- src/Platforms/Gcc/UtestPlatform.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/CppUTest/PlatformSpecificFunctions.h b/include/CppUTest/PlatformSpecificFunctions.h index 6737f582a..914475b56 100644 --- a/include/CppUTest/PlatformSpecificFunctions.h +++ b/include/CppUTest/PlatformSpecificFunctions.h @@ -33,8 +33,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment(); class TestPlugin; extern void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result); -extern int (*PlatformSpecificFork)(void); -extern int (*PlatformSpecificWaitPid)(int pid, int* status, int options); +extern pid_t (*PlatformSpecificFork)(void); +extern pid_t (*PlatformSpecificWaitPid)(int pid, int* status, int options); /* Platform specific interface we use in order to minimize dependencies with LibC. * This enables porting to different embedded platforms. diff --git a/src/Platforms/Gcc/UtestPlatform.cpp b/src/Platforms/Gcc/UtestPlatform.cpp index 430da5b16..9cdc19146 100644 --- a/src/Platforms/Gcc/UtestPlatform.cpp +++ b/src/Platforms/Gcc/UtestPlatform.cpp @@ -68,12 +68,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test result->addFailure(TestFailure(shell, "-p doesn't work on this platform, as it is lacking fork.\b")); } -static int PlatformSpecificForkImplementation(void) +static pid_t PlatformSpecificForkImplementation(void) { return 0; } -static int PlatformSpecificWaitPidImplementation(int, int*, int) +static pid_t PlatformSpecificWaitPidImplementation(int, int*, int) { return 0; } @@ -155,8 +155,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment() void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result) = GccPlatformSpecificRunTestInASeperateProcess; -int (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation; -int (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation; +pid_t (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation; +pid_t (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation; extern "C" { From aa5a9c9991bc2046551142580e5571297d1c511c Mon Sep 17 00:00:00 2001 From: Evgeny Litvinenko Date: Fri, 24 Jul 2020 00:51:16 +0300 Subject: [PATCH 2/6] Make function type and pointer to the function consistent in tests --- tests/CppUTest/UtestPlatformTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/CppUTest/UtestPlatformTest.cpp b/tests/CppUTest/UtestPlatformTest.cpp index bba56e9e7..6d6c23dbe 100644 --- a/tests/CppUTest/UtestPlatformTest.cpp +++ b/tests/CppUTest/UtestPlatformTest.cpp @@ -75,11 +75,11 @@ static int waitpid_while_debugging_stub_forced_failures = 0; extern "C" { - static int (*original_waitpid)(int, int*, int) = NULLPTR; + static pid_t (*original_waitpid)(int, int*, int) = NULLPTR; - static int fork_failed_stub(void) { return -1; } + static pid_t fork_failed_stub(void) { return -1; } - static int waitpid_while_debugging_stub(int pid, int* status, int options) + static pid_t waitpid_while_debugging_stub(int pid, int* status, int options) { static int saved_status; @@ -94,7 +94,7 @@ extern "C" { } } - static int waitpid_failed_stub(int, int*, int) { return -1; } + static pid_t waitpid_failed_stub(int, int*, int) { return -1; } } #include From 22d792a268651381ab9f1cd7541a838944270436 Mon Sep 17 00:00:00 2001 From: Evgeny Litvinenko Date: Sun, 26 Jul 2020 14:37:30 +0300 Subject: [PATCH 3/6] CMake and autotools checks for pid_t --- CMakeLists.txt | 6 ++++++ config.h.cmake | 2 ++ include/CppUTest/CppUTestConfig.h | 6 ++++++ include/CppUTest/PlatformSpecificFunctions.h | 4 ++-- src/Platforms/Gcc/UtestPlatform.cpp | 18 +++++++++--------- tests/CppUTest/UtestPlatformTest.cpp | 8 ++++---- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d36c6491e..a2dda151d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,12 @@ if(HAVE_STRDUP) add_definitions(-DCPPUTEST_HAVE_STRDUP=1) endif(HAVE_STRDUP) +include(CheckTypeSize) +CHECK_TYPE_SIZE(pid_t PID_T) +IF(NOT HAVE_PID_T) + SET(_cpputest_pid_t "int") +ENDIF(NOT HAVE_PID_T) + if (MINGW) # Apply workaround for MinGW timespec redefinition (pthread.h / time.h) include(CheckStructHasMember) diff --git a/config.h.cmake b/config.h.cmake index e8a4b9fd4..f4bc9408f 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -9,4 +9,6 @@ #cmakedefine INCLUDE_GTEST_TESTS +#cmakedefine _cpputest_pid_t @_cpputest_pid_t@ + #endif diff --git a/include/CppUTest/CppUTestConfig.h b/include/CppUTest/CppUTestConfig.h index 7c7371fe3..78606da73 100644 --- a/include/CppUTest/CppUTestConfig.h +++ b/include/CppUTest/CppUTestConfig.h @@ -32,6 +32,12 @@ #include "CppUTestGeneratedConfig.h" #endif +#ifdef _cpputest_pid_t +#define PID_T _cpputest_pid_t +#else +#define PID_T pid_t +#endif + /* * This file is added for some specific CppUTest configurations that earlier were spread out into multiple files. * diff --git a/include/CppUTest/PlatformSpecificFunctions.h b/include/CppUTest/PlatformSpecificFunctions.h index 914475b56..d0dd05f10 100644 --- a/include/CppUTest/PlatformSpecificFunctions.h +++ b/include/CppUTest/PlatformSpecificFunctions.h @@ -33,8 +33,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment(); class TestPlugin; extern void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result); -extern pid_t (*PlatformSpecificFork)(void); -extern pid_t (*PlatformSpecificWaitPid)(int pid, int* status, int options); +extern PID_T (*PlatformSpecificFork)(void); +extern PID_T (*PlatformSpecificWaitPid)(int pid, int* status, int options); /* Platform specific interface we use in order to minimize dependencies with LibC. * This enables porting to different embedded platforms. diff --git a/src/Platforms/Gcc/UtestPlatform.cpp b/src/Platforms/Gcc/UtestPlatform.cpp index 9cdc19146..53dc4eca1 100644 --- a/src/Platforms/Gcc/UtestPlatform.cpp +++ b/src/Platforms/Gcc/UtestPlatform.cpp @@ -68,12 +68,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test result->addFailure(TestFailure(shell, "-p doesn't work on this platform, as it is lacking fork.\b")); } -static pid_t PlatformSpecificForkImplementation(void) +static PID_T PlatformSpecificForkImplementation(void) { return 0; } -static pid_t PlatformSpecificWaitPidImplementation(int, int*, int) +static PID_T PlatformSpecificWaitPidImplementation(int, int*, int) { return 0; } @@ -95,9 +95,9 @@ static void SetTestFailureByStatusCode(UtestShell* shell, TestResult* result, in static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result) { - const pid_t syscallError = -1; - pid_t cpid; - pid_t w; + const PID_T syscallError = -1; + PID_T cpid; + PID_T w; int status = 0; cpid = PlatformSpecificFork(); @@ -136,12 +136,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test } } -static pid_t PlatformSpecificForkImplementation(void) +static PID_T PlatformSpecificForkImplementation(void) { return fork(); } -static pid_t PlatformSpecificWaitPidImplementation(int pid, int* status, int options) +static PID_T PlatformSpecificWaitPidImplementation(int pid, int* status, int options) { return waitpid(pid, status, options); } @@ -155,8 +155,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment() void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result) = GccPlatformSpecificRunTestInASeperateProcess; -pid_t (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation; -pid_t (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation; +PID_T (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation; +PID_T (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation; extern "C" { diff --git a/tests/CppUTest/UtestPlatformTest.cpp b/tests/CppUTest/UtestPlatformTest.cpp index 6d6c23dbe..835e33939 100644 --- a/tests/CppUTest/UtestPlatformTest.cpp +++ b/tests/CppUTest/UtestPlatformTest.cpp @@ -75,11 +75,11 @@ static int waitpid_while_debugging_stub_forced_failures = 0; extern "C" { - static pid_t (*original_waitpid)(int, int*, int) = NULLPTR; + static PID_T (*original_waitpid)(int, int*, int) = NULLPTR; - static pid_t fork_failed_stub(void) { return -1; } + static PID_T fork_failed_stub(void) { return -1; } - static pid_t waitpid_while_debugging_stub(int pid, int* status, int options) + static PID_T waitpid_while_debugging_stub(int pid, int* status, int options) { static int saved_status; @@ -94,7 +94,7 @@ extern "C" { } } - static pid_t waitpid_failed_stub(int, int*, int) { return -1; } + static PID_T waitpid_failed_stub(int, int*, int) { return -1; } } #include From 443e7caa7ff5ebd80bf015d94ce256edb2c04231 Mon Sep 17 00:00:00 2001 From: Evgeny Litvinenko Date: Sun, 26 Jul 2020 19:17:56 +0300 Subject: [PATCH 4/6] CMake and autotools checks for pid_t fix header --- include/CppUTest/PlatformSpecificFunctions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/CppUTest/PlatformSpecificFunctions.h b/include/CppUTest/PlatformSpecificFunctions.h index d0dd05f10..0a14dedbb 100644 --- a/include/CppUTest/PlatformSpecificFunctions.h +++ b/include/CppUTest/PlatformSpecificFunctions.h @@ -28,6 +28,7 @@ #ifndef PLATFORMSPECIFICFUNCTIONS_H_ #define PLATFORMSPECIFICFUNCTIONS_H_ +#include "CppUTest/CppUTestConfig.h" #include "CppUTest/TestOutput.h" TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment(); From f3b762a644a5f92ab4d85707bea85c403ebdb783 Mon Sep 17 00:00:00 2001 From: Evgeny Litvinenko Date: Sun, 26 Jul 2020 20:31:59 +0300 Subject: [PATCH 5/6] Use typedef instead of #define --- include/CppUTest/CppUTestConfig.h | 4 +--- include/CppUTest/PlatformSpecificFunctions.h | 4 ++-- src/Platforms/Gcc/UtestPlatform.cpp | 18 +++++++++--------- tests/CppUTest/UtestPlatformTest.cpp | 8 ++++---- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/CppUTest/CppUTestConfig.h b/include/CppUTest/CppUTestConfig.h index 78606da73..0bf140228 100644 --- a/include/CppUTest/CppUTestConfig.h +++ b/include/CppUTest/CppUTestConfig.h @@ -33,9 +33,7 @@ #endif #ifdef _cpputest_pid_t -#define PID_T _cpputest_pid_t -#else -#define PID_T pid_t +typedef _cpputest_pid_t pid_t; #endif /* diff --git a/include/CppUTest/PlatformSpecificFunctions.h b/include/CppUTest/PlatformSpecificFunctions.h index 0a14dedbb..1edbac5c1 100644 --- a/include/CppUTest/PlatformSpecificFunctions.h +++ b/include/CppUTest/PlatformSpecificFunctions.h @@ -34,8 +34,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment(); class TestPlugin; extern void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result); -extern PID_T (*PlatformSpecificFork)(void); -extern PID_T (*PlatformSpecificWaitPid)(int pid, int* status, int options); +extern pid_t (*PlatformSpecificFork)(void); +extern pid_t (*PlatformSpecificWaitPid)(int pid, int* status, int options); /* Platform specific interface we use in order to minimize dependencies with LibC. * This enables porting to different embedded platforms. diff --git a/src/Platforms/Gcc/UtestPlatform.cpp b/src/Platforms/Gcc/UtestPlatform.cpp index 53dc4eca1..9cdc19146 100644 --- a/src/Platforms/Gcc/UtestPlatform.cpp +++ b/src/Platforms/Gcc/UtestPlatform.cpp @@ -68,12 +68,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test result->addFailure(TestFailure(shell, "-p doesn't work on this platform, as it is lacking fork.\b")); } -static PID_T PlatformSpecificForkImplementation(void) +static pid_t PlatformSpecificForkImplementation(void) { return 0; } -static PID_T PlatformSpecificWaitPidImplementation(int, int*, int) +static pid_t PlatformSpecificWaitPidImplementation(int, int*, int) { return 0; } @@ -95,9 +95,9 @@ static void SetTestFailureByStatusCode(UtestShell* shell, TestResult* result, in static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result) { - const PID_T syscallError = -1; - PID_T cpid; - PID_T w; + const pid_t syscallError = -1; + pid_t cpid; + pid_t w; int status = 0; cpid = PlatformSpecificFork(); @@ -136,12 +136,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test } } -static PID_T PlatformSpecificForkImplementation(void) +static pid_t PlatformSpecificForkImplementation(void) { return fork(); } -static PID_T PlatformSpecificWaitPidImplementation(int pid, int* status, int options) +static pid_t PlatformSpecificWaitPidImplementation(int pid, int* status, int options) { return waitpid(pid, status, options); } @@ -155,8 +155,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment() void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result) = GccPlatformSpecificRunTestInASeperateProcess; -PID_T (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation; -PID_T (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation; +pid_t (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation; +pid_t (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation; extern "C" { diff --git a/tests/CppUTest/UtestPlatformTest.cpp b/tests/CppUTest/UtestPlatformTest.cpp index 835e33939..6d6c23dbe 100644 --- a/tests/CppUTest/UtestPlatformTest.cpp +++ b/tests/CppUTest/UtestPlatformTest.cpp @@ -75,11 +75,11 @@ static int waitpid_while_debugging_stub_forced_failures = 0; extern "C" { - static PID_T (*original_waitpid)(int, int*, int) = NULLPTR; + static pid_t (*original_waitpid)(int, int*, int) = NULLPTR; - static PID_T fork_failed_stub(void) { return -1; } + static pid_t fork_failed_stub(void) { return -1; } - static PID_T waitpid_while_debugging_stub(int pid, int* status, int options) + static pid_t waitpid_while_debugging_stub(int pid, int* status, int options) { static int saved_status; @@ -94,7 +94,7 @@ extern "C" { } } - static PID_T waitpid_failed_stub(int, int*, int) { return -1; } + static pid_t waitpid_failed_stub(int, int*, int) { return -1; } } #include From 1079417ae7a6fb4521142f82b99c622a661f8199 Mon Sep 17 00:00:00 2001 From: Evgeny Litvinenko Date: Tue, 28 Jul 2020 12:45:48 +0300 Subject: [PATCH 6/6] WIP: just to see why ci tests fail --- include/CppUTest/CppUTestConfig.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/CppUTest/CppUTestConfig.h b/include/CppUTest/CppUTestConfig.h index 0bf140228..c5e540abf 100644 --- a/include/CppUTest/CppUTestConfig.h +++ b/include/CppUTest/CppUTestConfig.h @@ -28,9 +28,7 @@ #ifndef CPPUTESTCONFIG_H_ #define CPPUTESTCONFIG_H_ -#ifndef CPPUTEST_USE_OWN_CONFIGURATION #include "CppUTestGeneratedConfig.h" -#endif #ifdef _cpputest_pid_t typedef _cpputest_pid_t pid_t;