[PATCH 2/2] testsuites: added compile tests for new APIs

Joel Sherrill joel at rtems.org
Fri Aug 6 13:58:56 UTC 2021


I'm hoping you sent the same patch twice. Otherwise, I don't know what
is the difference. :)

On Fri, Aug 6, 2021 at 8:42 AM Matt Joyce <mfjoyce2004 at gmail.com> wrote:
>
> Added compile only tests for new POSIX standard APIs pthread_cond_clockwait and
> pthread_mutex_clocklock in testsuites/psxtests/psxhdrs/pthread
> ---
>  spec/build/testsuites/psxtests/libpsxhdrs.yml |  2 +
>  .../psxhdrs/pthread/pthread_cond_clockwait.c  | 54 ++++++++++++++++++
>  .../psxhdrs/pthread/pthread_mutex_clocklock.c | 56 +++++++++++++++++++
>  3 files changed, 112 insertions(+)
>  create mode 100644 testsuites/psxtests/psxhdrs/pthread/pthread_cond_clockwait.c
>  create mode 100644 testsuites/psxtests/psxhdrs/pthread/pthread_mutex_clocklock.c
>
> diff --git a/spec/build/testsuites/psxtests/libpsxhdrs.yml b/spec/build/testsuites/psxtests/libpsxhdrs.yml
> index 5e9f808db5..d7fc430a36 100644
> --- a/spec/build/testsuites/psxtests/libpsxhdrs.yml
> +++ b/spec/build/testsuites/psxtests/libpsxhdrs.yml
> @@ -432,6 +432,7 @@ source:
>  - testsuites/psxtests/psxhdrs/pthread/pthread_cond_signal.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_cond_timedwait.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_cond_wait.c
> +- testsuites/psxtests/psxhdrs/pthread/pthread_cond_clockwait.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_condattr_destroy.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_condattr_getpshared.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_condattr_init.c
> @@ -453,6 +454,7 @@ source:
>  - testsuites/psxtests/psxhdrs/pthread/pthread_mutex_lock.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_mutex_setprioceiling.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_mutex_timedlock.c
> +- testsuites/psxtests/psxhdrs/pthread/pthread_mutex_clocklock.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_mutex_trylock.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_mutex_unlock.c
>  - testsuites/psxtests/psxhdrs/pthread/pthread_mutexattr_destroy.c
> diff --git a/testsuites/psxtests/psxhdrs/pthread/pthread_cond_clockwait.c b/testsuites/psxtests/psxhdrs/pthread/pthread_cond_clockwait.c
> new file mode 100644
> index 0000000000..427f5063c9
> --- /dev/null
> +++ b/testsuites/psxtests/psxhdrs/pthread/pthread_cond_clockwait.c
> @@ -0,0 +1,54 @@
> +/*
> +* @file
> +* @brief pthread_cond_clockwait() API Conformance Test
> +*/
> +
> +/*
> +* Copyright (C) 2021 Matthew Joyce
> +*
> +* Redistribution and use in source and binary forms, with or without
> +* modification, are permitted provided that the following conditions
> +* are met:
> +* 1. Redistributions of source code must retain the above copyright
> +*    notice, this list of conditions and the following disclaimer.
> +* 2. Redistributions in binary form must reproduce the above copyright
> +*    notice, this list of conditions and the following disclaimer in the
> +*    documentation and/or other materials provided with the distribution.
> +*
> +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> +* POSSIBILITY OF SUCH DAMAGE.
> +*/
> +
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <pthread.h>

If you don't define _GNU_SOURCE before including pthread.h, I don't
think you will see the prototypes for these methods.

Also add a comment that these appeared in Issue 8.

> +
> +#ifndef _POSIX_THREADS
> +#error "rtems is supposed to have pthread_cond_clockwait"
> +#endif
> +
> +int test( void );
> +
> +int test( void )
> +{
> +  pthread_cond_t        cond  = PTHREAD_COND_INITIALIZER;
> +  pthread_mutex_t       mutex = PTHREAD_MUTEX_INITIALIZER;
> +  clockid_t             clock_id = CLOCK_REALTIME;
> +  const struct timespec abstime;
> +  int result;
> +
> +  result = pthread_cond_clockwait( &cond, &mutex, clock_id, &abstime );
> +
> +  return result;
> +}
> diff --git a/testsuites/psxtests/psxhdrs/pthread/pthread_mutex_clocklock.c b/testsuites/psxtests/psxhdrs/pthread/pthread_mutex_clocklock.c
> new file mode 100644
> index 0000000000..22f94b5991
> --- /dev/null
> +++ b/testsuites/psxtests/psxhdrs/pthread/pthread_mutex_clocklock.c
> @@ -0,0 +1,56 @@
> +/*
> +* @file
> +* @brief pthread_mutex_clocklock() API Conformance Test
> +*/
> +
> +/*
> +* Copyright (C) 2021 Matthew Joyce
> +*
> +* Redistribution and use in source and binary forms, with or without
> +* modification, are permitted provided that the following conditions
> +* are met:
> +* 1. Redistributions of source code must retain the above copyright
> +*    notice, this list of conditions and the following disclaimer.
> +* 2. Redistributions in binary form must reproduce the above copyright
> +*    notice, this list of conditions and the following disclaimer in the
> +*    documentation and/or other materials provided with the distribution.
> +*
> +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> +* POSSIBILITY OF SUCH DAMAGE.
> +*/
> +
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <pthread.h>
> +
> +#ifndef _POSIX_THREADS
> +#error "rtems is supposed to have pthread_mutex_clocklock"
> +#endif
> +#ifndef _POSIX_TIMEOUTS
> +#error "rtems is supposed to have pthread_mutex_clocklock"
> +#endif
> +
> +int test( void );
> +
> +int test( void )
> +{
> +  pthread_mutex_t       mutex = PTHREAD_MUTEX_INITIALIZER;
> +  clockid_t             clock_id = CLOCK_REALTIME;

There is an odd amount of space. Single character or align the names.

> +  const struct timespec abstime;
> +  int result;
> +
> +  result = pthread_mutex_clocklock( &mutex, clock_id, &abstime );

abstime needs to be initialized.

Add (void) result; after the call to indicate result is being ignored. Probably
applies to all.
> +
> +  return result;
> +}
> --
> 2.31.1
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list