[PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

Gedare Bloom gedare at rtems.org
Wed Apr 15 14:11:28 UTC 2020


On Tue, Apr 14, 2020 at 10:56 PM Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
> Hello Utkarsh Rai,
>
> do we really need a new test program for this test case? I would prefer
> add it to an existing test program or add a generic POSIX test program
> using the RTEMS Test Framework.
>
I would also recommend this, or perhaps develop a test for clock
monotonic that encompasses several features (as done with clock
realtime).

> On 14/04/2020 19:17, Utkarsh Rai wrote:
> > This test checks for a simple 1 ns delay with clock_nanosleep with
> > CLOCK_MONOTONIC.
> > ---
> >   testsuites/psxtests/Makefile.am               |  9 +++
> >   testsuites/psxtests/configure.ac              |  1 +
> >   .../psxtests/psxclocknanosleep01/init.c       | 81 +++++++++++++++++++
> >   .../psxclocknanosleep01.doc                   | 10 +++
> >   .../psxclocknanosleep01.scn                   |  3 +
> >   5 files changed, 104 insertions(+)
> >   create mode 100644 testsuites/psxtests/psxclocknanosleep01/init.c
> >   create mode 100644 testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.doc
> >   create mode 100644 testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn
> >
> > diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
> > index 1f9e4233ec..e3918ae7a5 100755
> > --- a/testsuites/psxtests/Makefile.am
> > +++ b/testsuites/psxtests/Makefile.am
> > @@ -321,6 +321,15 @@ psxclockrealtime01_CPPFLAGS = $(AM_CPPFLAGS) \
> >       $(TEST_FLAGS_psxclockrealtime01) $(support_includes)
> >   endif
> >
> > +if TEST_psxclocknanosleep01
> > +psx_tests += psxclocknanosleep01
> > +psx_screens += psxclocknanosleep01/psxclocknanosleep01.scn
> > +psx_docs += psxclocknanosleep01/psxclocknanosleep01.doc
> > +psxclocknanosleep01_SOURCES = psxclocknanosleep01/init.c
> > +psxclocknanosleep01_CPPFLAGS = $(AM_CPPFLAGS) \
> > +     $(TEST_FLAGS_psxclocknanosleep01) $(support_includes)
> > +endif
> > +
> >   if TEST_psxconcurrency01
> >   psx_tests += psxconcurrency01
> >   psx_screens += psxconcurrency01/psxconcurrency01.scn
> > diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
> > index 139787cccb..9bfe8e2c0b 100644
> > --- a/testsuites/psxtests/configure.ac
> > +++ b/testsuites/psxtests/configure.ac
> > @@ -75,6 +75,7 @@ RTEMS_TEST_CHECK([psxcleanup01])
> >   RTEMS_TEST_CHECK([psxcleanup02])
> >   RTEMS_TEST_CHECK([psxclock])
> >   RTEMS_TEST_CHECK([psxclock01])
> > +RTEMS_TEST_CHECK([psxclocknanosleep01])
> >   RTEMS_TEST_CHECK([psxclockrealtime01])
> >   RTEMS_TEST_CHECK([psxconcurrency01])
> >   RTEMS_TEST_CHECK([psxcond01])
> > diff --git a/testsuites/psxtests/psxclocknanosleep01/init.c b/testsuites/psxtests/psxclocknanosleep01/init.c
> > new file mode 100644
> > index 0000000000..21b738627d
> > --- /dev/null
> > +++ b/testsuites/psxtests/psxclocknanosleep01/init.c
> > @@ -0,0 +1,81 @@
> > +/*
> > + * SPDX-License-Identifier: BSD-2-Clause
> > + *
> > + * Copyright (C) 2020 Utkarsh Rai
> > + *
> > + * 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.
> > + */
> > +
> > +#include <rtems.h>
> > +#include <rtems/test.h>
> > +#include <time.h>
> > +#include <tmacros.h>
> > +
> > +/*Forward declaration to avoid compiler warning*/
> > +void clock_sleep(void);
> Please use a static function instead. Most of these forward declarations
> are just lazy warning fixes and bad examples.
> > +
> > +rtems_task Init(rtems_task_argument ignored);
> > +
> > +const char rtems_test_name[] = "PSXCLOCKNANOSLEEP 01";
> > +
> > +void clock_sleep(void)
> > +{
> > +  struct timespec delay_time;
> > +  int    status;
> > +
> > +  delay_time.tv_sec = 0;
> > +  delay_time.tv_nsec = 1;
> > +
> > +  status=clock_nanosleep( CLOCK_MONOTONIC, 0, &delay_time, (struct timespec* )NULL );
> In C code this cast is superfluous, in C++ code using NULL is out dated.
> > +  rtems_test_assert( status == 0 );
> > +}
> > +
> > +rtems_task Init(rtems_task_argument ignored)
> > +{
> > +
> > +  struct timespec init_time;
> > +  struct timespec end_time;
> > +  int    status;
> > +
> > +  TEST_BEGIN();
> > +
> > +  status = clock_gettime( CLOCK_MONOTONIC, &init_time );
> > +  rtems_test_assert( status == 0 );
> > +
> > +  clock_sleep();
> > +
> > +  status = clock_gettime( CLOCK_MONOTONIC, &end_time );
> > +  rtems_test_assert( status == 0 );
> > +
> > +  rtems_test_assert( (end_time.tv_sec-init_time.tv_sec) == 0 );
>
> Is end_time.tv_sec - init_time.tv_sec == 0 under all circumstances?
>
> The test case code should be separated from the test suite boilerplate code.
>
> > +  rtems_test_assert( (end_time.tv_nsec-init_time.tv_nsec) >=1 );
> We really should think about using a C code formatter. I think that I
> waste my time telling someone to put spaces between operators.
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list