Update to build against libchrome-242728.

This CL updates metrics to build against libchrome-242728 and also converts
libmetrics into slotted libraries (libmetrics-180609 and libmetrics-242728).

BUG=chromium:341521
BUG=chromium:342866
CQ-DEPEND=CL:186027
CQ-DEPEND=CL:186026
CQ-DEPEND=CL:186037
CQ-DEPEND=CL:186092
CQ-DEPEND=CL:186028
CQ-DEPEND=CL:186029
CQ-DEPEND=CL:186038
CQ-DEPEND=CL:186093
CQ-DEPEND=CL:186100
CQ-DEPEND=CL:186039
TEST=Trybot run on paladin, release, and chromiumos-sdk builders.

Change-Id: I09dc3d47cfe24a22864abf217658c63493b35cba
Reviewed-on: https://chromium-review.googlesource.com/185187
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
This commit is contained in:
Ben Chan 2014-02-05 23:26:25 -08:00 committed by chrome-internal-fetch
parent 09a15fa954
commit 2e6543ddad
15 changed files with 133 additions and 94 deletions

View File

@ -7,7 +7,7 @@
#include <base/file_util.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
#include <base/string_util.h>
#include <base/strings/string_util.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@ -15,6 +15,7 @@
#include "counter_mock.h" // For TaggedCounterMock.
#include "metrics_library_mock.h"
using base::FilePath;
using ::testing::_;
using ::testing::MockFunction;
using ::testing::StrictMock;
@ -58,7 +59,7 @@ class TaggedCounterTest : public testing::Test {
virtual void TearDown() {
logging::SetLogMessageHandler(NULL);
test_ = NULL;
file_util::Delete(FilePath(kTestRecordFile), false);
base::DeleteFile(FilePath(kTestRecordFile), false);
}
// Asserts that the record file contains the specified contents.
@ -74,8 +75,8 @@ class TaggedCounterTest : public testing::Test {
}
TaggedCounter::Record record;
if (!file_util::ReadFromFD(fd, reinterpret_cast<char*>(&record),
sizeof(record))) {
if (!base::ReadFromFD(fd, reinterpret_cast<char*>(&record),
sizeof(record))) {
testing::Message msg;
msg << "Unable to read " << sizeof(record) << " bytes from "
<< kTestRecordFile;
@ -100,9 +101,9 @@ class TaggedCounterTest : public testing::Test {
bool AssertNoOrEmptyRecordFile() {
FilePath record_file(counter_.filename_);
int64 record_file_size;
return !file_util::PathExists(record_file) ||
(file_util::GetFileSize(record_file, &record_file_size) &&
record_file_size == 0);
return !base::PathExists(record_file) ||
(base::GetFileSize(record_file, &record_file_size) &&
record_file_size == 0);
}
// Adds a reporter call expectation that the specified tag/count
@ -196,7 +197,7 @@ TEST_F(TaggedCounterTest, BadFileLocation) {
EXPECT_TRUE(LogContains("Unable to open the persistent counter file: "
"No such file or directory"));
EXPECT_EQ(TaggedCounter::kRecordInvalid, counter_.record_state_);
file_util::Delete(FilePath(kDoesNotExistFile), false);
base::DeleteFile(FilePath(kDoesNotExistFile), false);
}
TEST_F(TaggedCounterTest, Flush) {

View File

@ -0,0 +1,8 @@
{
'variables': {
'libbase_ver': 180609,
},
'includes': [
'../metrics/libmetrics.gypi',
],
}

View File

@ -0,0 +1,8 @@
{
'variables': {
'libbase_ver': 242728,
},
'includes': [
'../metrics/libmetrics.gypi',
],
}

29
metrics/libmetrics.gypi Normal file
View File

@ -0,0 +1,29 @@
{
'target_defaults': {
'dependencies': [
'../libchromeos/libchromeos-<(libbase_ver).gyp:libchromeos-<(libbase_ver)',
],
'variables': {
'deps': [
'libchrome-<(libbase_ver)',
]
},
'cflags_cc': [
'-fno-exceptions',
],
},
'targets': [
{
'target_name': 'libmetrics-<(libbase_ver)',
'type': 'shared_library',
'cflags': [
'-fvisibility=default',
],
'sources': [
'c_metrics_library.cc',
'metrics_library.cc',
'timer.cc',
],
},
],
}

View File

@ -1,48 +1,32 @@
{
'variables': {
'libbase_ver': 242728,
},
'target_defaults': {
'dependencies': [
'../libchromeos/libchromeos-<(libbase_ver).gyp:libchromeos-<(libbase_ver)',
],
'variables': {
'deps': [
'dbus-1',
'dbus-glib-1',
'glib-2.0',
'gobject-2.0',
'gthread-2.0',
'libchrome-<(libbase_ver)',
]
},
'cflags_cc': [
'-fno-exceptions',
],
'dependencies': [
'../libchromeos/libchromeos-<(libbase_ver).gyp:libchromeos-<(libbase_ver)',
],
'variables': {
'deps': [
'dbus-1',
'dbus-glib-1',
'glib-2.0',
'gobject-2.0',
'gthread-2.0',
'libchrome-<(libbase_ver)',
]
},
'cflags_cc': [
'-fno-exceptions',
],
},
'targets': [
{
'target_name': 'metrics',
'type': 'static_library',
'sources': [
'c_metrics_library.cc',
'metrics_library.cc',
'timer.cc',
],
},
{
'target_name': 'libmetrics',
'type': 'shared_library',
'cflags': [
'-fvisibility=default',
],
'sources': [
'c_metrics_library.cc',
'metrics_library.cc',
'timer.cc',
],
},
{
'target_name': 'libmetrics_daemon',
'type': 'static_library',
'dependencies': ['libmetrics'],
'dependencies': [
'../metrics/libmetrics-<(libbase_ver).gyp:libmetrics-<(libbase_ver)',
],
'link_settings': {
'libraries': [
'-lrootdev',
@ -58,7 +42,9 @@
{
'target_name': 'metrics_client',
'type': 'executable',
'dependencies': ['libmetrics'],
'dependencies': [
'../metrics/libmetrics-<(libbase_ver).gyp:libmetrics-<(libbase_ver)',
],
'sources': [
'metrics_client.cc',
]
@ -79,7 +65,9 @@
{
'target_name': 'metrics_library_test',
'type': 'executable',
'dependencies': ['libmetrics'],
'dependencies': [
'../metrics/libmetrics-<(libbase_ver).gyp:libmetrics-<(libbase_ver)',
],
'includes': ['../common-mk/common_test.gypi'],
'sources': [
'metrics_library_test.cc',

View File

@ -11,15 +11,17 @@
#include <base/file_util.h>
#include <base/logging.h>
#include <base/string_number_conversions.h>
#include <base/string_util.h>
#include <base/string_split.h>
#include <base/stringprintf.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/string_split.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <chromeos/dbus/service_constants.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "counter.h"
using base::FilePath;
using base::StringPrintf;
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
@ -528,13 +530,13 @@ void MetricsDaemon::ProcessUncleanShutdown() {
bool MetricsDaemon::CheckSystemCrash(const string& crash_file) {
FilePath crash_detected(crash_file);
if (!file_util::PathExists(crash_detected))
if (!base::PathExists(crash_detected))
return false;
// Deletes the crash-detected file so that the daemon doesn't report
// another kernel crash in case it's restarted.
file_util::Delete(crash_detected,
false); // recursive
base::DeleteFile(crash_detected,
false); // recursive
return true;
}
@ -706,7 +708,7 @@ bool MetricsDaemon::VmStatsParseStats(const char* stats,
bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) {
string value_string;
FilePath* path = new FilePath(vmstats_path_);
if (!file_util::ReadFileToString(*path, &value_string)) {
if (!base::ReadFileToString(*path, &value_string)) {
delete path;
LOG(WARNING) << "cannot read " << vmstats_path_;
return false;
@ -718,11 +720,11 @@ bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) {
bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) {
const FilePath sysfs_path(sysfs_file_name);
string value_string;
if (!file_util::ReadFileToString(sysfs_path, &value_string)) {
if (!base::ReadFileToString(sysfs_path, &value_string)) {
LOG(WARNING) << "cannot read " << sysfs_path.value().c_str();
return false;
}
if (!RemoveChars(value_string, "\n", &value_string)) {
if (!base::RemoveChars(value_string, "\n", &value_string)) {
LOG(WARNING) << "no newline in " << value_string;
// Continue even though the lack of newline is suspicious.
}
@ -901,7 +903,7 @@ gboolean MetricsDaemon::MeminfoCallbackStatic(void* handle) {
bool MetricsDaemon::MeminfoCallback() {
string meminfo_raw;
const FilePath meminfo_path("/proc/meminfo");
if (!file_util::ReadFileToString(meminfo_path, &meminfo_raw)) {
if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
return false;
}
@ -1051,7 +1053,7 @@ void MetricsDaemon::MemuseCallback() {
bool MetricsDaemon::MemuseCallbackWork() {
string meminfo_raw;
const FilePath meminfo_path("/proc/meminfo");
if (!file_util::ReadFileToString(meminfo_path, &meminfo_raw)) {
if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
return false;
}

View File

@ -9,9 +9,9 @@
#include <glib.h>
#include <map>
#include <base/file_path.h>
#include <base/files/file_path.h>
#include <base/memory/scoped_ptr.h>
#include <base/time.h>
#include <base/time/time.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "metrics_library.h"
@ -195,7 +195,7 @@ class MetricsDaemon {
void ConfigureCrashFrequencyReporter(const char* histogram_name);
// Returns file path to persistent file for generating given histogram.
FilePath GetHistogramPath(const char* histogram_name);
base::FilePath GetHistogramPath(const char* histogram_name);
// Creates the event loop and enters it.
void Loop();

View File

@ -4,7 +4,7 @@
#include <base/logging.h>
#include <base/string_util.h>
#include <base/strings/string_util.h>
#include <gflags/gflags.h>
#include <rootdev/rootdev.h>

View File

@ -8,7 +8,7 @@
#include <vector>
#include <base/file_util.h>
#include <base/stringprintf.h>
#include <base/strings/stringprintf.h>
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
@ -16,6 +16,8 @@
#include "metrics_daemon.h"
#include "metrics_library_mock.h"
using base::FilePath;
using base::StringPrintf;
using base::Time;
using base::TimeTicks;
using chromeos_metrics::FrequencyCounter;
@ -132,8 +134,8 @@ class MetricsDaemonTest : public testing::Test {
EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_);
EXPECT_EQ(MetricsDaemon::kUnknownSessionState, daemon_.session_state_);
file_util::Delete(FilePath(kTestDir), true);
file_util::CreateDirectory(FilePath(kTestDir));
base::DeleteFile(FilePath(kTestDir), true);
base::CreateDirectory(FilePath(kTestDir));
}
virtual void TearDown() {
@ -261,7 +263,7 @@ class MetricsDaemonTest : public testing::Test {
// Creates or overwrites an input file containing a fake CPU frequency.
void CreateFakeCpuFrequencyFile(const char* filename, int frequency) {
FilePath path(filename);
file_util::Delete(path, false);
base::DeleteFile(path, false);
std::string frequency_string = StringPrintf("%d\n", frequency);
int frequency_string_length = frequency_string.length();
EXPECT_EQ(frequency_string.length(),
@ -291,12 +293,12 @@ TEST_F(MetricsDaemonTest, CheckSystemCrash) {
FilePath crash_detected(kKernelCrashDetected);
file_util::WriteFile(crash_detected, "", 0);
EXPECT_TRUE(file_util::PathExists(crash_detected));
EXPECT_TRUE(base::PathExists(crash_detected));
EXPECT_TRUE(daemon_.CheckSystemCrash(kKernelCrashDetected));
EXPECT_FALSE(file_util::PathExists(crash_detected));
EXPECT_FALSE(base::PathExists(crash_detected));
EXPECT_FALSE(daemon_.CheckSystemCrash(kKernelCrashDetected));
EXPECT_FALSE(file_util::PathExists(crash_detected));
file_util::Delete(crash_detected, false);
EXPECT_FALSE(base::PathExists(crash_detected));
base::DeleteFile(crash_detected, false);
}
TEST_F(MetricsDaemonTest, ReportDailyUse) {

View File

@ -86,8 +86,7 @@ static int WriteFileDescriptor(const int fd, const char* data, int size) {
MetricsLibrary::MetricsLibrary()
: uma_events_file_(NULL),
consent_file_(kConsentFile),
policy_provider_(NULL) {}
consent_file_(kConsentFile) {}
// We take buffer and buffer_size as parameters in order to simplify testing
// of various alignments of the |device_name| with |buffer_size|.

View File

@ -13,13 +13,14 @@
#include "c_metrics_library.h"
#include "metrics_library.h"
static const FilePath kTestUMAEventsFile("test-uma-events");
static const char kTestMounts[] = "test-mounts";
using base::FilePath;
using ::testing::_;
using ::testing::Return;
using ::testing::AnyNumber;
static const FilePath kTestUMAEventsFile("test-uma-events");
static const char kTestMounts[] = "test-mounts";
ACTION_P(SetMetricsPolicy, enabled) {
*arg0 = enabled;
return true;
@ -46,8 +47,8 @@ class MetricsLibraryTest : public testing::Test {
}
virtual void TearDown() {
file_util::Delete(FilePath(kTestMounts), false);
file_util::Delete(kTestUMAEventsFile, false);
base::DeleteFile(FilePath(kTestMounts), false);
base::DeleteFile(kTestUMAEventsFile, false);
}
void VerifyEnabledCacheHit(bool to_value);
@ -182,7 +183,7 @@ TEST_F(MetricsLibraryTest, SendEnumToUMA) {
char buf[100];
const int kLen = 40;
EXPECT_TRUE(lib_.SendEnumToUMA("Test.EnumMetric", 1, 3));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%clinearhistogram%cTest.EnumMetric 1 3",
@ -194,7 +195,7 @@ TEST_F(MetricsLibraryTest, SendMessageToChrome) {
EXPECT_TRUE(lib_.SendMessageToChrome(4, "test"));
EXPECT_TRUE(lib_.SendMessageToChrome(7, "content"));
std::string uma_events;
EXPECT_TRUE(file_util::ReadFileToString(kTestUMAEventsFile, &uma_events));
EXPECT_TRUE(base::ReadFileToString(kTestUMAEventsFile, &uma_events));
EXPECT_EQ("testcontent", uma_events);
}
@ -205,14 +206,14 @@ TEST_F(MetricsLibraryTest, SendMessageToChromeUMAEventsBadFileLocation) {
lib_.uma_events_file_ = kDoesNotExistFile;
static const char kDummyMessage[] = "Dummy Message";
EXPECT_FALSE(lib_.SendMessageToChrome(strlen(kDummyMessage), kDummyMessage));
file_util::Delete(FilePath(kDoesNotExistFile), false);
base::DeleteFile(FilePath(kDoesNotExistFile), false);
}
TEST_F(MetricsLibraryTest, SendToUMA) {
char buf[100];
const int kLen = 37;
EXPECT_TRUE(lib_.SendToUMA("Test.Metric", 2, 1, 100, 50));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
@ -223,7 +224,7 @@ TEST_F(MetricsLibraryTest, SendUserActionToUMA) {
char buf[100];
const int kLen = 30;
EXPECT_TRUE(lib_.SendUserActionToUMA("SomeKeyPressed"));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0);
@ -234,7 +235,7 @@ TEST_F(MetricsLibraryTest, SendSparseToUMA) {
char buf[100];
const int kLen = 4 + sizeof("sparsehistogram") + sizeof("Test.Sparse 1234");
EXPECT_TRUE(lib_.SendSparseToUMA("Test.Sparse", 1234));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%csparsehistogram%cTest.Sparse 1234", kLen, 0, 0, 0, 0);
@ -248,7 +249,7 @@ TEST_F(MetricsLibraryTest, SendCrashToUMA) {
0, 0, 0, 0, 0) + 1;
exp[0] = len;
char buf[100];
EXPECT_EQ(len, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(len, base::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(0, memcmp(exp, buf, len));
}
@ -275,7 +276,7 @@ class CMetricsLibraryTest : public testing::Test {
virtual void TearDown() {
CMetricsLibraryDelete(lib_);
file_util::Delete(kTestUMAEventsFile, false);
base::DeleteFile(kTestUMAEventsFile, false);
}
CMetricsLibrary lib_;
@ -297,7 +298,7 @@ TEST_F(CMetricsLibraryTest, SendEnumToUMA) {
char buf[100];
const int kLen = 40;
EXPECT_TRUE(CMetricsLibrarySendEnumToUMA(lib_, "Test.EnumMetric", 1, 3));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%clinearhistogram%cTest.EnumMetric 1 3",
@ -309,7 +310,7 @@ TEST_F(CMetricsLibraryTest, SendToUMA) {
char buf[100];
const int kLen = 37;
EXPECT_TRUE(CMetricsLibrarySendToUMA(lib_, "Test.Metric", 2, 1, 100, 50));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
@ -320,7 +321,7 @@ TEST_F(CMetricsLibraryTest, SendUserActionToUMA) {
char buf[100];
const int kLen = 30;
EXPECT_TRUE(CMetricsLibrarySendUserActionToUMA(lib_, "SomeKeyPressed"));
EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0);
@ -333,7 +334,7 @@ TEST_F(CMetricsLibraryTest, SendCrashToUMA) {
int len = sprintf(exp, "%c%c%c%ccrash%cuser", 0, 0, 0, 0, 0) + 1;
exp[0] = len;
EXPECT_TRUE(CMetricsLibrarySendCrashToUMA(lib_, "user"));
EXPECT_EQ(len, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(len, base::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(0, memcmp(exp, buf, len));
}

View File

@ -7,7 +7,6 @@
#include <string>
#include <base/memory/scoped_ptr.h>
#include <base/time.h>
#include "metrics_library.h"

View File

@ -10,7 +10,11 @@
#include <string>
#include <base/memory/scoped_ptr.h>
#if BASE_VER >= 242728
#include <base/time/time.h>
#else
#include <base/time.h>
#endif
#include <gtest/gtest_prod.h> // for FRIEND_TEST
class MetricsLibraryInterface;

View File

@ -9,7 +9,6 @@
#include <string>
#include <base/basictypes.h>
#include <base/time.h>
#include <gmock/gmock.h>
#include "timer.h"

View File

@ -3,7 +3,6 @@
// found in the LICENSE file.
#include <base/memory/scoped_ptr.h>
#include <base/time.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>