summaryrefslogtreecommitdiffstats
path: root/testsuites/samples/cdtest
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/samples/cdtest')
-rw-r--r--testsuites/samples/cdtest/init.c25
-rw-r--r--testsuites/samples/cdtest/main.cc58
-rw-r--r--testsuites/samples/cdtest/system.h25
3 files changed, 93 insertions, 15 deletions
diff --git a/testsuites/samples/cdtest/init.c b/testsuites/samples/cdtest/init.c
index 1cf2b20f77..77b5878b79 100644
--- a/testsuites/samples/cdtest/init.c
+++ b/testsuites/samples/cdtest/init.c
@@ -1,10 +1,29 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/*
* COPYRIGHT (c) 1989-2012.
* On-Line Applications Research Corporation (OAR).
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * 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
diff --git a/testsuites/samples/cdtest/main.cc b/testsuites/samples/cdtest/main.cc
index 894e404ba1..1c5057a32b 100644
--- a/testsuites/samples/cdtest/main.cc
+++ b/testsuites/samples/cdtest/main.cc
@@ -25,9 +25,11 @@
#include <rtems.h>
#include <rtems/bspIo.h>
#include <rtems/test-info.h>
+#include <rtems/sysinit.h>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <stdexcept>
#ifdef RTEMS_TEST_IO_STREAM
@@ -44,13 +46,6 @@ extern rtems_task main_task(rtems_task_argument);
static int num_inst = 0;
-static void check_begin_of_test(void)
-{
- if ( num_inst == 0 ) {
- TEST_BEGIN();
- }
-}
-
static void check_end_of_test(void)
{
if ( num_inst == 0 ) {
@@ -62,7 +57,6 @@ class AClass {
public:
AClass(const char *p = "LOCAL" ) : ptr( p )
{
- check_begin_of_test();
num_inst++;
printf(
"%s: Hey I'm in base class constructor number %d for %p.\n",
@@ -104,7 +98,6 @@ class BClass : public AClass {
public:
BClass(const char *p = "LOCAL" ) : AClass( p )
{
- check_begin_of_test();
num_inst++;
printf(
"%s: Hey I'm in derived class constructor number %d for %p.\n",
@@ -244,3 +237,50 @@ rtems_task main_task(
printf( "Global Dtors should be called after this line....\n" );
exit(0);
}
+
+/*
+ * Exceptions during system initialization work only on targets which do not
+ * need a registration of exception frames during the global construction. In
+ * particular, targets which use the DWARF2 unwinder cannot use exceptions
+ * during system initialization.
+ */
+#if defined(__arm__)
+#define CAN_DO_EXCEPTIONS_DURING_SYSINIT
+#endif
+
+#ifdef CAN_DO_EXCEPTIONS_DURING_SYSINIT
+static void early_exception()
+{
+ try
+ {
+ throw "early exception";
+ }
+ catch( const char *e )
+ {
+ rtems_test_assert(strcmp(e, "early exception") == 0);
+ throw "early exception 2";
+ }
+}
+#endif
+
+static void test_exceptions_during_system_init()
+{
+ TEST_BEGIN();
+
+#ifdef CAN_DO_EXCEPTIONS_DURING_SYSINIT
+ try
+ {
+ early_exception();
+ }
+ catch( const char *e )
+ {
+ rtems_test_assert(strcmp(e, "early exception 2") == 0);
+ }
+#endif
+}
+
+RTEMS_SYSINIT_ITEM(
+ test_exceptions_during_system_init,
+ RTEMS_SYSINIT_IDLE_THREADS,
+ RTEMS_SYSINIT_ORDER_LAST
+);
diff --git a/testsuites/samples/cdtest/system.h b/testsuites/samples/cdtest/system.h
index 7d14747a32..748e2ef1bc 100644
--- a/testsuites/samples/cdtest/system.h
+++ b/testsuites/samples/cdtest/system.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/* system.h
*
* This include file contains information that is included in every
@@ -6,9 +8,26 @@
* COPYRIGHT (c) 1989-1999.
* On-Line Applications Research Corporation (OAR).
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * 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>