diff options
author | digit@chromium.org <digit@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2013-04-24 10:06:14 +0000 |
---|---|---|
committer | digit@chromium.org <digit@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2013-04-24 10:06:14 +0000 |
commit | 593eff42ca4a5c38835577cf83152f356d262414 (patch) | |
tree | 6102e9d82b8f109d9aab1d52bdff2e4d75fcb9fe /src/client/linux/minidump_writer/line_reader_unittest.cc | |
parent | Cleanup: Remove duplicate wording in license headers. (diff) | |
download | breakpad-593eff42ca4a5c38835577cf83152f356d262414.tar.xz |
Improve ARM CPU info reporting.
This patch improves several things for Linux/ARM:
- Better detection of the number of CPUs on the target
device. The content of /proc/cpuinfo only matches the
number of "online" CPUs, which varies over time with
recent Android devices.
- Reconstruct the CPUID and ELF hwcaps values from
/proc/cpuinfo, this is useful to better identify
target devices in minidumps.
- Make minidump_dump display the new information
in useful ways.
- Write a small helper class to parse /proc/cpuinfo
and also use it for x86/64.
- Write a small helper class to parse sysfds cpu lists.
- Add a my_memchr() implementation.
- Add unit tests.
Tested on a Nexus S (1 CPU), Galaxy Nexus (2 CPUs)
and a Nexus 4 (4 CPUs).
Review URL: https://breakpad.appspot.com/540003
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1160 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/linux/minidump_writer/line_reader_unittest.cc')
-rw-r--r-- | src/client/linux/minidump_writer/line_reader_unittest.cc | 101 |
1 files changed, 37 insertions, 64 deletions
diff --git a/src/client/linux/minidump_writer/line_reader_unittest.cc b/src/client/linux/minidump_writer/line_reader_unittest.cc index 4448281d..928626e1 100644 --- a/src/client/linux/minidump_writer/line_reader_unittest.cc +++ b/src/client/linux/minidump_writer/line_reader_unittest.cc @@ -34,47 +34,41 @@ #include "client/linux/minidump_writer/line_reader.h" #include "breakpad_googletest_includes.h" #include "common/linux/eintr_wrapper.h" +#include "common/tests/auto_testfile.h" using namespace google_breakpad; -#if !defined(__ANDROID__) -#define TEMPDIR "/tmp" -#else -#define TEMPDIR "/data/local/tmp" -#endif - -static int TemporaryFile() { - static const char templ[] = TEMPDIR "/line-reader-unittest-XXXXXX"; - char templ_copy[sizeof(templ)]; - memcpy(templ_copy, templ, sizeof(templ)); - const int fd = mkstemp(templ_copy); - if (fd >= 0) - unlink(templ_copy); - - return fd; -} - namespace { + typedef testing::Test LineReaderTest; + +class ScopedTestFile : public AutoTestFile { +public: + explicit ScopedTestFile(const char* text) + : AutoTestFile("line_reader", text) { + } + + ScopedTestFile(const char* text, size_t text_len) + : AutoTestFile("line_reader", text, text_len) { + } +}; + } TEST(LineReaderTest, EmptyFile) { - const int fd = TemporaryFile(); - LineReader reader(fd); + ScopedTestFile file(""); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned len; ASSERT_FALSE(reader.GetNextLine(&line, &len)); - - close(fd); } TEST(LineReaderTest, OneLineTerminated) { - const int fd = TemporaryFile(); - const int r = HANDLE_EINTR(write(fd, "a\n", 2)); - ASSERT_EQ(2, r); - lseek(fd, 0, SEEK_SET); - LineReader reader(fd); + ScopedTestFile file("a\n"); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned int len; @@ -85,16 +79,12 @@ TEST(LineReaderTest, OneLineTerminated) { reader.PopLine(len); ASSERT_FALSE(reader.GetNextLine(&line, &len)); - - close(fd); } TEST(LineReaderTest, OneLine) { - const int fd = TemporaryFile(); - const int r = HANDLE_EINTR(write(fd, "a", 1)); - ASSERT_EQ(1, r); - lseek(fd, 0, SEEK_SET); - LineReader reader(fd); + ScopedTestFile file("a"); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned len; @@ -105,16 +95,12 @@ TEST(LineReaderTest, OneLine) { reader.PopLine(len); ASSERT_FALSE(reader.GetNextLine(&line, &len)); - - close(fd); } TEST(LineReaderTest, TwoLinesTerminated) { - const int fd = TemporaryFile(); - const int r = HANDLE_EINTR(write(fd, "a\nb\n", 4)); - ASSERT_EQ(4, r); - lseek(fd, 0, SEEK_SET); - LineReader reader(fd); + ScopedTestFile file("a\nb\n"); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned len; @@ -131,16 +117,12 @@ TEST(LineReaderTest, TwoLinesTerminated) { reader.PopLine(len); ASSERT_FALSE(reader.GetNextLine(&line, &len)); - - close(fd); } TEST(LineReaderTest, TwoLines) { - const int fd = TemporaryFile(); - const int r = HANDLE_EINTR(write(fd, "a\nb", 3)); - ASSERT_EQ(3, r); - lseek(fd, 0, SEEK_SET); - LineReader reader(fd); + ScopedTestFile file("a\nb"); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned len; @@ -157,18 +139,14 @@ TEST(LineReaderTest, TwoLines) { reader.PopLine(len); ASSERT_FALSE(reader.GetNextLine(&line, &len)); - - close(fd); } TEST(LineReaderTest, MaxLength) { - const int fd = TemporaryFile(); - char l[LineReader::kMaxLineLen - 1]; + char l[LineReader::kMaxLineLen-1]; memset(l, 'a', sizeof(l)); - const int r = HANDLE_EINTR(write(fd, l, sizeof(l))); - ASSERT_EQ(static_cast<ssize_t>(sizeof(l)), r); - lseek(fd, 0, SEEK_SET); - LineReader reader(fd); + ScopedTestFile file(l, sizeof(l)); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned len; @@ -176,22 +154,17 @@ TEST(LineReaderTest, MaxLength) { ASSERT_EQ(sizeof(l), len); ASSERT_TRUE(memcmp(l, line, sizeof(l)) == 0); ASSERT_EQ('\0', line[len]); - - close(fd); } TEST(LineReaderTest, TooLong) { - const int fd = TemporaryFile(); + // Note: this writes kMaxLineLen 'a' chars in the test file. char l[LineReader::kMaxLineLen]; memset(l, 'a', sizeof(l)); - const int r = HANDLE_EINTR(write(fd, l, sizeof(l))); - ASSERT_EQ(static_cast<ssize_t>(sizeof(l)), r); - lseek(fd, 0, SEEK_SET); - LineReader reader(fd); + ScopedTestFile file(l, sizeof(l)); + ASSERT_TRUE(file.IsOk()); + LineReader reader(file.GetFd()); const char *line; unsigned len; ASSERT_FALSE(reader.GetNextLine(&line, &len)); - - close(fd); } |