FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gridlab-d/assert/enum_assert.cpp at master · INFERLab/gridlab-d · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
INFERLab
/
gridlab-d
Public
forked from
gridlab-d/gridlab-d
Notifications
You must be signed in to change notification settings
Fork
2
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
gridlab-d
/
assert
/
enum_assert.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
251 lines (220 loc) · 8.74 KB
Breadcrumbs
gridlab-d
/
assert
/
enum_assert.cpp
Copy path
File metadata and controls
251 lines (220 loc) · 8.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
enum_assert
Very simple test that compares either integers or can be used to compare enumerated values
to their corresponding integer values. If the test fails at any time, it throws a 'zero' to
the commit function and breaks the simulator out with a failure code.
*/
#
include
<
stdlib.h
>
#
include
<
stdio.h
>
#
include
<
errno.h
>
#
include
<
math.h
>
#
include
<
complex.h
>
#
include
<
string.h
>
#
include
"
enum_assert.h
"
EXPORT_CREATE
(enum_assert);
EXPORT_INIT
(enum_assert);
EXPORT_COMMIT
(enum_assert);
CLASS
*enum_assert::oclass =
NULL
;
enum_assert *enum_assert::defaults =
NULL
;
enum_assert::enum_assert
(
MODULE
*
module
)
{
if
(oclass==
NULL
)
{
//
register to receive notice for first top down. bottom up, and second top down synchronizations
oclass =
gl_register_class
(
module
,
"
enum_assert
"
,
sizeof
(enum_assert),
PC_AUTOLOCK
|
PC_OBSERVER
);
if
(oclass==
NULL
)
throw
"
unable to register class enum_assert
"
;
else
oclass->
trl
=
TRL_PROVEN
;
if
(
gl_publish_variable
(oclass,
//
TO DO: publish your variables here
PT_enumeration,
"
status
"
,
get_status_offset
(),
PT_DESCRIPTION
,
"
Conditions for the assert checks
"
,
PT_KEYWORD
,
"
ASSERT_TRUE
"
,(enumeration)
ASSERT_TRUE
,
PT_KEYWORD
,
"
ASSERT_FALSE
"
,(enumeration)
ASSERT_FALSE
,
PT_KEYWORD
,
"
ASSERT_NONE
"
,(enumeration)
ASSERT_NONE
,
PT_int32,
"
value
"
,
get_value_offset
(),
PT_DESCRIPTION
,
"
Value to assert
"
,
PT_char1024,
"
target
"
,
get_target_offset
(),
PT_DESCRIPTION
,
"
Property to perform the assert upon
"
,
NULL
)<
1
){
char
msg[
256
];
sprintf
(msg,
"
unable to publish properties in %s
"
,__FILE__);
throw
msg;
}
defaults =
this
;
status =
ASSERT_TRUE
;
value =
0
;
}
}
/*
Object creation is called once for each object that is created by the core
*/
int
enum_assert::create
(
void
)
{
memcpy
(
this
,defaults,
sizeof
(*
this
));
return
1
;
/*
return 1 on success, 0 on failure
*/
}
int
enum_assert::init
(
OBJECT
*parent)
{
return
1
;
}
TIMESTAMP
enum_assert::commit
(
TIMESTAMP
t1,
TIMESTAMP
t2)
{
gld_property
target_prop
(
get_parent
(),
get_target
());
if
( !target_prop.
is_valid
() || target_prop.
get_type
()!=PT_enumeration )
{
gl_error
(
"
Specified target %s for %s is not valid.
"
,
get_target
(),
get_parent
()->
get_name
());
/*
TROUBLESHOOT
Check to make sure the target you are specifying is a published variable for the object
that you are pointing to. Refer to the documentation of the command flag --modhelp, or
check the wiki page to determine which variables can be published within the object you
are pointing to with the assert function.
*/
return
0
;
}
int32 x; target_prop.
getp
(x);
if
(status ==
ASSERT_TRUE
)
{
if
(value != x)
{
gl_error
(
"
Assert failed on %s: %s=%g did not match %g
"
,
get_parent
()->
get_name
(),
get_target
(), x, value);
return
0
;
}
else
{
gl_verbose
(
"
Assert passed on %s
"
,
get_parent
()->
get_name
());
return
TS_NEVER
;
}
}
else
if
(status ==
ASSERT_FALSE
)
{
if
(value == x)
{
gl_error
(
"
Assert failed on %s: %s=%g did match %g
"
,
get_parent
()->
get_name
(),
get_target
(), x, value);
return
0
;
}
else
{
gl_verbose
(
"
Assert passed on %s
"
,
get_parent
()->
get_name
());
return
TS_NEVER
;
}
}
else
{
gl_verbose
(
"
Assert test is not being run on %s
"
,
get_parent
()->
get_name
());
return
TS_NEVER
;
}
}
//
Deltamode compatible enumeration assert
EXPORT
SIMULATIONMODE
update_enum_assert
(
OBJECT
*obj,
TIMESTAMP
t0,
unsigned
int64 delta_time,
unsigned
long
dt,
unsigned
int
iteration_count_val)
{
char
buff[
64
];
char
dateformat[
8
]=
"
"
;
char
error_output_buff[
1024
];
char
datebuff[
64
];
enum_assert *da =
OBJECTDATA
(obj,enum_assert);
DATETIME
delta_dt_val;
double
del_clock;
TIMESTAMP
del_clock_int;
int
del_microseconds;
int32 *x;
//
Iteration checker - assert only valid on the first timestep
if
(iteration_count_val ==
0
)
{
//
Skip first timestep of any delta iteration -- nature of delta means it really isn't checking the right one
if
(delta_time>=dt)
{
//
Get the value
x = (int32*)
gl_get_enum_by_name
(obj->
parent
,da->
get_target
());
if
(x==
NULL
)
{
gl_error
(
"
Specified target %s for %s is not valid.
"
,da->
get_target
(),
gl_name
(obj->
parent
,buff,
64
));
/*
TROUBLESHOOT
Check to make sure the target you are specifying is a published variable for the object
that you are pointing to. Refer to the documentation of the command flag --modhelp, or
check the wiki page to determine which variables can be published within the object you
are pointing to with the assert function.
*/
return
SM_ERROR
;
}
else
if
(da->
get_status
() == da->
ASSERT_TRUE
)
{
if
(*x != da->
get_value
())
{
//
Calculate time
if
(delta_time>=dt)
//
After first iteration
del_clock = (
double
)t0 + (
double
)(delta_time-dt)/(
double
)
DT_SECOND
;
else
//
First second different, don't back out
del_clock = (
double
)t0 + (
double
)(delta_time)/(
double
)
DT_SECOND
;
del_clock_int = (
TIMESTAMP
)del_clock;
/*
Whole seconds - update from global clock because we could be in delta for over 1 second
*/
del_microseconds = (
int
)((del_clock-(
int
)(del_clock))*
1000000
+
0.5
);
/*
microseconds roll-over - biased upward (by 0.5)
*/
//
Convert out
gl_localtime
(del_clock_int,&delta_dt_val);
//
Determine output format
gl_global_getvar
(
"
dateformat
"
,dateformat,
sizeof
(dateformat));
//
Output date appropriately
if
(
strcmp
(dateformat,
"
ISO
"
)==
0
)
sprintf
(datebuff,
"
ERROR [%04d-%02d-%02d %02d:%02d:%02d.%.06d %s] :
"
,delta_dt_val.
year
,delta_dt_val.
month
,delta_dt_val.
day
,delta_dt_val.
hour
,delta_dt_val.
minute
,delta_dt_val.
second
,del_microseconds,delta_dt_val.
tz
);
else
if
(
strcmp
(dateformat,
"
US
"
)==
0
)
sprintf
(datebuff,
"
ERROR [%02d-%02d-%04d %02d:%02d:%02d.%.06d %s] :
"
,delta_dt_val.
month
,delta_dt_val.
day
,delta_dt_val.
year
,delta_dt_val.
hour
,delta_dt_val.
minute
,delta_dt_val.
second
,del_microseconds,delta_dt_val.
tz
);
else
if
(
strcmp
(dateformat,
"
EURO
"
)==
0
)
sprintf
(datebuff,
"
ERROR [%02d-%02d-%04d %02d:%02d:%02d.%.06d %s] :
"
,delta_dt_val.
day
,delta_dt_val.
month
,delta_dt_val.
year
,delta_dt_val.
hour
,delta_dt_val.
minute
,delta_dt_val.
second
,del_microseconds,delta_dt_val.
tz
);
else
sprintf
(datebuff,
"
ERROR .09f :
"
,del_clock);
//
Actual error part
sprintf
(error_output_buff,
"
Assert failed on %s - %s (%d) did not match %d
"
,
gl_name
(obj->
parent
, buff,
64
),da->
get_target
(), *x, da->
get_value
());
//
Send it out
gl_output
(
"
%s%s
"
,datebuff,error_output_buff);
return
SM_ERROR
;
}
else
{
gl_verbose
(
"
Assert passed on %s
"
,
gl_name
(obj->
parent
, buff,
64
));
return
SM_EVENT
;
}
}
else
if
(da->
get_status
() == da->
ASSERT_FALSE
)
{
if
(*x == da->
get_value
())
{
//
Calculate time
if
(delta_time>=dt)
//
After first iteration
del_clock = (
double
)t0 + (
double
)(delta_time-dt)/(
double
)
DT_SECOND
;
else
//
First second different, don't back out
del_clock = (
double
)t0 + (
double
)(delta_time)/(
double
)
DT_SECOND
;
del_clock_int = (
TIMESTAMP
)del_clock;
/*
Whole seconds - update from global clock because we could be in delta for over 1 second
*/
del_microseconds = (
int
)((del_clock-(
int
)(del_clock))*
1000000
+
0.5
);
/*
microseconds roll-over - biased upward (by 0.5)
*/
//
Convert out
gl_localtime
(del_clock_int,&delta_dt_val);
//
Determine output format
gl_global_getvar
(
"
dateformat
"
,dateformat,
sizeof
(dateformat));
//
Output date appropriately
if
(
strcmp
(dateformat,
"
ISO
"
)==
0
)
sprintf
(datebuff,
"
ERROR [%04d-%02d-%02d %02d:%02d:%02d.%.06d %s] :
"
,delta_dt_val.
year
,delta_dt_val.
month
,delta_dt_val.
day
,delta_dt_val.
hour
,delta_dt_val.
minute
,delta_dt_val.
second
,del_microseconds,delta_dt_val.
tz
);
else
if
(
strcmp
(dateformat,
"
US
"
)==
0
)
sprintf
(datebuff,
"
ERROR [%02d-%02d-%04d %02d:%02d:%02d.%.06d %s] :
"
,delta_dt_val.
month
,delta_dt_val.
day
,delta_dt_val.
year
,delta_dt_val.
hour
,delta_dt_val.
minute
,delta_dt_val.
second
,del_microseconds,delta_dt_val.
tz
);
else
if
(
strcmp
(dateformat,
"
EURO
"
)==
0
)
sprintf
(datebuff,
"
ERROR [%02d-%02d-%04d %02d:%02d:%02d.%.06d %s] :
"
,delta_dt_val.
day
,delta_dt_val.
month
,delta_dt_val.
year
,delta_dt_val.
hour
,delta_dt_val.
minute
,delta_dt_val.
second
,del_microseconds,delta_dt_val.
tz
);
else
sprintf
(datebuff,
"
ERROR .09f :
"
,del_clock);
//
Actual error part
sprintf
(error_output_buff,
"
Assert failed on %s - %s (%d) did not match %d
"
,
gl_name
(obj->
parent
, buff,
64
),da->
get_target
(), *x, da->
get_value
());
//
Send it out
gl_output
(
"
%s%s
"
,datebuff,error_output_buff);
return
SM_ERROR
;
}
else
{
gl_verbose
(
"
Assert passed on %s
"
,
gl_name
(obj->
parent
, buff,
64
));
return
SM_EVENT
;
}
}
else
{
gl_verbose
(
"
Assert test is not being run on %s
"
,
gl_name
(obj->
parent
, buff,
64
));
return
SM_EVENT
;
}
}
else
//
first timestep
return
SM_EVENT
;
}
else
//
Iteration, so don't care
return
SM_EVENT
;
}
Back
|
FazBrowse Home
|
New Git URL