blob: dd50ffc2beb51cf41295a0ef61ef3aa1d2e4a27e [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
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#include "debugd/src/memory_tool.h"
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -07006
Alex Vakulenko262be3f2014-07-30 15:25:50 -07007#include "debugd/src/process_with_id.h"
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -07008
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -07009namespace debugd {
10
Ben Chana0011d82014-05-13 00:19:29 -070011namespace {
12
13const char kMemtesterpath[] = "/usr/sbin/memtester";
14
15} // namespace
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070016
Eric Caruso0b241882018-04-04 13:43:46 -070017std::string MemtesterTool::Start(const base::ScopedFD& outfd,
Eric Carusoc93a15c2017-04-24 16:15:12 -070018 const uint32_t& memory) {
Ben Chan0d840a72018-09-27 00:24:48 -070019 ProcessWithId* p =
20 CreateProcess(false /* sandboxed */, false /* access_root_mount_ns */);
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070021 if (!p)
22 return "";
23
24 p->AddArg(kMemtesterpath);
Eric Caruso96d03d32017-04-25 18:01:17 -070025 p->AddArg(base::StringPrintf("%u", memory));
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070026 p->AddArg("1");
Eric Caruso0b241882018-04-04 13:43:46 -070027 p->BindFd(outfd.get(), STDOUT_FILENO);
28 p->BindFd(outfd.get(), STDERR_FILENO);
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070029 LOG(INFO) << "memtester: running process id: " << p->id();
30 p->Start();
31 return p->id();
32}
33
Ben Chana0011d82014-05-13 00:19:29 -070034} // namespace debugd