diff options
-rw-r--r-- | SConstruct | 19 | ||||
-rw-r--r-- | action_processor.cc | 2 | ||||
-rw-r--r-- | bzip.cc | 22 | ||||
-rw-r--r-- | decompressing_file_writer_unittest.cc | 3 | ||||
-rw-r--r-- | delta_diff_generator.cc | 3 | ||||
-rw-r--r-- | extent_writer.h | 6 | ||||
-rw-r--r-- | gzip.cc | 2 | ||||
-rw-r--r-- | http_fetcher_unittest.cc | 14 | ||||
-rw-r--r-- | mock_http_fetcher.h | 1 | ||||
-rw-r--r-- | subprocess.cc | 29 | ||||
-rw-r--r-- | test_http_server.cc | 9 | ||||
-rw-r--r-- | test_utils.cc | 9 | ||||
-rw-r--r-- | update_check_action.cc | 4 | ||||
-rw-r--r-- | update_check_action_unittest.cc | 11 | ||||
-rw-r--r-- | utils.cc | 2 |
15 files changed, 88 insertions, 48 deletions
@@ -40,8 +40,23 @@ proto_builder = Builder(generator = ProtocolBufferGenerator, suffix = '.pb.cc') env = Environment() +for key in Split('CC CXX AR RANLIB LD NM'): + value = os.environ.get(key) + if value != None: + env[key] = value +for key in Split('CFLAGS CCFLAGS CPPPATH LIBPATH'): + value = os.environ.get(key) + if value != None: + env[key] = Split(value) + +for key in Split('PKG_CONFIG_LIBDIR PKG_CONFIG_PATH SYSROOT'): + if os.environ.has_key(key): + env['ENV'][key] = os.environ[key] + + env['CCFLAGS'] = ' '.join("""-g -fno-exceptions + -fno-strict-aliasing -Wall -Werror -Wclobbered @@ -51,10 +66,13 @@ env['CCFLAGS'] = ' '.join("""-g -Wsign-compare -Wtype-limits -Wuninitialized + -D__STDC_FORMAT_MACROS=1 -D_FILE_OFFSET_BITS=64 -I/usr/include/libxml2""".split()); +env['CCFLAGS'] += (' ' + ' '.join(env['CFLAGS'])) env['LIBS'] = Split("""base + bz2 curl gflags glib-2.0 @@ -123,7 +141,6 @@ unittest_sources = Split("""action_unittest.cc extent_mapper_unittest.cc extent_writer_unittest.cc file_writer_unittest.cc - filesystem_copier_action_unittest.cc filesystem_iterator_unittest.cc graph_utils_unittest.cc http_fetcher_unittest.cc diff --git a/action_processor.cc b/action_processor.cc index d58b5ee3..e52cbcdc 100644 --- a/action_processor.cc +++ b/action_processor.cc @@ -4,7 +4,7 @@ #include "update_engine/action_processor.h" #include <string> -#include "chromeos/obsolete_logging.h" +#include "base/logging.h" #include "update_engine/action.h" using std::string; @@ -20,9 +20,9 @@ namespace { // Returns true on success. // Use one of BzipBuffToBuff*ompress as the template parameter to BzipData(). int BzipBuffToBuffDecompress(char* out, - size_t* out_length, + uint32_t* out_length, const char* in, - size_t in_length) { + uint32_t in_length) { return BZ2_bzBuffToBuffDecompress(out, out_length, const_cast<char*>(in), @@ -32,9 +32,9 @@ int BzipBuffToBuffDecompress(char* out, } int BzipBuffToBuffCompress(char* out, - size_t* out_length, + uint32_t* out_length, const char* in, - size_t in_length) { + uint32_t in_length) { return BZ2_bzBuffToBuffCompress(out, out_length, const_cast<char*>(in), @@ -45,11 +45,11 @@ int BzipBuffToBuffCompress(char* out, } template<int F(char* out, - size_t* out_length, + uint32_t* out_length, const char* in, - size_t in_length)> + uint32_t in_length)> bool BzipData(const char* const in, - const size_t in_size, + const int32_t in_size, vector<char>* const out) { TEST_AND_RETURN_FALSE(out); out->clear(); @@ -61,7 +61,7 @@ bool BzipData(const char* const in, out->resize(buf_size); for (;;) { - size_t data_size = buf_size; + uint32_t data_size = buf_size; int rc = F(&(*out)[0], &data_size, in, in_size); TEST_AND_RETURN_FALSE(rc == BZ_OUTBUFF_FULL || rc == BZ_OK); if (rc == BZ_OK) { @@ -79,7 +79,9 @@ bool BzipData(const char* const in, } // namespace {} bool BzipDecompress(const std::vector<char>& in, std::vector<char>* out) { - return BzipData<BzipBuffToBuffDecompress>(&in[0], in.size(), out); + return BzipData<BzipBuffToBuffDecompress>(&in[0], + static_cast<int32_t>(in.size()), + out); } bool BzipCompress(const std::vector<char>& in, std::vector<char>* out) { @@ -88,7 +90,7 @@ bool BzipCompress(const std::vector<char>& in, std::vector<char>* out) { namespace { template<bool F(const char* const in, - const size_t in_size, + const int32_t in_size, vector<char>* const out)> bool BzipString(const std::string& str, std::vector<char>* out) { diff --git a/decompressing_file_writer_unittest.cc b/decompressing_file_writer_unittest.cc index 1d689e7c..c1666dbc 100644 --- a/decompressing_file_writer_unittest.cc +++ b/decompressing_file_writer_unittest.cc @@ -75,7 +75,8 @@ TEST(GzipDecompressingFileWriterTest, LargeTest) { uncompressed_file.Close(); // compress the file - system((string("cat ") + kPath + " | gzip > " + kPathgz).c_str()); + EXPECT_EQ(0, + system((string("cat ") + kPath + " | gzip > " + kPathgz).c_str())); // Now read the compressed file and put it into a DecompressingFileWriter MockFileWriter mock_file_writer; diff --git a/delta_diff_generator.cc b/delta_diff_generator.cc index 4181057b..74bcaa0d 100644 --- a/delta_diff_generator.cc +++ b/delta_diff_generator.cc @@ -691,7 +691,6 @@ bool DeltaDiffGenerator::GenerateDeltaUpdateFile(const string& old_root, vector<Block> blocks(min(old_image_stbuf.st_size / kBlockSize, new_image_stbuf.st_size / kBlockSize)); - LOG(INFO) << "blocks (orig): " << (uint32)(&blocks); LOG(INFO) << "w:" << blocks[4097].writer; LOG(INFO) << "invalid: " << Vertex::kInvalidIndex; LOG(INFO) << "len: " << blocks.size(); @@ -826,7 +825,7 @@ bool DeltaDiffGenerator::GenerateDeltaUpdateFile(const string& old_root, // Write header TEST_AND_RETURN_FALSE(writer.Write(kDeltaMagic, strlen(kDeltaMagic)) == - strlen(kDeltaMagic)); + static_cast<ssize_t>(strlen(kDeltaMagic))); // Write version number TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer, kVersionNumber)); diff --git a/extent_writer.h b/extent_writer.h index cbb62fef..b250babc 100644 --- a/extent_writer.h +++ b/extent_writer.h @@ -29,7 +29,7 @@ class ExtentWriter { // Returns true on success. virtual bool Init(int fd, const std::vector<Extent>& extents, - size_t block_size) = 0; + uint32_t block_size) = 0; // Returns true on success. virtual bool Write(const void* bytes, size_t count) = 0; @@ -57,7 +57,7 @@ class DirectExtentWriter : public ExtentWriter { next_extent_index_(0) {} ~DirectExtentWriter() {} - bool Init(int fd, const std::vector<Extent>& extents, size_t block_size) { + bool Init(int fd, const std::vector<Extent>& extents, uint32_t block_size) { fd_ = fd; block_size_ = block_size; extents_ = extents; @@ -92,7 +92,7 @@ class ZeroPadExtentWriter : public ExtentWriter { bytes_written_mod_block_size_(0) {} ~ZeroPadExtentWriter() {} - bool Init(int fd, const std::vector<Extent>& extents, size_t block_size) { + bool Init(int fd, const std::vector<Extent>& extents, uint32_t block_size) { block_size_ = block_size; return underlying_extent_writer_->Init(fd, extents, block_size); } @@ -93,7 +93,7 @@ bool GzipCompressData(const char* const in, const size_t in_size, Z_DEFAULT_STRATEGY) == Z_OK); // guess that output will be roughly half the input size - *out_size = max(1U, in_size / 2); + *out_size = max(static_cast<size_t>(1), in_size / 2); *out = reinterpret_cast<char*>(malloc(*out_size)); TEST_AND_RETURN_FALSE(*out); diff --git a/http_fetcher_unittest.cc b/http_fetcher_unittest.cc index 8d9c3f83..a0e620b8 100644 --- a/http_fetcher_unittest.cc +++ b/http_fetcher_unittest.cc @@ -61,6 +61,7 @@ class HttpFetcherTest<MockHttpFetcher> : public ::testing::Test { } bool IsMock() const { return true; } typedef NullHttpServer HttpServer; + void IgnoreServerAborting(HttpServer* server) const {} }; class PythonHttpServer { @@ -69,6 +70,7 @@ class PythonHttpServer { char *argv[2] = {strdup("./test_http_server"), NULL}; GError *err; started_ = false; + validate_quit_ = true; if (!g_spawn_async(NULL, argv, NULL, @@ -93,12 +95,15 @@ class PythonHttpServer { if (!started_) return; // request that the server exit itself - system((string("wget --output-document=/dev/null ") + - LocalServerUrlForPath("/quitquitquit")).c_str()); + int rc = system((string("wget -t 1 --output-document=/dev/null ") + + LocalServerUrlForPath("/quitquitquit")).c_str()); + if (validate_quit_) + EXPECT_EQ(0, rc); waitpid(pid_, NULL, 0); } GPid pid_; bool started_; + bool validate_quit_; }; template <> @@ -120,6 +125,10 @@ class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { } bool IsMock() const { return false; } typedef PythonHttpServer HttpServer; + void IgnoreServerAborting(HttpServer* server) const { + PythonHttpServer *pyserver = reinterpret_cast<PythonHttpServer*>(server); + pyserver->validate_quit_ = false; + } }; typedef ::testing::Types<LibcurlHttpFetcher, MockHttpFetcher> @@ -277,6 +286,7 @@ TYPED_TEST(HttpFetcherTest, AbortTest) { fetcher->set_delegate(&delegate); typename TestFixture::HttpServer server; + this->IgnoreServerAborting(&server); ASSERT_TRUE(server.started_); GSource* timeout_source_; timeout_source_ = g_timeout_source_new(0); // ms diff --git a/mock_http_fetcher.h b/mock_http_fetcher.h index 2efd258d..5b9f8987 100644 --- a/mock_http_fetcher.h +++ b/mock_http_fetcher.h @@ -29,7 +29,6 @@ class MockHttpFetcher : public HttpFetcher { MockHttpFetcher(const char* data, size_t size) : sent_size_(0), timeout_source_(NULL), timout_tag_(0), paused_(false) { data_.insert(data_.end(), data, data + size); - LOG(INFO) << "timeout_source_ = " << (int)timeout_source_; } // Cleans up all internal state. Does not notify delegate diff --git a/subprocess.cc b/subprocess.cc index 89b6cadd..3a6597eb 100644 --- a/subprocess.cc +++ b/subprocess.cc @@ -9,6 +9,7 @@ #include <vector> #include "chromeos/obsolete_logging.h" #include "base/scoped_ptr.h" +#include "base/string_util.h" using std::string; using std::vector; @@ -18,7 +19,7 @@ namespace chromeos_update_engine { void Subprocess::GChildExitedCallback(GPid pid, gint status, gpointer data) { COMPILE_ASSERT(sizeof(guint) == sizeof(uint32), guint_uint32_size_mismatch); - guint *tag = reinterpret_cast<guint*>(data); + guint* tag = reinterpret_cast<guint*>(data); const SubprocessCallbackRecord& record = Get().callback_records_[*tag]; if (record.callback) record.callback(status, record.callback_data); @@ -38,16 +39,22 @@ void FreeArgv(char** argv) { uint32 Subprocess::Exec(const std::vector<std::string>& cmd, ExecCallback callback, - void *p) { + void* p) { GPid child_pid; - GError *err; - scoped_array<char *> argv(new char*[cmd.size() + 1]); + GError* err; + scoped_array<char*> argv(new char*[cmd.size() + 1]); for (unsigned int i = 0; i < cmd.size(); i++) { argv[i] = strdup(cmd[i].c_str()); } argv[cmd.size()] = NULL; - char *argp[1]; - argp[0] = NULL; + + scoped_array<char*> argp(new char*[2]); + argp[0] = argp[1] = NULL; + const char* kLdLibraryPathKey = "LD_LIBRARY_PATH"; + if (getenv(kLdLibraryPathKey)) { + argp[0] = strdup(StringPrintf("%s=%s", kLdLibraryPathKey, + getenv(kLdLibraryPathKey)).c_str()); + } SubprocessCallbackRecord callback_record; callback_record.callback = callback; @@ -55,7 +62,7 @@ uint32 Subprocess::Exec(const std::vector<std::string>& cmd, bool success = g_spawn_async(NULL, // working directory argv.get(), - argp, + argp.get(), G_SPAWN_DO_NOT_REAP_CHILD, // flags NULL, // child setup function NULL, // child setup data pointer @@ -66,7 +73,7 @@ uint32 Subprocess::Exec(const std::vector<std::string>& cmd, LOG(ERROR) << "g_spawn_async failed"; return 0; } - guint *tag = new guint; + guint* tag = new guint; *tag = g_child_watch_add(child_pid, GChildExitedCallback, tag); callback_records_[*tag] = callback_record; return *tag; @@ -80,13 +87,13 @@ void Subprocess::CancelExec(uint32 tag) { bool Subprocess::SynchronousExec(const std::vector<std::string>& cmd, int* return_code) { - GError *err = NULL; - scoped_array<char *> argv(new char*[cmd.size() + 1]); + GError* err = NULL; + scoped_array<char*> argv(new char*[cmd.size() + 1]); for (unsigned int i = 0; i < cmd.size(); i++) { argv[i] = strdup(cmd[i].c_str()); } argv[cmd.size()] = NULL; - char *argp[1]; + char* argp[1]; argp[0] = NULL; bool success = g_spawn_sync(NULL, // working directory diff --git a/test_http_server.cc b/test_http_server.cc index 94c88fa1..9fbe97f5 100644 --- a/test_http_server.cc +++ b/test_http_server.cc @@ -14,6 +14,7 @@ #include <sys/socket.h> #include <sys/types.h> #include <errno.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -98,7 +99,7 @@ void WriteString(int fd, const string& str) { string Itoa(off_t num) { char buf[100] = {0}; - snprintf(buf, sizeof(buf), "%lld", num); + snprintf(buf, sizeof(buf), "%" PRIi64, num); return buf; } @@ -120,6 +121,7 @@ void WriteHeaders(int fd, bool support_range, off_t full_size, } void HandleQuitQuitQuit(int fd) { + WriteHeaders(fd, true, 0, 0); exit(0); } @@ -142,14 +144,15 @@ void HandleBig(int fd, const HttpRequest& request) { void HandleFlaky(int fd, const HttpRequest& request) { const off_t full_length = kBigLength; WriteHeaders(fd, true, full_length, request.offset); - const off_t content_length = min(9000LL, full_length - request.offset); + const off_t content_length = + min(static_cast<off_t>(9000), full_length - request.offset); const bool should_sleep = (request.offset % (9000 * 7)) == 0; string buf; for (int i = request.offset; i % 10; i++) buf.append(1, 'a' + (i % 10)); - while (buf.size() < content_length) + while (static_cast<off_t>(buf.size()) < content_length) buf.append("abcdefghij"); buf.resize(content_length); diff --git a/test_utils.cc b/test_utils.cc index 1c2f8959..6a860254 100644 --- a/test_utils.cc +++ b/test_utils.cc @@ -57,14 +57,15 @@ std::string Readlink(const std::string& path) { std::vector<char> GzipCompressData(const std::vector<char>& data) { const char fname[] = "/tmp/GzipCompressDataTemp"; if (!WriteFileVector(fname, data)) { - system((string("rm ") + fname).c_str()); + EXPECT_EQ(0, system((string("rm ") + fname).c_str())); return vector<char>(); } - system((string("cat ") + fname + "|gzip>" + fname + ".gz").c_str()); - system((string("rm ") + fname).c_str()); + EXPECT_EQ(0, system((string("cat ") + fname + "|gzip>" + + fname + ".gz").c_str())); + EXPECT_EQ(0, system((string("rm ") + fname).c_str())); vector<char> ret; EXPECT_TRUE(utils::ReadFile(string(fname) + ".gz", &ret)); - system((string("rm ") + fname + ".gz").c_str()); + EXPECT_EQ(0, system((string("rm ") + fname + ".gz").c_str())); return ret; } diff --git a/update_check_action.cc b/update_check_action.cc index a9d303cb..b92e7886 100644 --- a/update_check_action.cc +++ b/update_check_action.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "update_engine/update_check_action.h" +#include <inttypes.h> #include <sstream> #include <libxml/parser.h> @@ -172,8 +173,7 @@ string XmlGetProperty(xmlNode* node, const char* name) { // error. off_t ParseInt(const string& str) { off_t ret = 0; - - int rc = sscanf(str.c_str(), "%lld", &ret); + int rc = sscanf(str.c_str(), "%" PRIi64, &ret); if (rc < 1) { // failure return 0; diff --git a/update_check_action_unittest.cc b/update_check_action_unittest.cc index 417a47e3..c57e2cd0 100644 --- a/update_check_action_unittest.cc +++ b/update_check_action_unittest.cc @@ -93,6 +93,7 @@ class ActionTraits<OutputObjectCollectorAction> { class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { public: + OutputObjectCollectorAction() : has_input_object_(false) {} void PerformAction() { // copy input object has_input_object_ = HasInputObject(); @@ -249,7 +250,7 @@ TEST(UpdateCheckActionTest, InvalidXmlTest) { "en-US", "unittest_track"); UpdateCheckResponse response; - ASSERT_TRUE( + ASSERT_FALSE( TestUpdateCheckAction(params, "invalid xml>", false, @@ -269,7 +270,7 @@ TEST(UpdateCheckActionTest, MissingStatusTest) { "en-US", "unittest_track"); UpdateCheckResponse response; - ASSERT_TRUE(TestUpdateCheckAction( + ASSERT_FALSE(TestUpdateCheckAction( params, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " @@ -292,7 +293,7 @@ TEST(UpdateCheckActionTest, InvalidStatusTest) { "en-US", "unittest_track"); UpdateCheckResponse response; - ASSERT_TRUE(TestUpdateCheckAction( + ASSERT_FALSE(TestUpdateCheckAction( params, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " @@ -315,7 +316,7 @@ TEST(UpdateCheckActionTest, MissingNodesetTest) { "en-US", "unittest_track"); UpdateCheckResponse response; - ASSERT_TRUE(TestUpdateCheckAction( + ASSERT_FALSE(TestUpdateCheckAction( params, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " @@ -435,7 +436,7 @@ TEST(UpdateCheckActionTest, XmlEncodeTest) { "en-US", "unittest_track"); UpdateCheckResponse response; - ASSERT_TRUE( + ASSERT_FALSE( TestUpdateCheckAction(params, "invalid xml>", false, @@ -80,7 +80,7 @@ void HexDumpArray(const unsigned char* const arr, const size_t length) { reinterpret_cast<const unsigned char* const>(arr); LOG(INFO) << "Logging array of length: " << length; const unsigned int bytes_per_line = 16; - for (size_t i = 0; i < length; i += bytes_per_line) { + for (uint32_t i = 0; i < length; i += bytes_per_line) { const unsigned int bytes_remaining = length - i; const unsigned int bytes_per_this_line = min(bytes_per_line, bytes_remaining); |