Overview
Namespaces
Classes
- AMemoryUsageDriver
- AProcessorDriver
- Controlor
- Libxslt1123phpProcessorDriver
- Libxslt1126phpProcessorDriver
- LinuxMemoryUsageDriver
- MemoryUsage
- MSXML30ProcessorDriver
- MSXML60ProcessorDriver
- Params
- Processor
- Runner
- Sablotron103cmdProcessorDriver
- Saxon655ProcessorDriver
- SaxonHE9402ProcessorDriver
- Test
- TestRunner
- WindowsMemoryUsageDriver
- Xalan271ProcessorDriver
- XmlParamsDriver
- Xsltproc1123ProcessorDriver
- Xsltproc1126ProcessorDriver
- XT20051206ProcessorDriver
Interfaces
1: <?php
2:
3: /**
4: * XSLT Benchmarking
5: * @link https://github.com/masicek/XSLT-Benchmarking
6: * @author Viktor Mašíček <viktor@masicek.net>
7: * @license "New" BSD License
8: */
9:
10: namespace XSLTBenchmarking\TestsRunner;
11:
12: require_once ROOT . '/Microtime.php';
13: require_once ROOT . '/Exceptions.php';
14: require_once LIBS . '/PhpPath/PhpPath.min.php';
15: require_once ROOT . '/Printer.php';
16:
17: use PhpPath\P;
18: use XSLTBenchmarking\Printer;
19:
20:
21: /**
22: * Class for run one test
23: *
24: * @author Viktor Mašíček <viktor@masicek.net>
25: */
26: class TestRunner
27: {
28:
29:
30: /**
31: * Factory class for making new objects
32: *
33: * @var \XSLTBenchmarking\Factory
34: */
35: private $factory;
36:
37: /**
38: * Object for runnig XSLT transformation
39: *
40: * @var \XSLTBenchmarking\TestsRunner\Processor
41: */
42: private $processor;
43:
44: /**
45: * List of processors selected for testing
46: *
47: * @var array
48: */
49: private $processorsNames;
50:
51: /**
52: * Number of repeatig for each test and processor
53: *
54: * @var int
55: */
56: private $repeating;
57:
58: /**
59: * Object for control that generated file is same as expected
60: *
61: * @var \XSLTBenchmarking\TestsRunner\Controlor
62: */
63: private $controlor;
64:
65: /**
66: * Path of temporary directory for generating output files by processors
67: *
68: * @var string
69: */
70: private $tmpDir;
71:
72:
73: /**
74: * Object configuration
75: *
76: * @param \XSLTBenchmarking\Factory $factory Factory class for making new objects
77: * @param \XSLTBenchmarking\TestsRunner\Processor $processor Class for parse one template in one processor
78: * @param array|TRUE $processorsSelected List of tested processors
79: * @param array $processors Exclude List of tested processors, that we want exclude form tested processors
80: * @param int $repeating Number of repeatig for each test and processor
81: * @param string $tmpDir Path of temporary directory
82: */
83: public function __construct(
84: \XSLTBenchmarking\Factory $factory,
85: \XSLTBenchmarking\TestsRunner\Processor $processor,
86: $processorsSelected,
87: array $processorsExclude,
88: $repeating,
89: \XSLTBenchmarking\TestsRunner\Controlor $controlor,
90: $tmpDir
91: )
92: {
93: $tmpDir = P::mcd($tmpDir);
94:
95: $processorsAvailable = array_keys($processor->getAvailable());
96: if ($processorsSelected === TRUE)
97: {
98: $processorsSelected = $processorsAvailable;
99: }
100:
101: $processorsFinal = $processorsSelected;
102: foreach ($processorsExclude as $processorExclude)
103: {
104: $key = array_search($processorExclude, $processorsFinal);
105: if ($key !== FALSE)
106: {
107: unset($processorsFinal[$key]);
108: }
109: }
110: $processorsFinal = array_values($processorsFinal);
111:
112: // check correct set of processors
113: foreach ($processorsSelected as $processorSelected)
114: {
115: if (!in_array($processorSelected, $processorsAvailable))
116: {
117: throw new \XSLTBenchmarking\InvalidArgumentException('Unknown processor name "' . $processorSelected . '"');
118: }
119: }
120:
121: $this->factory = $factory;
122: $this->processor = $processor;
123: $this->processorsNames = $processorsFinal;
124: $this->repeating = $repeating;
125: $this->controlor = $controlor;
126: $this->tmpDir = $tmpDir;
127: }
128:
129:
130: /**
131: * Run one test
132: *
133: * @param \XSLTBenchmarking\TestsRunner\Test $test
134: * @param bool $verbose Print information about each run test
135: *
136: * @return \XSLTBenchmarking\Reports\Report
137: */
138: public function run(\XSLTBenchmarking\TestsRunner\Test $test, $verbose = FALSE)
139: {
140: $templatePath = $test->getTemplatePath();
141: $couplesPaths = $test->getCouplesPaths();
142: $report = $this->factory->getReport(
143: $test->getName(),
144: $templatePath
145: );
146:
147: foreach ($this->processorsNames as $processorName)
148: {
149: if ($verbose)
150: {
151: Printer::info(' ' . $processorName);
152: }
153:
154: foreach ($couplesPaths as $xmlInputPath => $expectedOutputPath)
155: {
156: // unique filename
157: $pathInfo = pathinfo($expectedOutputPath);
158: $microtime = \XSLTBenchmarking\Microtime::now();
159: $microtime = str_replace('.', '-', $microtime);
160: $filename = isset($pathInfo['filename']) ? ($pathInfo['filename'] . '-') : '';
161: $extension = isset($pathInfo['extension']) ? ('.' . $pathInfo['extension']) : '';
162: $filename = $filename . $microtime . $extension;
163: $outputPath = P::m($this->tmpDir, $filename);
164:
165: // run transformations
166: $result = $this->processor->run(
167: $processorName,
168: $templatePath,
169: $xmlInputPath,
170: $outputPath,
171: $this->repeating
172: );
173:
174: // set times and success
175: if (is_array($result))
176: {
177: $success = TRUE;
178: $spendTimes = $result['times'];
179: $memoryUsage = $result['memory'];
180: }
181: else
182: {
183: $success = $result;
184: $spendTimes = array();
185: $memoryUsage = array();
186: }
187:
188: // set correctness
189: $correctness = FALSE;
190: if ($success === TRUE)
191: {
192: $correctness = $this->controlor->isSame($outputPath, $expectedOutputPath);
193: }
194:
195: // reported results
196: $report->addRecord(
197: $processorName,
198: $xmlInputPath,
199: $expectedOutputPath,
200: $outputPath,
201: $success,
202: $correctness,
203: $spendTimes,
204: $memoryUsage,
205: $this->repeating
206: );
207: }
208: }
209:
210: return $report;
211: }
212:
213:
214:
215: }
216: