5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * FMA Event Injector language parser
39 #include <inj_event.h>
47 inj_declmem_t
*l_declmem
;
49 inj_defnmem_t
*l_defnmem
;
51 inj_randelem_t
*l_randelem
;
60 %type
<l_decl
> decl_memlist
61 %type
<l_declmem
> decl_mem
62 %type
<l_declmem
> decl_baremem
63 %type
<l_declmem
> decl_mem_intr
64 %type
<l_number
> decl_intr_type
65 %type
<l_number
> decl_arraydim
66 %type
<l_declmem
> decl_mem_cplx
67 %type
<l_hash
> decl_enumlist
69 %type
<l_defn
> defn_memlist
70 %type
<l_defnmem
> defn_memvals
71 %type
<l_defnmem
> defn_val
73 %type
<l_command
> command
74 %type
<l_command
> cmd_repeatable
75 %type
<l_randelem
> rand_problist
76 %type
<l_randelem
> rand_element
78 %type
<l_defn
> defined_event
79 %type
<l_number
> number
80 %type
<l_hrtime
> hrtime
83 %token INJ_TOK_FMRIDEF
84 %token INJ_TOK_AUTHDEF
85 %token INJ_TOK_LISTDEF
95 %token INJ_TOK_BOOLEAN
104 %token INJ_TOK_ADDHRT
105 %token INJ_TOK_ENDHRT
107 %token INJ_TOK_REPEAT
108 %token INJ_TOK_RANDOMIZE
110 %token
<l_string
> INJ_TOK_IDENT
111 %token
<l_string
> INJ_TOK_FMACLASS
112 %token
<l_string
> INJ_TOK_IMM
113 %token
<l_string
> INJ_TOK_QSTRING
117 statement_list: /* EMPTY */
118 | statement_list statement
';'
130 * Event, FMRI, Authority, and list declarations
133 decl: INJ_TOK_EVDEF INJ_TOK_FMACLASS
'{' decl_memlist
'}' {
135 inj_decl_finish
($4, $2, ITEMTYPE_EVENT
);
137 | INJ_TOK_FMRIDEF INJ_TOK_IDENT
'{' decl_memlist
'}' {
139 inj_decl_finish
($4, $2, ITEMTYPE_FMRI
);
141 | INJ_TOK_AUTHDEF INJ_TOK_IDENT
'{' decl_memlist
'}' {
143 inj_decl_finish
($4, $2, ITEMTYPE_AUTH
);
145 | INJ_TOK_LISTDEF INJ_TOK_IDENT
'{' decl_memlist
'}' {
147 inj_decl_finish
($4, $2, ITEMTYPE_LIST
);
151 decl_memlist: /* EMPTY */ { $$
= NULL
; }
152 | decl_memlist decl_mem
';' {
155 } else if
($1 == NULL
) {
156 $$
= inj_decl_create
($2);
158 inj_decl_addmem
($1, $2);
164 decl_mem: decl_baremem
165 | decl_baremem decl_arraydim
{
167 inj_decl_mem_make_array
($1, $2);
172 decl_baremem: decl_mem_intr
176 decl_mem_intr: decl_intr_type INJ_TOK_IDENT
{
177 $$
= inj_decl_mem_create
($2, $1);
181 decl_intr_type: INJ_TOK_INT8
{ $$
= MEMTYPE_INT8
; }
182 | INJ_TOK_INT16
{ $$
= MEMTYPE_INT16
; }
183 | INJ_TOK_INT32
{ $$
= MEMTYPE_INT32
; }
184 | INJ_TOK_INT64
{ $$
= MEMTYPE_INT64
; }
185 | INJ_TOK_UINT8
{ $$
= MEMTYPE_UINT8
; }
186 | INJ_TOK_UINT16
{ $$
= MEMTYPE_UINT16
; }
187 | INJ_TOK_UINT32
{ $$
= MEMTYPE_UINT32
; }
188 | INJ_TOK_UINT64
{ $$
= MEMTYPE_UINT64
; }
189 | INJ_TOK_BOOLEAN
{ $$
= MEMTYPE_BOOL
; }
190 | INJ_TOK_STRING
{ $$
= MEMTYPE_STRING
; }
193 decl_arraydim: '[' number
']' {
201 decl_mem_cplx: INJ_TOK_ENUM INJ_TOK_IDENT
'{' decl_enumlist
'}' {
202 $$
= inj_decl_mem_create_enum
($2, $4);
204 | INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT
{
205 $$
= inj_decl_mem_create_defined
($3, $2,
208 | INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT
{
209 $$
= inj_decl_mem_create_defined
($3, $2,
212 | INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT
{
213 $$
= inj_decl_mem_create_defined
($3, $2,
216 | INJ_TOK_LIST INJ_TOK_IDENT INJ_TOK_IDENT
{
217 $$
= inj_decl_mem_create_defined
($3, $2,
222 decl_enumlist: INJ_TOK_IDENT
{
223 $$
= inj_zalloc
(sizeof
(inj_hash_t
));
224 inj_strhash_create
($$
);
226 inj_strhash_insert
($$
, $1, 1);
228 | decl_enumlist
',' INJ_TOK_IDENT
{
229 if
(inj_strhash_lookup
($1, $3) != NULL
)
230 yyerror("duplicate enum value \"%s\"", $3);
232 inj_strhash_insert
($1, $3, 1);
238 * Event, FMRI, Authority, and list definitions
241 defn: INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT
'='
242 '{' defn_memlist
'}' {
243 inj_defn_finish
($6, $2, $3, ITEMTYPE_EVENT
);
246 | INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT
'='
247 '{' defn_memlist
'}' {
248 inj_defn_finish
($6, $2, $3, ITEMTYPE_FMRI
);
251 | INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT
'='
252 '{' defn_memlist
'}' {
253 inj_defn_finish
($6, $2, $3, ITEMTYPE_AUTH
);
258 defn_memlist: defn_memvals
{
259 $$
= inj_defn_create
($1);
261 | defn_memlist
',' defn_memvals
{
262 inj_defn_addmem
($1, $3);
267 defn_memvals: defn_val
268 | INJ_TOK_EVENT INJ_TOK_FMACLASS
{
269 $$
= inj_defn_mem_create
($2, DEFNMEM_EVENT
);
271 | INJ_TOK_FMRI INJ_TOK_IDENT
{
272 $$
= inj_defn_mem_create
($2, DEFNMEM_FMRI
);
274 | INJ_TOK_AUTH INJ_TOK_IDENT
{
275 $$
= inj_defn_mem_create
($2, DEFNMEM_AUTH
);
277 |
'[' defn_memlist
']' {
278 $$
= inj_defn_mem_create_list
($2, DEFNMEM_ARRAY
);
280 |
'{' defn_memlist
'}' {
281 $$
= inj_defn_mem_create_list
($2, DEFNMEM_LIST
);
285 defn_val: INJ_TOK_IMM
{
286 $$
= inj_defn_mem_create
($1, DEFNMEM_IMM
);
289 $$
= inj_defn_mem_create
($1, DEFNMEM_IDENT
);
292 $$
= inj_defn_mem_create
($1, DEFNMEM_QSTRING
);
300 command: cmd_repeatable
301 | INJ_TOK_ADDHRT hrtime
{ $$
= inj_cmd_addhrt
($2); }
302 | INJ_TOK_ENDHRT
{ $$
= inj_cmd_endhrt
(); }
303 | INJ_TOK_SLEEP number
{ $$
= inj_cmd_sleep
($2); }
304 | INJ_TOK_REPEAT number cmd_repeatable
{
305 $$
= ($3 == NULL ? NULL
: inj_cmd_repeat
($3, $2));
309 cmd_repeatable: defined_event
{
310 $$
= ($1 == NULL ? NULL
: inj_cmd_send
($1));
312 | INJ_TOK_RANDOMIZE
'{' rand_problist
'}' {
313 $$
= ($3 == NULL ? NULL
: inj_cmd_rand
($3));
317 rand_problist: rand_element
318 | rand_problist
',' rand_element
{
319 $$
= ($1 == NULL ||
$3 == NULL
) ?
320 NULL
: inj_rand_add
($1, $3);
324 rand_element: '{' defined_event
',' number
'}' {
325 $$
= ($2 == NULL ? NULL
: inj_rand_create
($2, $4));
329 defined_event: INJ_TOK_IDENT
{
332 if
((ev
= inj_defn_lookup
($1, MEMTYPE_EVENT
)) ==
334 yyerror("unknown event \"%s\"\n", $1);
340 number: INJ_TOK_IMM
{
343 if
(inj_strtoull
($1, 32, &val
) < 0) {
344 yyerror("invalid number");
350 hrtime: INJ_TOK_IMM INJ_TOK_IDENT
{
353 if
(inj_strtoll
($1, 64, &val
) < 0 ||
354 inj_strtime
(&val
, $2) < 0) {
355 yyerror("invalid time");
364 inj_program_read
(const char *file
)
366 if
(strcmp
(file
, "-") == 0) {
370 if
((yyin
= fopen
(file
, "r")) == NULL
)
371 die
("failed to open %s", file
);
373 yyinname
= strrchr
(file
, '/');
374 if
(yyinname
!= NULL
)
386 if
(yynerrors
!= 0) {
387 die
("parsing failed - %d error%s\n", yynerrors
,
388 (yynerrors
> 1 ?
"s" : ""));
391 return
(inj_cmds_get
());