Hello,
In yesterday's weekly meeting I mentioned about fenv problems I faced while
developing testsuite.
.
Here is a very raw patch of my code as testsuite is still in development.
.
==================================================
Error 1
==================================================
I took three float values:
a = 0.0
b = 1.0
c = b/a
This should have automatically raised FE_DIVBYZERO exception, which does
not happens.
No exception flag is set.
.
.
==================================================
Error 2
==================================================
Then I tried to raise an exception manually using feraiseexcept(), but this
operation was also unsuccessful .
The method returned 1 on execution, but it should return 0 on successful
operation.
.
.
==================================================
Warning
==================================================
As mentioned in opengroup I tried to define a pragma
https://pubs.opengroup.org/onlinepubs/009696799/basedefs/fenv.h.html
.
#pragma STDC FENV_ACCESS ON
.
But this pragma is ignored while 'make -j 2'
/home/varodek/development/rtems/kernel/rtems/c/src/../../testsuites/psxtests/psxfenv01/init.c:50:
warning: ignoring #pragma STDC FENV_ACCESS [-Wunknown-pragmas]

.
.

--Vaibhav Gupta
From 3ed1e005dd7629c2b0501cac457a758f3103b1fe Mon Sep 17 00:00:00 2001
From: Vaibhav Gupta <vaibhavgupt...@gmail.com>
Date: Thu, 15 Aug 2019 15:09:28 +0530
Subject: [PATCH] Trial 10

---
 testsuites/psxtests/Makefile.am      |   8 ++
 testsuites/psxtests/configure.ac     |   1 +
 testsuites/psxtests/psxfenv01/init.c | 121 +++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 testsuites/psxtests/psxfenv01/init.c

diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index c12b03636d..f6ab42fab5 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -415,6 +415,14 @@ psxfchx01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxfchx01) \
 	$(support_includes) -I$(top_srcdir)/include
 endif
 
+if TEST_psxfenv01
+psx_tests += psxfenv01
+psxfenv01_SOURCES = psxfenv01/init.c
+psxfenv01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxfenv01) \
+       $(support_includes)
+psxfenv01_LDADD = -lm $(LDADD)
+endif
+
 if TEST_psxfile01
 psx_tests += psxfile01
 psx_screens += psxfile01/psxfile01.scn
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index bb44bb8883..92d3543acb 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -83,6 +83,7 @@ RTEMS_TEST_CHECK([psxenosys])
 RTEMS_TEST_CHECK([psxfatal01])
 RTEMS_TEST_CHECK([psxfatal02])
 RTEMS_TEST_CHECK([psxfchx01])
+RTEMS_TEST_CHECK([psxfenv01])
 RTEMS_TEST_CHECK([psxfile01])
 RTEMS_TEST_CHECK([psxfile02])
 RTEMS_TEST_CHECK([psxfilelock01])
diff --git a/testsuites/psxtests/psxfenv01/init.c b/testsuites/psxtests/psxfenv01/init.c
new file mode 100644
index 0000000000..eae02da22e
--- /dev/null
+++ b/testsuites/psxtests/psxfenv01/init.c
@@ -0,0 +1,121 @@
+/*
+ *  @file
+ *  @brief Test suite for fenv.h methods
+ */
+
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2019 Vaibhav Gupta
+ *
+ * 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
+
+/* header files are listed in lexical/lexicographical/alphabetical order */
+
+#include <errno.h>
+#include <limits.h>
+#include <math.h>
+#include <fenv.h>       /* contains declarations of fenv methods */
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <rtems/test.h>
+#include <tmacros.h>
+
+#pragma STDC FENV_ACCESS ON
+
+const char rtems_test_name[] = "PSXFENV 01";
+
+/* forward declarations to avoid warnings */
+rtems_task Init(rtems_task_argument ignored);
+
+/* Test Function Begins */
+rtems_task Init(rtems_task_argument ignored)
+{
+  double a, b, c;
+  int r;
+  fexcept_t excepts;
+  TEST_BEGIN();
+
+  /*
+   * 'FE_ALL_EXCEPT' will be defined only when 'feclearexcept()',
+   * 'fegetexceptflag()', 'feraiseexcept()', 'fesetexceptflag()' and
+   * 'fetestexcept()' functions are supported by the architecture.
+   * Hence their testcases can be wrapped under #ifdef and #endif. 
+   */
+  #ifdef FE_ALL_EXCEPT /* floating-point exceptions */
+  
+  /* Test 'feclearexcept()' and 'fetestexcept()' in one go. */
+  rtems_test_assert( feclearexcept( FE_ALL_EXCEPT ) == 0 );
+  /* Integer value for exceptions currently raised is zero */
+  rtems_test_assert( fetestexcept( FE_ALL_EXCEPT ) == 0 );
+  
+  /* Test 'FE_DIVBYZERO' */
+  puts( "\nDivide by zero and confirm fetestexcept()." );
+  a = 0.0;
+  b = 1.0;
+  c = b/a;
+
+  /* Dividing a number by zero should raise the exception automatically */
+  
+  printf("\n%d",FE_DIVBYZERO); /* Integer value for divide-by-zero exception */
+
+  fegetexceptflag(&excepts,FE_ALL_EXCEPT); /* integer value of excpetion
+  raised after mathematical operation. The value should be equal to that of 
+  divide-by-zero exception. */
+  
+  printf("\n%d",excepts);
+
+  rtems_test_assert( fetestexcept( FE_DIVBYZERO ) );
+
+  r = feraiseexcept(FE_DIVBYZERO); /* try to raise excpetion manually */
+  printf("\n%d\n",r);
+  rtems_test_assert( fetestexcept( FE_DIVBYZERO ) );
+
+  #endif /* floating-point exceptions */
+
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+/* NOTICE: the clock driver is explicitly disabled */
+
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS                  1
+
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+/* end of file */
-- 
2.21.0

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to