1 : // Copyright 2013 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_AGENT_ASAN_UNITTEST_UTIL_H_
16 : #define SYZYGY_AGENT_ASAN_UNITTEST_UTIL_H_
17 :
18 : #include "base/file_util.h"
19 : #include "base/scoped_temp_dir.h"
20 : #include "base/string_piece.h"
21 : #include "gtest/gtest.h"
22 : #include "syzygy/trace/logger/logger.h"
23 : #include "syzygy/trace/logger/logger_rpc_impl.h"
24 :
25 : namespace testing {
26 :
27 : // A unittest fixture that ensures that an ASAN logger instance is up and
28 : // running for the duration of the test. Output is captured to a file so that
29 : // its contents can be read after the test if necessary.
30 : class TestWithAsanLogger : public testing::Test {
31 : public:
32 : TestWithAsanLogger();
33 :
34 : // @name testing::Test overrides.
35 : // @{
36 : void SetUp() OVERRIDE;
37 : void TearDown() OVERRIDE;
38 : // @}
39 :
40 : // @name Accessors.
41 : // @{
42 E : const std::wstring& instance_id() const { return instance_id_; }
43 : const FilePath& log_file_path() const { return log_file_path_; }
44 : const FilePath& temp_dir() const { return temp_dir_.path(); }
45 : // @}
46 :
47 : bool LogContains(const base::StringPiece& message);
48 :
49 : private:
50 : // The log service instance.
51 : trace::logger::Logger log_service_;
52 :
53 : // Manages the binding between the RPC stub functions and a log service
54 : // instance.
55 : trace::logger::RpcLoggerInstanceManager log_service_instance_;
56 :
57 : // The instance ID used by the running logger instance.
58 : std::wstring instance_id_;
59 :
60 : // The path to the log file where the the logger instance will write.
61 : FilePath log_file_path_;
62 :
63 : // The open file handle, if any to which the logger instance will write.
64 : file_util::ScopedFILE log_file_;
65 :
66 : // A temporary directory into which the log file will be written.
67 : ScopedTempDir temp_dir_;
68 :
69 : // The contents of the log. These are read by calling LogContains.
70 : bool log_contents_read_;
71 : std::string log_contents_;
72 : };
73 :
74 : } // namespace testing
75 :
76 : #endif // SYZYGY_AGENT_ASAN_UNITTEST_UTIL_H_
|