# HCVEinfo.def: Defines Health Check/Validation Engine Macros # $Id: HCVEinfo.def,v 1.39 2009/03/31 06:46:14 mschenke Exp $ # ARCS: $Header: /u02/webapps/workbench/cvs/RDA_4/src/scripting/lib/modules/HCVEinfo.def,v 1.39 2009/03/31 06:46:14 mschenke Exp $ # # Change History # 20090331 MSC Improve the style compliance. =head1 NAME HCVEinfo - Defines Health Check/Validation Engine Macros =head1 DESCRIPTION This persistent sub module regroups macros to perform health check rules within RDA. The following macros are available: =cut # 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_msg,%tb_rul var (@tb_grp,@tb_res,%tb_msg,%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 ?xmlValue($xml,$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 # Display the page header var $fmt = "%-6s %-20.20s %-7.7s %-s" echo "\012Test \042",$ttl,"\042 executed at ",localtime() echo "\012Test Results\012~~~~~~~~~~~~\012" echo sprintf($fmt,"ID","NAME","RESULT","VALUE") echo "====== ==================== ======= ===================================\ =======" # Display a rule overview loop $rid (@tb_res) {var $mod = getDataValue('res',$rid,'mod') var $nam = getDataValue('res',$rid,'nam') var $res = getDataValue('res',$rid,'res') # Determine the value contribution if and(compare('eq',$mod,'LOG'),\ compare('ne',$res,'ERROR')) var $val = 'See Log' elsif ?getDataValue('res',$rid,'val') {var $val = replace(getDataValue('res',$rid,'val'),"\012",' ',true) if expr('>',length($val),40) var $val = concat(substr($val,0,37),'..>') } else var $val = '' # Display the rule result echo sprintf($fmt,$rid,$nam,$res,nvl($val,'')) # Check when if abort occurred if expr('eq',$rid,$hlt) {var $sep = repeat('-',getSetting('RDA_COLUMNS',78)) 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(getDataKeys('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 # Detect circular references var $val = getDataValue('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 !?xmlValue($rul,'condition') return (true) # Evaluate the condition var $flg = false var $tst = xmlValue($rul,'condition','') var $tbl{'tst'} = $tst if compare('eq',$tst,'IS') {var $tbl{'min'} = rpl_hcve_ref(xmlValue($rul,'minimum')) var $flg = match($val,last) } else {var $val = nvl(getHcveResult($rid),'') if compare('eq',$tst,'=~') {var $tbl{'min'} = rpl_hcve_ref(xmlValue($rul,'minimum')) var $flg = match($val,last) } elsif compare('eq',$tst,'!~') {var $tbl{'min'} = rpl_hcve_ref(xmlValue($rul,'minimum')) var $flg = not(match($val,last)) } elsif match($tst,'^([=!]=|[<>]=?)$') {var $min = rpl_hcve_ref(xmlValue($rul,'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(xmlValue($rul,'minimum')) var $max = rpl_hcve_ref(xmlValue($rul,'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(xmlValue($rul,'minimum')) var $max = rpl_hcve_ref(xmlValue($rul,'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(xmlValue($rul,'minimum')) var $tbl{'min'} = $min var $flg = cond(compare($tst,$val,$min)) } elsif match($tst,'^VB',true) {var $min = rpl_hcve_ref(xmlValue($rul,'minimum')) var $max = rpl_hcve_ref(xmlValue($rul,'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(xmlValue($rul,'minimum')) var $max = rpl_hcve_ref(xmlValue($rul,'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_rul keep @tb_res,%tb_rul var $rul = $tb_rul{$rid} var $mod = uc(xmlValue($rul,'mode','?')) var $nam = xmlValue($rul,'name',$rid) call setDataValue('res',$rid,'dsc',xmlData(xmlFind($rul,'sdp_description'))) call setDataValue('res',$rid,'mod',$mod) call setDataValue('res',$rid,'nam',$nam) call setDataValue('res',$rid,'res','LOOP') call setDataValue('res',$rid,'val','') # Check the dependencies loop $dep (xmlFind($rul,'sdp_dependencies/sdp_dependency')) {var $did = xmlValue($dep,'id','') # Resolve the dependency if missingData('res',$did) {if missing($tb_rul{$did}) {debug sprintf('Executing Rule: [%-6s] %-20.20s - missing.',$did,'') call setDataValue('err',$did,'Rule: Missing rule') call setDataValue('res',$did,'nam','???') call setDataValue('res',$did,'res','ERROR') call setDataValue('res',$did,'val','NA') var @tb_res = (@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) call setDataValue('res',$rid,'dep',$did) if exists($tbl{'err'}) {call setDataValue('res',$rid,'res',$tbl{'err'}) call setDataValue('err',$rid,$tbl{'msg'}) } else {var $syn = xmlValue($dep,'syntax','text') call setDataValue('res',$rid,'prv',$val) call setDataValue('res',$rid,'res',xmlValue($dep,'result','FAILED')) call setDataValue('res',$rid,'syn',$syn) call setDataValue('res',$rid,'txt',get_text($dep,$syn)) call setDataValue('res',$rid,'val',xmlValue($dep,'value','NA')) loop $key (keys(%tbl)) call setDataValue('res',$rid,$key,$tbl{$key}) if xmlValue($dep,'error') call setDataValue('err',$rid,last) } var @tb_res = (@tb_res,$rid) return undef } # Get the value var @tb_res = (@tb_res,$rid) call setHcveRule($rid) var ($msg,$val) = () loop $itm (xmlFind($rul,'sdp_command')) {var $typ = uc(xmlValue($itm,'type','?')) var $cmd = rpl_hcve_ref(xmlData($itm)) if !$cmd var $msg = 'Command: Missing command' elsif compare('eq',$typ,'ATTACH') {if testFile('rf',$cmd) {var $val = basename($cmd) data 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' call setDataValue('res',$rid,'mod',$mod) } elsif compare('eq',$typ,'PROMPT') {call setTempSetting('HCVE_VARIABLE',$cmd) call setTempSetting('HCVE_DEFAULT',\ replaceEnv(rpl_hcve_ref(xmlValue($itm,'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) call setDataValue('res',$rid,'res','ERROR') call setDataValue('res',$rid,'val','NA') call setDataValue('err',$rid,$msg) return cond(compare('eq',$mod,'VERIFY_ABORT'),$rid,undef) } # Define parameter and variable var $key = xmlValue($itm,'parameter') if match($key,'^((\w+\.)+\w+)$') call setHcveParameter($key,$val) if match(xmlValue($itm,'variable'),'^(\$\w+)$') call addHcveVariable(last,$val) } # Perform the validation debug sprintf('Executing Rule: [%-6s] %-20.20s - completed.',$rid,$nam) call setDataValue('res',$rid,'val',setHcveResult($val)) if compare('eq',$mod,'ATTACH') call setDataValue('res',$rid,'res','ATTACH') elsif compare('eq',$mod,'LOG') call setDataValue('res',$rid,'res','LOGGED') elsif compare('eq',$mod,'RECORD') call setDataValue('res',$rid,'res','RECORD') elsif match($mod,'VERIFY(_ABORT)?') {call setDataValue('res',$rid,'act',list()) call setDataValue('res',$rid,'res','FAILED') # Identify the action loop $act (xmlFind($rul,'sdp_actions/sdp_action')) {# Check the action condition var ($flg,undef,%tbl) = eval_hcve_condition($act,$rid) # Apply the action if $flg {var $res = xmlValue($act,'result','FAILED') var $syn = xmlValue($act,'syntax','text') call setDataValue('res',$rid,'res',$res) call setDataValue('res',$rid,'syn',$syn) call setDataValue('res',$rid,'txt',get_text($act,$syn)) loop $key (keys(%tbl)) call setDataValue('res',$rid,$key,$tbl{$key}) if xmlValue($act,'error') call setDataValue('err',$rid,last) # Store the variable when requested if match(xmlValue($act,'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 addDataValue('res',$rid,'act',join("\001",%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 keep @tb_grp,@tb_res var @tb_res = () call setHcveContext(nvl($ini,'HCVEinit')) call clearData('err') call clearData('res') loop $grp (@tb_grp) {var ($flg,@rul) = split("\001",$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_msg,%tb_rul keep @tb_grp,%tb_msg,%tb_rul var (@tb_grp,%tb_msg,%tb_rul) = () # Load the fact collectors loop $itm (xmlFind($xml, 'sdp_facts/sdp_fact')) {var $uid = xmlValue($itm,'id','') if !match($uid,'^\w+$') return -1 call setHcveFact($uid,$itm) } # Load the messages loop $itm (xmlFind($xml,'sdp_messages/sdp_message')) {var $uid = xmlValue($itm,'id','') if !match($uid,'^\w+$') return -2 var $tb_msg{$uid} = xmlData($itm) if xmlValue($itm,'prefix') call setHcveParameter(concat(last,'.',$uid),$tb_msg{$uid}) } # Validate the rules and dependency identifiers loop $grp (xmlFind($xml,'sdp_group')) {# Initialize the group record var $rec = xmlValue($grp,'exec',1) # Load the rules loop $rul (xmlFind($grp,'sdp_rule')) {# Validate the rule identifier var $rid = xmlValue($rul,'id','') if !match($rid,'^\w+$') return -3 var $tb_rul{$rid} = $rul # Validate the dependency identifiers loop $dep (xmlFind($rul,'sdp_dependencies/sdp_dependency')) {if !match(xmlValue($dep,'id',''),'^\w+$') return -4 } # Add the rule to the group var $rec = join("\001",$rec,$rid) } var @tb_grp = (@tb_grp,$rec) } return 0 } =head2 S This macro writes the test errors in the output file. =cut macro wrt_hcve_errors {var ($ttl) = @arg if $ttl {prefix {write $ttl write 'Tests executed at ',gmtime('%d-%b-%Y %X') } } loop $rid (getDataKeys('err')) {write '---' write '(Error) Execution of rule ',$rid,' failed.' write '---' write getDataValue('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 # Treat the messages loop $itm (xmlFind($xml,'sdp_messages/sdp_message')) {if ?xmlValue($itm,'id') var $tbl{last} = xmlData($itm) } 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 xmlFind($xml,'sdp_facts/sdp_fact') {var @tbl = last write '---++ Facts' loop $itm (@tbl) {var $uid = xmlValue($itm,'id') write '---+++ Fact ',nvl($uid,'?') if xmlData(xmlFind($itm,'sdp_description')) write fmt_hcve_str(last,true),'%BR%%BR%' if xmlFind($itm,'sdp_parameters/sdp_parameter') {var @trg = last write "''For parameters:''" loop $trg (@trg) {if ?xmlValue($trg,'name') write ' * ',uc(last) } write '%BR%' } var $sep = '' loop $cmd (xmlFind($itm,'sdp_command')) {var $typ = uc(xmlValue($cmd,'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 xmlData($cmd) write '' if xmlValue($cmd,'parameter') write "''It stores the rule value in the ``",uc(last),\ "`` parameter.''%BR%" if xmlValue($cmd,'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 (xmlFind($xml,'sdp_group')) {# Display the group title var $str = cond(xmlValue($grp,'exec',1),'Rule Group','Optional Rule Group') if xmlValue($grp,'id') var $str = concat($str,': ',last) if xmlValue($grp,'title') var $str = concat($str,' - ',fmt_hcve_str(last)) write '---++ ',$str # Display the rules loop $rul (xmlFind($grp,'sdp_rule')) {var $rid = xmlValue($rul,'id') write '#Rule',$rid write '---+++ Rule ',$rid,': ',fmt_hcve_str(xmlValue($rul,'name')) if xmlData(xmlFind($rul,'sdp_description')) write fmt_hcve_str(last,true),'%BR%%BR%' # Display possible dependencies loop $dep (xmlFind($rul,'sdp_dependencies/sdp_dependency id="\w+"')) {var $did = xmlValue($dep,'id') var $lnk = concat('[[#Rule',$did,'][rule ',$did,']]') var $tst = uc(xmlValue($dep,'condition')) if ?$tst {write "''HCVE treats this test as ",\ fmt_hcve_val(xmlValue($dep,'result','FAILED')),\ " unless the ",$lnk," \134" if match($tst,'^(V?[BO])') {var ($val) = last write "has ",$tb_max{$val},\ fmt_hcve_val(xmlValue($dep,'minimum'))," and ",\ fmt_hcve_val(xmlValue($dep,'maximum')),"\134" } elsif compare('eq',$tst,'IS') write "has a ",fmt_hcve_val(xmlValue($dep,'minimum'))," status\134" elsif match($tst,'^N') write "has a numeric result\134" else write "has ",nvl($tb_tst{$tst},$tst),\ fmt_hcve_val(xmlValue($dep,'minimum')),"\134" write ".''%BR%" } else write "''This rules requires the execution of ",$lnk,".''%BR%" if xmlValue($dep,'message') {write "''The text is composed of the following messages:'' ``",\ replace(last,',','``, ``',true),"``" write } elsif xmlData($dep) {var $str = last if compare('eq',xmlValue($act,'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 (xmlFind($rul,'sdp_command')) {var $typ = uc(xmlValue($cmd,'type','')) if compare('eq',$typ,'PROMPT') {write '|*Prompt*|',fmt_hcve_str(xmlData($cmd)),' |' write '|*Default Value*|',fmt_hcve_str(xmlValue($cmd,'default')),' |' } else {if compare('eq',$typ,'OS') write $sep,"''Run the following command from the Operating System \ command line and record the result:''" elsif compare('eq',$typ,'PERL') write $sep,"''Run the following Perl code and record the result:''" elsif compare('eq',$typ,'RDA') write $sep,"''Run the following RDA code and record the result:''" elsif compare('eq',$typ,'SDCL') write $sep,"''Run the following SDCL code and record the result:''" elsif compare('eq',$typ,'SQL') write $sep,"''Run the following command from a SQL command prompt \ and record the result:''" else write "''",$typ,"''" write '' write xmlData($cmd) write '' } if xmlValue($cmd,'parameter') write "''It stores the rule value in the ``",uc(last),\ "`` parameter.''%BR%" if xmlValue($cmd,'variable') write "''It stores the rule value in the ``",last,\ "`` variable in the evaluation context.''%BR%" var $sep = "%BR%" } var $mod = xmlValue($rul,'mode') if match($mod,'VERIFY(_ABORT)?',true) {loop $act (xmlFind($rul,'sdp_actions/sdp_action')) {var $tst = uc(xmlValue($act,'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(xmlValue($dep,'minimum'))," and ",\ fmt_hcve_val(xmlValue($dep,'maximum')),"\134" } elsif compare('eq',$tst,'IS') write "has a ",fmt_hcve_val(xmlValue($act,'minimum'))," status\134" elsif match($tst,'^N') write "returns a numeric result\134" else write "returns ",nvl($tb_tst{$tst},$tst),\ fmt_hcve_val(xmlValue($act,'minimum')),"\134" write ", then\134" } else write "%BR%''Otherwise,\134" write " HCVE treats this test as ",\ fmt_hcve_val(xmlValue($act,'result','FAILED')),".\134" if xmlValue($act,'variable') write " It stores the rule value in the ``",last,\ "`` variable in the evaluation context.\134" write "''%BR%" if ?xmlValue($act,'message') {write "''The text is composed of the following messages:'' ``",\ replace(last,',','``, ``',true),"``" write } elsif xmlData($act) {var $str = last if compare('eq',xmlValue($act,'syntax'),'wiki') call wrt_hcve_man_txt($str) else write fmt_hcve_str($str) write } } } 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 (xmlContent($xml)) {incr $cnt var ($tag,%tbl) = (xmlName($itm)) loop $key (xmlAttributes($itm)) var $tbl{$key} = xmlValue($itm,$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 xmlData($itm) {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*|``',xmlValue($xml,'title',$set),'`` |' if xmlData(xmlFind($xml,'sdp_description')) write '|*Description*|',last,' |' if ?xmlValue($xml,'type') write '|*Type*|',nvl($tb_typ{last},concat('``',last,'``')),' |' if ?xmlValue($xml,'family') write '|*Family*|``',last,'`` |' if ?xmlValue($xml,'platform') write '|*Platform*|``',last,'`` |' if ?xmlValue($xml,'product') write '|*Product*|``',last,'`` |' write $TOP # Display the target information if xmlFind($xml,'sdp_meta type="target"') {var ($tgt) = last prefix write '---+ Target Information' loop $key (xmlAttributes($tgt)) {next compare('eq',$key,'type') write '|*',ucfirst($key),'*|',xmlValue($tgt,$key),' |' } if hasOutput(true) write $TOP } write '---' # Analyze the diaglet content var $cnt = 0 loop $sub (xmlFind($xml,'sdp_content')) {incr $cnt var $ttl = xmlValue($sub,'title') var $typ = xmlValue($sub,'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 ',localtime('%d-%b-%Y %X') } =head2 S This macro writes the test results in the output file. When the flag is set, it also reports the details. =cut macro wrt_hcve_results {var ($ttl,$hlt,$flg) = @arg import @tb_res,$TOC,$TOP if $ttl {write $ttl write 'Tests executed at ',gmtime('%d-%b-%Y %X') write write $TOC } # Report the test results write '---+ Test Results' write '|*Rule*|*Name*|*Result*|*Value*|' loop $rid (@tb_res) {var $mod = getDataValue('res',$rid,'mod') var $nam = getDataValue('res',$rid,'nam') var $res = getDataValue('res',$rid,'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",getDataValue('res',$rid,'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 = getDataValue('res',$rid,'val') # Display the rule result if and($flg,match($res,'(FAILED|LOGGED|PASSED|SKIPPED)')) var $res = concat('[[#Rule',$rid,'][',$res,']]') write '|',$rid,' |',fmt_hcve_str($nam),' |',$res,' |',fmt_hcve_res($val),' |' # Check when if abort occurred if expr('==',$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(getDataKeys('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 (getDataKeys('res')) {# Only consider failed rules next !compare('eq',getDataValue('res',$rid,'res'),'FAILED') # Get the result components var ($val,%val) = (getDataValue('res',$rid,'val')) if isNumber($val) var $val{getDataValue('res',$rid,'nam')} = 0 loop $str (split('[\|\012]',$val)) var $val{replace($str,'\[.*?\]','...',true)} = 1 # Determine the action var @act = () if existsData('res',$rid,'txt') {var $str = rpl_hcve_ref(getDataValue('res',$rid,'txt')) if compare('eq',getDataValue('res',$rid,'syn'),'wiki') {loop $lin (split("\012",$str)) {if match($lin,'^\s*\|([^\|]+)\|(.*)\|\s*$') {var ($str,$act) = (last) if $val{trim($str)} var @act = (@act,getHcveValues($act)) } elsif !match($lin,'^\s*\|.*\|\s*$') var @act = (@act,getHcveValues($lin)) } } else var @act = (@act,fmt_hcve_str($str)) } # Print the rule details write '|',$rid,' |',fmt_hcve_str(getDataValue('res',$rid,'dsc'),true),\ ' |', fmt_hcve_res(replace($val,'[\[\]]','',true)),' |',\ join('%BR%',@act),' |' } if hasOutput(true) write $TOP # Report detailed results if $flg {var $TTL = '---+ Detailed Results' loop $rid (getDataKeys('res')) {var $res = getDataValue('res',$rid,'res') # Print the actions prefix {write $TTL var $TTL = '---' write '#Rule',$rid,' ---## Rule ',$rid,': ',\ fmt_hcve_str(getDataValue('res',$rid,'nam')) write '---### Description' write fmt_hcve_str(getDataValue('res',$rid,'dsc'),true) } if existsData('res',$rid,'dep') {var $did = getDataValue('res',$rid,'dep') var $str = rpl_hcve_ref(getDataValue('res',$rid,'txt')) write '---### Dependency Failures' write ' * Dependency: ',$did,' - ',getDataValue('res',$did,'nam') write ' * Result: **',getDataValue('res',$rid,'res'),'**' write ' * Condition: ``',\ fmt_hcve_str(join(' ',getDataValue('res',$rid,'prv'),\ getDataValue('res',$rid,'tst'),\ getDataValue('res',$rid,'min'),\ getDataValue('res',$rid,'max'))),'``' if compare('eq',getDataValue('res',$rid,'syn'),'wiki') call wrt_hcve_res_txt($str) else write fmt_hcve_str($str) write } elsif existsData('res',$rid,'act') {var @act = getDataValue('res',$rid,'act') if @act {write '---### Unmatched Actions' loop $act (@act) {var %act = split("\001",$act) write ' * ',\ fmt_hcve_res(getDataValue('res',$rid,'val')),'`` ',\ fmt_hcve_str(join(' ',$act{'tst'},\ $act{'min'},\ $act{'max'})),'``' } } if ?getDataValue('res',$rid,'tst') {write '---### Action' write ' * Result: **',getDataValue('res',$rid,'res'),'**' write ' * Condition: ',\ fmt_hcve_res(getDataValue('res',$rid,'val')),'`` ',\ fmt_hcve_str(join(' ',getDataValue('res',$rid,'tst'),\ getDataValue('res',$rid,'min'),\ getDataValue('res',$rid,'max'))),'``' } else {write '---### Default Action' write ' * Result: **',getDataValue('res',$rid,'res'),'**' write ' * Value: ',fmt_hcve_res(getDataValue('res',$rid,'val')) } var $str = rpl_hcve_ref(getDataValue('res',$rid,'txt')) if compare('eq',getDataValue('res',$rid,'syn'),'wiki') call wrt_hcve_res_txt($str) else write fmt_hcve_str($str) write } if hasOutput(true) write $TOP } # Report logged results prefix write '---+ Logged Results' loop $rid (getDataKeys('res')) {next compare('ne',getDataValue('res',$rid,'res'),'LOGGED') write '#Rule',$rid,' ---## Rule ',$rid,': ',\ fmt_hcve_str(getDataValue('res',$rid,'nam')) write '' write getDataValue('res',$rid,'val') write '' } if hasOutput(true) write $TOP } } # --- Internal errors --------------------------------------------------------- # Get the associated text macro get_text {var ($obj,$syn) = @arg import %tb_msg keep %tb_msg if ?xmlValue($obj,'message') {loop $mid (split(',',rpl_hcve_ref(last))) {if exists($tb_msg{$mid}) var @tbl = (@tbl,$tb_msg{$mid}) } return nvl(join(cond(compare('eq',$syn,'wiki'),'%BR%',"\012"),@tbl),'') } return xmlData($obj) } # Define a macro to remove references macro rpl_hcve_ref {var ($str) = @arg # 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,'\.'),getHcveParameter($rid),\ getHcveResult($rid)) 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 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(getHcveValues($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),'|',$txt,'|' } else write $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-2009, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut