blob: 7a16d6009568b66b9bdb0cdf3f894ebb45e535b9 [file] [log] [blame]
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "memory_tool.h"
6
7#include "process_with_id.h"
8
Ben Chan55903dd2014-04-24 00:29:04 -07009using base::StringPrintf;
10
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070011namespace debugd {
12
Ben Chana0011d82014-05-13 00:19:29 -070013namespace {
14
15const char kMemtesterpath[] = "/usr/sbin/memtester";
16
17} // namespace
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070018
19MemtesterTool::MemtesterTool() { }
Ben Chana0011d82014-05-13 00:19:29 -070020
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070021MemtesterTool::~MemtesterTool() { }
22
23std::string MemtesterTool::Start(const DBus::FileDescriptor& outfd,
24 const uint32_t& memory,
Ben Chana0011d82014-05-13 00:19:29 -070025 DBus::Error* error) {
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070026 ProcessWithId* p = CreateProcess(false);
27 if (!p)
28 return "";
29
30 p->AddArg(kMemtesterpath);
31 p->AddArg(StringPrintf("%u", memory));
32 p->AddArg("1");
33 p->BindFd(outfd.get(), STDOUT_FILENO);
34 p->BindFd(outfd.get(), STDERR_FILENO);
35 LOG(INFO) << "memtester: running process id: " << p->id();
36 p->Start();
37 return p->id();
38}
39
Ben Chana0011d82014-05-13 00:19:29 -070040} // namespace debugd