简体   繁体   English

在 fork 中使用 HwBinder

[英]Using HwBinder inside fork

I'm implementing a HAL component for which I'm creating a test.我正在实现一个 HAL 组件,我正在为其创建一个测试。 The test is actually about creating a mock of the HAL callbacks in a different process, and registering itself to the HAL.该测试实际上是关于在不同的进程中创建 HAL 回调的模拟,并将其自身注册到 HAL。 In other words, I'm mocking the client of the HAL, then simulating a client crash causing a transaction failure to test the HAL ability to handle errors.换句话说,我在模拟 HAL 的客户端,然后模拟导致事务失败的客户端崩溃来测试 HAL 处理错误的能力。 The problem is, trying to use Binder IPC inside a fork causes a segfault.问题是,尝试在 fork 中使用 Binder IPC 会导致段错误。 Reading this question and from thedocumentation I understood that the HwBinder thread starts automatically by linking to the libbiner.阅读这个问题并从文档中我了解到 HwBinder 线程通过链接到 libbiner 自动启动。

Given that fork() does not copy the running threads of the parent, this means that the forked process will not find the helper HwBinder thread, or it does assume it exists and try to use it anyway?鉴于fork()不复制父进程的运行线程,这意味着分叉进程将找不到帮助程序 HwBinder 线程,或者它确实假设它存在并尝试使用它?

This creates a chain of errors ending up by having a SEGV_MAPERR.这会产生一连串错误,最终出现 SEGV_MAPERR。

My question is, is there anyway to re-initiate the HwBinder thread inside my forked child without having to use exec ?我的问题是,是否可以在不必使用exec情况下重新启动我分叉的孩子内部的 HwBinder 线程?

Here is my code:这是我的代码:

pid_t pid = fork();
if (pid == 0) {
    using namespace ::android::hardware;
    using namespace testing;
   /**
    * Crash happens here
    */
    android::sp<IMyHal> iMyHal = IMyHal::getService();

    IMyHal->deregisterMyHalCallback();
    sp<MockIMyHalCallback> callbackMock(new MockIMyHalCallback());
    iMyHal->deregisterMyHalCallback(callbackMock);
    Status hidlStatus;
    hidlStatus.setException(Status::EX_TRANSACTION_FAILED, "Transaction Failed");
    EXPECT_CALL(*callbackMock, testFunction(Eq("1"), _))
        .WillOnce(DoAll(testing::Return(ByMove(android::hardware::Return<void>(hidlStatus)))))
        .Times(Exactly(1));
} else if (pid > 0) {
    /**
     * This will trigger iMyHal to call callbackMock.testFunction();
     */
    mProxy->callTestFunction("1", 2);
}

This results in this error:这导致此错误:

2020-10-30 19:18:31.440 18917-18917/? A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xef400000 in tid 18917 (vendor.xxx.remo), pid 18917 (vendor.xxx.remo)

Do you intend to test your HAL or cross-process HwBinder implementation?您是否打算测试您的 HAL 或跨进程 HwBinder 实现? In the first case, you may not need to create a whole separate process to test your HAL.在第一种情况下,您可能不需要创建一个完整的单独进程来测试您的 HAL。

The usual way it's done is:通常的做法是:

  • providing default HAL implementation, which may be a mock ( example )提供默认的 HAL 实现,它可能是一个模拟( 示例
  • implementing a VTS test for the HAL ( example ), which can be run against real HAL as well为 HAL 实施 VTS 测试( 示例),它也可以针对真实的 HAL 运行
  • running default implementation at device start (or just from adb shell ) and VTS test separately在设备启动时(或仅从adb shell )运行默认实现并分别进行 VTS 测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM