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

Commit 8bf7316e authored by Yifan Hong's avatar Yifan Hong
Browse files

lshal: add tests for ListCommand::fetch* and dumpVintf

Test: lshal_test
Change-Id: I9e519ec93709ba4dfa7f95e4c5fff60cbda36134
parent b2a2ecb6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ cc_test {
        "libgmock"
    ],
    shared_libs: [
        "libvintf",
        "android.hardware.tests.baz@1.0"
    ],
    srcs: [
+2 −2
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ NullableOStream<std::ostream> ListCommand::err() const {
    return mLshal.err();
}

std::string getCmdline(pid_t pid) {
std::string ListCommand::parseCmdline(pid_t pid) const {
    std::ifstream ifs("/proc/" + std::to_string(pid) + "/cmdline");
    std::string cmdline;
    if (!ifs.is_open()) {
@@ -70,7 +70,7 @@ const std::string &ListCommand::getCmdline(pid_t pid) {
    if (pair != mCmdlines.end()) {
        return pair->second;
    }
    mCmdlines[pid] = ::android::lshal::getCmdline(pid);
    mCmdlines[pid] = parseCmdline(pid);
    return mCmdlines[pid];
}

+10 −6
Original line number Diff line number Diff line
@@ -36,9 +36,16 @@ namespace lshal {

class Lshal;

struct PidInfo {
    std::map<uint64_t, Pids> refPids; // pids that are referenced
    uint32_t threadUsage; // number of threads in use
    uint32_t threadCount; // number of threads total
};

class ListCommand {
public:
    ListCommand(Lshal &lshal);
    virtual ~ListCommand() = default;
    Status main(const std::string &command, const Arg &arg);
protected:
    Status parseArgs(const std::string &command, const Arg &arg);
@@ -50,12 +57,7 @@ protected:
    Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
    Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);

    struct PidInfo {
        std::map<uint64_t, Pids> refPids; // pids that are referenced
        uint32_t threadUsage; // number of threads in use
        uint32_t threadCount; // number of threads total
    };
    bool getPidInfo(pid_t serverPid, PidInfo *info) const;
    virtual bool getPidInfo(pid_t serverPid, PidInfo *info) const;

    void dumpTable(const NullableOStream<std::ostream>& out) const;
    void dumpVintf(const NullableOStream<std::ostream>& out) const;
@@ -64,6 +66,8 @@ protected:
                 const std::string &serverCmdline, const std::string &address,
                 const std::string &clients, const std::string &clientCmdlines) const;
    void addLine(TextTable *table, const TableEntry &entry);
    // Read and return /proc/{pid}/cmdline.
    virtual std::string parseCmdline(pid_t pid) const;
    // Return /proc/{pid}/cmdline if it exists, else empty string.
    const std::string &getCmdline(pid_t pid);
    // Call getCmdline on all pid in pids. If it returns empty string, the process might
+22 −0
Original line number Diff line number Diff line
@@ -152,5 +152,27 @@ TextTable MergedTable::createTextTable() {
    return textTable;
}

bool TableEntry::operator==(const TableEntry& other) const {
    if (this == &other) {
        return true;
    }
    return interfaceName == other.interfaceName && transport == other.transport &&
        serverPid == other.serverPid && threadUsage == other.threadUsage &&
        threadCount == other.threadCount && serverCmdline == other.serverCmdline &&
        serverObjectAddress == other.serverObjectAddress && clientPids == other.clientPids &&
        clientCmdlines == other.clientCmdlines && arch == other.arch;
}

std::string TableEntry::to_string() const {
    std::stringstream ss;
    ss << "name=" << interfaceName << ";transport=" << transport << ";thread=" << getThreadUsage()
       << ";server=" << serverPid
       << "(" << serverObjectAddress << ";" << serverCmdline << ");clients=["
       << join(clientPids, ";") << "](" << join(clientCmdlines, ";") << ");arch="
       << getArchString(arch);
    return ss.str();

}

} // namespace lshal
} // namespace android
+4 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ struct TableEntry {
    }

    std::string getField(TableColumnType type) const;

    bool operator==(const TableEntry& other) const;
    std::string to_string() const;
};

using SelectedColumns = std::vector<TableColumnType>;
@@ -97,6 +100,7 @@ public:
    Entries::const_iterator begin() const { return mEntries.begin(); }
    Entries::iterator end() { return mEntries.end(); }
    Entries::const_iterator end() const { return mEntries.end(); }
    size_t size() const { return mEntries.size(); }

    void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); }

Loading