Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 3 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 6 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 2 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
6 changes: 6 additions & 0 deletions 6 include/CppUTest/CppUTestConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#include "CppUTestGeneratedConfig.h"
#endif

#ifdef _cpputest_pid_t
#define PID_T _cpputest_pid_t
Copy link
Contributor

@offa offa Jul 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't typedef a better choice here? #define can be harmful at many places.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed #define to typedef.

#else
#define PID_T pid_t
#endif

/*
* This file is added for some specific CppUTest configurations that earlier were spread out into multiple files.
*
Expand Down
4 changes: 2 additions & 2 deletions 4 include/CppUTest/PlatformSpecificFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions 18 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 All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 8 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.