[PATCH] Test for clock_nanosleep with CLOCK_MONOTONIC option.

Utkarsh Rai utkarsh.rai60 at gmail.com
Tue Apr 14 12:02:53 UTC 2020


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..462ee114f8
--- /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);
+
+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);
+  rtems_test_assert(!status);
+}
+
+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);
+
+  clock_sleep();
+
+  status = clock_gettime(CLOCK_MONOTONIC, &end_time);
+  rtems_test_assert(!status);
+
+  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<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..ac70182aa0
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.doc
@@ -0,0 +1,10 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name:  psxclocknanosleep01
+
+directives: clock_nanosleep
+
+concepts:
+
++ This test ensures that the clock_nanosleep produces a 1 ns delay while using
+CLOCK_MONOTONIC option
\ 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..2f1b39f4f7
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn
@@ -0,0 +1,3 @@
+*** BEGIN OF TEST PSXCLOCKNANOSLEEP 01 ***
+
+*** END OF TEST PSXCLOCKNANOSLEEP 01 ***
-- 
2.17.1



More information about the devel mailing list