<div dir="ltr"><div dir="ltr">I am pretty sure I can report that it won't execute on just visually reviewing it.</div><div dir="ltr"><br><div>First, it assumes at least a semi-functional pthread_getcpuclockid() and there is not one in the tree.</div><div><br></div><div>You should be testing things yourself. There are multiple simulators which have BSPs and are easy to run. We can discuss which one in another thread. </div><div><br></div><div>Other comments interspersed.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 9, 2020 at 3:30 PM Eshan dhawan <<a href="mailto:eshandhawan51@gmail.com">eshandhawan51@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
testsuites/psxtests/Makefile.am | 10 ++<br>
testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 1 +<br>
testsuites/psxtests/psxgetcpuclockid01/init.c | 120 ++++++++++++++++++<br>
.../psxgetcpuclockid01/psxgetcpuclockid01.doc | 19 +++<br>
.../psxgetcpuclockid01/psxgetcpuclockid01.scn | 4 +<br>
5 files changed, 154 insertions(+)<br>
create mode 100644 testsuites/psxtests/psxgetcpuclockid01/init.c<br>
create mode 100644 testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc<br>
create mode 100644 testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn<br>
<br>
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am<br>
index 1f9e4233ec..ffadff16e7 100755<br>
--- a/testsuites/psxtests/Makefile.am<br>
+++ b/testsuites/psxtests/Makefile.am<br>
@@ -462,6 +462,16 @@ psxgetattrnp01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxgetattrnp01) \<br>
$(support_includes) -I$(top_srcdir)/include<br>
endif<br>
<br>
+if TEST_psxgetcpuclockid01<br>
+psx_tests += psxgetcpuclockid01<br>
+psx_screens += psxgetcpuclockid01/psxgetcpuclockid01.scn<br>
+psx_docs += psxgetcpuclockid01/psxgetcpuclockid01.doc<br>
+psxgetcpuclockid01_SOURCES = psxgetcpuclockid01/init.c<br>
+psxgetcpuclockid01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxgetcpuclockid01) \<br>
+ $(support_includes)<br>
+endif<br>
+<br>
+<br>
if TEST_psxgetrusage01<br>
psx_tests += psxgetrusage01<br>
psx_screens += psxgetrusage01/psxgetrusage01.scn<br>
diff --git a/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index 139787cccb..c509086abc 100644<br>
--- a/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -91,6 +91,7 @@ RTEMS_TEST_CHECK([psxfile01])<br>
RTEMS_TEST_CHECK([psxfile02])<br>
RTEMS_TEST_CHECK([psxfilelock01])<br>
RTEMS_TEST_CHECK([psxgetattrnp01])<br>
+RTEMS_TEST_CHECK([psxgetcpuclockid01])<br>
RTEMS_TEST_CHECK([psxgetrusage01])<br>
RTEMS_TEST_CHECK([psxglobalcon01])<br>
RTEMS_TEST_CHECK([psxglobalcon02])<br>
diff --git a/testsuites/psxtests/psxgetcpuclockid01/init.c b/testsuites/psxtests/psxgetcpuclockid01/init.c<br>
new file mode 100644<br>
index 0000000000..8e1093e44b<br>
--- /dev/null<br>
+++ b/testsuites/psxtests/psxgetcpuclockid01/init.c<br>
@@ -0,0 +1,120 @@<br>
+/*<br>
+ * @file<br>
+ * @brief Test suite for getcpuclockid methods<br>
+ */<br>
+<br>
+/*<br>
+ * SPDX-License-Identifier: BSD-2-Clause<br>
+ *<br>
+ * Copyright (C) 2020 Eshan Dhawan<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with or without<br>
+ * modification, are permitted provided that the following conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above copyright<br>
+ * notice, this list of conditions and the following disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the above copyright<br>
+ * notice, this list of conditions and the following disclaimer in the<br>
+ * documentation and/or other materials provided with the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+<br>
+#ifdef HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <errno.h><br>
+#include <pthread.h><br>
+#include <stdint.h><br>
+#include <rtems/test.h><br>
+#include <sys/utsname.h><br>
+#include <unistd.h><br>
+#include <errno.h><br>
+#include <sched.h><br><br></blockquote><div>I am sure at least some of these are not needed. I suspect almost everything below rtems/test.h is not needed. </div><div><br></div><div>errno.h is twice.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+#include <rtems/score/todimpl.h><br>
+#include <rtems/score/threadimpl.h><br></blockquote><div><br></div><div>Why are these needed?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+#include "tmacros.h"<br>
+<br>
+const char rtems_test_name[] = "PSXGETCPUCLOCKID 1";<br>
+<br>
+/* Forward declaration to avoid warnings */<br>
+rtems_task Init(rtems_task_argument ignored);<br>
+void *test_pthread(void *);<br>
+/* test_task function begins */<br>
+void *test_pthread(void *arg)<br>
+{<br>
+ int r;<br>
+ clockid_t cid;<br>
+<br>
+ r = pthread_getcpuclockid( pthread_self(), &cid );<br>
+ if(r)<br>
+ {<br>
+ printf( "pthread_getcpuclockid : 0x%d", r );<br>
+ }<br>
+ rtems_test_assert( r == 0 );<br>
+<br>
+ pthread_exit(0);<br>
+ return NULL;<br>
+}<br>
+<br>
+/* init test function begins */<br>
+rtems_task Init(rtems_task_argument ignored)<br>
+{<br></blockquote><div><br></div><div>For POSIX tests, use a POSIX Initialization thread unless specifically verifying that a Classic API task has particular behavior when using POSIX methods.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ TEST_BEGIN();<br>
+<br>
+ int r;<br>
+ clockid_t cid;<br>
+ pthread_t thread_id;<br>
+<br>
+ r= pthread_create( &thread_id, NULL, test_pthread, NULL );<br>
+ if( r )<br>
+ {<br>
+ printf( "pthread_create : 0x%d", r );<br>
+ }<br>
+ rtems_test_assert( r == 0 );<br></blockquote><div><br></div><div><br></div><div>First, "0x%d" will print a 0x saying it is hex and then print a decimal number.</div><div><br></div><div>Next, I think there are macro constants if you need to print RTEMS types. I can't find anything except pritime.h and primode.h. Perhaps someone else can step in here for help. </div><div><br></div><div>Some style issues:</div><div><br></div><div>+ if( should be "if ("<br></div><div><br></div><div>+ Braces should follow the denser K&R style:<br></div><div> if (condition) {</div><div> } else {</div><div> }</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ r = pthread_join( thread_id, NULL );<br>
+ if( r )<br>
+ {<br>
+ printf( "pthread_join : 0x%d", r );<br>
+ }<br>
+ rtems_test_assert( r == 0 );<br></blockquote><div><br></div><div>You did not set any pthread attributes so you can't be certain that the thread you created is joinable. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ r = pthread_getcpuclockid( thread_id, &cid );<br>
+ if( r != ESRCH )<br>
+ {<br>
+ printf( "pthread_getcpuclockid : 0x%d", r );<br>
+ }<br>
+ rtems_test_assert( r == ESRCH );<br></blockquote><div><br></div><div>I would start with a simple functional test on a single pthread that gets cpu clock id (should succeed).</div><div><br></div><div>Then get its cpu clock and save that time.</div><div><br></div><div>Use some get time API in a loop and spin (no blocking) for say 1/2 second of wall time passage.</div><div><br></div><div>Then see if the CPU time used went up 1/2 second as expected.</div><div><br></div><div>Be aware that the increase in CPU time used will not be exactly 1/2 second. It will be at least 1/2 second but there is a reasonable upper bounds above that. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ TEST_END();<br>
+ rtems_test_exit(0);<br>
+}<br>
+<br>
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER<br>
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER<br>
+<br>
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 2<br>
+#define CONFIGURE_MAXIMUM_TASKS 1<br></blockquote><div><br></div><div>I see a need for 1 pthread in the code as written. Should stay 2 pthreads because you need to switch to pthread initialization thread. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION<br>
+<br>
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE<br></blockquote><div><br></div><div>Switch here to pthread initialization threads. And change Init task to POSIX_Init thread.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+#define CONFIGURE_INIT<br>
+<br>
+#include <rtems/confdefs.h><br>
+<br>
diff --git a/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc<br>
new file mode 100644<br>
index 0000000000..145f009337<br>
--- /dev/null<br>
+++ b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.doc<br>
@@ -0,0 +1,19 @@<br>
+# COPYRIGHT (c) 2020<br>
+# On-Line Applications Research Corporation (OAR).<br>
+#<br>
+# SPDX-License-Identifier: BSD-2-Clause<br>
+#<br>
+<br>
+This file describes the directives and concepts tested by this test set.<br>
+<br>
+test set name: psxgetcpuclockid 1<br>
+<br>
+Directives:<br>
+ Pthread_getcpuclockid()<br>
+<br>
+Concepts:<br>
+<br>
++ This test exercises the getcpuclockid methods.<br>
+<br>
++ For pthread_getcpuclockid it created a pthread using pthread_create and then finds<br>
+the clockid_t of that thread and then ends the thread.<br>
+After the thread is ended it again tried to find the clockid_t of the thread to check<br>
+for ESRCH exception.<br>
+<br>
diff --git a/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn<br>
new file mode 100644<br>
index 0000000000..937a908fd5<br>
--- /dev/null<br>
+++ b/testsuites/psxtests/psxgetcpuclockid01/psxgetcpuclockid01.scn<br>
@@ -0,0 +1,4 @@<br>
+*** BEGIN OF TEST PSXGETCLOCKID 1 ***<br>
+<br>
+*** END OF TEST PSXGETCPUCLOCKID 1 ***<br>
+<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div>