Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-08-12 Thread Utkarsh Rai
Hello Joel,
I had sent a v3 patch
https://lists.rtems.org/pipermail/devel/2020-April/059603.html, but it
somehow went unnoticed. This may need a bit of fine-tuning, and I plan to
pursue it after my GSoC ends (I have too many things on my plate right now
:))

On Thu, Aug 13, 2020 at 3:46 AM Joel Sherrill  wrote:

> What's the status of this test? The last email seems to indicate it needed
> further work before being merged.
>
> On Wed, Apr 15, 2020 at 9:16 AM Joel Sherrill  wrote:
>
>>
>>
>> On Wed, Apr 15, 2020 at 9:11 AM Gedare Bloom  wrote:
>>
>>> On Tue, Apr 14, 2020 at 10:56 PM Sebastian Huber
>>>  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).
>>>
>>
>> In theory, the clock monotonic test could be the clock realtime one
>> reused
>> with the clock type changed. There are a few cases of doing something
>> similar.
>> The behavior is supposed to be the same for delays.
>>
>> Missing in this discussion and maybe what Gedare is hinting at is that you
>> any sleep/delay/etc type of operation is never specified as a precise
>> delay,
>> it is a minimum delay. The minimum may be set by clock tick time quantum,
>> other threads, processes, etc. The POSIX standard has precise language
>> about this for clock_nanosleep. From
>> https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html
>>
>> "The suspension time caused by this function may be longer than requested
>> because the argument value is rounded up to an integer multiple of the
>> sleep resolution, or because of the scheduling of other activity by the
>> system."
>>
>> --joel
>>
>>
>>> > 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 00..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 

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-08-12 Thread Joel Sherrill
What's the status of this test? The last email seems to indicate it needed
further work before being merged.

On Wed, Apr 15, 2020 at 9:16 AM Joel Sherrill  wrote:

>
>
> On Wed, Apr 15, 2020 at 9:11 AM Gedare Bloom  wrote:
>
>> On Tue, Apr 14, 2020 at 10:56 PM Sebastian Huber
>>  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).
>>
>
> In theory, the clock monotonic test could be the clock realtime one reused
> with the clock type changed. There are a few cases of doing something
> similar.
> The behavior is supposed to be the same for delays.
>
> Missing in this discussion and maybe what Gedare is hinting at is that you
> any sleep/delay/etc type of operation is never specified as a precise
> delay,
> it is a minimum delay. The minimum may be set by clock tick time quantum,
> other threads, processes, etc. The POSIX standard has precise language
> about this for clock_nanosleep. From
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html
>
> "The suspension time caused by this function may be longer than requested
> because the argument value is rounded up to an integer multiple of the
> sleep resolution, or because of the scheduling of other activity by the
> system."
>
> --joel
>
>
>> > 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 00..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"
>> > 

Re: [PATCH v2] Test for clock_nanosleep() with CLOCK_MONOTONIC option.

2020-04-29 Thread Eshan Dhawan
On Mon, Apr 27, 2020 at 8:18 PM Sebastian Huber <
sebastian.hu...@embedded-brains.de> wrote:

> On 23/04/2020 19:15, Utkarsh Rai wrote:
>
> > I encountered linkage error while  using the new test framework, in
> > particular
> > undefined reference to `_Stack_Space_size'
> > undefined reference to `_Thread_Initial_thread_count'.
> > I did not realize that we needed a runner for using the new test
> > framework (As you mention here
> > to
> > Eshan), can you please explain what all and how to use RTEMS
> > configurations
> >   to write a generic runner.
> Please have a look at the attached file. Maybe it makes sense to move
> some parts of the generic runner in a header and source file.
>
The runner was a great help and works fine.
I have integrated it in the psxgetcpuclockid test
and I will send the latest patch soon.
This needs to be added to documentation as well

Thanks
-Eshan
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep() with CLOCK_MONOTONIC option.

2020-04-27 Thread Sebastian Huber

On 23/04/2020 19:15, Utkarsh Rai wrote:

I encountered linkage error while  using the new test framework, in 
particular

undefined reference to `_Stack_Space_size'
undefined reference to `_Thread_Initial_thread_count'.
I did not realize that we needed a runner for using the new test 
framework (As you mention here 
to 
Eshan), can you please explain what all and how to use RTEMS 
configurations

  to write a generic runner.
Please have a look at the attached file. Maybe it makes sense to move 
some parts of the generic runner in a header and source file.
/* SPDX-License-Identifier: BSD-2-Clause */

/*
 * Copyright (C) 2020 embedded brains GmbH
 *
 * 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 

#include 
#include 

#include 

const char rtems_test_name[] = "PSX WHATEVER 1";

static char buffer[512];

static const T_action actions[] = {
	T_report_hash_sha256,
	T_check_task_context,
	T_check_file_descriptors,
	T_check_rtems_barriers,
	T_check_rtems_extensions,
	T_check_rtems_message_queues,
	T_check_rtems_partitions,
	T_check_rtems_periods,
	T_check_rtems_regions,
	T_check_rtems_semaphores,
	T_check_rtems_tasks,
	T_check_rtems_timers,
	T_check_posix_keys
};

static const T_config config = {
	.name = "POSIXWhatever1",
	.buf = buffer,
	.buf_size = sizeof(buffer),
	.putchar = rtems_put_char,
	.verbosity = T_VERBOSE,
	.now = T_now_clock,
	.action_count = T_ARRAY_SIZE(actions),
	.actions = actions
};

static void
Init(rtems_task_argument arg)
{
	int exit_code;

	(void)arg;
	TEST_BEGIN();

	T_register();
	exit_code = T_main();
	if (exit_code == 0) {
		TEST_END();
	}

	rtems_test_exit(exit_code);
}

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 32

#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 8

#define CONFIGURE_UNIFIED_WORK_AREAS

#define CONFIGURE_UNLIMITED_OBJECTS

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include 
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep() with CLOCK_MONOTONIC option.

2020-04-22 Thread Sebastian Huber

On 22/04/2020 17:53, Utkarsh Rai wrote:


Rationale for a new test-


Although most of the test cases for this test have been taken from 
clockrealtime,

adding it to the current test with CLOCK_MONOTONIC may break the existing cases.


This test has a new case which tests for no change of delay with monotonic 
clock when

the realtime clock has been modified, this is easier to add in a new test.
---
  testsuites/psxtests/Makefile.am   |  10 ++
  testsuites/psxtests/configure.ac  |   1 +
  .../psxtests/psxclocknanosleep01/init.c   | 155 ++
  .../psxclocknanosleep01.doc   |  15 ++
  .../psxclocknanosleep01.scn   |  14 ++
  5 files changed, 195 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..ba79804be7 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -312,6 +312,16 @@ psxclock01_CPPFLAGS = $(AM_CPPFLAGS) 
$(TEST_FLAGS_psxclock01) \
$(support_includes) -I$(top_srcdir)/include
  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_psxclockrealtime01
  psx_tests += psxclockrealtime01
  psx_screens += psxclockrealtime01/psxclockrealtime01.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 00..c1f10b9eb9
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/init.c
@@ -0,0 +1,155 @@
+/*
+ *  Copyright (c) 2020 Utkarsh Rai.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */


Please use this template for new files (BSD-2-Clause license):

https://docs.rtems.org/branches/master/eng/coding-file-hdr.html#c-c-assembler-source-file-template


+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef enum {
+  MODE_TIMEOUT_FINITE,
+  MODE_TIMEOUT_NEGATIVE_SEC,
+  MODE_TIMEOUT_NEGATIVE_NSEC,
+  MODE_TIMEOUT_NEGATIVE_SEC_NSEC,
+  MODE_TIMEOUT_HUGE_NSEC,
+  MODE_TIMEOUT_CLOCK_MODIFY
+} test_mode;
+
+static void assert_eno(const char *hint, int eno, int expected_eno)
+{
+  const char *warn = "";
+
+  if ( eno != expected_eno ) {
+warn = "WARNING: ";
+  }
+
+  printf(
+"%s%s: actual '%s', expected '%s'\n",
+warn,
+hint,
+strerror(eno),
+strerror(expected_eno)
+  );
+
+  rtems_test_assert( eno == expected_eno );
+}
+
+
+static void assert_rv(const char *hint, int rv, int expected_eno)
+{
+  int eno;
+
+  if ( rv != 0 ) {
+eno = EINVAL;
+  } else {
+eno = 0;
+  }
+
+  assert_eno( hint, eno, expected_eno );
+}


I am not in favour of adding new test support code like this. The new 
test framework has for example:


https://docs.rtems.org/branches/master/eng/test-framework.html#posix-error-numbers


+
+static void run(test_mode mode, const char* test_name)
+{
+ struct timespec  delay_time;
+ struct timespec  configure_time;
+ int rv;
+ int expected_eno;
+
+ printf("***%s*\n", test_name);

The new test framework prints stuff like this in a format easy to parse.

+
+ switch (mode) {
+   case MODE_TIMEOUT_FINITE:
+ rv = clock_gettime( CLOCK_MONOTONIC, _time );
+ rtems_test_assert( rv == 0 );
+
+ delay_time.tv_sec += 1;
+ delay_time.tv_nsec += 1;
+ expected_eno = ETIMEDOUT;
+ break;


I think this switch case just make the code harder to read. What is the 
benefit? In the new test framework one of the test cases could look like:


T_TEST_CASE(POSIXClockGettimeTimeoutFinite)
{
    struct timespec delay_time;
    int eno;

    eno = clock_gettime( CLOCK_MONOTONIC, _time );
    T_eno_success( eno );

    delay_time.tv_sec += 1;
    delay_time.tv_nsec += 1; // This can result in an invalid time, 
e.g. if 1.9 before the addition


    eno = 

[PATCH v2] Test for clock_nanosleep() with CLOCK_MONOTONIC option.

2020-04-22 Thread Utkarsh Rai
Rationale for a new test-

>Although most of the test cases for this test have been taken from 
>clockrealtime,
adding it to the current test with CLOCK_MONOTONIC may break the existing cases.

>This test has a new case which tests for no change of delay with monotonic 
>clock when
the realtime clock has been modified, this is easier to add in a new test.
---
 testsuites/psxtests/Makefile.am   |  10 ++
 testsuites/psxtests/configure.ac  |   1 +
 .../psxtests/psxclocknanosleep01/init.c   | 155 ++
 .../psxclocknanosleep01.doc   |  15 ++
 .../psxclocknanosleep01.scn   |  14 ++
 5 files changed, 195 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..ba79804be7 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -312,6 +312,16 @@ psxclock01_CPPFLAGS = $(AM_CPPFLAGS) 
$(TEST_FLAGS_psxclock01) \
$(support_includes) -I$(top_srcdir)/include
 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_psxclockrealtime01
 psx_tests += psxclockrealtime01
 psx_screens += psxclockrealtime01/psxclockrealtime01.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 00..c1f10b9eb9
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/init.c
@@ -0,0 +1,155 @@
+/*
+ *  Copyright (c) 2020 Utkarsh Rai.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef enum {
+  MODE_TIMEOUT_FINITE,
+  MODE_TIMEOUT_NEGATIVE_SEC,
+  MODE_TIMEOUT_NEGATIVE_NSEC,
+  MODE_TIMEOUT_NEGATIVE_SEC_NSEC,
+  MODE_TIMEOUT_HUGE_NSEC,
+  MODE_TIMEOUT_CLOCK_MODIFY
+} test_mode;
+
+static void assert_eno(const char *hint, int eno, int expected_eno)
+{
+  const char *warn = "";
+
+  if ( eno != expected_eno ) {
+warn = "WARNING: ";
+  }
+
+  printf(
+"%s%s: actual '%s', expected '%s'\n",
+warn,
+hint,
+strerror(eno),
+strerror(expected_eno)
+  );
+
+  rtems_test_assert( eno == expected_eno );
+}
+
+
+static void assert_rv(const char *hint, int rv, int expected_eno)
+{
+  int eno;
+
+  if ( rv != 0 ) {
+eno = EINVAL;
+  } else {
+eno = 0;
+  }
+
+  assert_eno( hint, eno, expected_eno );
+}
+
+static void run(test_mode mode, const char* test_name)
+{
+ struct timespec  delay_time;
+ struct timespec  configure_time;
+ int rv;
+ int expected_eno;
+
+ printf("***%s*\n", test_name);
+
+ switch (mode) {
+   case MODE_TIMEOUT_FINITE:
+ rv = clock_gettime( CLOCK_MONOTONIC, _time );
+ rtems_test_assert( rv == 0 );
+
+ delay_time.tv_sec += 1;
+ delay_time.tv_nsec += 1;
+ expected_eno = ETIMEDOUT;
+ break;
+
+   case MODE_TIMEOUT_HUGE_NSEC:
+ delay_time.tv_sec = 1;
+ delay_time.tv_nsec = LONG_MAX;
+ expected_eno = EINVAL;
+ break;
+
+   case MODE_TIMEOUT_NEGATIVE_NSEC:
+ delay_time.tv_sec = 1;
+ delay_time.tv_nsec = -1;
+ expected_eno = EINVAL;
+ break;
+
+   case MODE_TIMEOUT_NEGATIVE_SEC_NSEC:
+ delay_time.tv_sec = -1;
+ delay_time.tv_nsec = -1;
+ expected_eno = EINVAL;
+ break;
+
+   case MODE_TIMEOUT_NEGATIVE_SEC:
+ delay_time.tv_sec = -1;
+ delay_time.tv_nsec = 1;
+ expected_eno = ETIMEDOUT;
+ break;
+
+   case MODE_TIMEOUT_CLOCK_MODIFY:
+ rv = clock_gettime( CLOCK_REALTIME, _time );
+ rtems_test_assert( rv == 0 );
+
+ configure_time.tv_sec += 3600;
+ rv = clock_settime( CLOCK_REALTIME, _time );
+ rtems_test_assert( rv == 0 );
+
+ rv = clock_gettime( CLOCK_MONOTONIC, _time );
+ rtems_test_assert( rv == 0 );
+
+ delay_time.tv_sec += 1;
+ delay_time.tv_nsec += 

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Joel Sherrill
On Wed, Apr 15, 2020 at 9:11 AM Gedare Bloom  wrote:

> On Tue, Apr 14, 2020 at 10:56 PM Sebastian Huber
>  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).
>

In theory, the clock monotonic test could be the clock realtime one reused
with the clock type changed. There are a few cases of doing something
similar.
The behavior is supposed to be the same for delays.

Missing in this discussion and maybe what Gedare is hinting at is that you
any sleep/delay/etc type of operation is never specified as a precise delay,
it is a minimum delay. The minimum may be set by clock tick time quantum,
other threads, processes, etc. The POSIX standard has precise language
about this for clock_nanosleep. From
https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html

"The suspension time caused by this function may be longer than requested
because the argument value is rounded up to an integer multiple of the
sleep resolution, or because of the scheduling of other activity by the
system."

--joel


> > 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 00..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, 

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Utkarsh Rai
Oh, I missed that, basically the difference between the second would amount
to 59 and hence my assumption would be wrong
Thank you for the clarification, I will remember to consider the cases.

On Wed 15 Apr, 2020, 7:37 PM Gedare Bloom,  wrote:

> I appreciate what Sebastian is doing, but I'll be a bit more explicit.
> You should understand what resources/APIs already exist that may help
> you, such as:
> https://docs.rtems.org/branches/master/c-user/timespec_helpers.html#timespec-helpers
>
> What happens when the time is 11:59:59.9 (HH:MM:SS.mmmuuunnn)
> and you delay for 1 ns?
>
> On Wed, Apr 15, 2020 at 8:00 AM Sebastian Huber
>  wrote:
> >
> > On 15/04/2020 15:55, Utkarsh Rai wrote:
> >
> > Yes sir.
> >
> > Ok, good, then you should do this. Maybe someone else solved this
> problem already.
> >
> >
> > On Wed 15 Apr, 2020, 7:21 PM Sebastian Huber, <
> sebastian.hu...@embedded-brains.de> wrote:
> >>
> >> On 15/04/2020 15:00, Utkarsh Rai wrote:
> >>
> >> > Okay, so from what I could gather the time between the two gettime
> >> > calls can exceed 1 sec if it is preempted by another process in
> >> > between. Is my line of thought correct?
> >> There is no other process. What you want to know is if the difference
> >> between two struct timespec is greater than or equal to 1ns, right?
> >
> > ___
> > devel mailing list
> > devel@rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Gedare Bloom
On Tue, Apr 14, 2020 at 10:56 PM Sebastian Huber
 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 00..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 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*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;
> > +  intstatus;
> > +
> > +  delay_time.tv_sec = 0;
> > +  delay_time.tv_nsec = 1;
> > +
> > +  

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Gedare Bloom
I appreciate what Sebastian is doing, but I'll be a bit more explicit.
You should understand what resources/APIs already exist that may help
you, such as:  
https://docs.rtems.org/branches/master/c-user/timespec_helpers.html#timespec-helpers

What happens when the time is 11:59:59.9 (HH:MM:SS.mmmuuunnn)
and you delay for 1 ns?

On Wed, Apr 15, 2020 at 8:00 AM Sebastian Huber
 wrote:
>
> On 15/04/2020 15:55, Utkarsh Rai wrote:
>
> Yes sir.
>
> Ok, good, then you should do this. Maybe someone else solved this problem 
> already.
>
>
> On Wed 15 Apr, 2020, 7:21 PM Sebastian Huber, 
>  wrote:
>>
>> On 15/04/2020 15:00, Utkarsh Rai wrote:
>>
>> > Okay, so from what I could gather the time between the two gettime
>> > calls can exceed 1 sec if it is preempted by another process in
>> > between. Is my line of thought correct?
>> There is no other process. What you want to know is if the difference
>> between two struct timespec is greater than or equal to 1ns, right?
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Sebastian Huber

On 15/04/2020 15:55, Utkarsh Rai wrote:


Yes sir.
Ok, good, then you should do this. Maybe someone else solved this 
problem already.


On Wed 15 Apr, 2020, 7:21 PM Sebastian Huber, 
> wrote:


On 15/04/2020 15:00, Utkarsh Rai wrote:

> Okay, so from what I could gather the time between the two gettime
> calls can exceed 1 sec if it is preempted by another process in
> between. Is my line of thought correct?
There is no other process. What you want to know is if the difference
between two struct timespec is greater than or equal to 1ns, right?

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Utkarsh Rai
Yes sir.

On Wed 15 Apr, 2020, 7:21 PM Sebastian Huber, <
sebastian.hu...@embedded-brains.de> wrote:

> On 15/04/2020 15:00, Utkarsh Rai wrote:
>
> > Okay, so from what I could gather the time between the two gettime
> > calls can exceed 1 sec if it is preempted by another process in
> > between. Is my line of thought correct?
> There is no other process. What you want to know is if the difference
> between two struct timespec is greater than or equal to 1ns, right?
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Sebastian Huber

On 15/04/2020 15:00, Utkarsh Rai wrote:

Okay, so from what I could gather the time between the two gettime 
calls can exceed 1 sec if it is preempted by another process in 
between. Is my line of thought correct?
There is no other process. What you want to know is if the difference 
between two struct timespec is greater than or equal to 1ns, right?

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Utkarsh Rai
Okay, so from what I could gather the time between the two gettime calls
can exceed 1 sec if it is preempted by another process in between. Is my
line of thought correct?

On Wed, Apr 15, 2020 at 6:01 PM Sebastian Huber <
sebastian.hu...@embedded-brains.de> wrote:

>
> On 15/04/2020 14:29, Utkarsh Rai wrote:
>
> On Wed, Apr 15, 2020 at 5:35 PM Sebastian Huber <
> sebastian.hu...@embedded-brains.de> wrote:
>
>> On 15/04/2020 14:02, Utkarsh Rai wrote:
>>
>> > +  status = clock_gettime( CLOCK_MONOTONIC, _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?
>>>
>>
>> My idea was to check for a 1ns delay with a reasonable amount of
>> overhead, hence I checked for  end_time.tv_sec - init_time.tv_sec == 0.
>>
>> Exists there a value of init_time for which end_time.tv_sec !=
>> init_time.tv_sec and still 1ns elapsed?
>>
>
> Sorry, maybe I am confused in my concept, kidly help me out. I want to
> produce a 1ns delay, so I make a call to clock_nanosleep with flag value as
> 0 (to sleep for specified time) and the delay being 1ns. I recorded the
> time before the sleep call and after the sleep call. Now, I want to check
> if the delay produced was actually 1ns with a reasonable overhead, my
> assumption for an unreasonable overhead was that if I specify a delay of
> 1ns
>
> Up to here everything is fine.
>
> and I get a delay in seconds, it would be an error.
>
> Think about this once more.
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Sebastian Huber


On 15/04/2020 14:29, Utkarsh Rai wrote:
On Wed, Apr 15, 2020 at 5:35 PM Sebastian Huber 
> wrote:


On 15/04/2020 14:02, Utkarsh Rai wrote:


> +  status = clock_gettime( CLOCK_MONOTONIC, _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?


My idea was to check for a 1ns delay with a reasonable amount of
overhead, hence I checked for  end_time.tv_sec - init_time.tv_sec
== 0.

Exists there a value of init_time for which end_time.tv_sec !=
init_time.tv_sec and still 1ns elapsed?


Sorry, maybe I am confused in my concept, kidly help me out. I want to 
produce a 1ns delay, so I make a call to clock_nanosleep with flag 
value as 0 (to sleep for specified time) and the delay being 1ns. I 
recorded the time before the sleep call and after the sleep call. Now, 
I want to check if the delay produced was actually 1ns with a 
reasonable overhead, my assumption for an unreasonable overhead was 
that if I specify a delay of 1ns

Up to here everything is fine.

and I get a delay in seconds, it would be an error.

Think about this once more.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Utkarsh Rai
On Wed, Apr 15, 2020 at 5:35 PM Sebastian Huber <
sebastian.hu...@embedded-brains.de> wrote:

> On 15/04/2020 14:02, Utkarsh Rai wrote:
>
> > +  status = clock_gettime( CLOCK_MONOTONIC, _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?
>>
>
> My idea was to check for a 1ns delay with a reasonable amount of overhead,
> hence I checked for  end_time.tv_sec - init_time.tv_sec == 0.
>
> Exists there a value of init_time for which end_time.tv_sec !=
> init_time.tv_sec and still 1ns elapsed?
>

Sorry, maybe I am confused in my concept, kidly help me out. I want to
produce a 1ns delay, so I make a call to clock_nanosleep with flag value as
0 (to sleep for specified time) and the delay being 1ns. I recorded the
time before the sleep call and after the sleep call. Now, I want to check
if the delay produced was actually 1ns with a reasonable overhead, my
assumption for an unreasonable overhead was that if I specify a delay of
1ns and I get a delay in seconds, it would be an error.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Sebastian Huber

On 15/04/2020 14:02, Utkarsh Rai wrote:


> +  status = clock_gettime( CLOCK_MONOTONIC, _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?


My idea was to check for a 1ns delay with a reasonable amount of 
overhead, hence I checked for  end_time.tv_sec - init_time.tv_sec == 0.
Exists there a value of init_time for which end_time.tv_sec != 
init_time.tv_sec and still 1ns elapsed?
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-15 Thread Utkarsh Rai
On Wed, Apr 15, 2020 at 10:26 AM Sebastian Huber <
sebastian.hu...@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.
>
Would it be alright to add the test cases for clock nanosleep in
psxtests/psxclock? I had two test cases in mind-
To check for a simple desired delay and to check that clock_nanosleep
produces the required delay with CLOCK_MONOTONIC even when CLOCK_REALTIME
is modified.

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 00..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 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*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 

Re: [PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-14 Thread Sebastian Huber

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.


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 00..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 
+#include 
+#include 
+#include 
+
+/*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;
+  intstatus;
+
+  delay_time.tv_sec = 0;
+  delay_time.tv_nsec = 1;
+
+  status=clock_nanosleep( CLOCK_MONOTONIC, 0, _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;
+  intstatus;
+
+  TEST_BEGIN();
+
+  status = clock_gettime( CLOCK_MONOTONIC, _time );
+  rtems_test_assert( status == 0 );
+
+  clock_sleep();
+
+  status = clock_gettime( CLOCK_MONOTONIC, _time );
+  rtems_test_assert( status == 0 );
+
+  rtems_test_assert( (end_time.tv_sec-init_time.tv_sec) == 0 );


Is end_time.tv_sec - 

[PATCH v2] Test for clock_nanosleep with CLOCK_MONOTONIC option.

2020-04-14 Thread Utkarsh Rai
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 00..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 
+#include 
+#include 
+#include 
+
+/*Forward declaration to avoid compiler warning*/
+void clock_sleep(void);
+
+rtems_task Init(rtems_task_argument ignored);
+
+const char rtems_test_name[] = "PSXCLOCKNANOSLEEP 01";
+
+void clock_sleep(void)
+{
+  struct timespec delay_time;
+  intstatus;
+
+  delay_time.tv_sec = 0;
+  delay_time.tv_nsec = 1;
+
+  status=clock_nanosleep( CLOCK_MONOTONIC, 0, _time, (struct timespec* 
)NULL );
+  rtems_test_assert( status == 0 );
+}
+
+rtems_task Init(rtems_task_argument ignored)
+{
+
+  struct timespec init_time;
+  struct timespec end_time;
+  intstatus;
+
+  TEST_BEGIN();
+
+  status = clock_gettime( CLOCK_MONOTONIC, _time );
+  rtems_test_assert( status == 0 );
+
+  clock_sleep();
+
+  status = clock_gettime( CLOCK_MONOTONIC, _time );
+  rtems_test_assert( status == 0 );
+
+  rtems_test_assert( (end_time.tv_sec-init_time.tv_sec) == 0 );
+  rtems_test_assert( (end_time.tv_nsec-init_time.tv_nsec) >=1 );
+
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS  1
+#define CONFIGURE_INIT
+#include 
\ No newline at end of file
diff --git a/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.doc 
b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.doc
new file mode 100644
index