Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types pid_t and int are not always the same. #1411

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@

#cmakedefine INCLUDE_GTEST_TESTS

#cmakedefine _cpputest_pid_t @_cpputest_pid_t@

#endif
4 changes: 3 additions & 1 deletion include/CppUTest/CppUTestConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#ifndef CPPUTESTCONFIG_H_
#define CPPUTESTCONFIG_H_

#ifndef CPPUTEST_USE_OWN_CONFIGURATION
#include "CppUTestGeneratedConfig.h"

#ifdef _cpputest_pid_t
typedef _cpputest_pid_t pid_t;
#endif

/*
Expand Down
5 changes: 3 additions & 2 deletions include/CppUTest/PlatformSpecificFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
#ifndef PLATFORMSPECIFICFUNCTIONS_H_
#define PLATFORMSPECIFICFUNCTIONS_H_

#include "CppUTest/CppUTestConfig.h"
#include "CppUTest/TestOutput.h"
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.
Expand Down
8 changes: 4 additions & 4 deletions src/Platforms/Gcc/UtestPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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" {

Expand Down
8 changes: 4 additions & 4 deletions tests/CppUTest/UtestPlatformTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 <unistd.h>
Expand Down