1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | *
|
---|
9 | * ä¸è¨è使¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
11 | * ã«ãã£ã¦å
|
---|
12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
15 | å¸ï¼ä»¥ä¸ï¼
|
---|
16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
21 | * ç¨ã§ããå½¢ã§åé
|
---|
22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
24 | * è
|
---|
25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
30 | * ã¨ï¼
|
---|
31 | * (a) åé
|
---|
32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
34 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
35 | * (b) åé
|
---|
36 | å¸ã®å½¢æ
|
---|
37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
38 | * å ±åãããã¨ï¼
|
---|
39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
40 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
42 | 責ãããã¨ï¼
|
---|
43 | *
|
---|
44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
45 | ã
|
---|
46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
49 | *
|
---|
50 | * @(#) $Id: manager.cpp,v 1.11 2003/12/15 07:32:13 takayuki Exp $
|
---|
51 | */
|
---|
52 |
|
---|
53 | // $Header: /home/CVS/configurator/base/manager.cpp,v 1.11 2003/12/15 07:32:13 takayuki Exp $
|
---|
54 |
|
---|
55 | #ifdef _MSC_VER
|
---|
56 | # pragma warning(disable:4786)
|
---|
57 | # define CDECL __cdecl
|
---|
58 | #else
|
---|
59 | # define CDECL
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #include <stdlib.h>
|
---|
63 | #include <fstream>
|
---|
64 | #include <iostream>
|
---|
65 |
|
---|
66 | #include "base/event.h"
|
---|
67 | #include "base/message.h"
|
---|
68 | #include "base/component.h"
|
---|
69 | #include "base/directorymap.h"
|
---|
70 |
|
---|
71 | using namespace std;
|
---|
72 |
|
---|
73 | Event<StartupEvent> startupEvent;
|
---|
74 | Event<ShutdownEvent> shutdownEvent;
|
---|
75 |
|
---|
76 | int CDECL main(int argc, char ** argv)
|
---|
77 | {
|
---|
78 | ShutdownEvent evt;
|
---|
79 | OptionParameter & option= getOptionParameter();
|
---|
80 |
|
---|
81 | evt.exit_code = EXIT_FAILURE;
|
---|
82 |
|
---|
83 | if(SingletonBase::isValid() && Component::isValid()) {
|
---|
84 |
|
---|
85 | option.parseOption(argc, argv, "-h");
|
---|
86 |
|
---|
87 | try {
|
---|
88 | startupEvent.raise();
|
---|
89 | Component::executeComponents(option);
|
---|
90 | evt.exit_code = EXIT_SUCCESS;
|
---|
91 | }
|
---|
92 | catch(Exception & e)
|
---|
93 | {
|
---|
94 | cerr << Message("Program failed in its process by following reason.\n","ããã°ã©ã ã¯è´å½çãªã¨ã©ã¼ã«ãã䏿ããã¾ãã.\n");
|
---|
95 | cerr << " " << e.getDetails() << '\n';
|
---|
96 | }
|
---|
97 | catch(ExceptionMessage & e) {
|
---|
98 | CHECKPOINT("catch(ExceptionMessage)");
|
---|
99 | cerr << "Program failed : " << e << '\n';
|
---|
100 | }
|
---|
101 | catch(bad_alloc & e) {
|
---|
102 | CHECKPOINT("catch(bad_alloc)");
|
---|
103 | cerr << "Program failed : bad_alloc (" << e.what() << ")\n";
|
---|
104 | }
|
---|
105 | catch(...) {
|
---|
106 | CHECKPOINT("catch(...)");
|
---|
107 | cerr << "Program filed : Unknown Exception Occured\n";
|
---|
108 | }
|
---|
109 | }
|
---|
110 | else
|
---|
111 | cerr << "Program initialization failure\n";
|
---|
112 |
|
---|
113 | try {
|
---|
114 | DebugMessage("shutdown event - exitcode(%)\n") << evt.exit_code;
|
---|
115 | shutdownEvent.raise(evt);
|
---|
116 | }
|
---|
117 | catch(Exception & e)
|
---|
118 | {
|
---|
119 | DebugMessage("exception was raised in the event - %\n") << e.getDetails();
|
---|
120 | cerr << Message("Program failed in its process by following reason.\n","ããã°ã©ã ã¯è´å½çãªã¨ã©ã¼ã«ãã䏿ããã¾ãã.\n");
|
---|
121 | cerr << " " << e.getDetails() << '\n';
|
---|
122 | }
|
---|
123 |
|
---|
124 | catch(...) {
|
---|
125 | DebugMessage("exception was raised in the event\n");
|
---|
126 | CHECKPOINT("catch(...) in shutdownEvent::raise");
|
---|
127 | evt.exit_code = EXIT_FAILURE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | DebugMessage("Exit code (%)\n") << evt.exit_code;
|
---|
131 |
|
---|
132 | return evt.exit_code;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /************************************* ãã¹ãã¹ã£ã¼ã *************************************/
|
---|
136 |
|
---|
137 | #ifdef TESTSUITE
|
---|
138 | #include "coverage_undefs.h"
|
---|
139 |
|
---|
140 | namespace {
|
---|
141 |
|
---|
142 | extern void testsuite(TestSuiteControl & _suite_control);
|
---|
143 | TestSuite testsuite_onTop("Entrypoint(main)", testsuite);
|
---|
144 |
|
---|
145 | class TestComponent : public Component
|
---|
146 | {
|
---|
147 | public:
|
---|
148 | int mode;
|
---|
149 |
|
---|
150 | void parseOption(OptionParameter &)
|
---|
151 | {
|
---|
152 | switch(mode) {
|
---|
153 | case 0:
|
---|
154 | CHECKPOINT("TestComponent::case 0");
|
---|
155 | break;
|
---|
156 | case 1:
|
---|
157 | ExceptionMessage("exception").throwException();
|
---|
158 | case 2:
|
---|
159 | throw bad_alloc();
|
---|
160 | }
|
---|
161 | }
|
---|
162 | };
|
---|
163 |
|
---|
164 | void dummyStartupHandler(StartupEvent &)
|
---|
165 | {
|
---|
166 | TestSuite::check("dummyStartupHandler");
|
---|
167 | }
|
---|
168 |
|
---|
169 | int dummyShutdownHandler_exit_code;
|
---|
170 | void dummyShutdownHandler(ShutdownEvent & evt)
|
---|
171 | {
|
---|
172 | dummyShutdownHandler_exit_code = evt.exit_code;
|
---|
173 | TestSuite::check("dummyShutdownHandler");
|
---|
174 | }
|
---|
175 |
|
---|
176 | //ãã¹ãã¹ã£ã¼ãã®æ¬ä½
|
---|
177 | void testsuite(TestSuiteControl & _suite_control)
|
---|
178 | {
|
---|
179 | SingletonBase::ContextChain chain;
|
---|
180 |
|
---|
181 | chain.saveContext<Component::ComponentInfo>();
|
---|
182 | chain.saveContext<Event<StartupEvent>::handler_list_type>();
|
---|
183 | chain.saveContext<Event<ShutdownEvent>::handler_list_type>();
|
---|
184 |
|
---|
185 | BEGIN_CASE("1","main颿°åä½ + ã³ã³ãã¼ãã³ããªã") {
|
---|
186 | chain.renewInstance();
|
---|
187 |
|
---|
188 | Event<StartupEvent>::add(dummyStartupHandler);
|
---|
189 | Event<ShutdownEvent>::add(dummyShutdownHandler);
|
---|
190 |
|
---|
191 | BEGIN_CASE("1","æ®éã«å®è¡ãã") {
|
---|
192 | TestSuite::clearCheckpoints();
|
---|
193 |
|
---|
194 | char * argv[] = { "test.exe" };
|
---|
195 |
|
---|
196 | Exception::setThrowControl(true);
|
---|
197 | TestComponent test;
|
---|
198 | test.mode = 0;
|
---|
199 |
|
---|
200 | TEST_CASE("1","main颿°ã¯EXIT_SUCCESSãè¿ã", main(1, argv) == EXIT_SUCCESS);
|
---|
201 |
|
---|
202 | TEST_CASE("2","ä¾å¤ãå®è¡ãããªã catch(Exception)", !TestSuite::isReached("catch(Exception)"));
|
---|
203 | TEST_CASE("3","ä¾å¤ãå®è¡ãããªã catch(bad_alloc)", !TestSuite::isReached("catch(bad_alloc)"));
|
---|
204 | TEST_CASE("4","ä¾å¤ãå®è¡ãããªã catch(...)", !TestSuite::isReached("catch(...)"));
|
---|
205 | TEST_CASE("5","Componentãå®è¡ããã¦ãã", TestSuite::isReached("TestComponent::case 0"));
|
---|
206 | TEST_CASE("6","ã¹ã¿ã¼ãã¢ãããã³ãã©ãèµ·åããã¦ãã", TestSuite::isReached("dummyStartupHandler"));
|
---|
207 | TEST_CASE("7","ã·ã£ãããã¦ã³ãã³ãã©ãèµ·åããã¦ãã", TestSuite::isReached("dummyShutdownHandler"));
|
---|
208 | TEST_CASE("8","ã·ã£ãããã¦ã³ãã³ãã©ã¯EXIT_SUCCESSãåãã¦ãã", dummyShutdownHandler_exit_code == EXIT_SUCCESS);
|
---|
209 | } END_CASE;
|
---|
210 |
|
---|
211 | BEGIN_CASE("2","Exceptionä¾å¤ãè¿ã") {
|
---|
212 | TestSuite::clearCheckpoints();
|
---|
213 |
|
---|
214 | char * argv[] = { "test.exe" };
|
---|
215 |
|
---|
216 | Exception::setThrowControl(true);
|
---|
217 | TestComponent test;
|
---|
218 | test.mode = 1;
|
---|
219 |
|
---|
220 | TEST_CASE("1","main颿°ã¯EXIT_FAILUREãè¿ã", main(1, argv) == EXIT_FAILURE);
|
---|
221 |
|
---|
222 | TEST_CASE("2","ä¾å¤ãå®è¡ããã catch(Exception)", TestSuite::isReached("catch(Exception)"));
|
---|
223 | TEST_CASE("3","ä¾å¤ãå®è¡ãããªã catch(bad_alloc)", !TestSuite::isReached("catch(bad_alloc)"));
|
---|
224 | TEST_CASE("4","ä¾å¤ãå®è¡ãããªã catch(...)", !TestSuite::isReached("catch(...)"));
|
---|
225 | TEST_CASE("5","ã¹ã¿ã¼ãã¢ãããã³ãã©ãèµ·åããã¦ãã", TestSuite::isReached("dummyStartupHandler"));
|
---|
226 | TEST_CASE("6","ã·ã£ãããã¦ã³ãã³ãã©ãèµ·åããã¦ãã", TestSuite::isReached("dummyShutdownHandler"));
|
---|
227 | TEST_CASE("7","ã·ã£ãããã¦ã³ãã³ãã©ã¯EXIT_FAILUREãåãã¦ãã", dummyShutdownHandler_exit_code == EXIT_FAILURE);
|
---|
228 | } END_CASE;
|
---|
229 |
|
---|
230 | BEGIN_CASE("3","bad_allocä¾å¤ãè¿ã") {
|
---|
231 | TestSuite::clearCheckpoints();
|
---|
232 |
|
---|
233 | char * argv[] = { "test.exe" };
|
---|
234 |
|
---|
235 | Exception::setThrowControl(true);
|
---|
236 | TestComponent test;
|
---|
237 | test.mode = 2;
|
---|
238 |
|
---|
239 | TEST_CASE("1","main颿°ã¯EXIT_FAILUREãè¿ã", main(1, argv) == EXIT_FAILURE);
|
---|
240 |
|
---|
241 | TEST_CASE("2","対å¿ããcatchã®ã¿ãå®è¡ããã¦ãã", !TestSuite::isReached("catch(Exception)") && TestSuite::isReached("catch(bad_alloc)") && !TestSuite::isReached("catch(...)"));
|
---|
242 | TEST_CASE("3","ã¹ã¿ã¼ãã¢ãããã³ãã©ãèµ·åããã¦ãã", TestSuite::isReached("dummyStartupHandler"));
|
---|
243 | TEST_CASE("4","ã·ã£ãããã¦ã³ãã³ãã©ãèµ·åããã¦ãã", TestSuite::isReached("dummyShutdownHandler"));
|
---|
244 | TEST_CASE("5","ã·ã£ãããã¦ã³ãã³ãã©ã¯EXIT_FAILUREãåãã¦ãã", dummyShutdownHandler_exit_code == EXIT_FAILURE);
|
---|
245 | } END_CASE;
|
---|
246 | } END_CASE;
|
---|
247 |
|
---|
248 | chain.restoreContext();
|
---|
249 | }
|
---|
250 |
|
---|
251 | }
|
---|
252 |
|
---|
253 | #endif
|
---|
254 |
|
---|
255 |
|
---|