Coverage for /Syzygy/kasko/testing/upload_observer.h

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

Line-by-line coverage:

   1    :  // Copyright 2015 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    :  #ifndef SYZYGY_KASKO_TESTING_UPLOAD_OBSERVER_H_
  16    :  #define SYZYGY_KASKO_TESTING_UPLOAD_OBSERVER_H_
  17    :  
  18    :  #include <map>
  19    :  #include <string>
  20    :  
  21    :  #include "base/macros.h"
  22    :  #include "base/files/file_path.h"
  23    :  #include "base/synchronization/waitable_event.h"
  24    :  #include "base/threading/simple_thread.h"
  25    :  
  26    :  namespace kasko {
  27    :  namespace testing {
  28    :  
  29    :  // Observes an upload directory and a permanent failure directory to allow tests
  30    :  // to observe when a crash report has either been successfully uploaded or has
  31    :  // permanently failed. Requires the observed directories to be empty before
  32    :  // beginning observation.
  33    :  class UploadObserver {
  34    :   public:
  35    :    // Instantiates an instance to watch the supplied directories. The instance
  36    :    // must be created before upload attempts begin. The instance is actively
  37    :    // observing by the time the constructor returns.
  38    :    // @param upload_directory The 'incoming' directory of the TestServer instance
  39    :    //     that is listening for crash reports.
  40    :    // @param permanent_failure_directory The permanent failure directory
  41    :    //     parameter of the reporter under test.
  42    :    UploadObserver(const base::FilePath& upload_directory,
  43    :                   const base::FilePath& permanent_failure_directory);
  44    :    ~UploadObserver();
  45    :  
  46    :    // Blocks until a crash report appears in either the upload or permanent
  47    :    // failure directory. Returns immediately if the report already appeared since
  48    :    // the constructor invocation.
  49    :    // @param minidump_path Receives the path to the minidump from the uploaded
  50    :    //     crash report.
  51    :    // @param crash_keys Receives the crash keys from the uploaded crash
  52    :    //     report.
  53    :    // @param upload_success Will be set to true if the report appeared in the
  54    :    //     upload directory and false if it appeared in the permanent failure
  55    :    //     directory.
  56    :    void WaitForUpload(base::FilePath* minidump_path,
  57    :                       std::map<std::string, std::string>* crash_keys,
  58    :                       bool* upload_success);
  59    :  
  60    :   private:
  61    :    class UploadObserverThread : public base::SimpleThread {
  62    :     public:
  63    :      UploadObserverThread(const base::FilePath& upload_directory,
  64    :                           const base::FilePath& permanent_failure_directory);
  65    :      ~UploadObserverThread() override;
  66    :  
  67  E :      const base::FilePath& minidump_path() { return minidump_path_; }
  68  E :      const std::map<std::string, std::string>& crash_keys() {
  69  E :        return crash_keys_;
  70  E :      }
  71  E :      bool upload_success() { return upload_success_; }
  72    :  
  73    :      void WaitUntilReady();
  74    :  
  75    :      // base::SimpleThread implementation.
  76    :      void Run() override;
  77    :  
  78    :     private:
  79    :      void WatchForPermanentFailure(const base::FilePath& path, bool error);
  80    :      void WatchForUpload(const base::FilePath& path, bool error);
  81    :  
  82    :      base::WaitableEvent ready_;
  83    :  
  84    :      base::FilePath upload_directory_;
  85    :      base::FilePath permanent_failure_directory_;
  86    :  
  87    :      base::FilePath minidump_path_;
  88    :      std::map<std::string, std::string> crash_keys_;
  89    :      bool upload_success_ = false;
  90    :  
  91    :      DISALLOW_COPY_AND_ASSIGN(UploadObserverThread);
  92    :    };
  93    :  
  94    :    UploadObserverThread thread_;
  95    :  
  96    :    DISALLOW_COPY_AND_ASSIGN(UploadObserver);
  97    :  };
  98    :  
  99    :  }  // namespace testing
 100    :  }  // namespace kasko
 101    :  
 102    :  #endif  // SYZYGY_KASKO_TESTING_UPLOAD_OBSERVER_H_

Coverage information generated Thu Jan 14 17:40:38 2016.