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 : #ifndef SYZYGY_PE_UNITTEST_UTIL_H_
16 : #define SYZYGY_PE_UNITTEST_UTIL_H_
17 :
18 : #include <windows.h>
19 :
20 : #include "base/file_util.h"
21 : #include "base/files/file_path.h"
22 : #include "gtest/gtest.h"
23 : #include "syzygy/common/unittest_util.h"
24 :
25 : namespace testing {
26 :
27 : // Name of the test DLL and PDB. These exist in the output directory, and again
28 : // in the test_data directory.
29 : extern const wchar_t kTestDllName[];
30 : extern const wchar_t kTestDllPdbName[];
31 :
32 : // Name of the various test DLLs generated by the test_data project.
33 : // These are placed in $(OutputDir)\test_data, so use
34 : // GetExeTestDataRelativePath to build paths to them.
35 : extern const wchar_t kAsanInstrumentedTestDllName[];
36 : extern const wchar_t kAsanInstrumentedTestDllPdbName[];
37 : extern const wchar_t kBBEntryInstrumentedTestDllName[];
38 : extern const wchar_t kBBEntryInstrumentedTestDllPdbName[];
39 : extern const wchar_t kCallTraceInstrumentedTestDllName[];
40 : extern const wchar_t kCallTraceInstrumentedTestDllPdbName[];
41 : extern const wchar_t kCoverageInstrumentedTestDllName[];
42 : extern const wchar_t kCoverageInstrumentedTestDllPdbName[];
43 : extern const wchar_t kProfileInstrumentedTestDllName[];
44 : extern const wchar_t kProfileInstrumentedTestDllPdbName[];
45 : extern const wchar_t kRandomizedTestDllName[];
46 : extern const wchar_t kRandomizedTestDllPdbName[];
47 :
48 : // Name of the various trace files. These are also relative to the test data
49 : // directory.
50 : extern const wchar_t *kBBEntryTraceFiles[4];
51 : extern const wchar_t *kCallTraceTraceFiles[4];
52 : extern const wchar_t *kCoverageTraceFiles[4];
53 : extern const wchar_t *kProfileTraceFiles[4];
54 :
55 : // This class wraps an HMODULE and ensures that ::FreeLibrary is called when it
56 : // goes out of scope.
57 : class ScopedHMODULE {
58 : public:
59 : ScopedHMODULE();
60 : explicit ScopedHMODULE(HMODULE v);
61 : ~ScopedHMODULE();
62 :
63 : void Reset(HMODULE v);
64 : void Release();
65 :
66 E : operator HMODULE() const {
67 E : return value_;
68 E : }
69 :
70 : private:
71 : HMODULE value_;
72 : };
73 :
74 : class PELibUnitTest : public testing::ApplicationTestBase {
75 : public:
76 : // Performs a series of assertions on the test DLL's integrity.
77 : static void CheckTestDll(const base::FilePath& path);
78 :
79 : // Performs a series of assertions on the test DLL's integrity, and returns
80 : // the module handle to allow more tests to be executed.
81 : static void CheckTestDll(const base::FilePath& path, ScopedHMODULE* module);
82 : };
83 :
84 : } // namespace testing
85 :
86 : #endif // SYZYGY_PE_UNITTEST_UTIL_H_
|