ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
653 stars 269 forks source link

Function pthread_create Argument __restrict__thread. Function called with unexpected argument value. #398

Closed janaranjanahl closed 3 months ago

janaranjanahl commented 2 years ago

I am trying to create my own header file with for pthread.h. my_pthread.h

I am having a issue with pthread_create function with following.

At line (399): "Element 0 Expected 0 Was 10. Function pthread_create Argument __restrict__thread. Function called with unexpected argument value."

my_pthread.h looks like below.

typedef unsigned long int pthread_t;
typedef union pthread_attr_t pthread_attr_t;

int pthread_create(pthread_t * __restrict__thread,
                   const pthread_attr_t *attr,
                   void *(*start_routine) (void *arg),
                   void * __restrict__arg);
int pthread_cancel (pthread_t __th);
int pthread_setcancelstate (int __state, int *__oldstate);
int pthread_cancel (pthread_t __th);
void pthread_testcancel (void);

my test looks like below

    pthread_create_ExpectAndReturn(&can_tx_thread_id, NULL, can_recieve_thread, NULL, SUCCESS);
    TEST_ASSERT_EQUAL(SUCCESS, can_rx_thread_init());

I tried changing the yml file as below but no success. :treat_as: uint8: HEX8 uint16: HEX16 uint32: UINT32 int8: INT8 bool: UINT8 pthread_t: UINT32 in actual pthead.h I have follwing image image

I have a unity helper and I checked at following. https://github.com/ThrowTheSwitch/CMock/issues/167 https://papers707.rssing.com/chan-6065534/latest.php#c6065534a4?zx=813. But does not solve the issue and get following error

In file included from test/support/evcc_pthread.h:3:0,
                 from build/test/mocks/mock_evcc_pthread.h:6,
                 from test/comms/test_can.c:8:
test/support/unity_helper.h:9:2: error: conflicting types for ‘pthread_t’
 }pthread_t;
  ^~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:254:0,
                 from /usr/include/net/if.h:25,
                 from include/comms/can.h:7,
                 from src/comms/can.c:3,
                 from test/comms/test_can.c:3:
/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:27:27: note: previous declaration of ‘pthread_t’ was here
 typedef unsigned long int pthread_t;

(original cause to doing this Ceedling can not find /usr/include/pthread.h in the search paths although that file exists) ERROR: Found no file 'pthread.h' in search paths.

How can I get pthread_create_ExpectAndReturn working properly?

kristyan-osborne-paxton commented 1 year ago

The error is saying you have multiple declarations of pthread_t. Remove the typedefs from your my_pthead.h file