|
| 1 | +<?php |
| 2 | +/*========================================================================= |
| 3 | +MIDAS Server |
| 4 | +Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. |
| 5 | +69328 Lyon, FRANCE. |
| 6 | +
|
| 7 | +See Copyright.txt for details. |
| 8 | +This software is distributed WITHOUT ANY WARRANTY; without even |
| 9 | +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 10 | +PURPOSE. See the above copyright notices for more information. |
| 11 | +=========================================================================*/ |
| 12 | + |
| 13 | +/** CDash Componenet */ |
| 14 | +class CDashComponent extends AppComponent |
| 15 | + { |
| 16 | + /** submit tests to dashboard*/ |
| 17 | + public function submitToCdash($serverUrl, $projectName, $tests, $machineName = "Midas", $buildName = "Midas Build", $buildType = "Experimental") |
| 18 | + { |
| 19 | + if(strpos($serverUrl, "http") === false) |
| 20 | + { |
| 21 | + throw new Zend_Exception("Error url format"); |
| 22 | + } |
| 23 | + if(!is_string($projectName) || !is_array($tests) || !is_string($machineName) || !is_string($buildName) || !is_scalar($buildType)) |
| 24 | + { |
| 25 | + throw new Zend_Exception("Error parametors"); |
| 26 | + } |
| 27 | + foreach($tests as $name => $test) |
| 28 | + { |
| 29 | + if(!is_string($name)) |
| 30 | + { |
| 31 | + throw new Zend_Exception("test array keys should be the name of the test"); |
| 32 | + } |
| 33 | + if(!isset($test['fullname'])) |
| 34 | + { |
| 35 | + throw new Zend_Exception("Please set the name of the test."); |
| 36 | + } |
| 37 | + if(!isset($test['output'])) |
| 38 | + { |
| 39 | + throw new Zend_Exception("Please set the ouput of the test."); |
| 40 | + } |
| 41 | + if($test['status'] != 'failed' && $test['status'] != 'passed') |
| 42 | + { |
| 43 | + throw new Zend_Exception("The status should be passed or failed"); |
| 44 | + } |
| 45 | + } |
| 46 | + $xml = '<?xml version="1.0" encoding="UTF-8"?> |
| 47 | + <Site BuildName="'.$buildName.'" |
| 48 | + BuildStamp="'.date('Ymd').'-'.((int)date('G')*60 + (int)date('i')).'-'.$buildType.'" |
| 49 | + Name="'.$machineName.'" |
| 50 | + Generator="" |
| 51 | + CompilerName="" |
| 52 | + OSName="" |
| 53 | + Hostname="" |
| 54 | + OSRelease="" |
| 55 | + OSVersion="" |
| 56 | + OSPlatform="" |
| 57 | + Is64Bits="" |
| 58 | + VendorString="" |
| 59 | + VendorID="" |
| 60 | + FamilyID="" |
| 61 | + ModelID="" |
| 62 | + ProcessorCacheSize="" |
| 63 | + NumberOfLogicalCPU="" |
| 64 | + NumberOfPhysicalCPU="" |
| 65 | + TotalVirtualMemory="" |
| 66 | + TotalPhysicalMemory="" |
| 67 | + LogicalProcessorsPerPhysical="" |
| 68 | + ProcessorClockFrequency="" |
| 69 | + > |
| 70 | + <Testing> |
| 71 | + <StartDateTime>'.date('M m H:i T').'</StartDateTime> |
| 72 | + <StartTestTime>'.time().'</StartTestTime> |
| 73 | + <TestList> |
| 74 | + '; |
| 75 | + foreach($tests as $name => $test) |
| 76 | + { |
| 77 | + $xml .= '<Test>'.$name.'</Test> |
| 78 | + '; |
| 79 | + } |
| 80 | + $xml .='</TestList> |
| 81 | + '; |
| 82 | + foreach($tests as $name => $test) |
| 83 | + { |
| 84 | + $xml .= ' |
| 85 | + <Test Status="'.$test['status'].'"> |
| 86 | + <Name>'.$name.'</Name> |
| 87 | + <Path>.</Path> |
| 88 | + <FullName>'.$test['fullname'].'</FullName> |
| 89 | + <FullCommandLine></FullCommandLine> |
| 90 | + <Results> |
| 91 | + <NamedMeasurement type="text/string" name="Exit Code"><Value>0</Value></NamedMeasurement> |
| 92 | + <NamedMeasurement type="text/string" name="Exit Value"><Value>0</Value></NamedMeasurement> |
| 93 | + <NamedMeasurement type="numeric/double" name="Execution Time"><Value>0.1</Value></NamedMeasurement> |
| 94 | + <NamedMeasurement type="text/string" name="Completion Status"><Value>Completed</Value></NamedMeasurement> |
| 95 | + <NamedMeasurement type="text/string" name="Command Line"><Value></Value></NamedMeasurement> |
| 96 | + <Measurement> |
| 97 | + <Value><![CDATA['.$test['output'].']]></Value> |
| 98 | + </Measurement> |
| 99 | + </Results> |
| 100 | + </Test>'; |
| 101 | + } |
| 102 | + $xml .=' |
| 103 | + <EndDateTime>'.date('M m H:i T').'</EndDateTime> |
| 104 | + <EndTestTime>'.time().'</EndTestTime> |
| 105 | + <ElapsedMinutes>0</ElapsedMinutes></Testing> |
| 106 | + </Site>'; |
| 107 | + |
| 108 | + $params = array('http' => array( |
| 109 | + 'method' => 'PUT', |
| 110 | + 'content' => $xml, |
| 111 | + 'header' => array('Content-type": "text/xml"') |
| 112 | + )); |
| 113 | + |
| 114 | + $url = $serverUrl.'/submit.php?project='.htmlentities($projectName); |
| 115 | + |
| 116 | + $ctx = stream_context_create($params); |
| 117 | + $fp = fopen($url, 'rb', false, $ctx); |
| 118 | + if(!$fp) |
| 119 | + { |
| 120 | + throw new Zend_Exception("Problem with ".$url.", ".$php_errormsg); |
| 121 | + } |
| 122 | + $response = stream_get_contents($fp); |
| 123 | + if ($response === false) |
| 124 | + { |
| 125 | + throw new Zend_Exception("Problem reading data from ".$url.", ".$php_errormsg); |
| 126 | + } |
| 127 | + } |
| 128 | + } // end class |
0 commit comments