Coverage for /Syzygy/agent/asan/asan_logger_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%25250.C++test

Line-by-line coverage:

   1    :  // Copyright 2012 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  
  15    :  #include "syzygy/agent/asan/asan_logger.h"
  16    :  
  17    :  #include <string>
  18    :  
  19    :  #include "base/environment.h"
  20    :  #include "base/file_path.h"
  21    :  #include "base/file_util.h"
  22    :  #include "base/scoped_temp_dir.h"
  23    :  #include "base/string_util.h"
  24    :  #include "base/stringprintf.h"
  25    :  #include "base/utf_string_conversions.h"
  26    :  #include "base/memory/scoped_ptr.h"
  27    :  #include "gmock/gmock.h"
  28    :  #include "gtest/gtest.h"
  29    :  #include "syzygy/trace/logger/logger.h"
  30    :  #include "syzygy/trace/logger/logger_rpc_impl.h"
  31    :  #include "syzygy/trace/protocol/call_trace_defs.h"
  32    :  
  33    :  namespace agent {
  34    :  namespace asan {
  35    :  
  36    :  namespace {
  37    :  
  38    :  class TestAsanLogger : public AsanLogger {
  39    :   public:
  40    :    using AsanLogger::instance_id_;
  41    :    using AsanLogger::rpc_binding_;
  42    :  };
  43    :  
  44    :  }  // namespace
  45    :  
  46  E :  TEST(AsanLoggerTest, EndToEnd) {
  47    :    // Setup the instance id.
  48  E :    std::wstring instance_id(base::StringPrintf(L"%d", ::GetCurrentProcessId()));
  49    :  
  50    :    // The location to which we'll write log messages.
  51  E :    ScopedTempDir temp_dir;
  52  E :    ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
  53  E :    FilePath temp_path(temp_dir.path().Append(L"log.txt"));
  54  E :    const std::string kMessage("This is the test message\n");
  55    :  
  56    :    {
  57    :      // Setup a log file destination.
  58  E :      file_util::ScopedFILE destination(file_util::OpenFile(temp_path, "wb"));
  59    :  
  60    :      // Start up the logging service.
  61  E :      trace::logger::Logger server;
  62  E :      trace::logger::RpcLoggerInstanceManager instance_manager(&server);
  63  E :      server.set_instance_id(instance_id);
  64  E :      server.set_destination(destination.get());
  65  E :      ASSERT_TRUE(server.Start());
  66    :  
  67    :      // Create and use the AsanLogger client.
  68  E :      TestAsanLogger client;
  69  E :      client.set_instance_id(instance_id);
  70  E :      client.Init();
  71  E :      ASSERT_EQ(instance_id, client.instance_id_);
  72  E :      ASSERT_TRUE(client.rpc_binding_.Get() != NULL);
  73  E :      client.Write(kMessage);
  74    :  
  75    :      // Shutdown the logging service.
  76  E :      ASSERT_TRUE(server.Stop());
  77  E :      ASSERT_TRUE(server.RunToCompletion());
  78  E :    }
  79    :  
  80  E :    std::string content;
  81  E :    ASSERT_TRUE(file_util::ReadFileToString(temp_path, &content));
  82  E :    ASSERT_THAT(content, testing::EndsWith(kMessage));
  83  E :  }
  84    :  
  85    :  }  // namespace asan
  86    :  }  // namespace agent

Coverage information generated Thu Mar 14 11:53:36 2013.