Loading cmds/incidentd/src/Section.cpp +4 −2 Original line number Original line Diff line number Diff line Loading @@ -319,8 +319,10 @@ status_t GZipSection::Execute(ReportRequestSet* requests) const { index++; // look at the next file. index++; // look at the next file. } } VLOG("GZipSection is using file %s, fd=%d", mFilenames[index], fd.get()); 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; FdBuffer buffer; Fpipe p2cPipe; Fpipe p2cPipe; Fpipe c2pPipe; Fpipe c2pPipe; Loading cmds/incidentd/tests/PrivacyBuffer_test.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,7 @@ const uint8_t STRING_TYPE = 9; const uint8_t MESSAGE_TYPE = 11; const uint8_t MESSAGE_TYPE = 11; const string STRING_FIELD_0 = "\x02\viamtestdata"; const string STRING_FIELD_0 = "\x02\viamtestdata"; const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150 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 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 FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1 const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2; const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2; Loading cmds/incidentd/tests/Section_test.cpp +16 −5 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <android-base/file.h> #include <android-base/file.h> #include <android-base/test_utils.h> #include <android-base/test_utils.h> #include <android/os/IncidentReportArgs.h> #include <android/os/IncidentReportArgs.h> #include <android/util/protobuf.h> #include <frameworks/base/libs/incident/proto/android/os/header.pb.h> #include <frameworks/base/libs/incident/proto/android/os/header.pb.h> #include <gmock/gmock.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <gtest/gtest.h> Loading @@ -31,12 +32,13 @@ const int REVERSE_PARSER = 1; const int QUICK_TIMEOUT_MS = 100; const int QUICK_TIMEOUT_MS = 100; const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150 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 FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1 using namespace android::base; using namespace android::base; using namespace android::binder; using namespace android::binder; using namespace android::os; using namespace android::os; using namespace android::util; using namespace std; using namespace std; using ::testing::StrEq; using ::testing::StrEq; using ::testing::Test; using ::testing::Test; Loading Loading @@ -154,17 +156,26 @@ TEST_F(SectionTest, GZipSection) { requests.setMainDest(android::os::DEST_LOCAL); requests.setMainDest(android::os::DEST_LOCAL); ASSERT_EQ(NO_ERROR, gs.Execute(&requests)); 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(testGzFile, &gzFile)); ASSERT_TRUE(ReadFileToString(tf.path, &actual)); ASSERT_TRUE(ReadFileToString(tf.path, &actual)); expect = "\x2\xC6\x6\n\"" + testFile + "\x12\x9F\x6" + gzFile; // generates the expected protobuf result. EXPECT_THAT(actual, StrEq(expect)); 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) { TEST_F(SectionTest, GZipSectionNoFileFound) { GZipSection gs(NOOP_PARSER, "/tmp/nonexist1", "/tmp/nonexist2", NULL); GZipSection gs(NOOP_PARSER, "/tmp/nonexist1", "/tmp/nonexist2", NULL); requests.setMainFd(STDOUT_FILENO); requests.setMainFd(STDOUT_FILENO); ASSERT_EQ(-1, gs.Execute(&requests)); ASSERT_EQ(NO_ERROR, gs.Execute(&requests)); } } TEST_F(SectionTest, CommandSectionConstructor) { TEST_F(SectionTest, CommandSectionConstructor) { Loading core/proto/android/os/incident.proto +2 −2 Original line number Original line Diff line number Diff line Loading @@ -175,9 +175,9 @@ message IncidentProto { ]; ]; optional GZippedFileProto last_kmsg = 2007 [ 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", (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 // System Services Loading Loading
cmds/incidentd/src/Section.cpp +4 −2 Original line number Original line Diff line number Diff line Loading @@ -319,8 +319,10 @@ status_t GZipSection::Execute(ReportRequestSet* requests) const { index++; // look at the next file. index++; // look at the next file. } } VLOG("GZipSection is using file %s, fd=%d", mFilenames[index], fd.get()); 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; FdBuffer buffer; Fpipe p2cPipe; Fpipe p2cPipe; Fpipe c2pPipe; Fpipe c2pPipe; Loading
cmds/incidentd/tests/PrivacyBuffer_test.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,7 @@ const uint8_t STRING_TYPE = 9; const uint8_t MESSAGE_TYPE = 11; const uint8_t MESSAGE_TYPE = 11; const string STRING_FIELD_0 = "\x02\viamtestdata"; const string STRING_FIELD_0 = "\x02\viamtestdata"; const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150 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 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 FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1 const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2; const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2; Loading
cmds/incidentd/tests/Section_test.cpp +16 −5 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <android-base/file.h> #include <android-base/file.h> #include <android-base/test_utils.h> #include <android-base/test_utils.h> #include <android/os/IncidentReportArgs.h> #include <android/os/IncidentReportArgs.h> #include <android/util/protobuf.h> #include <frameworks/base/libs/incident/proto/android/os/header.pb.h> #include <frameworks/base/libs/incident/proto/android/os/header.pb.h> #include <gmock/gmock.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <gtest/gtest.h> Loading @@ -31,12 +32,13 @@ const int REVERSE_PARSER = 1; const int QUICK_TIMEOUT_MS = 100; const int QUICK_TIMEOUT_MS = 100; const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150 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 FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1 using namespace android::base; using namespace android::base; using namespace android::binder; using namespace android::binder; using namespace android::os; using namespace android::os; using namespace android::util; using namespace std; using namespace std; using ::testing::StrEq; using ::testing::StrEq; using ::testing::Test; using ::testing::Test; Loading Loading @@ -154,17 +156,26 @@ TEST_F(SectionTest, GZipSection) { requests.setMainDest(android::os::DEST_LOCAL); requests.setMainDest(android::os::DEST_LOCAL); ASSERT_EQ(NO_ERROR, gs.Execute(&requests)); 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(testGzFile, &gzFile)); ASSERT_TRUE(ReadFileToString(tf.path, &actual)); ASSERT_TRUE(ReadFileToString(tf.path, &actual)); expect = "\x2\xC6\x6\n\"" + testFile + "\x12\x9F\x6" + gzFile; // generates the expected protobuf result. EXPECT_THAT(actual, StrEq(expect)); 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) { TEST_F(SectionTest, GZipSectionNoFileFound) { GZipSection gs(NOOP_PARSER, "/tmp/nonexist1", "/tmp/nonexist2", NULL); GZipSection gs(NOOP_PARSER, "/tmp/nonexist1", "/tmp/nonexist2", NULL); requests.setMainFd(STDOUT_FILENO); requests.setMainFd(STDOUT_FILENO); ASSERT_EQ(-1, gs.Execute(&requests)); ASSERT_EQ(NO_ERROR, gs.Execute(&requests)); } } TEST_F(SectionTest, CommandSectionConstructor) { TEST_F(SectionTest, CommandSectionConstructor) { Loading
core/proto/android/os/incident.proto +2 −2 Original line number Original line Diff line number Diff line Loading @@ -175,9 +175,9 @@ message IncidentProto { ]; ]; optional GZippedFileProto last_kmsg = 2007 [ 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", (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 // System Services Loading