# HCVEinfo.def: Defines Health Check/Validation Engine Macros # $Id: HCVEinfo.def,v 2.18 2012/01/27 10:25:42 mschenke Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_4/src/scripting/lib/modules/HCVEinfo.def,v 2.18 2012/01/27 10:25:42 mschenke Exp $ # # Change History # 20120127 MSC Replace the variables in texts when evaluating the rule. =head1 NAME HCVEinfo - Defines Health Check/Validation Engine Macros =head1 DESCRIPTION This persistent submodule regroups macros to perform health check rules within RDA. The following macros are available: =cut use Xml # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('dsp_hcve_results','exe_hcve_rules',\ 'get_hcve_desc','get_hcve_rules',\ 'wrt_hcve_errors','wrt_hcve_man','wrt_hcve_results',\ 'fmt_hcve_res','fmt_hcve_str','fmt_hcve_val',\ 'rpl_hcve_ref','wrt_hcve_man_txt','wrt_hcve_res_txt') # Define HCVE variables keep @tb_grp,@tb_res,%tb_err,%tb_grp,%tb_msg,%tb_res,%tb_rul var (@tb_grp,@tb_res,%tb_err,%tb_grp,%tb_msg,%tb_res,%tb_rul) = () =head2 S This macro gets the rule set description. =cut macro get_hcve_desc {var (\%tbl,$xml) = @arg var %dsc = ('fam','family',\ 'ini','init',\ 'plt','platform',\ 'prd','product',\ 'set','set',\ 'ttl','title',\ 'typ','type') loop $key (keys(%dsc)) {if ?$xml->get_value($dsc{$key}) var $tbl{$key} = last } } =head2 S This macro reports the test results on the screen. =cut macro dsp_hcve_results {var ($ttl,$hlt) = @arg import @tb_res,%tb_err,%tb_res keep @tb_res,%tb_err,%tb_res # Display the page header var $fmt = "%-6s %-20.20s %-7.7s %-s" dump "\012Test \042",$ttl,"\042 executed at ",${RDA.LOCALTIME} dump "\012Test Results\012~~~~~~~~~~~~\012" dump sprintf($fmt,"ID","NAME","RESULT","VALUE") dump "====== ==================== ======= ===================================\ =======" # Display a rule overview loop $rid (@tb_res) {var $mod = $tb_res{$rid,'mod'} var $nam = $tb_res{$rid,'nam'} var $res = $tb_res{$rid,'res'} # Determine the value contribution if and(compare('eq',$mod,'LOG'),\ compare('ne',$res,'ERROR'),\ compare('ne',$res,'LOOP')) var $val = 'See Log' elsif ?$tb_res{$rid,'val'} {var $val = replace(last,"\012",' ',true) if expr('>',length($val),40) var $val = concat(substr($val,0,37),'..>') } else var $val = '' # Display the rule result dump sprintf($fmt,$rid,$nam,$res,nvl($val,'')) # Check when if abort occurred if expr('eq',$rid,$hlt) {var $sep = repeat('-',${RDA.COLUMNS}) echo $sep if compare('eq',$res,'ERROR') echo "(ABORT) Execution of rule \042",$nam,"\042 completed with errors." else echo "(ABORT) Execution of rule \042",$nam,"\042 was FAILED." echo 'To be able to continue with remaing tests, this test has to be PASSED.' echo $sep break } } # Report execution errors if scalar(keys(%tb_err)) echo '\012Execution of ',last,' rule(s) completed with errors.' } =head2 S This macro evaluates a HCVE condition. =cut macro eval_hcve_condition {var ($rul,$rid) = @arg import %tb_res keep %tb_res # Detect circular references var $val = $tb_res{$rid,'res'} if compare('eq',$val,'LOOP') return (false,undef,\ err => 'LOOP',\ msg => concat('Rule: Circular dependencies found in ',$rid)) # Check if a condition is specified if !?$rul->get_value('condition') return (true) # Evaluate the condition var $flg = false var $tst = $rul->get_value('condition','') var $tbl{'tst'} = $tst if compare('eq',$tst,'IS') {var $tbl{'min'} = rpl_hcve_ref($rul->get_value('minimum')) var $flg = match($val,last) } else {var $val = nvl(getHcveResult($rid),'') if compare('eq',$tst,'=~') {var $tbl{'min'} = rpl_hcve_ref($rul->get_value('minimum')) var $flg = match($val,last) } elsif compare('eq',$tst,'!~') {var $tbl{'min'} = rpl_hcve_ref($rul->get_value('minimum')) var $flg = not(match($val,last)) } elsif match($tst,'^([=!]=|[<>]=?)$') {var $min = rpl_hcve_ref($rul->get_value('minimum')) var $tbl{'min'} = $min var $flg = cond(and(isNumber($val),isNumber($min)),\ expr($tst,$val,$min),\ compare($tst,$val,$min)) } elsif match($tst,'^B',true) {var $min = rpl_hcve_ref($rul->get_value('minimum')) var $max = rpl_hcve_ref($rul->get_value('maximum')) var $tbl{'min'} = $min var $tbl{'max'} = $max var $flg = cond(and(isNumber($val),isNumber($min),isNumber($max)),\ and(expr('>=',$val,$min),expr('<=',$val,$max)),\ and(compare('ge',$val,$min),compare('le',$val,$max))) } elsif match($tst,'^N',true) var $flg = isNumber($val) elsif match($tst,'^O',true) {var $min = rpl_hcve_ref($rul->get_value('minimum')) var $max = rpl_hcve_ref($rul->get_value('maximum')) var $tbl{'min'} = $min var $tbl{'max'} = $max var $flg = cond(and(isNumber($val),isNumber($min),isNumber($max)),\ or(expr('<',$val,$min),expr('>',$val,$max)),\ or(compare('lt',$val,$min),compare('gt',$val,$max))) } elsif match($tst,'^V[\-\+=!<>]$') {var $min = rpl_hcve_ref($rul->get_value('minimum')) var $tbl{'min'} = $min var $flg = cond(compare($tst,$val,$min)) } elsif match($tst,'^VB',true) {var $min = rpl_hcve_ref($rul->get_value('minimum')) var $max = rpl_hcve_ref($rul->get_value('maximum')) var $tbl{'min'} = $min var $tbl{'max'} = $max var $flg = and(compare('V+',$val,$min),compare('V-',$val,$max)) } elsif match($tst,'^VO',true) {var $min = rpl_hcve_ref($rul->get_value('minimum')) var $max = rpl_hcve_ref($rul->get_value('maximum')) var $tbl{'min'} = $min var $tbl{'max'} = $max var $flg = or(compare('V<',$val,$min),compare('V>',$val,$max)) } } return ($flg,$val,%tbl) } =head2 S This macro executes a validation rule and its dependencies. =cut macro exe_hcve_rule {var ($rid) = @arg import @tb_res,%tb_err,%tb_grp,%tb_res,%tb_rul keep @tb_res,%tb_err,%tb_grp,%tb_res,%tb_rul var $rul = $tb_rul{$rid} var $tb_res{$rid} = {\ dsc => $rul->find('sdp_description')->get_data,\ mod => $mod = uc($rul->get_value('mode','?')),\ nam => $nam = $rul->get_value('name',$rid),\ res => 'LOOP',\ val => ''} # Check the dependencies loop $dep ($rul->find('sdp_dependencies/sdp_dependency')) {var $did = $dep->get_value('id','') # Resolve the dependency if missing($tb_res{$did}) {if missing($tb_rul{$did}) {debug sprintf('Executing Rule: [%-6s] %-20.20s - missing.',$did,'') var $tb_err{$did} = 'Rule: Missing rule' var $tb_res{$did} = {nam => '???',\ res => 'ERROR',\ val => 'NA'} call push(@tb_res,$did) } elsif ?exe_hcve_rule($did) return last } # Check the condition var ($flg,$val,%tbl) = eval_hcve_condition($dep,$did) next $flg debug sprintf('Executing Rule: [%-6s] %-20.20s - dependency failure.',\ $rid,$nam) var $tb_res{$rid,'dep'} = $did if exists($tbl{'err'}) {var $tb_res{$rid,'res'} = $tbl{'err'} var $tb_err{$rid} = $tbl{'msg'} } else { var $tb_res{$rid,'prv'} = $val var $tb_res{$rid,'res'} = $dep->get_value('result','FAILED') var $tb_res{$rid,'syn'} = $dep->get_value('syntax','text') var $tb_res{$rid,'val'} = $dep->get_value('value','NA') call get_text($tb_res{$rid},$dep) loop $key (keys(%tbl)) var $tb_res{$rid,$key} = $tbl{$key} if $dep->get_value('error') var $tb_err{$rid} = last } call push(@tb_res,$rid) return undef } # Get the value call push(@tb_res,$rid) call setHcveRule($rid) var ($msg,$val) = () loop $itm ($rul->find('sdp_command')) {if $itm->get_value('exec') next !getHcveFact(last) var $typ = uc($itm->get_value('type','?')) var $cmd = rpl_hcve_ref($itm->get_data) if !$cmd var $msg = 'Command: Missing command' elsif compare('eq',$typ,'ATTACH') {if testFile('rf',$cmd) {var $val = basename($cmd) output D,concat('hcve_',$val) if !writeData($cmd) var $msg = join("\012",'Command:',\ '',\ $cmd,\ '',\ 'Result: Copy failed') close } else var $msg = join("\012",'Command:',\ '',\ $cmd,\ '',\ 'Result: Cannot find or read the file') var $mod = 'ATTACH' var $tb_res{$rid,'mod'} = $mod } elsif compare('eq',$typ,'GROUP') {if exists($tb_grp{$cmd}) {var ($flg,@rul) = @{$tb_grp{$cmd}} if !$flg {loop $det (@rul) break ?exe_hcve_rule($det) } } else var $msg = concat("Missing group ",$cmd) } elsif compare('eq',$typ,'PROMPT') {call setTempSetting('HCVE_INFO','prompt') call setTempSetting('HCVE_VARIABLE',$cmd) call setTempSetting('HCVE_DEFAULT',\ replaceEnv(rpl_hcve_ref($itm->get_value('default')),true)) call requestSetting('HCVEinfo') var $val = replaceEnv(getSetting('HCVE_PROMPT')) } elsif compare('eq',$typ,'SDCL') {next } elsif compare('eq',$typ,'SQL') {var ($val,$msg,@err) = evalHcveCommand($typ, $cmd) if $msg {var $msg = join("\012",'Command:',\ '',\ $cmd,\ '',\ concat('Result: ',$msg),\ 'Value:',\ '',\ $val,\ '') if @err var $msg = join("\012",$msg,\ 'Return code: ',\ '',\ @err,\ '') } } else {var ($val,$msg,@err) = evalHcveCommand($typ, $cmd) if $msg var $msg = join("\012",'Command:',\ '',\ $cmd,\ '',\ join('%BR%',concat('Result: ',$msg),\ concat('Value: ',nvl($val,'NA')),\ @err)) } # Treat the error if $msg {debug sprintf('Executing Rule: [%-6s] %-20.20s - error encountered.',\ $rid,$nam) var $tb_res{$rid,'res'} = 'ERROR' var $tb_res{$rid,'val'} = 'NA' var $tb_err{$rid} = $msg return cond(compare('eq',$mod,'VERIFY_ABORT'),$rid,undef) } # Define parameter and variable var $key = $itm->get_value('parameter') if match($key,'^((\w+\.)+\w+)$') call setHcveParameter($key,$val) if match($itm->get_value('variable'),'^(\$\w+)$') call addHcveVariable(last,$val) } # Perform the validation debug sprintf('Executing Rule: [%-6s] %-20.20s - completed.',$rid,$nam) var $tb_res{$rid,'val'} = setHcveResult($val) if compare('eq',$mod,'ATTACH') var $tb_res{$rid,'res'} = 'ATTACH' elsif compare('eq',$mod,'LOG') var $tb_res{$rid,'res'} = 'LOGGED' elsif compare('eq',$mod,'RECORD') var $tb_res{$rid,'res'} = 'RECORD' elsif match($mod,'VERIFY(_ABORT)?') {var $tb_res{$rid,'act'} = $prv = [] var $tb_res{$rid,'res'} = 'FAILED' # Identify the action loop $act ($rul->find('sdp_actions/sdp_action')) {# Check the action condition var ($flg,undef,%tbl) = eval_hcve_condition($act,$rid) # Apply the action if $flg {var $tb_res{$rid,'res'} = $act->get_value('result','FAILED') var $tb_res{$rid,'syn'} = $act->get_value('syntax','text') call get_text($tb_res{$rid},$act) loop $key (keys(%tbl)) var $tb_res{$rid,$key} = $tbl{$key} if $act->get_value('error') var $tb_err{$rid} = last # Store the variable when requested if match($act->get_value('variable'),'^(\$\w+)$') call addHcveVariable(last,$val) # Check if the rule execution must be aborted if compare('eq',$mod,'VERIFY_ABORT') {if match($res,'(FAILED|ERROR)') return $rid } break } call push($prv,{%tbl}) } } # Continue the rule evaluation return undef } =head2 S This macro executes the validation rules. =cut macro exe_hcve_rules {var ($ini) = @arg import @tb_grp,@tb_res,%tb_err,%tb_res keep @tb_grp,@tb_res,%tb_err,%tb_res var (@tb_res,%tb_err,%tb_res) = () call setHcveContext(nvl($ini,'HCVEinit')) loop $grp (@tb_grp) {var ($flg,@rul) = @{$grp} next !$flg loop $rid (@rul) {if ?exe_hcve_rule($rid) return last } } return undef } =head2 S This macro loads the validation rules. It returns 0 on successful completion, -1 for parsing errors at file load, or the rule index for a missing identifier. By default, the module is searched in the hcve directory. =cut macro get_hcve_rules {var ($xml) = @arg import @tb_grp,%tb_grp,%tb_msg,%tb_rul keep @tb_grp,%tb_grp,%tb_msg,%tb_rul var (@tb_grp,%tb_grp,%tb_msg,%tb_rul) = () # Load the fact collectors loop $itm ($xml->find('sdp_facts/sdp_fact')) {var $uid = $itm->get_value('id','') if !match($uid,'^\w+$') return -1 call setHcveFact($uid,$itm) } # Load the messages loop $itm ($xml->find('sdp_messages/sdp_message')) {var $uid = $itm->get_value('id','') if !match($uid,'^\w+$') return -2 var $tb_msg{$uid} = $itm->get_data if $itm->get_value('prefix') call setHcveParameter(concat(last,'.',$uid),$tb_msg{$uid}) } # Get the list of opted-out rules var %out = () if $xml->get_value('id') {var $key = concat('HCVE_SKIP_',last) loop $rul (split(',',getSetting($key,getEnv($key,'')))) {if match($rul,'^\w+$') $out{$rul} = 1 } } # Validate the rules and dependency identifiers loop $grp ($xml->find('sdp_group')) {# Initialize the group record var $out = $grp->get_value('opt_out') var $rec = [$grp->get_value('exec',1)] # Load the rules loop $rul ($grp->find('sdp_rule')) {# Validate the rule identifier var $rid = $rul->get_value('id','') if !match($rid,'^\w+$') return -3 var $tb_rul{$rid} = $rul # Validate the dependency identifiers loop $dep ($rul->find('sdp_dependencies/sdp_dependency')) {if !match($dep->get_value('id',''),'^\w+$') return -4 } # Add the rule to the group if !and($rul->get_value('opt_out',$out),exists($out{$rid})) call push($rec,$rid) } call push(@tb_grp,$rec) if $grp->get_value('id',1) var $tb_grp{last} = $rec } return 0 } =head2 S This macro writes the test errors in the output file. =cut macro wrt_hcve_errors {var ($ttl) = @arg import %tb_err keep %tb_err if $ttl {prefix {write $ttl write 'Tests executed at ',${RDA.GMTIME},' UTC' } } loop $rid (keys(%tb_err)) {write '---' write '(Error) Execution of rule ',$rid,' failed.' write '---' write $tb_err{$rid} } unprefix } =head2 S This macro writes a complete description of the specified rule set. =cut macro wrt_hcve_man {var ($set,$xml) = @arg import $TOC,$TOP var %tb_max = ('B', 'a result between ',\ 'O', 'a result not between ',\ 'VB','a version between ',\ 'VO','a version not between ') var %tb_tst = ('==','',\ '!=','a result different from ',\ '<', 'a result less than ',\ '<=','a result less than or equal to ',\ '>', 'a result greater than ',\ '>=','a result greater than or equal to ',\ '=~','a result matching ',\ '!~','a result not matching ',\ 'V=','a version equal to ',\ 'V!','a version different from ',\ 'V<','a version less than ',\ 'V-','a version less than or equal to ',\ 'V>','a version greater than ',\ 'V+','a version greater than or equal to ') var %typ = ('A','Pre-Install','P','Post-Install') # Produce a rule set description macro dsp_check {var ($xml,$ttl) = @arg import %tb_max,%tb_tst,$TOP keep %tb_max,%tb_tst,$TOP write '---+ ',$ttl if ?$xml->get_value('id') write '|*Identifier*|',last,' |' # Treat the messages loop $itm ($xml->find('sdp_messages/sdp_message')) {if ?$itm->get_value('id') var $tbl{last} = $itm->get_data } prefix {write '---++ Messages' write '|*Identifier*|*Text*|' } loop $key (keys(%tbl)) write '|',$key,' |',$tbl{$key},' |' if hasOutput(true) {write $TOP write '---' } # Treat the fact collectors if $xml->find('sdp_facts/sdp_fact') {var @tbl = last write '---++ Facts' loop $itm (@tbl) {var $uid = $itm->get_value('id') write '---+++ Fact ',nvl($uid,'?') if $itm->find('sdp_description')->get_data write fmt_hcve_str(last,true),'%BR%%BR%' if $itm->find('sdp_parameters/sdp_parameter') {var @trg = last write "''For parameters:''" loop $trg (@trg) {if ?$trg->get_value('name') write ' * ',uc(last) } write '%BR%' } var $sep = '' loop $cmd ($itm->find('sdp_command')) {var $typ = uc($cmd->get_value('type','')) if compare('eq',$typ,'OS') write $sep,"''Run the following command from the operating system \ command line:''" elsif compare('eq',$typ,'PERL') write $sep,"''Run the following Perl code:''" elsif compare('eq',$typ,'RDA') write $sep,"''Run the following RDA code:''" elsif compare('eq',$typ,'SDCL') write $sep,"''Run the following SDCL code:''" elsif compare('eq',$typ,'SQL') write $sep,"''Run the following command from a SQL command prompt:''" else write $sep,"''``",$typ,"``''" write '' write $cmd->get_data write '' if $cmd->get_value('parameter') write "''It stores the rule value in the ``",uc(last),\ "`` parameter.''%BR%" if $cmd->get_value('variable') write "''It stores the rule value in the ``",last,\ "`` variable in the evaluation context.''%BR%" var $sep = "%BR%" } write $TOP write '---' } } # Treat the rule groups loop $grp ($xml->find('sdp_group')) {# Display the group title var $str = cond($grp->get_value('exec',1),'Rule Group','Optional Rule Group') if $grp->get_value('id') var $str = concat($str,': ',last) if $grp->get_value('title') var $str = concat($str,' - ',fmt_hcve_str(last)) var $out = $grp->get_value('opt_out') write '---++ ',$str # Display the rules loop $rul ($grp->find('sdp_rule')) {var $rid = $rul->get_value('id') write '#Rule',$rid write '---+++ Rule ',$rid,': ',fmt_hcve_str($rul->get_value('name')) if $rul->find('sdp_description')->get_data write fmt_hcve_str(last,true),'%BR%%BR%' # Display possible dependencies loop $dep ($rul->find('sdp_dependencies/sdp_dependency id="\w+"')) {var $did = $dep->get_value('id') var $lnk = concat('[[#Rule',$did,'][rule ',$did,']]') var $tst = uc($dep->get_value('condition')) if ?$tst {write "''HCVE treats this test as ",\ fmt_hcve_val($dep->get_value('result','FAILED')),\ " unless the ",$lnk," \134" if match($tst,'^(V?[BO])') {var ($val) = last write "has ",$tb_max{$val},\ fmt_hcve_val($dep->get_value('minimum'))," and ",\ fmt_hcve_val($dep->get_value('maximum')),"\134" } elsif compare('eq',$tst,'IS') write "has a ",fmt_hcve_val($dep->get_value('minimum'))," status\134" elsif match($tst,'^N') write "has a numeric result\134" else write "has ",nvl($tb_tst{$tst},$tst),\ fmt_hcve_val($dep->get_value('minimum')),"\134" write ".''%BR%" } else write "''This rule requires the execution of ",$lnk,".''%BR%" if $dep->get_value('message') {write "''The text is composed of the following messages:'' ``",\ replace(last,',','``, ``',true),"``" write } elsif $dep->get_data {var $str = last if compare('eq',$act->get_value('syntax'),'wiki') call wrt_hcve_man_txt($str) else write fmt_hcve_str($str) write } write "%BR%" } # Display the rule content var $sep = '' loop $cmd ($rul->find('sdp_command')) {var $typ = uc($cmd->get_value('type','')) if compare('eq',$typ,'PROMPT') {write '|*Prompt*|',fmt_hcve_str($cmd->get_data),' |' write '|*Default Value*|',fmt_hcve_str($cmd->get_value('default')),' |' } else {if $cmd->get_value('exec') var $cnd = concat(' when the HCVE fact ``',last,'`` is true') else var $cnd = '' if compare('eq',$typ,'GROUP') write $sep,"''Execute the rules from the following group",$cnd,":''" elsif compare('eq',$typ,'OS') write $sep,"''Run the following command from the Operating System \ command line and record the result",$cnd,":''" elsif compare('eq',$typ,'PERL') write $sep,"''Run the following Perl code and record the result",$cnd,\ ":''" elsif compare('eq',$typ,'RDA') write $sep,"''Run the following RDA code and record the result",$cnd,\ ":''" elsif compare('eq',$typ,'SDCL') write $sep,"''Run the following SDCL code and record the result",$cnd,\ ":''" elsif compare('eq',$typ,'SQL') write $sep,"''Run the following command from a SQL command prompt \ and record the result",$cnd,":''" else write "''``",$typ,"``",$cnd,"''" write '' write $cmd->get_data write '' } if $cmd->get_value('parameter') write "''It stores the rule value in the ``",uc(last),\ "`` parameter.''%BR%" if $cmd->get_value('variable') write "''It stores the rule value in the ``",last,\ "`` variable in the evaluation context.''%BR%" var $sep = "%BR%" } var $mod = $rul->get_value('mode') if match($mod,'VERIFY(_ABORT)?',true) {loop $act ($rul->find('sdp_actions/sdp_action')) {var $tst = uc($act->get_value('condition')) if ?$tst {write "%BR%''If the rule code \134" if match($tst,'^(V?[BO])') {var ($val) = last write "returns ",$tb_max{$val},\ fmt_hcve_val($dep->get_value('minimum'))," and ",\ fmt_hcve_val($dep->get_value('maximum')),"\134" } elsif compare('eq',$tst,'IS') write "has a ",fmt_hcve_val($act->get_value('minimum'))," status\134" elsif match($tst,'^N') write "returns a numeric result\134" else write "returns ",nvl($tb_tst{$tst},$tst),\ fmt_hcve_val($act->get_value('minimum')),"\134" write ", then\134" } else write "%BR%''Otherwise,\134" write " HCVE treats this test as ",\ fmt_hcve_val($act->get_value('result','FAILED')),".\134" if $act->get_value('variable') write " It stores the rule value in the ``",last,\ "`` variable in the evaluation context.\134" write "''%BR%" if ?$act->get_value('message') {write "''The text is composed of the following messages:'' ``",\ replace(last,',','``, ``',true),"``" write } elsif $act->get_data {var $str = last if compare('eq',$act->get_value('syntax'),'wiki') call wrt_hcve_man_txt($str) else write fmt_hcve_str($str) write } } } if $rul->get_value('opt_out',$out) write "%BR%''Users can opt out this rule.''%BR%" write $TOP write '---' } } } # Produce an eval block description macro dsp_eval {var ($xml,$ttl) = @arg import $TOP keep $TOP write '---+ ',$ttl var $cnt = 0 loop $itm ($xml->get_content) {incr $cnt var ($tag,%tbl) = ($itm->get_name) loop $key ($itm->get_attr) var $tbl{$key} = $itm->get_value($key) # Identify the request if compare('eq',$tag,'sdp_ask') {if !$tbl{'name'} {write '---++ Prompt ',$cnt write '**Missing property name**' next } write '---++ Prompt for ',last delete $tbl{'name'} } elsif compare('eq',$tag,'sdp_exec') {if !$tbl{'command'} {write '---++ Command ',$cnt write '**Missing command**' next } var $ttl = concat('---++ Execute ',last,' Command') if $tbl{'on'} var $ttl = concat($ttl,' on ',last) write $ttl delete $tbl{'command'} delete $tbl{'on'} } else next # Display the attribute prefix write '|*Attribute*|*Value*|' loop $key (keys(%tbl)) write '|',$key,'|',$tbl{$key},'|' unprefix # Display the associated data if $itm->get_data {var $str = last write '---### Associated Data:' write '' write $str write '' } } } # Produce a rule description write '---+!! ',getHcveName($set) write $TOC write '---+ Generalities' write '|*Name*|``',$set,'`` |' write '|*Title*|``',$xml->get_value('title',$set),'`` |' if $xml->find('sdp_description')->get_data write '|*Description*|',last,' |' if ?$xml->get_value('type') write '|*Type*|',nvl($tb_typ{last},concat('``',last,'``')),' |' if ?$xml->get_value('family') write '|*Family*|``',last,'`` |' if ?$xml->get_value('platform') write '|*Platform*|``',last,'`` |' if ?$xml->get_value('product') write '|*Product*|``',last,'`` |' write $TOP # Display the target information if $xml->find('sdp_meta type="target"') {var ($tgt) = last prefix write '---+ Target Information' loop $key ($tgt->get_attr) {next compare('eq',$key,'type') write '|*',ucfirst($key),'*|',$tgt->get_value($key),' |' } if hasOutput(true) write $TOP } write '---' # Analyze the diaglet content var $cnt = 0 loop $sub ($xml->find('sdp_content')) {incr $cnt var $ttl = $sub->get_value('title') var $typ = $sub->get_value('type') if compare('eq',$typ,'check') call dsp_check($sub,nvl($ttl,concat('Rule Set ',$cnt))) elsif compare('eq',$typ,'eval') call dsp_eval($sub,nvl($ttl,concat('Command Set ',$cnt))) } if isCreated(true) write 'Generated on ',${RDA.LOCALTIME} } =head2 S This macro writes the test results in the output file. When the flag is set, it reports the details also. =cut macro wrt_hcve_results {var ($ttl,$hlt,$flg) = @arg import @tb_res,%tb_err,%tb_res,$TOC,$TOP keep @tb_res,%tb_err,%tb_res,$TOC,$TOP if $ttl {write $ttl write 'Tests executed at ',${RDA.GMTIME},' UTC' write write $TOC } # Report the test results write '---+ Test Results' write '|*Rule*|*Name*|*Result*|*Value*|' loop $rid (@tb_res) {var $rec = $tb_res{$rid} var $mod = $rec->{'mod'} var $nam = $rec->{'nam'} var $res = $rec->{'res'} # Determine the value contribution if and(compare('eq',$mod,'ATTACH'),\ compare('ne',$res,'ERROR'),\ compare('ne',$res,'LOOP')) {var @tbl = () loop $itm (split("\012",$rec->{'val'})) {var ($lnk,$rpt) = split("\|",$itm,2) if length($lnk) var @tbl = (@tbl,concat('[[',$lnk,'][_blank][',nvl($rpt,$lnk),']]')) } var $val = join("\012",@tbl) } elsif and(compare('eq',$mod,'LOG'),\ compare('ne',$res,'ERROR'),\ compare('ne',$res,'LOOP')) var $val = 'See Log' else var $val = $rec->{'val'} # Display the rule result if and($flg,match($res,'(FAILED|LOGGED|PASSED|SKIPPED|WARNING)')) var $res = concat('[[#Rule',$rid,'][',$res,']]') write '|',$rid,' |',fmt_hcve_str($nam),' |',$res,' |',fmt_hcve_res($val),' |' # Check when if abort occurred if expr('eq',$rid,$hlt) {write '---' if compare('eq',$res,'ERROR') write '(ABORT) Execution of rule "',$nam,'" completed with errors.' else write '(ABORT) Execution of rule "',$nam,'" was FAILED.' write 'To be able to continue with remaing tests, this test has to be \ PASSED.' write '---' break } } if scalar(keys(%tb_err)) write 'Execution of ',last,' rule(s) completed with errors.%BR%' write $TOP # Failure lists prefix {write '---+ Failure Summary' write '|*Rule*|*Description*|*Result*|*Action*|' } loop $rid (keys(%tb_res)) {var $rec = $tb_res{$rid} if compare('eq',$rec->{'res'},'FAILED') write '|',$rid,' |',fmt_hcve_str($rec->{'dsc'},true),\ ' |',fmt_hcve_res(replace($rec->{'val'},'[\[\]]','',true)),\ ' |',$rec->{'txt'},' |' } if hasOutput(true) {write $TOP call setSetting('RDA_EXIT',1) } # Report detailed results if $flg {var $TTL = '---+ Detailed Results' loop $rid (keys(%tb_res)) {var $rec = $tb_res{$rid} var $res = $rec->{'res'} # Print the actions prefix {write $TTL var $TTL = '---' write '#Rule',$rid,' ---## Rule ',$rid,': ',fmt_hcve_str($rec->{'nam'}) write '---### Description' write fmt_hcve_str($rec->{'dsc'},true) } if exists($rec->{'dep'}) {var $did = $rec->{'dep'} write '---### Dependency Failures' write ' * Dependency: ',$did,' - ',$tb_res{$did,'nam'} write ' * Result: **',$rec->{'res'},'**' write ' * Condition: ``',\ fmt_hcve_str(join(' ',$rec->{'prv'},\ $rec->{'tst'},\ $rec->{'min'},\ $rec->{'max'})),'``' if ?$rec->{'txt'} write last write } if exists($rec->{'act'}) {if @{$rec->{'act'}} {write '---### Unmatched Actions' loop $act (@{$rec->{'act'}}) write ' * ',\ fmt_hcve_res($rec->{'val'}),'`` ',\ fmt_hcve_str(join(' ',$act->{'tst'},\ $act->{'min'},\ $act->{'max'})),'``' } if ?$rec->{'tst'} {write '---### Action' write ' * Result: **',$rec->{'res'},'**' write ' * Condition: ',\ fmt_hcve_res($rec->{'val'}),'`` ',\ fmt_hcve_str(join(' ',$rec->{'tst'},\ $rec->{'min'},\ $rec->{'max'})),'``' } else {write '---### Default Action' write ' * Result: **',$rec->{'res'},'**' write ' * Value: ',fmt_hcve_res($rec->{'val'}) } if ?$rec->{'txt'} write last write } if hasOutput(true) write $TOP } # Report logged results prefix write '---+ Logged Results' loop $rid (keys(%tb_res)) {var $rec = $tb_res{$rid} next compare('ne',$rec->{'res'},'LOGGED') write '#Rule',$rid,' ---## Rule ',$rid,': ',fmt_hcve_str($rec->{'nam'}) write '' write $rec->{'val'} write '' } if hasOutput(true) write $TOP } } # --- Internal errors --------------------------------------------------------- # Get the associated text macro get_text {var ($rec,$obj) = @arg import %tb_msg keep %tb_msg # Get the text blocks var (@lin,@txt) = () if ?$obj->get_value('message') {loop $mid (split(',',rpl_hcve_ref(last))) {if exists($tb_msg{$mid}) call push(@lin,split('\n',rpl_hcve_ref($tb_msg{$mid}))) } } else call push(@lin,split('\n',rpl_hcve_ref($obj->get_data))) # Format the text blocks if compare('eq',$rec->{'syn'},'wiki') {var ($val,%val) = ($rec->{'val'}) if isNumber($val) var $val{$rec->{'nam'}} = 0 loop $str (split('[\|\012]',$val)) var $val{replace($str,'\[.*?\]','...',true)} = 1 loop $lin (@lin) {if match($lin,'^\s*\|([^\|]+)\|(.*)\|\s*$') {var ($str,$act) = (last) if exists($val{trim($str)}) call push(@txt,getHcveValues($act)) } elsif !match($lin,'^\s*\|.*\|\s*$') call push(@txt,getHcveValues($lin)) } } else {loop $lin (@lin) call push(@txt,fmt_hcve_str(getHcveValues($lin))) } if @txt var $rec->{'txt'} = join('%BR%',@txt) } # Define a macro to remove references macro rpl_hcve_ref {var ($str) = @arg import %tb_res keep %tb_res # Reject missing or empty string if !$str return $str # Replace the references var $chr = "\224" while match($str,'(%+(.*?)%+)') {var ($ref,$rid) = (last) var $val = cond(match($rid,'\.'),getHcveFact($rid),$tb_res{$rid,'val'}) if match($val,'^NA') return 'NA:' if defined($val) var $str = replace($str,concat('%+',$rid,'%+'),$val,true) else {# Escape when not a reference var $ref = replace($ref,'%!','%') var $ref = replace($ref,'!%','%') var $ref = replace($ref,'%',$chr,true) var $str = replace($str,concat('%+',$rid,'%+'),$ref,true) } } return replace($str,$chr,'%',true) } # Format a man string macro fmt_hcve_man return s($arg[0],"\$\{([\'\`\*])(\w+)\}","$1$1\${$2}$1$1",true) # Format a result value macro fmt_hcve_res return concat('``',replace(encode($arg[0]),"\012",'%BR%',true),'``') # Format a string macro fmt_hcve_str {var ($str,$flg) = @arg var $str = encode($str,$flg) var $str = replace($str,'\|','|',true) var $str = replace($str,'\*','*',true) var $str = replace($str,"\012",'%BR%',true) return $str } # Format a value macro fmt_hcve_val {var $val = $arg[0] if isNumber($val) return $val return concat('``',$val,'``') } # Write a Wiki documentation text macro wrt_hcve_man_txt {var ($str) = @arg loop $lin (split("\012",$str)) {if match($lin,'^\s*\|\s*\*') write $lin elsif match($lin,'^\s*\|([^\|]+)\|(.*)\|\s*$') {var ($val,$txt) = last write '|',fmt_hcve_val($val,true),'|',fmt_hcve_man($txt),'|' } else write fmt_hcve_man($lin) } } # Write a Wiki result text macro wrt_hcve_res_txt {var ($str) = @arg loop $lin (split("\012",$str)) {if match($lin,'^\s*\|\s*\*') write getHcveValues($lin) elsif match($lin,'^\s*\|([^\|]+)\|(.*)\|\s*$') {var ($val,$txt) = last write '|',fmt_hcve_val($val,true),'|',getHcveValues($txt),'|' } else write getHcveValues($lin) } } =head1 SEE ALSO L =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut