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_MOCK_SERVICE_H_
16 : #define SYZYGY_KASKO_TESTING_MOCK_SERVICE_H_
17 :
18 : #include <stdint.h>
19 :
20 : #include <map>
21 : #include <string>
22 : #include <vector>
23 :
24 : #include "base/macros.h"
25 : #include "base/process/process_handle.h"
26 : #include "base/strings/string16.h"
27 : #include "base/threading/platform_thread.h"
28 : #include "syzygy/kasko/minidump_request.h"
29 : #include "syzygy/kasko/service.h"
30 :
31 m : namespace kasko {
32 m : namespace testing {
33 :
34 : // Handles Kasko RPC invocations by logging their parameters.
35 m : class MockService : public Service {
36 m : public:
37 : // Records the parameters of an RPC invocation.
38 m : struct CallRecord {
39 : // The caller process ID.
40 m : const base::ProcessId client_process_id;
41 :
42 : // The supplied exception info address.
43 m : uint32_t exception_info_address;
44 :
45 : // The supplied thread id.
46 m : base::PlatformThreadId thread_id;
47 :
48 : // The requested minidump type.
49 m : MinidumpRequest::Type minidump_type;
50 :
51 : // The supplied memory ranges.
52 m : const std::vector<MinidumpRequest::MemoryRange> user_selected_memory_ranges;
53 :
54 : // The supplied crash keys.
55 m : const std::map<base::string16, base::string16> crash_keys;
56 :
57 : // The supplied custom streams.
58 m : const std::map<uint32_t, std::string> custom_streams;
59 m : };
60 :
61 : // Instantiates a service that records calls in the provided vector.
62 : // @param call_log The vector in which calls should be recorded.
63 : // @note call_log will be modified in whichever thread the RPC is handled.
64 : // It is the client's responsibility to prevent problems from concurrent
65 : // access.
66 m : explicit MockService(std::vector<CallRecord>* call_log);
67 m : virtual ~MockService();
68 :
69 : // Service implementation.
70 m : virtual void SendDiagnosticReport(base::ProcessId client_process_id,
71 m : base::PlatformThreadId thread_id,
72 m : const MinidumpRequest& request) override;
73 :
74 m : private:
75 m : std::vector<CallRecord>* call_log_;
76 :
77 m : DISALLOW_COPY_AND_ASSIGN(MockService);
78 m : };
79 :
80 m : } // namespace testing
81 m : } // namespace kasko
82 :
83 : #endif // SYZYGY_KASKO_TESTING_MOCK_SERVICE_H_
|