diff options
author | Alex Deymo <deymo@chromium.org> | 2014-03-25 17:53:56 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-03-26 05:34:44 +0000 |
commit | 032e772f76a6cd0b4caf1af7bd02dd81af2dc7dd (patch) | |
tree | 73f75c03ae5c589e8bfe2781c4e4faa8b4701113 /utils_unittest.cc | |
parent | 04f2b380d4707a3903098a7459443c9509745943 (diff) |
Log the file format of cros_install on postinstall action
This patch adds a new function to utils which determines the format
of a file based on magic constants on the header and returns a
human-readable description of it. This currently only supports ELF
files and is used to log the file format of the cros_install
binary on post-install.
BUG=chromium:356187
TEST=Unittests.
Change-Id: Ie6e91c3f5fa398c39894704db9071489560a8ff7
Reviewed-on: https://chromium-review.googlesource.com/191609
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'utils_unittest.cc')
-rw-r--r-- | utils_unittest.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/utils_unittest.cc b/utils_unittest.cc index d75a6b04..ef771b9f 100644 --- a/utils_unittest.cc +++ b/utils_unittest.cc @@ -327,6 +327,48 @@ TEST(UtilsTest, GetInstallDevTest) { } namespace { +void GetFileFormatTester(const string& expected, + const vector<uint8>& contents) { + ScopedTempFile file; + ASSERT_TRUE(utils::WriteFile(file.GetPath().c_str(), + reinterpret_cast<const char*>(contents.data()), + contents.size())); + EXPECT_EQ(expected, utils::GetFileFormat(file.GetPath())); +} +} + +TEST(UtilsTest, GetFileFormatTest) { + EXPECT_EQ("File not found.", utils::GetFileFormat("/path/to/nowhere")); + GetFileFormatTester("data", vector<uint8>{1, 2, 3, 4, 5, 6, 7, 8}); + GetFileFormatTester("ELF", vector<uint8>{0x7f, 0x45, 0x4c, 0x46}); + + // Real tests from cros_installer on different boards. + // ELF 32-bit LSB executable, Intel 80386 + GetFileFormatTester( + "ELF 32-bit little-endian x86", + vector<uint8>{0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x90, 0x83, 0x04, 0x08, 0x34, 0x00, 0x00, 0x00}); + + // ELF 32-bit LSB executable, ARM + GetFileFormatTester( + "ELF 32-bit little-endian arm", + vector<uint8>{0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x85, 0x8b, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00}); + + // ELF 64-bit LSB executable, x86-64 + GetFileFormatTester( + "ELF 64-bit little-endian x86-64", + vector<uint8>{0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xb0, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00}); +} + +namespace { gboolean TerminateScheduleCrashReporterUploadTest(void* arg) { GMainLoop* loop = reinterpret_cast<GMainLoop*>(arg); g_main_loop_quit(loop); |