Skip to content

Commit a39446c

Browse files
author
epriestley
committedAug 28, 2014
Add a basic arc unit test binding to XHProf
Summary: This allows "arc unit" to more-or-less run the PHP extension tests in an approximately correct way. Note that there are two test failures at HEAD on recent PHP, and they've been failing for some time. Test Plan: Used `arc unit` to run some tests. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D10373
1 parent 7adedec commit a39446c

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed
 

‎.arcconfig

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"phabricator.uri": "https://secure.phabricator.com/"
2+
"phabricator.uri": "https://secure.phabricator.com/",
3+
"load": ["support/libxhprof"],
4+
"unit.engine": "XHProfExtensionUnitTestEngine"
35
}

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ extension/tests/*.out
1111
extension/tests/*.diff
1212
extension/tests/*.log
1313
extension/tests/*.php
14+
15+
support/libxhprof/.phutil_module_cache
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
phutil_register_library('libxhprof', __FILE__);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* This file is automatically generated. Use 'arc liberate' to rebuild it.
5+
*
6+
* @generated
7+
* @phutil-library-version 2
8+
*/
9+
phutil_register_library_map(array(
10+
'__library_version__' => 2,
11+
'class' => array(
12+
'XHProfExtensionUnitTestEngine' => 'unit/XHProfUnitTestEngine.php',
13+
),
14+
'function' => array(),
15+
'xmap' => array(
16+
'XHProfExtensionUnitTestEngine' => 'ArcanistUnitTestEngine',
17+
),
18+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
final class XHProfExtensionUnitTestEngine extends ArcanistUnitTestEngine {
4+
5+
public function run() {
6+
$root = $this->getWorkingCopy()->getProjectRoot().'/extension/';
7+
8+
$start_time = microtime(true);
9+
10+
id(new ExecFuture('phpize && ./configure && make -j4'))
11+
->setCWD($root)
12+
->resolvex();
13+
14+
$out = id(new ExecFuture('make -f Makefile.local test_with_exit_status'))
15+
->setCWD($root)
16+
->setEnv(
17+
array(
18+
'TEST_PHP_ARGS' => '-q',
19+
))
20+
->resolvex();
21+
22+
// NOTE: REPORT_EXIT_STATUS doesn't seem to work properly in some versions
23+
// of PHP. Just "parse" stdout to approximate the results.
24+
25+
list($stdout) = $out;
26+
27+
$tests = array();
28+
29+
foreach (phutil_split_lines($stdout) as $line) {
30+
$matches = null;
31+
32+
// NOTE: The test script writes the name of the test originally, then
33+
// uses "\r" to erase it and write the result. This splits as a single
34+
// line.
35+
if (preg_match('/^TEST .*\r(PASS|FAIL) (.*)/', $line, $matches)) {
36+
if ($matches[1] == 'PASS') {
37+
$result = ArcanistUnitTestResult::RESULT_PASS;
38+
} else {
39+
$result = ArcanistUnitTestResult::RESULT_FAIL;
40+
}
41+
42+
$name = trim($matches[2]);
43+
44+
$tests[] = id(new ArcanistUnitTestResult())
45+
->setName($name)
46+
->setResult($result)
47+
->setDuration(microtime(true) - $start_time);
48+
}
49+
}
50+
51+
return $tests;
52+
}
53+
}

0 commit comments

Comments
 (0)
Please sign in to comment.