Search in sources :

Example 1 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class AndroidBinaryIntegrationTest method testNativeRelinker.

@Test
public void testNativeRelinker() throws IOException, InterruptedException {
    NdkCxxPlatform platform = AndroidNdkHelper.getNdkCxxPlatform(workspace, filesystem);
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Path tmpDir = tmpFolder.newFolder("xdso");
    SymbolGetter syms = new SymbolGetter(new DefaultProcessExecutor(new TestConsole()), tmpDir, platform.getObjdump(), pathResolver);
    Symbols sym;
    Path apkPath = workspace.buildAndReturnOutput("//apps/sample:app_xdso_dce");
    sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_top.so");
    assertTrue(sym.global.contains("_Z10JNI_OnLoadii"));
    assertTrue(sym.undefined.contains("_Z10midFromTopi"));
    assertTrue(sym.undefined.contains("_Z10botFromTopi"));
    assertFalse(sym.all.contains("_Z6unusedi"));
    sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_mid.so");
    assertTrue(sym.global.contains("_Z10midFromTopi"));
    assertTrue(sym.undefined.contains("_Z10botFromMidi"));
    assertFalse(sym.all.contains("_Z6unusedi"));
    sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_bot.so");
    assertTrue(sym.global.contains("_Z10botFromTopi"));
    assertTrue(sym.global.contains("_Z10botFromMidi"));
    assertFalse(sym.all.contains("_Z6unusedi"));
    // Run some verification on the same apk with native_relinker disabled.
    apkPath = workspace.buildAndReturnOutput("//apps/sample:app_no_xdso_dce");
    sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_top.so");
    assertTrue(sym.all.contains("_Z6unusedi"));
    sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_mid.so");
    assertTrue(sym.all.contains("_Z6unusedi"));
    sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_bot.so");
    assertTrue(sym.all.contains("_Z6unusedi"));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Symbols(com.facebook.buck.android.relinker.Symbols) SymbolGetter(com.facebook.buck.android.AndroidNdkHelper.SymbolGetter) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 2 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class DxStepTest method createExecutionContext.

private ExecutionContext createExecutionContext(int verbosityLevel) throws IOException {
    Verbosity verbosity = VerbosityParser.getVerbosityForLevel(verbosityLevel);
    TestConsole console = new TestConsole(verbosity);
    return TestExecutionContext.newBuilder().setConsole(console).setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
}
Also used : Verbosity(com.facebook.buck.util.Verbosity) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 3 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class CodeSignIdentityStoreTest method testCodeSignIdentitiesCommandOverride.

@Test
public void testCodeSignIdentitiesCommandOverride() throws Exception {
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    Path testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("code_sign_identity_store");
    CodeSignIdentityStore store = CodeSignIdentityStore.fromSystem(executor, ImmutableList.of(testdataDir.resolve("fake_identities.sh").toString()));
    ImmutableList<CodeSignIdentity> expected = ImmutableList.of(CodeSignIdentity.builder().setFingerprint(CodeSignIdentity.toFingerprint("0000000000000000000000000000000000000000")).setSubjectCommonName("iPhone Developer: Fake").build());
    assertThat(store.getIdentities(), is(equalTo(expected)));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 4 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class XctoolRunTestsStepTest method xctoolCommandWithTestSelectorFailsIfListTestsOnlyFails.

@Test
public void xctoolCommandWithTestSelectorFailsIfListTestsOnlyFails() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/FooTest.xctest"), Paths.get("/path/to/BarTest.xctest")), ImmutableMap.of(), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.builder().addRawSelectors("#.*Magic.*").build(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolListOnlyParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "run-tests", "-logicTest", "/path/to/FooTest.xctest", "-logicTest", "/path/to/BarTest.xctest", "-listTestsOnly")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    FakeProcess fakeXctoolListTestsFailureProcess = new FakeProcess(42, "", "Chopper Dave, we have Uh-Oh");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolListOnlyParams, fakeXctoolListTestsFailureProcess));
    TestConsole testConsole = new TestConsole();
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).setConsole(testConsole).build();
    assertThat(step.execute(executionContext).getExitCode(), equalTo(42));
    assertThat(testConsole.getTextWrittenToStdErr(), allOf(containsString("xctool failed with exit code 42: Chopper Dave, we have Uh-Oh"), containsString("Failed to query tests with xctool")));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 5 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class ProvisioningProfileCopyStepTest method testDoesNotFailInDryRunMode.

@Test
public void testDoesNotFailInDryRunMode() throws Exception {
    assumeTrue(Platform.detect() == Platform.MACOS);
    Path emptyDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles_empty");
    ProvisioningProfileCopyStep step = new ProvisioningProfileCopyStep(projectFilesystem, testdataDir.resolve("Info.plist"), ApplePlatform.IPHONEOS, Optional.empty(), Optional.empty(), ProvisioningProfileStore.fromSearchPath(new DefaultProcessExecutor(new TestConsole()), ProvisioningProfileStore.DEFAULT_READ_COMMAND, emptyDir), outputFile, xcentFile, codeSignIdentityStore, Optional.of(dryRunResultFile));
    Future<Optional<ProvisioningProfileMetadata>> profileFuture = step.getSelectedProvisioningProfileFuture();
    step.execute(executionContext);
    assertTrue(profileFuture.isDone());
    assertNotNull(profileFuture.get());
    assertFalse(profileFuture.get().isPresent());
    Optional<String> resultContents = projectFilesystem.readFileIfItExists(dryRunResultFile);
    assertTrue(resultContents.isPresent());
    NSDictionary resultPlist = (NSDictionary) PropertyListParser.parse(resultContents.get().getBytes(Charsets.UTF_8));
    assertEquals(new NSString("com.example.TestApp"), resultPlist.get("bundle-id"));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Optional(java.util.Optional) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) TestConsole(com.facebook.buck.testutil.TestConsole) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Aggregations

TestConsole (com.facebook.buck.testutil.TestConsole)100 Test (org.junit.Test)74 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)27 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)27 ExecutionContext (com.facebook.buck.step.ExecutionContext)25 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)25 Path (java.nio.file.Path)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)16 BuckEventBus (com.facebook.buck.event.BuckEventBus)15 FakeProcess (com.facebook.buck.util.FakeProcess)14 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)13 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)12 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)11 Clock (com.facebook.buck.timing.Clock)10 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 BuildTarget (com.facebook.buck.model.BuildTarget)8