1 /* 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 #ifndef SRC_TRACE_REDACTION_TRACE_REDACTION_INTEGRATION_FIXTURE_H_ 18 #define SRC_TRACE_REDACTION_TRACE_REDACTION_INTEGRATION_FIXTURE_H_ 19 20 #include <string> 21 22 #include "perfetto/ext/base/status_or.h" 23 #include "src/base/test/tmp_dir_tree.h" 24 #include "src/trace_redaction/trace_redaction_framework.h" 25 #include "src/trace_redaction/trace_redactor.h" 26 27 namespace perfetto::trace_redaction { 28 29 class TraceRedactionIntegrationFixure { 30 protected: 31 TraceRedactionIntegrationFixure(); 32 33 void SetSourceTrace(std::string_view source_file); 34 35 // Redact the source file and write it to the destination file. The contents 36 // of each file can be read using LoadOriginal() and LoadRedacted(). 37 base::Status Redact(const TraceRedactor& redactor, Context* context); 38 39 base::StatusOr<std::string> LoadOriginal() const; 40 41 base::StatusOr<std::string> LoadRedacted() const; 42 43 private: 44 base::StatusOr<std::string> ReadRawTrace(const std::string& path) const; 45 46 base::TmpDirTree tmp_dir_; 47 48 std::string src_trace_; 49 50 // Path to the redacted trace. This will only be valid after Redact() 51 // completely. If redaction was successful, this file will be tracked by 52 // tmp_dir_. 53 std::string dest_trace_; 54 }; 55 56 } // namespace perfetto::trace_redaction 57 58 #endif // SRC_TRACE_REDACTION_TRACE_REDACTION_INTEGRATION_FIXTURE_H_ 59