[PATCH v4 1/1] Test for clock_nanosleep() with CLOCK_MONOTONIC option

Utkarsh Rai utkarsh.rai60 at gmail.com
Wed Oct 21 03:28:24 UTC 2020


---
 .../psxtests/psxclocknanosleep01.yml          |  19 +++
 spec/build/testsuites/psxtmtests/grp.yml      |   4 +
 .../psxtmtests/psxtmclocknanosleep04.yml      |  19 +++
 .../psxtmtests/psxtmclocknanosleep05.yml      |  19 +++
 .../psxtests/psxclocknanosleep01/init.c       | 145 ++++++++++++++++++
 .../psxclocknanosleep01.doc                   |  13 ++
 .../psxclocknanosleep01.scn                   |  50 ++++++
 .../psxtmtests/psxtmclocknanosleep04/init.c   |  70 +++++++++
 .../psxtmtests/psxtmclocknanosleep05/init.c   | 116 ++++++++++++++
 9 files changed, 455 insertions(+)
 create mode 100644 spec/build/testsuites/psxtests/psxclocknanosleep01.yml
 create mode 100644 spec/build/testsuites/psxtmtests/psxtmclocknanosleep04.yml
 create mode 100644 spec/build/testsuites/psxtmtests/psxtmclocknanosleep05.yml
 create mode 100644 testsuites/psxtests/psxclocknanosleep01/init.c
 create mode 100644 testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.doc
 create mode 100644 testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn
 create mode 100644 testsuites/psxtmtests/psxtmclocknanosleep04/init.c
 create mode 100644 testsuites/psxtmtests/psxtmclocknanosleep05/init.c

diff --git a/spec/build/testsuites/psxtests/psxclocknanosleep01.yml b/spec/build/testsuites/psxtests/psxclocknanosleep01.yml
new file mode 100644
index 0000000000..990e4a633c
--- /dev/null
+++ b/spec/build/testsuites/psxtests/psxclocknanosleep01.yml
@@ -0,0 +1,19 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Utkarsh Rai(utkarsh.rai60 at gmail.com)
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags: []
+links: []
+source:
+- testsuites/psxtests/psxclocknanosleep01/init.c
+stlib: []
+target: testsuites/psxtests/psxclocknanosleep01.exe
+type: build
+use-after: []
+use-before: []
diff --git a/spec/build/testsuites/psxtmtests/grp.yml b/spec/build/testsuites/psxtmtests/grp.yml
index 2d4c5b2b97..409d1c45b7 100644
--- a/spec/build/testsuites/psxtmtests/grp.yml
+++ b/spec/build/testsuites/psxtmtests/grp.yml
@@ -31,6 +31,10 @@ links:
   uid: psxtmclocknanosleep02
 - role: build-dependency
   uid: psxtmclocknanosleep03
+- role: build-dependency
+  uid: psxtmclocknanosleep04
+- role: build-dependency
+  uid: psxtmclocknanosleep05
 - role: build-dependency
   uid: psxtmcond01
 - role: build-dependency
diff --git a/spec/build/testsuites/psxtmtests/psxtmclocknanosleep04.yml b/spec/build/testsuites/psxtmtests/psxtmclocknanosleep04.yml
new file mode 100644
index 0000000000..12672c79ed
--- /dev/null
+++ b/spec/build/testsuites/psxtmtests/psxtmclocknanosleep04.yml
@@ -0,0 +1,19 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Utkarsh Rai (utkarsh.rai60 at gmail.com)
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags: []
+links: []
+source:
+- testsuites/psxtmtests/psxtmclocknanosleep04/init.c
+stlib: []
+target: testsuites/psxtmtests/psxtmclocknanosleep04.exe
+type: build
+use-after: []
+use-before: []
diff --git a/spec/build/testsuites/psxtmtests/psxtmclocknanosleep05.yml b/spec/build/testsuites/psxtmtests/psxtmclocknanosleep05.yml
new file mode 100644
index 0000000000..a3634341de
--- /dev/null
+++ b/spec/build/testsuites/psxtmtests/psxtmclocknanosleep05.yml
@@ -0,0 +1,19 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Utkarsh Rai (utkarsh.rai60 at gmail.com)
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags: []
+links: []
+source:
+- testsuites/psxtmtests/psxtmclocknanosleep05/init.c
+stlib: []
+target: testsuites/psxtmtests/psxtmclocknanosleep05.exe
+type: build
+use-after: []
+use-before: []
diff --git a/testsuites/psxtests/psxclocknanosleep01/init.c b/testsuites/psxtests/psxclocknanosleep01/init.c
new file mode 100644
index 0000000000..278683953c
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/init.c
@@ -0,0 +1,145 @@
+/* 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <time.h>
+#include <rtems/test.h>
+#include <rtems/test-info.h>
+
+T_TEST_CASE( POSIXClock_Timeout_finite )
+{
+  struct timespec delay_time;
+  int eno;
+
+  eno = clock_gettime( CLOCK_MONOTONIC, &delay_time );
+  T_eno_success( eno );
+
+  delay_time.tv_sec += 1;
+
+  eno = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &delay_time, NULL );
+  T_eno_success( eno );
+}
+
+T_TEST_CASE( POSIXClock_Timeout_huge_nsec )
+{
+  struct timespec delay_time;
+  int eno;
+
+  delay_time.tv_sec = 1;
+  delay_time.tv_nsec = LONG_MAX;
+
+  eno = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &delay_time, NULL );
+  T_eno( EINVAL, eno );
+}
+
+T_TEST_CASE( POSIXClock_Timeout_negative_sec )
+{
+  struct timespec delay_time;
+  int eno;
+
+  delay_time.tv_sec = -1;
+  delay_time.tv_nsec = 1;
+
+  eno = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &delay_time, NULL );
+  T_eno_success( eno );
+
+}
+
+T_TEST_CASE( POSIXClock_Timeout_negative_nsec )
+{
+  struct timespec delay_time;
+  int eno;
+
+  delay_time.tv_sec = 1;
+  delay_time.tv_nsec = -1;
+
+  eno = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &delay_time, NULL );
+  T_eno( EINVAL, eno );
+}
+
+T_TEST_CASE(POSIXClock_Timeout_negative_sec_nsec)
+{
+  struct timespec delay_time;
+  int eno;
+
+  delay_time.tv_sec = -1;
+  delay_time.tv_nsec = -1;
+
+  eno = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &delay_time, NULL );
+  T_eno( EINVAL, eno);
+}
+
+T_TEST_CASE( POSIXClock_Timeout_clock_modify )
+{
+  struct timespec configure_time;
+  struct timespec delay_time;
+  int eno;
+
+/**
+ * Modify the REALTIME clock, this should not have any effect on the sleep time
+ * with the MONOTONIC clock.
+*/
+
+  eno = clock_gettime( CLOCK_REALTIME, &configure_time );
+  T_eno_success( eno );
+
+  configure_time.tv_sec += 3600;
+  eno = clock_settime( CLOCK_REALTIME, &configure_time );
+  T_eno_success( eno );
+
+  eno = clock_gettime( CLOCK_MONOTONIC, &delay_time );
+  T_eno_success( eno );
+
+  delay_time.tv_sec += 1;
+
+  eno = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &delay_time, NULL );
+  T_eno_success( eno );
+}
+
+const char rtems_test_name[] = "POSIXCLOCKNANOSLEEP01";
+
+static rtems_task Init ( rtems_task_argument argument )
+{
+    rtems_test_run( argument, TEST_STATE );
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
\ 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 0000000000..803c2cff15
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.doc
@@ -0,0 +1,13 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: psxclocknanosleep01
+
+directives:
+
+- clock_nanosleep()
+
+concepts:
+
+- Test some invalid and extreme timeout values.
+- Ensure that the CLOCK_MONOTONIC based delay is not affected by changes to
+  CLOCK_REALTIME
\ No newline at end of file
diff --git a/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn
new file mode 100644
index 0000000000..38479c27fd
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn
@@ -0,0 +1,50 @@
+** BEGIN OF TEST POSIXCLOCKNANOSLEEP01 ***
+*** TEST VERSION: 6.0.0.560c08cc3d458cdeb4abc014deef8f4ce42a5d54
+*** TEST STATE: EXPECTED_PASS
+*** TEST BUILD:
+*** TEST TOOLS: 10.2.1 20200918 (RTEMS 6, RSB ed5030bc24dbfdfac52074ed78cf4231bf1f353d, Newlib 749cbcc)
+A:POSIXCLOCKNANOSLEEP01
+S:Platform:RTEMS
+S:Compiler:10.2.1 20200918 (RTEMS 6, RSB ed5030bc24dbfdfac52074ed78cf4231bf1f353d, Newlib 749cbcc)
+S:Version:6.0.0.560c08cc3d458cdeb4abc014deef8f4ce42a5d54
+S:BSP:realview_pbx_a9_qemu
+S:RTEMS_DEBUG:0
+S:RTEMS_MULTIPROCESSING:0
+S:RTEMS_POSIX_API:0
+S:RTEMS_PROFILING:0
+S:RTEMS_SMP:0
+B:POSIXClock_Timeout_negative_sec_nsec
+P:0:0:UI1:init.c:99
+E:POSIXClock_Timeout_negative_sec_nsec:N:1:F:0:D:0.004953
+B:POSIXClock_Timeout_negative_sec
+P:0:0:UI1:init.c:74
+E:POSIXClock_Timeout_negative_sec:N:1:F:0:D:0.000541
+B:POSIXClock_Timeout_negative_nsec
+P:0:0:UI1:init.c:87
+E:POSIXClock_Timeout_negative_nsec:N:1:F:0:D:0.000347
+B:POSIXClock_Timeout_huge_nsec
+P:0:0:UI1:init.c:62
+E:POSIXClock_Timeout_huge_nsec:N:1:F:0:D:0.000271
+B:POSIXClock_Timeout_finite
+P:0:0:UI1:init.c:43
+P:1:0:UI1:init.c:50
+E:POSIXClock_Timeout_finite:N:2:F:0:D:0.009012
+B:POSIXClock_Timeout_clock_modify
+P:0:0:UI1:init.c:109
+P:1:0:UI1:init.c:113
+P:2:0:UI1:init.c:116
+P:3:0:UI1:init.c:121
+E:POSIXClock_Timeout_clock_modify:N:4:F:0:D:1.008998
+Z:POSIXCLOCKNANOSLEEP01:C:6:N:10:F:0:D:1.027995
+Y:ReportHash:SHA256:7abe99f057e7ed39a7cd7ffd51c6ff0e0ec85ef1b8fe153399bd1b0a185bcfeb
+
+*** END OF TEST POSIXCLOCKNANOSLEEP01 ***
+
+
+*** FATAL ***
+fatal source: 5 (RTEMS_FATAL_SOURCE_EXIT)
+fatal code: 0 (0x00000000)
+RTEMS version: 6.0.0.560c08cc3d458cdeb4abc014deef8f4ce42a5d54
+RTEMS tools: 10.2.1 20200918 (RTEMS 6, RSB ed5030bc24dbfdfac52074ed78cf4231bf1f353d, Newlib 749cbcc)
+executing thread ID: 0x08a010001
+executing thread name: UI1
diff --git a/testsuites/psxtmtests/psxtmclocknanosleep04/init.c b/testsuites/psxtmtests/psxtmclocknanosleep04/init.c
new file mode 100644
index 0000000000..4dd83b3201
--- /dev/null
+++ b/testsuites/psxtmtests/psxtmclocknanosleep04/init.c
@@ -0,0 +1,70 @@
+/* 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <time.h>
+#include <timesys.h>
+#include <pthread.h>
+#include <rtems/btimer.h>
+#include <rtems/test.h>
+#include <rtems/test-info.h>
+
+const char rtems_test_name[] = "PSXTMCLOCKNANOSLEEP 04";
+
+T_TEST_CASE( POSIX_Clocknanosleep_monotonic_yield )
+{
+  benchmark_timer_t end_time;
+  struct timespec sleep_time;
+
+  sleep_time.tv_sec = 0;
+  sleep_time.tv_nsec = 1;
+
+  benchmark_timer_initialize();
+  clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &sleep_time, NULL );
+  end_time = benchmark_timer_read();
+
+  put_time( "clock_nanosleep(MONOTONIC): yield", end_time, 1, 0, 0 );
+
+}
+
+static rtems_task Init( rtems_task_argument argument)
+{
+    rtems_test_run( argument, TEST_STATE );
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
\ No newline at end of file
diff --git a/testsuites/psxtmtests/psxtmclocknanosleep05/init.c b/testsuites/psxtmtests/psxtmclocknanosleep05/init.c
new file mode 100644
index 0000000000..dd43b4dc36
--- /dev/null
+++ b/testsuites/psxtmtests/psxtmclocknanosleep05/init.c
@@ -0,0 +1,116 @@
+/* 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <time.h>
+#include <timesys.h>
+#include <rtems/btimer.h>
+#include <rtems/test.h>
+#include <rtems/test-info.h>
+
+const char rtems_test_name[] = "PSXTMCLOCKNANOSLEEP 05";
+
+void *Low(
+  void *argument
+)
+{
+  benchmark_timer_t end_time;
+
+  end_time = benchmark_timer_read();
+
+  put_time(
+    "clock_nanosleep(MONOTONIC): blocking",
+    end_time,
+    OPERATION_COUNT,
+    0,
+    0
+  );
+
+  return NULL;
+}
+
+void *Middle(
+  void *argument
+)
+{
+  /* calling nanosleep */
+  struct timespec sleepTime;
+  sleepTime.tv_sec = 0;
+  sleepTime.tv_nsec = 1;
+
+  clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &sleepTime, NULL );
+
+  return NULL;
+}
+
+T_TEST_CASE( POSIX_Clocknanosleep_monotonic_blocking )
+{
+  int        i;
+  int        status;
+  pthread_t  threadId;
+  struct timespec sleepTime;
+  struct timespec remainder;
+
+  sleepTime.tv_sec = 0;
+  sleepTime.tv_nsec = 1;
+  remainder.tv_sec = 0;
+  remainder.tv_nsec = 0;
+
+  for ( i = 0 ; i < OPERATION_COUNT - 1 ; i++ ) {
+    status = pthread_create( &threadId, NULL, Middle, NULL );
+    T_psx_success( status );
+  }
+
+  status = pthread_create( &threadId, NULL, Low, NULL );
+  T_psx_success( status );
+
+  /* start the timer and switch through all the other tasks */
+  benchmark_timer_initialize();
+  /* calling clock_nanosleep*/
+  clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &sleepTime, &remainder );
+
+}
+
+static rtems_task Init( rtems_task_argument argument)
+{
+    rtems_test_run( argument, TEST_STATE );
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 1
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
\ No newline at end of file
-- 
2.25.1



More information about the devel mailing list