Enable Last Kmsg, also fix the GZipSection test.

Bug: 73354384, 76208934
Test: atest incidentd_test and manual as well
Change-Id: I074027f4d972686ae3e9415b50e4d3967f6a2355
This commit is contained in:
Yi Jin 2018-03-28 15:32:50 -07:00
parent ab34199e9c
commit c858e2781c
4 changed files with 24 additions and 11 deletions

View File

@ -319,8 +319,10 @@ status_t GZipSection::Execute(ReportRequestSet* requests) const {
index++; // look at the next file.
}
VLOG("GZipSection is using file %s, fd=%d", mFilenames[index], fd.get());
if (fd.get() == -1) return -1;
if (fd.get() == -1) {
ALOGW("GZipSection %s can't open all the files", this->name.string());
return NO_ERROR; // e.g. LAST_KMSG will reach here in user build.
}
FdBuffer buffer;
Fpipe p2cPipe;
Fpipe c2pPipe;

View File

@ -38,7 +38,7 @@ const uint8_t STRING_TYPE = 9;
const uint8_t MESSAGE_TYPE = 11;
const string STRING_FIELD_0 = "\x02\viamtestdata";
const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
const string STRING_FIELD_2 = "\x12\vwhatthefuck";
const string STRING_FIELD_2 = "\x12\vandroidwins";
const string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
const string FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1
const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2;
@ -274,4 +274,4 @@ TEST_F(PrivacyBufferTest, AutoMessage) {
autoMsg->children = list;
string expected = "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_AUTOMATIC, expected, 1, autoMsg);
}
}

View File

@ -19,6 +19,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <android/os/IncidentReportArgs.h>
#include <android/util/protobuf.h>
#include <frameworks/base/libs/incident/proto/android/os/header.pb.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@ -31,12 +32,13 @@ const int REVERSE_PARSER = 1;
const int QUICK_TIMEOUT_MS = 100;
const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
const string STRING_FIELD_2 = "\x12\vwhatthefuck";
const string STRING_FIELD_2 = "\x12\vandroidwins";
const string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
using namespace android::base;
using namespace android::binder;
using namespace android::os;
using namespace android::util;
using namespace std;
using ::testing::StrEq;
using ::testing::Test;
@ -154,17 +156,26 @@ TEST_F(SectionTest, GZipSection) {
requests.setMainDest(android::os::DEST_LOCAL);
ASSERT_EQ(NO_ERROR, gs.Execute(&requests));
std::string expect, gzFile, actual;
std::string expected, gzFile, actual;
ASSERT_TRUE(ReadFileToString(testGzFile, &gzFile));
ASSERT_TRUE(ReadFileToString(tf.path, &actual));
expect = "\x2\xC6\x6\n\"" + testFile + "\x12\x9F\x6" + gzFile;
EXPECT_THAT(actual, StrEq(expect));
// generates the expected protobuf result.
size_t fileLen = testFile.size();
size_t totalLen = 1 + get_varint_size(fileLen) + fileLen + 3 + gzFile.size();
uint8_t header[20];
header[0] = '\x2'; // header 0 << 3 + 2
uint8_t* ptr = write_raw_varint(header + 1, totalLen);
*ptr = '\n'; // header 1 << 3 + 2
ptr = write_raw_varint(++ptr, fileLen);
expected.assign((const char*)header, ptr - header);
expected += testFile + "\x12\x9F\x6" + gzFile;
EXPECT_THAT(actual, StrEq(expected));
}
TEST_F(SectionTest, GZipSectionNoFileFound) {
GZipSection gs(NOOP_PARSER, "/tmp/nonexist1", "/tmp/nonexist2", NULL);
requests.setMainFd(STDOUT_FILENO);
ASSERT_EQ(-1, gs.Execute(&requests));
ASSERT_EQ(NO_ERROR, gs.Execute(&requests));
}
TEST_F(SectionTest, CommandSectionConstructor) {

View File

@ -175,9 +175,9 @@ message IncidentProto {
];
optional GZippedFileProto last_kmsg = 2007 [
(section).type = SECTION_NONE, // disable until selinux permission is gained
(section).type = SECTION_GZIP,
(section).args = "/sys/fs/pstore/console-ramoops /sys/fs/pstore/console-ramoops-0 /proc/last_kmsg",
(privacy).dest = DEST_AUTOMATIC
(privacy).dest = DEST_EXPLICIT
];
// System Services