use of com.facebook.buck.util.FakeProcess in project buck by facebook.
the class AppleSimulatorDiscoveryTest method appleSimulatorsDiscoveredFromSimctlList.
@Test
public void appleSimulatorsDiscoveredFromSimctlList() throws IOException, InterruptedException {
ImmutableSet<AppleSimulator> simulators;
try (OutputStream stdin = new ByteArrayOutputStream();
InputStream stdout = getClass().getResourceAsStream("testdata/simctl-list.txt");
InputStream stderr = new ByteArrayInputStream(new byte[0])) {
FakeProcess fakeXcrunSimctlList = new FakeProcess(0, stdin, stdout, stderr);
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("path/to/simctl", "list")).build();
FakeProcessExecutor fakeProcessExecutor = new FakeProcessExecutor(ImmutableMap.of(processExecutorParams, fakeXcrunSimctlList));
simulators = AppleSimulatorDiscovery.discoverAppleSimulators(fakeProcessExecutor, Paths.get("path/to/simctl"));
}
ImmutableSet<AppleSimulator> expected = ImmutableSet.<AppleSimulator>builder().add(AppleSimulator.builder().setName("iPhone 4s").setUdid("F7C1CC9A-945E-4258-BA84-DEEBE683798B").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPhone 5").setUdid("45BD7164-686C-474F-8C68-3730432BC5F2").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPhone 5s").setUdid("70200ED8-EEF1-4BDB-BCCF-3595B137D67D").setSimulatorState(AppleSimulatorState.BOOTED).build()).add(AppleSimulator.builder().setName("iPhone 6 Plus").setUdid("92340ACF-2C44-455F-BACD-573B133FB20E").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPhone 6").setUdid("A75FF972-FE12-4656-A8CC-99572879D4A3").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPad 2").setUdid("CC1B0BAD-BAE6-4A53-92CF-F79850654057").setSimulatorState(AppleSimulatorState.SHUTTING_DOWN).build()).add(AppleSimulator.builder().setName("iPad Retina").setUdid("137AAA25-54A1-42E8-8202-84DEADD668E1").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("iPad Air").setUdid("554B2E0F-63F3-4400-8319-5C5062CF4C95").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).add(AppleSimulator.builder().setName("Resizable iPhone").setUdid("58E3748F-F7E6-4A45-B52C-A136B59F7A42").setSimulatorState(AppleSimulatorState.CREATING).build()).add(AppleSimulator.builder().setName("Resizable iPad").setUdid("56FE1CBC-61FF-443D-8E23-19D05864C6DB").setSimulatorState(AppleSimulatorState.SHUTDOWN).build()).build();
assertThat(simulators, is(equalTo(expected)));
}
use of com.facebook.buck.util.FakeProcess in project buck by facebook.
the class ProjectBuildFileParserTest method fakeProcessWithBserOutput.
private static FakeProcess fakeProcessWithBserOutput(int returnCode, List<Object> values, Optional<List<Object>> diagnostics, Optional<String> stdout) {
BserSerializer bserSerializer = new BserSerializer();
ByteBuffer buffer = ByteBuffer.allocate(512).order(ByteOrder.nativeOrder());
try {
Map<String, Object> outputToSerialize = new LinkedHashMap<>();
outputToSerialize.put("values", values);
if (diagnostics.isPresent()) {
outputToSerialize.put("diagnostics", diagnostics.get());
}
buffer = bserSerializer.serializeToBuffer(outputToSerialize, buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
buffer.flip();
return new FakeProcess(returnCode, new ByteArrayOutputStream(), new ByteArrayInputStream(buffer.array()), new ByteArrayInputStream(stdout.orElse("").getBytes(StandardCharsets.UTF_8)));
}
use of com.facebook.buck.util.FakeProcess in project buck by facebook.
the class JavacStepTest method failedCompileSendsStdoutAndStderrToConsole.
@Test
public void failedCompileSendsStdoutAndStderrToConsole() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
// JavacStep itself writes stdout to the console on error; we expect the Build class to write
// the stderr stream returned in the StepExecutionResult
assertThat(result, equalTo(StepExecutionResult.of(1, Optional.of("javac stderr\n"))));
assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("javac stdout\n")));
}
use of com.facebook.buck.util.FakeProcess in project buck by facebook.
the class JavacStepTest method existingBootclasspathDirSucceeds.
@Test
public void existingBootclasspathDirSucceeds() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/this-totally-exists").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> true, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(0, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
assertThat(result, equalTo(StepExecutionResult.SUCCESS));
assertThat(listener.getLogMessages(), empty());
}
use of com.facebook.buck.util.FakeProcess in project buck by facebook.
the class ProcessTrackerTest method testInteraction.
@Test
public void testInteraction() throws Exception {
BlockingQueue<ProcessResourceConsumptionEvent> events = new LinkedBlockingQueue<>();
try (ProcessTrackerForTest processTracker = createProcessTracker(events)) {
processTracker.explicitStartUp();
processTracker.verifyThisProcessInfo(PID, "<buck-process>");
assertEquals(1, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that ProcessTracker subscribes to ProcessRegistry and that calling
// registerProcess causes ProcessTracker to start tracking the process.
FakeNuProcess proc41 = new FakeNuProcess(41);
processTracker.verifyNoProcessInfo(41);
assertEquals(1, processTracker.processesInfo.size());
processRegistry.registerProcess(proc41, createParams("proc41"), CONTEXT);
processTracker.verifyExternalProcessInfo(41, proc41, createParams("proc41"));
assertEquals(2, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that after registering a new process, both are being tracked
FakeNuProcess proc42 = new FakeNuProcess(42);
processRegistry.registerProcess(proc42, createParams("proc42"), CONTEXT);
processTracker.verifyExternalProcessInfo(41, proc41, createParams("proc41"));
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
assertEquals(3, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that after registering a process with an already tracked pid,
// the old process info gets discarded.
FakeNuProcess proc41b = new FakeNuProcess(41);
processRegistry.registerProcess(proc41b, createParams("proc41b"), CONTEXT);
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
assertEquals(3, processTracker.processesInfo.size());
// Verify an event has been posted to the bus on remove
verifyEvents(ImmutableMap.of("proc41", Optional.of(createParams("proc41"))), null, events);
// Verify that processes whose pid cannot be obtained are ignored
processRegistry.registerProcess(new FakeProcess(0), createParams("proc0"), CONTEXT);
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
assertEquals(3, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that ongoing processes are kept after refresh
processTracker.explicitRunOneIteration();
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
assertEquals(3, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that finished processes are removed after refresh
proc42.finish(0);
processTracker.explicitRunOneIteration();
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
processTracker.verifyNoProcessInfo(42);
assertEquals(2, processTracker.processesInfo.size());
// Verify an event has been posted to the bus on remove
verifyEvents(ImmutableMap.of("proc42", Optional.of(createParams("proc42"))), null, events);
processTracker.explicitShutDown();
processTracker.verifyNoProcessInfo(41);
processTracker.verifyNoProcessInfo(PID);
assertEquals(0, processTracker.processesInfo.size());
// Verify events for the existing processes have been posted to the bus on shut down
verifyEvents(ImmutableMap.of("proc41b", Optional.of(createParams("proc41b")), "<buck-process>", Optional.empty()), null, events);
}
// verify no events are sent after closing ProcessTracker
processRegistry.registerProcess(new FakeNuProcess(43), createParams("proc43"), CONTEXT);
verifyEvents(ImmutableMap.of(), null, events);
}
Aggregations