Mercurial > ecos-v2_0-branch
comparison packages/infra/current/tests/cxxsupp.cxx @ 789:4eccdc2c0c7d
* tests/cxxsupp.cxx: Added this test program to check that basic
C++ support is present. It checks that pure virtual functions can
be defined, that new and delete are present and functional, and
that calls to as-yet undefined inline functions work. Most of
these are linker and runtime system issues, so the actual run of
the program is almost a non-event.
* cdl/infra.cdl:
Added CYGFUN_INFRA_DUMMY_ABORT and CYGFUN_INFRA_DUMMY_STRLEN
options to conrol inclusion of dummy abort() and strlen()
functions. These are needed to be present by the compiler's C++
runtime system, although they should never be called.
Added CYGPKG_INFRA_TESTS to define test programs.
Added CYGPKG_INFRA_LDFLAGS_REMOVE and CYGPKG_INFRA_LDFLAGS_ADD to
modify the linkage options for the infra package
tests. Specifically they remove the --gc-sections option and make
all linker warning fatal. This is necessary if cxxsupp.cxx is to
test what it needs correctly.
* src/abort.cxx: Added this dummy implementation of abort() to
satisfy references in the C++ runtime system.
* src/strlen.cxx: Added this dummy implementation of strlen() to
satisfy references in the C++ runtime system.
| author | nickg |
|---|---|
| date | Thu, 10 Apr 2003 18:08:36 +0000 |
| parents | |
| children | 3e6c23786362 |
comparison
equal
deleted
inserted
replaced
| 788:c759da109f6b | 789:4eccdc2c0c7d |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // cxxsupp.cxx | |
| 4 // | |
| 5 // C++ runtime support test | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 9 // ------------------------------------------- | |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 11 // Copyright (C) 2003 Nick Garnett <nickg@calivar.com> | |
| 12 // | |
| 13 // eCos is free software; you can redistribute it and/or modify it under | |
| 14 // the terms of the GNU General Public License as published by the Free | |
| 15 // Software Foundation; either version 2 or (at your option) any later version. | |
| 16 // | |
| 17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 20 // for more details. | |
| 21 // | |
| 22 // You should have received a copy of the GNU General Public License along | |
| 23 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 25 // | |
| 26 // As a special exception, if other files instantiate templates or use macros | |
| 27 // or inline functions from this file, or you compile this file and link it | |
| 28 // with other works to produce a work based on this file, this file does not | |
| 29 // by itself cause the resulting work to be covered by the GNU General Public | |
| 30 // License. However the source code for this file must still be made available | |
| 31 // in accordance with section (3) of the GNU General Public License. | |
| 32 // | |
| 33 // This exception does not invalidate any other reasons why a work based on | |
| 34 // this file might be covered by the GNU General Public License. | |
| 35 // | |
| 36 // Alternative licenses for eCos may be arranged by contacting the copyright | |
| 37 // holders. | |
| 38 // ------------------------------------------- | |
| 39 //####ECOSGPLCOPYRIGHTEND#### | |
| 40 //========================================================================== | |
| 41 //#####DESCRIPTIONBEGIN#### | |
| 42 // | |
| 43 // Author(s): nickg | |
| 44 // Contributors: nickg | |
| 45 // Date: 2003-04-01 | |
| 46 // Description: Simple test for C++ runtime support. | |
| 47 // | |
| 48 //####DESCRIPTIONEND#### | |
| 49 //========================================================================== | |
| 50 | |
| 51 #include <pkgconf/kernel.h> | |
| 52 #include <pkgconf/hal.h> | |
| 53 #include <pkgconf/isoinfra.h> | |
| 54 | |
| 55 #include <cyg/infra/testcase.h> | |
| 56 #include <cyg/infra/diag.h> | |
| 57 | |
| 58 #include <new> | |
| 59 | |
| 60 //========================================================================== | |
| 61 | |
| 62 class Pure | |
| 63 { | |
| 64 protected: | |
| 65 int instance; | |
| 66 public: | |
| 67 Pure(int i); | |
| 68 virtual void pure_fun1(void) = 0; | |
| 69 virtual void pure_fun2(void) = 0; | |
| 70 virtual void impure_fun1(void); | |
| 71 inline void inline_fun1(void); | |
| 72 }; | |
| 73 | |
| 74 Pure::Pure(int i) | |
| 75 { | |
| 76 instance = i; | |
| 77 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 78 } | |
| 79 | |
| 80 void Pure::impure_fun1() | |
| 81 { | |
| 82 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 83 } | |
| 84 | |
| 85 //========================================================================== | |
| 86 | |
| 87 class Derived : public Pure | |
| 88 { | |
| 89 public: | |
| 90 Derived(int i); | |
| 91 void pure_fun1(void); | |
| 92 void pure_fun2(void); | |
| 93 void impure_fun2(void); | |
| 94 }; | |
| 95 | |
| 96 Derived::Derived(int i) | |
| 97 : Pure(i) | |
| 98 { | |
| 99 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 100 } | |
| 101 | |
| 102 void Derived::pure_fun1(void) | |
| 103 { | |
| 104 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 105 } | |
| 106 | |
| 107 void Derived::pure_fun2(void) | |
| 108 { | |
| 109 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 110 } | |
| 111 | |
| 112 | |
| 113 void Derived::impure_fun2(void) | |
| 114 { | |
| 115 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 116 } | |
| 117 | |
| 118 //========================================================================== | |
| 119 | |
| 120 __externC void | |
| 121 cyg_start( void ) | |
| 122 { | |
| 123 | |
| 124 CYG_TEST_INIT(); | |
| 125 | |
| 126 Derived derived(1); | |
| 127 Pure *pure = &derived; | |
| 128 | |
| 129 CYG_TEST_INFO("Calling derived members"); | |
| 130 derived.pure_fun1(); | |
| 131 derived.pure_fun2(); | |
| 132 derived.impure_fun1(); | |
| 133 derived.impure_fun2(); | |
| 134 derived.inline_fun1(); | |
| 135 | |
| 136 CYG_TEST_INFO("Calling pure members"); | |
| 137 pure->pure_fun1(); | |
| 138 pure->pure_fun2(); | |
| 139 pure->impure_fun1(); | |
| 140 pure->inline_fun1(); | |
| 141 | |
| 142 #ifdef CYGINT_ISO_MALLOC | |
| 143 Derived *derived2 = new Derived(2); | |
| 144 Pure *pure2 = derived2; | |
| 145 | |
| 146 CYG_TEST_INFO("Calling derived2 members"); | |
| 147 derived2->pure_fun1(); | |
| 148 derived2->pure_fun2(); | |
| 149 derived2->impure_fun1(); | |
| 150 derived2->impure_fun2(); | |
| 151 derived2->inline_fun1(); | |
| 152 | |
| 153 CYG_TEST_INFO("Calling pure2 members"); | |
| 154 pure2->pure_fun1(); | |
| 155 pure2->pure_fun2(); | |
| 156 pure2->impure_fun1(); | |
| 157 pure2->inline_fun1(); | |
| 158 | |
| 159 delete derived2; | |
| 160 | |
| 161 #else | |
| 162 CYG_TEST_INFO("No malloc support, new and delete not tested"); | |
| 163 #endif | |
| 164 | |
| 165 CYG_TEST_PASS_FINISH("C++ Support OK"); | |
| 166 } | |
| 167 | |
| 168 //========================================================================== | |
| 169 | |
| 170 void Pure::inline_fun1() | |
| 171 { | |
| 172 diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance); | |
| 173 } | |
| 174 | |
| 175 //========================================================================== | |
| 176 // EOF cxxsupp.cxx |
