[PATCH v4] Test for clock_nanosleep() with CLOCK_MONOTONIC option
Utkarsh Rai
utkarsh.rai60 at gmail.com
Mon Sep 21 15:15:32 UTC 2020
From: Utkarsh <utkarsh.rai60 at gmail.com>
Closes #3890
Signed-off-by: Utkarsh Rai <utkarsh.rai60 at gmail.com>
---
spec/build/testsuites/psxtests/grp.yml | 2 +
.../psxtests/psxclocknanosleep01.yml | 20 +++
.../psxtests/psxclocknanosleep01/init.c | 94 ++++++++++++++
.../psxclocknanosleep01.doc | 13 ++
.../psxclocknanosleep01.scn | 41 ++++++
.../test-clock-nanosleep.c | 120 ++++++++++++++++++
6 files changed, 290 insertions(+)
create mode 100644 spec/build/testsuites/psxtests/psxclocknanosleep01.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/psxtests/psxclocknanosleep01/test-clock-nanosleep.c
diff --git a/spec/build/testsuites/psxtests/grp.yml b/spec/build/testsuites/psxtests/grp.yml
index 47dedac275..3342fc6c18 100644
--- a/spec/build/testsuites/psxtests/grp.yml
+++ b/spec/build/testsuites/psxtests/grp.yml
@@ -79,6 +79,8 @@ links:
uid: psxclock
- role: build-dependency
uid: psxclock01
+- role: build-dependency
+ uid: psxclocknanosleep01
- role: build-dependency
uid: psxclockrealtime01
- role: build-dependency
diff --git a/spec/build/testsuites/psxtests/psxclocknanosleep01.yml b/spec/build/testsuites/psxtests/psxclocknanosleep01.yml
new file mode 100644
index 0000000000..39ec1657d2
--- /dev/null
+++ b/spec/build/testsuites/psxtests/psxclocknanosleep01.yml
@@ -0,0 +1,20 @@
+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 mail.com)
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags: []
+links: []
+source:
+- testsuites/psxtests/psxclocknanosleep01/init.c
+- testsuites/psxtests/psxclocknanosleep01/test-clock-nanosleep.c
+stlib: []
+target: testsuites/psxtests/psxclocknanosleep01.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..a5cb4d6054
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/init.c
@@ -0,0 +1,94 @@
+/* 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 <rtems.h>
+#include <rtems/bspIo.h>
+#include <rtems/linkersets.h>
+#include <rtems/test.h>
+#include <rtems/test-info.h>
+#include <tmacros.h>
+
+const char rtems_test_name[] = "PSXCLOCKNANOSLEEP01";
+
+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 = "POSIXCLOCKNANOSLEEPTEST01",
+ .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( &config );
+ if (exit_code == 0) {
+ TEST_END();
+ }
+
+ rtems_test_exit( exit_code );
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_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/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..aa0050e3cd
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/psxclocknanosleep01.scn
@@ -0,0 +1,41 @@
+*** BEGIN OF TEST PSXCLOCKNANOSLEEP01 ***
+*** TEST VERSION: 6.0.0.314dae32156aa3d1f54f1ee104b26604a32cae4f
+*** TEST STATE: EXPECTED_PASS
+*** TEST BUILD:
+*** TEST TOOLS: 10.2.1 20200904 (RTEMS 6, RSB 47f32b8b1a597b5ed3475722bdc155249ef51115, Newlib a0d7982)
+A:POSIXCLOCKNANOSLEEPTEST01
+S:Platform:RTEMS
+S:Compiler:10.2.1 20200904 (RTEMS 6, RSB 47f32b8b1a597b5ed3475722bdc155249ef51115, Newlib a0d7982)
+S:Version:6.0.0.314dae32156aa3d1f54f1ee104b26604a32cae4f
+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:test-clock-nanosleep.c:97
+E:POSIXClock_Timeout_negative_sec_nsec:N:1:F:0:D:0.003693
+B:POSIXClock_Timeout_negative_sec
+P:0:0:UI1:test-clock-nanosleep.c:72
+E:POSIXClock_Timeout_negative_sec:N:1:F:0:D:0.000347
+B:POSIXClock_Timeout_negative_nsec
+P:0:0:UI1:test-clock-nanosleep.c:85
+E:POSIXClock_Timeout_negative_nsec:N:1:F:0:D:0.000227
+B:POSIXClock_Timeout_huge_nsec
+P:0:0:UI1:test-clock-nanosleep.c:60
+E:POSIXClock_Timeout_huge_nsec:N:1:F:0:D:0.000224
+B:POSIXClock_Timeout_finite
+P:0:0:UI1:test-clock-nanosleep.c:43
+P:1:0:UI1:test-clock-nanosleep.c:48
+E:POSIXClock_Timeout_finite:N:2:F:0:D:0.002504
+B:POSIXClock_Timeout_clock_modify
+P:0:0:UI1:test-clock-nanosleep.c:107
+P:1:0:UI1:test-clock-nanosleep.c:111
+P:2:0:UI1:test-clock-nanosleep.c:114
+P:3:0:UI1:test-clock-nanosleep.c:119
+E:POSIXClock_Timeout_clock_modify:N:4:F:0:D:1.009321
+Z:POSIXCLOCKNANOSLEEPTEST01:C:6:N:10:F:0:D:1.018286
+Y:ReportHash:SHA256:cc043d8e8d1a25d2d3a5fb341169ebd8b64e8ba10bc85f34c9905e89c1e01b4f
+
+*** END OF TEST PSXCLOCKNANOSLEEP01 ***
\ No newline at end of file
diff --git a/testsuites/psxtests/psxclocknanosleep01/test-clock-nanosleep.c b/testsuites/psxtests/psxclocknanosleep01/test-clock-nanosleep.c
new file mode 100644
index 0000000000..d61829c5fe
--- /dev/null
+++ b/testsuites/psxtests/psxclocknanosleep01/test-clock-nanosleep.c
@@ -0,0 +1,120 @@
+/* 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;
+
+ 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 );
+}
\ No newline at end of file
--
2.17.1
More information about the devel
mailing list