Skip to content

Commit 19bee4c

Browse files
zijiehe-google-comCommit Queue
authored and
Commit Queue
committed
[Fuchsia] Really running cfv2 test
Though it's still failing, the test-script integration has pretty much finished. ```=== 298 tests passed, 40 failed ===``` Errors are mainly ``` Exhausted heap space, trying to allocate 32 bytes. ../../runtime/vm/object.cc: 2854: error: Out of memory. ``` This change requires https://crrev.com/c/4913284 and `"fuchsia_sdk_version": "version:15.20231007.2.1",` in DEPS. Bug: #38752 Change-Id: I92a387f4289fce7d05d84e483560729301541c1b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330025 Commit-Queue: Zijie He <[email protected]> Reviewed-by: Ryan Macnak <[email protected]> Reviewed-by: Alexander Thomas <[email protected]>
1 parent 37cd536 commit 19bee4c

File tree

4 files changed

+118
-41
lines changed

4 files changed

+118
-41
lines changed

pkg/test_runner/lib/src/fuchsia.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ abstract class FuchsiaEmulator {
1717
void stop();
1818
// Returns a command to execute a set of tests against the running Fuchsia
1919
// environment.
20-
VMCommand getTestCommand(String mode, String arch, List<String> arguments);
20+
VMCommand getTestCommand(
21+
String buildDir, String mode, String arch, List<String> arguments);
2122

2223
static final FuchsiaEmulator _instance = _create();
2324

pkg/test_runner/lib/src/fuchsia_cfv1.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class FuchsiaEmulatorCFv1 extends FuchsiaEmulator {
7474
}
7575

7676
@override
77-
VMCommand getTestCommand(String mode, String arch, List<String> arguments) {
77+
VMCommand getTestCommand(
78+
String buildDir, String mode, String arch, List<String> arguments) {
7879
arguments = arguments
7980
.map((arg) => arg.replaceAll(Repository.uri.toFilePath(), '/pkg/data/'))
8081
.toList();

pkg/test_runner/lib/src/fuchsia_cfv2.dart

Lines changed: 107 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,136 @@ class FuchsiaEmulatorCFv2 extends FuchsiaEmulator {
1616
static const String ffx = "./third_party/fuchsia/sdk/linux/tools/x64/ffx";
1717
static const String testScriptRoot =
1818
"./third_party/fuchsia/test_scripts/test/";
19+
static const String withEnv = "./build/fuchsia/with_envs.py";
20+
static const String tmpRoot = "/tmp/dart_ffi_test/";
21+
static const String cmName = "fuchsia_ffi_test_component.cm";
1922

23+
final Map<String, String> envs = <String, String>{};
2024
Process? daemonProc;
2125
Process? emuProc;
2226
String? emuName;
27+
Process? repoProc;
2328

2429
@override
2530
Future<void> publishPackage(String buildDir, String mode, String arch) async {
26-
housekeeping();
27-
31+
try {
32+
Directory(tmpRoot).deleteSync(recursive: true);
33+
} catch (_) {}
34+
// The /tmp/ should always be present, recursive creation is not expected.
35+
Directory(tmpRoot).createSync();
2836
assert(daemonProc == null);
29-
daemonProc = await runWithOutput("isolate_daemon.py", []);
37+
daemonProc = await _run("isolate_daemon.py", []);
38+
var isolateDir = await _captureStdout(daemonProc!);
39+
print("+ ffx daemon running on $isolateDir should be ready now.");
40+
envs["FFX_ISOLATE_DIR"] = isolateDir;
3041
assert(emuProc == null);
31-
emuProc = await run(
32-
"start_emulator.py", ["--disable-graphics", "--target-id-only"]);
33-
emuName = await emuProc!.stdout.transform(utf8.decoder).first;
42+
emuProc = await _run("start_emulator.py", [
43+
"--disable-graphics",
44+
"--target-id-only",
45+
"--device-spec",
46+
"virtual_device_large"
47+
]);
48+
emuName = await _captureStdout(emuProc!);
3449
print("+ Targeting emu name $emuName");
50+
await _assertRun("test_connection.py", [emuName!]);
51+
await _assertRun("publish_package.py", [
52+
"--packages",
53+
_testPackagePath(buildDir, mode),
54+
"--purge-repo",
55+
"--repo",
56+
_tempDirectoryOf("repo")
57+
]);
58+
repoProc = await _run("serve_repo.py", [
59+
"run",
60+
"--serve-repo",
61+
_tempDirectoryOf("repo"),
62+
"--repo-name",
63+
"dart-ffi-test-repo",
64+
"--target-id",
65+
emuName!
66+
]);
67+
print("+ Fuchsia repo ${await _captureStdout(repoProc!)} is running "
68+
"at ${_tempDirectoryOf('repo')}");
69+
await _assertRun("pkg_resolve.py", [emuName!, cmName]);
3570
}
3671

3772
@override
38-
void stop() {
39-
// isolate_daemon.py should respect the sigterm and gracefully stop the
40-
// daemon process.
73+
Future<void> stop() async {
74+
assert(repoProc != null);
75+
repoProc!.kill();
76+
await repoProc!.exitCode;
77+
assert(emuProc != null);
78+
emuProc!.kill();
79+
await emuProc!.exitCode;
4180
assert(daemonProc != null);
4281
daemonProc!.kill();
43-
emuProc!.kill();
44-
45-
// In case anything goes wrong, ensure everything is cleaned up.
46-
housekeeping();
82+
await daemonProc!.exitCode;
4783
}
4884

4985
@override
50-
VMCommand getTestCommand(String mode, String arch, List<String> arguments) {
51-
return VMCommand("echo", arguments, <String, String>{});
86+
VMCommand getTestCommand(
87+
String buildDir, String mode, String arch, List<String> arguments) {
88+
return VMCommand(
89+
withEnv,
90+
_runArgs("run_executable_test.py", [
91+
"--target-id",
92+
emuName!,
93+
"--out-dir",
94+
_tempDirectoryOf("out"),
95+
"--test-name",
96+
"fuchsia-pkg://fuchsia.com/${_testPackageName(mode)}#meta/$cmName",
97+
"--logs-dir",
98+
_tempDirectoryOf("logs"),
99+
"--package-deps",
100+
_testPackagePath(buildDir, mode),
101+
...arguments
102+
]),
103+
envs);
104+
}
105+
106+
static String _testPackageName(String mode) {
107+
return "dart_ffi_test_cfv2_$mode";
108+
}
109+
110+
static String _testPackagePath(String buildDir, String mode) {
111+
var farName = _testPackageName(mode);
112+
return "$buildDir/gen/$farName/$farName.far";
113+
}
114+
115+
static String _tempDirectoryOf(String name) {
116+
return tmpRoot + name;
117+
}
118+
119+
List<String> _runArgs(String script, List<String> args) {
120+
return [testScriptRoot + script, ...args];
121+
}
122+
123+
/// Executes a test script inside of third_party/fuchsia/test_scripts/test/
124+
/// with the required environment setup and the arguments.
125+
Future<Process> _run(String script, List<String> args) async {
126+
var newArgs = _runArgs(script, args);
127+
print("+ Start $withEnv with $newArgs with environment $envs.");
128+
return Process.start(withEnv, newArgs, environment: envs);
52129
}
53130

54-
static void housekeeping() {
55-
Process.runSync(ffx, ["emu", "stop", "--all"]);
56-
Process.runSync(ffx, ["repository", "server", "stop"]);
57-
Process.runSync(ffx, ["daemon", "stop", "-t", "10000"]);
131+
/// Executes a test script and asserts its return code is 0; see _run and
132+
/// _assert.
133+
Future<void> _assertRun(String script, List<String> args) async {
134+
_assert((await (await _run(script, args)).exitCode) == 0);
58135
}
59136

60-
// Same as run, but capture the stdout and stderr.
61-
static Future<Process> runWithOutput(String script, List<String> args) async {
62-
return run(script, args).then((proc) {
63-
proc.stdout.transform(utf8.decoder).forEach((x) {
64-
print("++ [$script] stdout: $x");
65-
});
66-
proc.stderr.transform(utf8.decoder).forEach((x) {
67-
print("++ [$script] stderr: $x");
68-
});
69-
return proc;
70-
});
137+
/// Captures the first line of output in utf8.
138+
Future<String> _captureStdout(Process proc) async {
139+
// The stderr needs to be fully consumed as well.
140+
proc.stderr.transform(utf8.decoder).forEach((x) => stderr.write(x));
141+
return (await proc.stdout.transform(utf8.decoder).first).trim();
71142
}
72143

73-
// Executes a test script inside of third_party/fuchsia/test_scripts/test/
74-
// with the required environment setup and the arguments.
75-
static Future<Process> run(String script, List<String> args) async {
76-
return Process.start("./build/fuchsia/with_envs.py",
77-
[Uri.directory(testScriptRoot).resolve(script).toString(), ...args]);
144+
/// Unlike assert keyword, always evaluates the input function and throws
145+
/// exception when the evaluated result is false.
146+
void _assert(bool condition) {
147+
if (!condition) {
148+
throw AssertionError();
149+
}
78150
}
79151
}

pkg/test_runner/lib/src/runtime_configuration.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,15 @@ class DartkFuchsiaEmulatorRuntimeConfiguration
476476
arguments.insert(0, '--suppress-core-dump');
477477
}
478478
var command = FuchsiaEmulator.instance().getTestCommand(
479-
_configuration.mode.name, _configuration.architecture.name, arguments);
479+
_configuration.buildDirectory,
480+
_configuration.mode.name,
481+
_configuration.architecture.name,
482+
arguments);
480483
command.arguments
481484
.insert(command.arguments.length - 1, '--disable-dart-dev');
482-
return [
483-
VMCommand(command.executable, command.arguments, environmentOverrides)
484-
];
485+
command.environmentOverrides.addAll(environmentOverrides);
486+
print("+ About to run command $command to test against fuchsia vm");
487+
return [command];
485488
}
486489
}
487490

0 commit comments

Comments
 (0)