Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9881df97 authored by Yifan Hong's avatar Yifan Hong
Browse files

Add tests to lshal.

Test: lshal_test
Bug: 37954458
Change-Id: I1914e6274974ed5eb0ce2d655f1333d2344b49f5
parent 48dc9f85
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

cc_binary {
    name: "lshal",
cc_library_shared {
    name: "liblshal",
    shared_libs: [
        "libbase",
        "libcutils",
@@ -31,3 +31,37 @@ cc_binary {
        "utils.cpp",
    ],
}

cc_defaults {
    name: "lshal_defaults",
    shared_libs: [
        "libbase",
        "libhidlbase",
        "libhidltransport",
        "liblshal",
        "libutils",
    ]
}

cc_binary {
    name: "lshal",
    defaults: ["lshal_defaults"],
    srcs: [
        "main.cpp"
    ]
}

cc_test {
    name: "lshal_test",
    defaults: ["lshal_defaults"],
    gtest: true,
    static_libs: [
        "libgmock"
    ],
    shared_libs: [
        "android.hardware.tests.baz@1.0"
    ],
    srcs: [
        "test.cpp"
    ]
}
+2 −3
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@

#include <android-base/parseint.h>
#include <android/hidl/manager/1.0/IServiceManager.h>
#include <hidl/ServiceManagement.h>
#include <hidl-util/FQName.h>
#include <private/android_filesystem_config.h>
#include <sys/stat.h>
@@ -558,7 +557,7 @@ Status ListCommand::fetchBinderized(const sp<IServiceManager> &manager) {

Status ListCommand::fetch() {
    Status status = OK;
    auto bManager = ::android::hardware::defaultServiceManager();
    auto bManager = mLshal.serviceManager();
    if (bManager == nullptr) {
        mErr << "Failed to get defaultServiceManager()!" << std::endl;
        status |= NO_BINDERIZED_MANAGER;
@@ -568,7 +567,7 @@ Status ListCommand::fetch() {
        status |= fetchPassthrough(bManager);
    }

    auto pManager = ::android::hardware::getPassthroughServiceManager();
    auto pManager = mLshal.passthroughManager();
    if (pManager == nullptr) {
        mErr << "Failed to get getPassthroughServiceManager()!" << std::endl;
        status |= NO_PASSTHROUGH_MANAGER;
+30 −14
Original line number Diff line number Diff line
@@ -33,7 +33,19 @@ namespace lshal {

using ::android::hidl::manager::V1_0::IServiceManager;

Lshal::Lshal() {
Lshal::Lshal()
    : mOut(std::cout), mErr(std::cerr),
      mServiceManager(::android::hardware::defaultServiceManager()),
      mPassthroughManager(::android::hardware::getPassthroughServiceManager()) {
}

Lshal::Lshal(std::ostream &out, std::ostream &err,
            sp<hidl::manager::V1_0::IServiceManager> serviceManager,
            sp<hidl::manager::V1_0::IServiceManager> passthroughManager)
    : mOut(out), mErr(err),
      mServiceManager(serviceManager),
      mPassthroughManager(passthroughManager) {

}

void Lshal::usage(const std::string &command) const {
@@ -125,8 +137,7 @@ Status Lshal::emitDebugInfo(
        NullableOStream<std::ostream> err) const {
    using android::hidl::base::V1_0::IBase;

    hardware::Return<sp<IBase>> retBase =
        ::android::hardware::defaultServiceManager()->get(interfaceName, instanceName);
    hardware::Return<sp<IBase>> retBase = serviceManager()->get(interfaceName, instanceName);

    if (!retBase.isOk()) {
        std::string msg = "Cannot get " + interfaceName + "/" + instanceName + ": "
@@ -196,7 +207,17 @@ Status Lshal::parseArgs(const Arg &arg) {
    return USAGE;
}

void signalHandler(int sig) {
    if (sig == SIGINT) {
        int retVal;
        pthread_exit(&retVal);
    }
}

Status Lshal::main(const Arg &arg) {
    // Allow SIGINT to terminate all threads.
    signal(SIGINT, signalHandler);

    Status status = parseArgs(arg);
    if (status != OK) {
        return status;
@@ -223,18 +244,13 @@ NullableOStream<std::ostream> Lshal::out() const {
    return mOut;
}

void signalHandler(int sig) {
    if (sig == SIGINT) {
        int retVal;
        pthread_exit(&retVal);
const sp<IServiceManager> &Lshal::serviceManager() const {
    return mServiceManager;
}

const sp<IServiceManager> &Lshal::passthroughManager() const {
    return mPassthroughManager;
}

}  // namespace lshal
}  // namespace android

int main(int argc, char **argv) {
    using namespace ::android::lshal;
    signal(SIGINT, signalHandler);
    return Lshal{}.main(Arg{argc, argv});
}
+10 −2
Original line number Diff line number Diff line
@@ -33,10 +33,15 @@ namespace lshal {
class Lshal {
public:
    Lshal();
    Lshal(std::ostream &out, std::ostream &err,
            sp<hidl::manager::V1_0::IServiceManager> serviceManager,
            sp<hidl::manager::V1_0::IServiceManager> passthroughManager);
    Status main(const Arg &arg);
    void usage(const std::string &command = "") const;
    NullableOStream<std::ostream> err() const;
    NullableOStream<std::ostream> out() const;
    const sp<hidl::manager::V1_0::IServiceManager> &serviceManager() const;
    const sp<hidl::manager::V1_0::IServiceManager> &passthroughManager() const;

    Status emitDebugInfo(
            const std::string &interfaceName,
@@ -48,8 +53,11 @@ private:
    Status parseArgs(const Arg &arg);
    std::string mCommand;
    Arg mCmdArgs;
    NullableOStream<std::ostream> mErr = std::cerr;
    NullableOStream<std::ostream> mOut = std::cout;
    NullableOStream<std::ostream> mOut;
    NullableOStream<std::ostream> mErr;

    sp<hidl::manager::V1_0::IServiceManager> mServiceManager;
    sp<hidl::manager::V1_0::IServiceManager> mPassthroughManager;

    DISALLOW_COPY_AND_ASSIGN(Lshal);
};

cmds/lshal/main.cpp

0 → 100644
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Lshal.h"

int main(int argc, char **argv) {
    using namespace ::android::lshal;
    return Lshal{}.main(Arg{argc, argv});
}
Loading