blob: 8941d0d10a35585be0ca1a853226f6c2a945af42 [file] [log] [blame]
Aaron Vaaged6482e12024-04-08 08:45:11 -07001/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "src/trace_redaction/trace_redaction_integration_fixture.h"
18
19#include "perfetto/ext/base/file_utils.h"
20#include "src/base/test/utils.h"
21
22namespace perfetto::trace_redaction {
23
24TraceRedactionIntegrationFixure::TraceRedactionIntegrationFixure() {
Aaron Vaaged6482e12024-04-08 08:45:11 -070025 dest_trace_ = tmp_dir_.AbsolutePath("dst.pftrace");
Aaron Vaage1a19e542024-06-12 09:05:23 -070026
27 // TODO: Most of the tests were written usng this trace. Those tests make a
28 // lot of assumption around using this trace. Those tests should be
29 // transitioned to the other constructor to remove this assumption.
30 SetSourceTrace("test/data/trace-redaction-general.pftrace");
31}
32
33void TraceRedactionIntegrationFixure::SetSourceTrace(
34 std::string_view source_file) {
35 src_trace_ = base::GetTestDataPath(std::string(source_file));
Aaron Vaaged6482e12024-04-08 08:45:11 -070036}
37
Aaron Vaage5b2ea112024-06-14 08:05:54 -070038base::Status TraceRedactionIntegrationFixure::Redact(
39 const TraceRedactor& redactor,
40 Context* context) {
41 auto status = redactor.Redact(src_trace_, dest_trace_, context);
Aaron Vaaged6482e12024-04-08 08:45:11 -070042
43 if (status.ok()) {
44 tmp_dir_.TrackFile("dst.pftrace");
45 }
46
47 return status;
48}
49
50base::StatusOr<std::string> TraceRedactionIntegrationFixure::LoadOriginal()
51 const {
52 return ReadRawTrace(src_trace_);
53}
54
55base::StatusOr<std::string> TraceRedactionIntegrationFixure::LoadRedacted()
56 const {
57 return ReadRawTrace(dest_trace_);
58}
59
60base::StatusOr<std::string> TraceRedactionIntegrationFixure::ReadRawTrace(
61 const std::string& path) const {
62 std::string redacted_buffer;
63
64 if (base::ReadFile(path, &redacted_buffer)) {
65 return redacted_buffer;
66 }
67
68 return base::ErrStatus("Failed to read %s", path.c_str());
69}
70
71} // namespace perfetto::trace_redaction