source: UsbWattMeter/trunk/asp_dcre/library/test_lib.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 7 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 4.4 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2005-2013 by Embedded and Real-Time Systems Laboratory
6 * Graduate School of Information Science, Nagoya Univ., JAPAN
7 *
8 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
9 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
10 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
11 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
12 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
13 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
14 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
15 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
16ƒƒ“ƒgi—˜—p
17 * ŽÒƒ}ƒjƒ…
18ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
19 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
20 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
21 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
22 * ‚ƁD
23 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
24ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
25ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
26 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
27 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
28 * •ñ‚·‚邱‚ƁD
29 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
30 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
31 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
32 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
33 * –Ɛӂ·‚邱‚ƁD
34 *
35 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
36 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
37 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
38 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
39 * ‚̐ӔC‚𕉂í‚È‚¢D
40 *
41 * @(#) $Id: test_lib.c 164 2016-03-07 11:33:50Z coas-nagasima $
42 */
43
44/*
45 * ƒeƒXƒgƒvƒƒOƒ‰ƒ€—pƒ‰ƒCƒuƒ‰ƒŠ
46 */
47
48#include <kernel.h>
49#include <sil.h>
50#include <t_syslog.h>
51#include <t_stdlib.h>
52#include <log_output.h>
53#include "syssvc/syslog.h"
54#include "target_syssvc.h"
55#include <test_lib.h>
56
57/*
58 * ƒ`ƒFƒbƒNƒ|ƒCƒ“ƒg
59 */
60static uint_t check_count = 0u;
61
62/*
63 * Ž©ŒÈf’fŠÖ”
64 */
65static BIT_FUNC check_bit_func = NULL;
66
67/*
68 * Ž©ŒÈf’fŠÖ”‚̐ݒè
69 */
70void
71set_bit_func(BIT_FUNC bit_func)
72{
73 check_bit_func = bit_func;
74}
75
76/*
77 * ƒeƒXƒgƒvƒƒOƒ‰ƒ€‚ÌŠJŽn
78 */
79void
80test_start(char *progname)
81{
82 syslog_1(LOG_NOTICE, "Test program: %s", progname);
83}
84
85/*
86 * ƒVƒXƒeƒ€ƒƒO‚̏o—͏ˆ—
87 */
88void
89syslog_flush(void)
90{
91 SYSLOG logbuf;
92 ER_UINT rercd;
93
94 /*
95 * ƒƒOƒoƒbƒtƒ@‚É‹L˜^‚³‚ꂽƒƒOî•ñ‚ðC’჌ƒxƒ‹o—Í‹@”\‚ð—p‚¢‚ďo
96 * —Í‚·‚éD
97 */
98 while ((rercd = syslog_rea_log(&logbuf)) >= 0) {
99 if (rercd > 0) {
100 syslog_lostmsg((uint_t) rercd, target_fput_log);
101 }
102 if (logbuf.logtype >= LOG_TYPE_COMMENT) {
103 syslog_print(&logbuf, target_fput_log);
104 target_fput_log('\n');
105 }
106 }
107}
108
109/*
110 * ƒeƒXƒgƒvƒƒOƒ‰ƒ€‚̏I—¹
111 */
112void
113test_finish(void)
114{
115 SIL_PRE_LOC;
116
117 SIL_LOC_INT();
118 syslog_flush();
119 (void) ext_ker();
120
121 /* ‚±‚±‚Ö—ˆ‚邱‚Æ‚Í‚È‚¢‚Í‚¸ */
122 SIL_UNL_INT();
123}
124
125/*
126 * ƒ`ƒFƒbƒNƒ|ƒCƒ“ƒg
127 */
128void
129check_point(uint_t count)
130{
131 bool_t errorflag = false;
132 ER rercd;
133 SIL_PRE_LOC;
134
135 /*
136 * Š„ž‚݃ƒbƒNó‘Ô‚É
137 */
138 SIL_LOC_INT();
139
140 /*
141 * ƒV[ƒPƒ“ƒXƒ`ƒFƒbƒN
142 */
143 if (++check_count == count) {
144 syslog_1(LOG_NOTICE, "Check point %d passed.", count);
145 }
146 else {
147 syslog_1(LOG_ERROR, "## Unexpected check point %d.", count);
148 errorflag = true;
149 }
150
151 /*
152 * ƒJ[ƒlƒ‹‚Ì“à•”ó‘Ô‚ÌŒŸ¸
153 */
154 if (check_bit_func != NULL) {
155 rercd = (*check_bit_func)();
156 if (rercd < 0) {
157 syslog_2(LOG_ERROR, "## Internal inconsistency detected (%s, %d).",
158 itron_strerror(rercd), SERCD(rercd));
159 errorflag = true;
160 }
161 }
162
163 /*
164 * ƒGƒ‰[‚ªŒŸo‚³‚ꂽê‡‚́CƒeƒXƒgƒvƒƒOƒ‰ƒ€‚ðI—¹‚·‚éD
165 */
166 if (errorflag) {
167 test_finish();
168 }
169
170 /*
171 * Š„ž‚݃ƒbƒNó‘Ô‚ð‰ðœ
172 */
173 SIL_UNL_INT();
174}
175
176/*
177 * Š®—¹ƒ`ƒFƒbƒNƒ|ƒCƒ“ƒg
178 */
179void
180check_finish(uint_t count)
181{
182 check_point(count);
183 syslog_0(LOG_NOTICE, "All check points passed.");
184 test_finish();
185}
186
187/*
188 * ðŒƒ`ƒFƒbƒN‚̃Gƒ‰[ˆ—
189 */
190void
191_check_assert(const char *expr, const char *file, int_t line)
192{
193 syslog_3(LOG_ERROR, "## Assertion `%s' failed at %s:%u.",
194 expr, file, line);
195 test_finish();
196}
197
198/*
199 * ƒGƒ‰[ƒR[ƒhƒ`ƒFƒbƒN‚̃Gƒ‰[ˆ—
200 */
201void
202_check_ercd(ER ercd, const char *file, int_t line)
203{
204 syslog_3(LOG_ERROR, "## Unexpected error %s detected at %s:%u.",
205 itron_strerror(ercd), file, line);
206 test_finish();
207}
Note: See TracBrowser for help on using the repository browser.