17c478bd9Sstevel@tonic-gate %{ 27c478bd9Sstevel@tonic-gate /* 37c478bd9Sstevel@tonic-gate * CDDL HEADER START 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 67c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 77c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 87c478bd9Sstevel@tonic-gate * with the License. 97c478bd9Sstevel@tonic-gate * 107c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 117c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 127c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 137c478bd9Sstevel@tonic-gate * and limitations under the License. 147c478bd9Sstevel@tonic-gate * 157c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 167c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 177c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 187c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 197c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 207c478bd9Sstevel@tonic-gate * 217c478bd9Sstevel@tonic-gate * CDDL HEADER END 227c478bd9Sstevel@tonic-gate * 23*7aec1d6eScindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * FMA Event Injector language parser 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 337c478bd9Sstevel@tonic-gate #include <limits.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <inj.h> 367c478bd9Sstevel@tonic-gate #include <inj_err.h> 377c478bd9Sstevel@tonic-gate #include <inj_event.h> 387c478bd9Sstevel@tonic-gate #include <inj_hash.h> 397c478bd9Sstevel@tonic-gate #include <inj_lex.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate %} 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate %union { 447c478bd9Sstevel@tonic-gate inj_decl_t *l_decl; 457c478bd9Sstevel@tonic-gate inj_declmem_t *l_declmem; 467c478bd9Sstevel@tonic-gate inj_defn_t *l_defn; 477c478bd9Sstevel@tonic-gate inj_defnmem_t *l_defnmem; 487c478bd9Sstevel@tonic-gate inj_cmd_t *l_command; 497c478bd9Sstevel@tonic-gate inj_randelem_t *l_randelem; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate inj_hash_t *l_hash; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate char *l_string; 547c478bd9Sstevel@tonic-gate uint_t l_number; 557c478bd9Sstevel@tonic-gate hrtime_t l_hrtime; 567c478bd9Sstevel@tonic-gate } 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate %type <l_decl> decl_memlist 597c478bd9Sstevel@tonic-gate %type <l_declmem> decl_mem 607c478bd9Sstevel@tonic-gate %type <l_declmem> decl_baremem 617c478bd9Sstevel@tonic-gate %type <l_declmem> decl_mem_intr 627c478bd9Sstevel@tonic-gate %type <l_number> decl_intr_type 637c478bd9Sstevel@tonic-gate %type <l_number> decl_arraydim 647c478bd9Sstevel@tonic-gate %type <l_declmem> decl_mem_cplx 657c478bd9Sstevel@tonic-gate %type <l_hash> decl_enumlist 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate %type <l_defn> defn_memlist 687c478bd9Sstevel@tonic-gate %type <l_defnmem> defn_memvals 697c478bd9Sstevel@tonic-gate %type <l_defnmem> defn_val 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate %type <l_command> command 727c478bd9Sstevel@tonic-gate %type <l_command> cmd_repeatable 737c478bd9Sstevel@tonic-gate %type <l_randelem> rand_problist 747c478bd9Sstevel@tonic-gate %type <l_randelem> rand_element 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate %type <l_defn> defined_event 777c478bd9Sstevel@tonic-gate %type <l_number> number 787c478bd9Sstevel@tonic-gate %type <l_hrtime> hrtime 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate %token INJ_TOK_EVDEF 817c478bd9Sstevel@tonic-gate %token INJ_TOK_FMRIDEF 827c478bd9Sstevel@tonic-gate %token INJ_TOK_AUTHDEF 83*7aec1d6eScindi %token INJ_TOK_LISTDEF 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate %token INJ_TOK_INT8 867c478bd9Sstevel@tonic-gate %token INJ_TOK_INT16 877c478bd9Sstevel@tonic-gate %token INJ_TOK_INT32 887c478bd9Sstevel@tonic-gate %token INJ_TOK_INT64 897c478bd9Sstevel@tonic-gate %token INJ_TOK_UINT8 907c478bd9Sstevel@tonic-gate %token INJ_TOK_UINT16 917c478bd9Sstevel@tonic-gate %token INJ_TOK_UINT32 927c478bd9Sstevel@tonic-gate %token INJ_TOK_UINT64 937c478bd9Sstevel@tonic-gate %token INJ_TOK_BOOLEAN 947c478bd9Sstevel@tonic-gate %token INJ_TOK_STRING 957c478bd9Sstevel@tonic-gate %token INJ_TOK_ENUM 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate %token INJ_TOK_EVENT 987c478bd9Sstevel@tonic-gate %token INJ_TOK_FMRI 997c478bd9Sstevel@tonic-gate %token INJ_TOK_AUTH 100*7aec1d6eScindi %token INJ_TOK_LIST 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate %token INJ_TOK_ADDHRT 1037c478bd9Sstevel@tonic-gate %token INJ_TOK_ENDHRT 1047c478bd9Sstevel@tonic-gate %token INJ_TOK_SLEEP 1057c478bd9Sstevel@tonic-gate %token INJ_TOK_REPEAT 1067c478bd9Sstevel@tonic-gate %token INJ_TOK_RANDOMIZE 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate %token <l_string> INJ_TOK_IDENT 1097c478bd9Sstevel@tonic-gate %token <l_string> INJ_TOK_FMACLASS 1107c478bd9Sstevel@tonic-gate %token <l_string> INJ_TOK_IMM 1117c478bd9Sstevel@tonic-gate %token <l_string> INJ_TOK_QSTRING 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate %% 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate statement_list: /* EMPTY */ 1167c478bd9Sstevel@tonic-gate | statement_list statement ';' 1177c478bd9Sstevel@tonic-gate ; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate statement: decl 1207c478bd9Sstevel@tonic-gate | defn 1217c478bd9Sstevel@tonic-gate | command { 1227c478bd9Sstevel@tonic-gate if ($1 != NULL) 1237c478bd9Sstevel@tonic-gate inj_cmds_add($1); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate ; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* 128*7aec1d6eScindi * Event, FMRI, Authority, and list declarations 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate decl: INJ_TOK_EVDEF INJ_TOK_FMACLASS '{' decl_memlist '}' { 1327c478bd9Sstevel@tonic-gate if ($4 != NULL) 1337c478bd9Sstevel@tonic-gate inj_decl_finish($4, $2, ITEMTYPE_EVENT); 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate | INJ_TOK_FMRIDEF INJ_TOK_IDENT '{' decl_memlist '}' { 1367c478bd9Sstevel@tonic-gate if ($4 != NULL) 1377c478bd9Sstevel@tonic-gate inj_decl_finish($4, $2, ITEMTYPE_FMRI); 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate | INJ_TOK_AUTHDEF INJ_TOK_IDENT '{' decl_memlist '}' { 1407c478bd9Sstevel@tonic-gate if ($4 != NULL) 1417c478bd9Sstevel@tonic-gate inj_decl_finish($4, $2, ITEMTYPE_AUTH); 1427c478bd9Sstevel@tonic-gate } 143*7aec1d6eScindi | INJ_TOK_LISTDEF INJ_TOK_IDENT '{' decl_memlist '}' { 144*7aec1d6eScindi if ($4 != NULL) 145*7aec1d6eScindi inj_decl_finish($4, $2, ITEMTYPE_LIST); 146*7aec1d6eScindi } 1477c478bd9Sstevel@tonic-gate ; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate decl_memlist: /* EMPTY */ { $$ = NULL; } 1507c478bd9Sstevel@tonic-gate | decl_memlist decl_mem ';' { 1517c478bd9Sstevel@tonic-gate if ($2 == NULL) { 1527c478bd9Sstevel@tonic-gate $$ = $1; 1537c478bd9Sstevel@tonic-gate } else if ($1 == NULL) { 1547c478bd9Sstevel@tonic-gate $$ = inj_decl_create($2); 1557c478bd9Sstevel@tonic-gate } else { 1567c478bd9Sstevel@tonic-gate inj_decl_addmem($1, $2); 1577c478bd9Sstevel@tonic-gate $$ = $1; 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate ; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate decl_mem: decl_baremem 1637c478bd9Sstevel@tonic-gate | decl_baremem decl_arraydim { 1647c478bd9Sstevel@tonic-gate if ($1 != NULL) 1657c478bd9Sstevel@tonic-gate inj_decl_mem_make_array($1, $2); 1667c478bd9Sstevel@tonic-gate $$ = $1; 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate ; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate decl_baremem: decl_mem_intr 1717c478bd9Sstevel@tonic-gate | decl_mem_cplx 1727c478bd9Sstevel@tonic-gate ; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate decl_mem_intr: decl_intr_type INJ_TOK_IDENT { 1757c478bd9Sstevel@tonic-gate $$ = inj_decl_mem_create($2, $1); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate ; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate decl_intr_type: INJ_TOK_INT8 { $$ = MEMTYPE_INT8; } 1807c478bd9Sstevel@tonic-gate | INJ_TOK_INT16 { $$ = MEMTYPE_INT16; } 1817c478bd9Sstevel@tonic-gate | INJ_TOK_INT32 { $$ = MEMTYPE_INT32; } 1827c478bd9Sstevel@tonic-gate | INJ_TOK_INT64 { $$ = MEMTYPE_INT64; } 1837c478bd9Sstevel@tonic-gate | INJ_TOK_UINT8 { $$ = MEMTYPE_UINT8; } 1847c478bd9Sstevel@tonic-gate | INJ_TOK_UINT16 { $$ = MEMTYPE_UINT16; } 1857c478bd9Sstevel@tonic-gate | INJ_TOK_UINT32 { $$ = MEMTYPE_UINT32; } 1867c478bd9Sstevel@tonic-gate | INJ_TOK_UINT64 { $$ = MEMTYPE_UINT64; } 1877c478bd9Sstevel@tonic-gate | INJ_TOK_BOOLEAN { $$ = MEMTYPE_BOOL; } 1887c478bd9Sstevel@tonic-gate | INJ_TOK_STRING { $$ = MEMTYPE_STRING; } 1897c478bd9Sstevel@tonic-gate ; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate decl_arraydim: '[' number ']' { 1927c478bd9Sstevel@tonic-gate $$ = $2; 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate | '[' ']' { 1957c478bd9Sstevel@tonic-gate $$ = 0; 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate ; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate decl_mem_cplx: INJ_TOK_ENUM INJ_TOK_IDENT '{' decl_enumlist '}' { 2007c478bd9Sstevel@tonic-gate $$ = inj_decl_mem_create_enum($2, $4); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate | INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT { 2037c478bd9Sstevel@tonic-gate $$ = inj_decl_mem_create_defined($3, $2, 2047c478bd9Sstevel@tonic-gate ITEMTYPE_EVENT); 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate | INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT { 2077c478bd9Sstevel@tonic-gate $$ = inj_decl_mem_create_defined($3, $2, 2087c478bd9Sstevel@tonic-gate ITEMTYPE_FMRI); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate | INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT { 2117c478bd9Sstevel@tonic-gate $$ = inj_decl_mem_create_defined($3, $2, 2127c478bd9Sstevel@tonic-gate ITEMTYPE_AUTH); 2137c478bd9Sstevel@tonic-gate } 214*7aec1d6eScindi | INJ_TOK_LIST INJ_TOK_IDENT INJ_TOK_IDENT { 215*7aec1d6eScindi $$ = inj_decl_mem_create_defined($3, $2, 216*7aec1d6eScindi ITEMTYPE_LIST); 217*7aec1d6eScindi } 2187c478bd9Sstevel@tonic-gate ; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate decl_enumlist: INJ_TOK_IDENT { 2217c478bd9Sstevel@tonic-gate $$ = inj_zalloc(sizeof (inj_hash_t)); 2227c478bd9Sstevel@tonic-gate inj_strhash_create($$); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate inj_strhash_insert($$, $1, 1); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate | decl_enumlist ',' INJ_TOK_IDENT { 2277c478bd9Sstevel@tonic-gate if (inj_strhash_lookup($1, $3) != NULL) 2287c478bd9Sstevel@tonic-gate yyerror("duplicate enum value \"%s\"", $3); 2297c478bd9Sstevel@tonic-gate else 2307c478bd9Sstevel@tonic-gate inj_strhash_insert($1, $3, 1); 2317c478bd9Sstevel@tonic-gate $$ = $1; 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate ; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 236*7aec1d6eScindi * Event, FMRI, Authority, and list definitions 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate defn: INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT '=' 2407c478bd9Sstevel@tonic-gate '{' defn_memlist '}' { 2417c478bd9Sstevel@tonic-gate inj_defn_finish($6, $2, $3, ITEMTYPE_EVENT); 2427c478bd9Sstevel@tonic-gate inj_strfree($2); 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate | INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT '=' 2457c478bd9Sstevel@tonic-gate '{' defn_memlist '}' { 2467c478bd9Sstevel@tonic-gate inj_defn_finish($6, $2, $3, ITEMTYPE_FMRI); 2477c478bd9Sstevel@tonic-gate inj_strfree($2); 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate | INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT '=' 2507c478bd9Sstevel@tonic-gate '{' defn_memlist '}' { 2517c478bd9Sstevel@tonic-gate inj_defn_finish($6, $2, $3, ITEMTYPE_AUTH); 2527c478bd9Sstevel@tonic-gate inj_strfree($2); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate ; 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate defn_memlist: defn_memvals { 2577c478bd9Sstevel@tonic-gate $$ = inj_defn_create($1); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate | defn_memlist ',' defn_memvals { 2607c478bd9Sstevel@tonic-gate inj_defn_addmem($1, $3); 2617c478bd9Sstevel@tonic-gate $$ = $1; 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate ; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate defn_memvals: defn_val 2667c478bd9Sstevel@tonic-gate | INJ_TOK_EVENT INJ_TOK_FMACLASS { 2677c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create($2, DEFNMEM_EVENT); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate | INJ_TOK_FMRI INJ_TOK_IDENT { 2707c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create($2, DEFNMEM_FMRI); 2717c478bd9Sstevel@tonic-gate } 2727c478bd9Sstevel@tonic-gate | INJ_TOK_AUTH INJ_TOK_IDENT { 2737c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create($2, DEFNMEM_AUTH); 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate | '[' defn_memlist ']' { 2767c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create_list($2, DEFNMEM_ARRAY); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate | '{' defn_memlist '}' { 279*7aec1d6eScindi $$ = inj_defn_mem_create_list($2, DEFNMEM_LIST); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate ; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate defn_val: INJ_TOK_IMM { 2847c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create($1, DEFNMEM_IMM); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate | INJ_TOK_IDENT { 2877c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create($1, DEFNMEM_IDENT); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate | INJ_TOK_QSTRING { 2907c478bd9Sstevel@tonic-gate $$ = inj_defn_mem_create($1, DEFNMEM_QSTRING); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate ; 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate /* 2957c478bd9Sstevel@tonic-gate * Commands 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate command: cmd_repeatable 2997c478bd9Sstevel@tonic-gate | INJ_TOK_ADDHRT hrtime { $$ = inj_cmd_addhrt($2); } 3007c478bd9Sstevel@tonic-gate | INJ_TOK_ENDHRT { $$ = inj_cmd_endhrt(); } 3017c478bd9Sstevel@tonic-gate | INJ_TOK_SLEEP number { $$ = inj_cmd_sleep($2); } 3027c478bd9Sstevel@tonic-gate | INJ_TOK_REPEAT number cmd_repeatable { 3037c478bd9Sstevel@tonic-gate $$ = ($3 == NULL ? NULL : inj_cmd_repeat($3, $2)); 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate ; 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate cmd_repeatable: defined_event { 3087c478bd9Sstevel@tonic-gate $$ = ($1 == NULL ? NULL : inj_cmd_send($1)); 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate | INJ_TOK_RANDOMIZE '{' rand_problist '}' { 3117c478bd9Sstevel@tonic-gate $$ = ($3 == NULL ? NULL : inj_cmd_rand($3)); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate ; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate rand_problist: rand_element 3167c478bd9Sstevel@tonic-gate | rand_problist ',' rand_element { 3177c478bd9Sstevel@tonic-gate $$ = ($1 == NULL || $3 == NULL) ? 3187c478bd9Sstevel@tonic-gate NULL : inj_rand_add($1, $3); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate ; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate rand_element: '{' defined_event ',' number '}' { 3237c478bd9Sstevel@tonic-gate $$ = ($2 == NULL ? NULL : inj_rand_create($2, $4)); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate ; 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate defined_event: INJ_TOK_IDENT { 3287c478bd9Sstevel@tonic-gate inj_defn_t *ev; 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate if ((ev = inj_defn_lookup($1, MEMTYPE_EVENT)) == 3317c478bd9Sstevel@tonic-gate NULL) { 3327c478bd9Sstevel@tonic-gate yyerror("unknown event \"%s\"\n", $1); 3337c478bd9Sstevel@tonic-gate $$ = NULL; 3347c478bd9Sstevel@tonic-gate } else 3357c478bd9Sstevel@tonic-gate $$ = ev; 3367c478bd9Sstevel@tonic-gate } 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate number: INJ_TOK_IMM { 3397c478bd9Sstevel@tonic-gate u_longlong_t val; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate if (inj_strtoull($1, 32, &val) < 0) { 3427c478bd9Sstevel@tonic-gate yyerror("invalid number"); 3437c478bd9Sstevel@tonic-gate $$ = 0; 3447c478bd9Sstevel@tonic-gate } else 3457c478bd9Sstevel@tonic-gate $$ = (uint32_t)val; 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate hrtime: INJ_TOK_IMM INJ_TOK_IDENT { 3497c478bd9Sstevel@tonic-gate longlong_t val; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate if (inj_strtoll($1, 64, &val) < 0 || 3527c478bd9Sstevel@tonic-gate inj_strtime(&val, $2) < 0) { 3537c478bd9Sstevel@tonic-gate yyerror("invalid time"); 3547c478bd9Sstevel@tonic-gate $$ = 0; 3557c478bd9Sstevel@tonic-gate } else 3567c478bd9Sstevel@tonic-gate $$ = val; 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate %% 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate inj_list_t * 3627c478bd9Sstevel@tonic-gate inj_program_read(const char *file) 3637c478bd9Sstevel@tonic-gate { 3647c478bd9Sstevel@tonic-gate if (strcmp(file, "-") == 0) { 3657c478bd9Sstevel@tonic-gate yyin = stdin; 3667c478bd9Sstevel@tonic-gate yyinname = "stdin"; 3677c478bd9Sstevel@tonic-gate } else { 3687c478bd9Sstevel@tonic-gate if ((yyin = fopen(file, "r")) == NULL) 3697c478bd9Sstevel@tonic-gate die("failed to open %s", file); 3707c478bd9Sstevel@tonic-gate 371*7aec1d6eScindi yyinname = strrchr(file, '/'); 372*7aec1d6eScindi if (yyinname != NULL) 373*7aec1d6eScindi yyinname++; 374*7aec1d6eScindi else 3757c478bd9Sstevel@tonic-gate yyinname = file; 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate yyreset(); 3797c478bd9Sstevel@tonic-gate (void) yyparse(); 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate if (yyin != stdin) 3827c478bd9Sstevel@tonic-gate (void) fclose(yyin); 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate if (yynerrors != 0) { 3857c478bd9Sstevel@tonic-gate die("parsing failed - %d error%s\n", yynerrors, 3867c478bd9Sstevel@tonic-gate (yynerrors > 1 ? "s" : "")); 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate return (inj_cmds_get()); 3907c478bd9Sstevel@tonic-gate } 391