[PATCH] Tests for pthread_getcpuclockid method. Ticket:3891

Eshan dhawan eshandhawan51 at gmail.com
Fri Jul 10 23:01:39 UTC 2020


The test wont run as there are no support by clock_gettime

Signed-off-by: Eshan dhawan <eshandhawan51 at gmail.com>
---
 testsuites/psxtests/Makefile.am               |   9 +
 testsuites/psxtests/configure.ac              |   1 +
 testsuites/psxtests/psxgetcpuclockid01/init.c | 204 ++++++++++++++++++
 .../psxgetcpuclockid01/psxgetcpuclockid01.doc |  23 ++
 .../psxgetcpuclockid01/psxgetcpuclockid01.scn |   4 +
 5 files changed, 241 insertions(+)
 create mode 100644 testsuites/psxtests/psxgetcpuclockid01/init.c
 create mode 100644 testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc
 create mode 100644 testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn

diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 1f9e4233ec..7924bbea5d 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -462,6 +462,15 @@ psxgetattrnp01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxgetattrnp01) \
 	$(support_includes) -I$(top_srcdir)/include
 endif
 
+if TEST_psxgetcpuclockid01
+psx_tests += psxgetcpuclockid01
+psx_screens += psxgetcpuclockid01/psxgetcpuclockid01.scn
+psx_docs += psxgetcpuclockid01/psxgetcpuclockid01.doc
+psxgetcpuclockid01_SOURCES = psxgetcpuclockid01/init.c
+psxgetcpuclockid01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxgetcpuclockid01) \
+	$(support_includes)
+endif
+
 if TEST_psxgetrusage01
 psx_tests += psxgetrusage01
 psx_screens += psxgetrusage01/psxgetrusage01.scn
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 139787cccb..c509086abc 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -91,6 +91,7 @@ RTEMS_TEST_CHECK([psxfile01])
 RTEMS_TEST_CHECK([psxfile02])
 RTEMS_TEST_CHECK([psxfilelock01])
 RTEMS_TEST_CHECK([psxgetattrnp01])
+RTEMS_TEST_CHECK([psxgetcpuclockid01])
 RTEMS_TEST_CHECK([psxgetrusage01])
 RTEMS_TEST_CHECK([psxglobalcon01])
 RTEMS_TEST_CHECK([psxglobalcon02])
diff --git a/testsuites/psxtests/psxgetcpuclockid01/init.c b/testsuites/psxtests/psxgetcpuclockid01/init.c
new file mode 100644
index 0000000000..4977a11290
--- /dev/null
+++ b/testsuites/psxtests/psxgetcpuclockid01/init.c
@@ -0,0 +1,204 @@
+/*
+ *  @file
+ *  @brief Test suite for getcpuclockid methods
+ */
+
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2020 embedded brains GmbH, Eshan Dhawan
+ *
+ * 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 <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <rtems.h>
+#include <rtems/timespec.h>
+#include <rtems/test.h>
+#include <time.h>
+#include <unistd.h>
+#include <t.h>
+#include <rtems/bspIo.h>
+
+#include "tmacros.h"
+#include "test_support.h"
+
+const char rtems_test_name[] = "PSXGETCPUCLOCKID 1";
+
+/* Forward declaration to avoid warnings */
+void *POSIX_Init (void * argument);
+void *test_pthread(void *);
+
+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 = "psxgetcpuclockid1",
+  .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
+};
+
+/* test_pthread function begins */
+void *test_pthread(void *arg)
+{
+  int i;
+  /*do something*/
+  for( i = 0; i < 200000; i++ );
+
+  pthread_exit(0);
+  return NULL;
+}
+
+/* init test function begins */
+T_TEST_CASE(pthread_getcpuclockid)
+{
+
+  int r;
+  clockid_t cid;
+  pthread_t thread_id;
+  struct timespec start_cpu, start_wall, finish;
+  struct timespec time_passed_wall, time_passed_cpu ;
+  bool result ;
+  /* setting  the timespecs to zero */
+  rtems_timespec_zero( &start_cpu );
+  rtems_timespec_zero( &start_wall );
+  rtems_timespec_zero( &finish );
+  rtems_timespec_zero( &time_passed_wall );
+  rtems_timespec_zero( &time_passed_cpu );
+
+  /* getting the cpuclock_id */
+  r = pthread_getcpuclockid( pthread_self(), &cid );
+  /* Error checking for pthread_getcpuclockid() */
+  T_quiet_psx_success(r);
+
+  /* getting the start cpu time of the pthread */
+  r = clock_gettime( cid, &start_cpu );
+  /* Error checking for clock_gettime() */
+  T_quiet_psx_success(r);
+
+  /* starting the wall time */
+  r = clock_gettime( CLOCK_MONOTONIC, &start_wall );
+  /* Error checking clock_gettime */
+  T_quiet_psx_success(r);
+
+  /* starting the loop for .5 seconds of wall time passed */
+  while (1) {
+    /* getting the wall time */
+  clock_gettime( CLOCK_MONOTONIC, &finish );
+  /* calculating the time elapsed */
+  rtems_timespec_subtract( &start_wall, &finish, &time_passed_wall );
+  if(time_passed_wall.tv_nsec >= 500000000 || time_passed_wall.tv_sec >= 0.5 ){
+     break;
+    }
+  }
+
+  /* getting the end cpu clock time */
+  r = clock_gettime( cid, &finish );
+  /* Error checking for clock_gettime() */
+  T_quiet_psx_success(r);
+
+  /* calculating the cpu time elapsed */
+  rtems_timespec_subtract( &start_cpu, &finish, &time_passed_cpu );
+  /* comparing the wall and cpu times*/
+  /* cpu time should be greater then the wall time */
+  result = rtems_timespec_less_than( &time_passed_wall, &time_passed_cpu );
+  /* checking the result */
+  if( !result )
+  {
+    printf( "CPU time elapsed is less than the wall time" );
+  }
+  T_quiet_psx_success( result );
+
+  /* creating a pthread to chech for ESRCH Exeption */
+  r= pthread_create( &thread_id, NULL, test_pthread, NULL );
+  /* Checking error in pthread_create() */
+  T_quiet_psx_success(r);
+
+  /* joining the pthread to make the thread_id invalid */
+  r = pthread_join( thread_id, NULL );
+  /* Checking for error in pthread_join() */
+  T_quiet_psx_success(r);
+
+  /* checking the ESRCH Exeption */
+  r = pthread_getcpuclockid( thread_id, &cid );
+  /* Checking for ESRCH exeption */
+  T_quiet_psx_error( r, ESRCH );
+
+}
+
+void *POSIX_Init (void * argument)
+{
+  int exit_code;
+
+  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_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS  2
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc
new file mode 100644
index 0000000000..ef148182d5
--- /dev/null
+++ b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc
@@ -0,0 +1,23 @@
+#  COPYRIGHT (c) 2020
+#  On-Line Applications Research Corporation (OAR).
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name:  psxgetcpuclockid 1
+
+Directives:
+  Pthread_getcpuclockid()
+
+Concepts:
+
++ This test exercises the getcpuclockid methods.
+
++ For pthread_getcpuclockid it created a pthread using pthread_create and
+ then finds the clockid_t of that thread then used gettime() add a pause of .5 seconds
+ and then ends the thread.
+ After the thread is ended it again tried to find the clockid_t of the thread to
+ check for ESRCH exception.
+
diff --git a/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn
new file mode 100644
index 0000000000..705a08d51b
--- /dev/null
+++ b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn
@@ -0,0 +1,4 @@
+*** BEGIN OF TEST PSXGETCPUCLOCKID 1 ***
+
+*** END OF TEST PSXGETCPUCLOCKID 1 ***
+
-- 
2.17.1



More information about the devel mailing list