• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Virtual machine Management Terminal User Interface


Commit MetaInfo

Révisioncf768442103863c39e99fb2ab50a3bf10dda46a9 (tree)
l'heure2022-07-18 21:52:49
AuteurKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Message de Log

Implement ErrInfo_GetMessage() function.

Change Summary

Modification

--- a/src/errinfo.c
+++ b/src/errinfo.c
@@ -89,6 +89,34 @@ int
8989 /* ===========================================================================*/
9090 VMTUI_ERRINFO_EXTERN
9191 int
92+ ErrInfo_GetMessage(
93+ ErrInfo *p_errinfo )
94+{
95+ int i_remain;
96+ ErrInfo *p_now;
97+
98+ if( 0 >= gi_get_remain ) { return 0; }
99+
100+ if( NULL == p_errinfo )
101+ { return -0x01; }
102+
103+ pthread_mutex_lock( &gt_errmtx );
104+
105+ p_now = (gp_errinfo + gi_get_start);
106+ gi_get_remain--;
107+ gi_get_start = (gi_get_start + 1) % gi_errinfo_allocs;
108+
109+ memcpy( p_errinfo, p_now, sizeof( ErrInfo ) );
110+ i_remain = gi_get_remain;
111+
112+ pthread_mutex_unlock( &gt_errmtx );
113+
114+ return i_remain;
115+}
116+
117+/* ===========================================================================*/
118+VMTUI_ERRINFO_EXTERN
119+int
92120 ErrInfo_SetMessage(
93121 char *pstr_srcfile,
94122 int i_srcline,
@@ -110,6 +138,12 @@ int
110138 gi_errinfo_now = (gi_errinfo_now + 1) % gi_errinfo_allocs;
111139 p_err = (gp_errinfo + gi_errinfo_now);
112140
141+ gi_get_remain++;
142+ if( gi_get_remain > gi_errinfo_allocs ) {
143+ gi_get_remain = gi_errinfo_allocs;
144+ gi_get_start = (gi_get_start + 1) % gi_errinfo_allocs;
145+ }
146+
113147 strncpy( p_err->str_srcfile, pstr_srcfile, 32 );
114148 p_err->i_srcline = i_srcline;
115149 p_err->t_errtime = time( NULL );
@@ -192,7 +226,7 @@ int
192226
193227 i_allocs = ERRINFO_DEFAULT_ALLOCS;
194228 if( 0 < i_errnums )
195- { i_allocs = ERRINFO_DEFAULT_ALLOCS; }
229+ { i_allocs = i_errnums; }
196230
197231 p_errinfo = (ErrInfo *)malloc( sizeof( ErrInfo ) * i_allocs );
198232 if( NULL == p_errinfo ) {
@@ -207,6 +241,9 @@ int
207241 gi_errinfo_allocs = i_allocs;
208242 gi_errinfo_now = i_allocs - 1;
209243
244+ gi_get_start = 0;
245+ gi_get_remain = 0;
246+
210247 gb_flag = b_flag;
211248
212249 if( ERRINFO_FLAG_SYSLOG & gb_flag )
--- a/src/errinfo.h
+++ b/src/errinfo.h
@@ -70,6 +70,7 @@ VMTUI_ERRINFO_EXTERN int ErrInfo_GetErrInfos( void );
7070 VMTUI_ERRINFO_EXTERN void ErrInfo_SetErrLevel( Byte b_errlevel );
7171 VMTUI_ERRINFO_EXTERN Byte ErrInfo_GetErrLevel( void );
7272 VMTUI_ERRINFO_EXTERN int ErrInfo_Get( ErrInfo *p_errinfo, int i_history );
73+VMTUI_ERRINFO_EXTERN int ErrInfo_GetMessage( ErrInfo *p_errinfo );
7374 VMTUI_ERRINFO_EXTERN int ErrInfo_SetMessage(
7475 char *pstr_srcfile, int i_srcline, Byte b_level,
7576 char *pstr_errormsg, int i_hvisor, int i_guest,
@@ -93,6 +94,8 @@ VMTUI_ERRINFO_EXTERN int ErrInfo_Term( void );
9394 static ErrInfo *gp_errinfo = NULL;
9495 static int gi_errinfo_allocs = 0;
9596 static int gi_errinfo_now = -0x01;
97+static int gi_get_start = 0;
98+static int gi_get_remain = 0;
9699 static pthread_mutex_t gt_errmtx;
97100 static Byte gb_flag = ERRINFO_FLAG_NONE;
98101 static Byte gb_errlevel = ERRINFO_LV_NONE;
--- a/src/test_errinfo.c
+++ b/src/test_errinfo.c
@@ -111,7 +111,7 @@ void
111111
112112 /* ===========================================================================*/
113113 void
114- Test_ErrInfo_SetAndGetMessage_OK001(
114+ Test_ErrInfo_SetMessageAndGet_OK001(
115115 void ) {
116116
117117 int i_hist;
@@ -155,6 +155,111 @@ void
155155 }
156156
157157 /* ===========================================================================*/
158+void
159+ Test_ErrInfo_GetMessage_OK001(
160+ void ) {
161+
162+ int i_err;
163+ int i_cnt;
164+ ErrInfo t_err;
165+ char str_msg[64];
166+
167+ i_err = ErrInfo_Init( 10, ERRINFO_FLAG_NONE );
168+ CU_ASSERT( 0x00 == i_err );
169+
170+ ErrInfo_SetErrLevel( ERRINFO_LV_DEBUG );
171+
172+ // Test Phase 1 ---
173+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
174+ i_err = ErrInfo_Error( str_msg, i_cnt, i_cnt, i_cnt, i_cnt, i_cnt, (DWord)i_cnt, str_msg );
175+ CU_ASSERT( 0x00 == i_err );
176+
177+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
178+
179+ i_err = ErrInfo_GetMessage( &t_err );
180+ CU_ASSERT( 0x00 == i_err );
181+
182+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_errormsg );
183+ CU_ASSERT( i_cnt == t_err.i_hvisor );
184+ CU_ASSERT( i_cnt == t_err.i_guest );
185+ CU_ASSERT( i_cnt == t_err.i_request );
186+ CU_ASSERT( i_cnt == t_err.i_errno );
187+ CU_ASSERT( i_cnt == t_err.i_param );
188+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_param );
189+
190+ // Test Phase 2 ---
191+ for( i_cnt = 0; i_cnt < 9; i_cnt++ ) {
192+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
193+ i_err = ErrInfo_Error( str_msg, i_cnt, i_cnt, i_cnt, i_cnt, i_cnt, (DWord)i_cnt, str_msg );
194+ CU_ASSERT( 0x00 == i_err );
195+ }
196+
197+ for( i_cnt = 0; i_cnt < 9; i_cnt++ ) {
198+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
199+
200+ i_err = ErrInfo_GetMessage( &t_err );
201+ CU_ASSERT( i_err == (8 - i_cnt) );
202+
203+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_errormsg );
204+ CU_ASSERT( i_cnt == t_err.i_hvisor );
205+ CU_ASSERT( i_cnt == t_err.i_guest );
206+ CU_ASSERT( i_cnt == t_err.i_request );
207+ CU_ASSERT( i_cnt == t_err.i_errno );
208+ CU_ASSERT( i_cnt == t_err.i_param );
209+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_param );
210+ }
211+
212+ // Test Phase 3 ---
213+ for( i_cnt = 0; i_cnt < 10; i_cnt++ ) {
214+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
215+ i_err = ErrInfo_Error( str_msg, i_cnt, i_cnt, i_cnt, i_cnt, i_cnt, (DWord)i_cnt, str_msg );
216+ CU_ASSERT( 0x00 == i_err );
217+ }
218+
219+ for( i_cnt = 0; i_cnt < 10; i_cnt++ ) {
220+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
221+
222+ i_err = ErrInfo_GetMessage( &t_err );
223+ CU_ASSERT( i_err == (9 - i_cnt) );
224+
225+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_errormsg );
226+ CU_ASSERT( i_cnt == t_err.i_hvisor );
227+ CU_ASSERT( i_cnt == t_err.i_guest );
228+ CU_ASSERT( i_cnt == t_err.i_request );
229+ CU_ASSERT( i_cnt == t_err.i_errno );
230+ CU_ASSERT( i_cnt == t_err.i_param );
231+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_param );
232+ }
233+
234+ // Test Phase 4 ---
235+ for( i_cnt = 0; i_cnt < 15; i_cnt++ ) {
236+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
237+ i_err = ErrInfo_Error( str_msg, i_cnt, i_cnt, i_cnt, i_cnt, i_cnt, (DWord)i_cnt, str_msg );
238+ CU_ASSERT( 0x00 == i_err );
239+ }
240+
241+ for( i_cnt = 5; i_cnt < 15; i_cnt++ ) {
242+ snprintf( str_msg, 64, "ErrInfo Set&GetMessages Error %02d", i_cnt );
243+
244+ i_err = ErrInfo_GetMessage( &t_err );
245+ CU_ASSERT( i_err == (14 - i_cnt) );
246+
247+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_errormsg );
248+ CU_ASSERT( i_cnt == t_err.i_hvisor );
249+ CU_ASSERT( i_cnt == t_err.i_guest );
250+ CU_ASSERT( i_cnt == t_err.i_request );
251+ CU_ASSERT( i_cnt == t_err.i_errno );
252+ CU_ASSERT( i_cnt == t_err.i_param );
253+ CU_ASSERT_STRING_EQUAL( str_msg, t_err.str_param );
254+ }
255+
256+ i_err = ErrInfo_Term();
257+ CU_ASSERT( 0x00 == i_err );
258+
259+ return;
260+}
261+
262+/* ===========================================================================*/
158263 VMTUI_TEST_ERRINFO_EXTERN
159264 int
160265 Test_ErrInfo(
@@ -166,7 +271,8 @@ int
166271
167272 CU_add_test( pt_errinfo, "VMTUI_ErrInfo_InitTerm_OK001", Test_ErrInfo_InitTerm_OK001 );
168273 CU_add_test( pt_errinfo, "VMTUI_ErrInfo_SetMessage_OK001", Test_ErrInfo_SetMessage_OK001 );
169- CU_add_test( pt_errinfo, "VMTUI_ErrInfo_SetAndGetMessage_OK001", Test_ErrInfo_SetAndGetMessage_OK001 );
274+ CU_add_test( pt_errinfo, "VMTUI_ErrInfo_SetMessageAndGet_OK001", Test_ErrInfo_SetMessageAndGet_OK001 );
275+ CU_add_test( pt_errinfo, "VMTUI_ErrInfo_GetMessage_OK001", Test_ErrInfo_GetMessage_OK001 );
170276
171277 return 0x00;
172278 }