blob: a28cd1e12932765e81ce3ae269cc919891cd375b [file] [log] [blame]
Steven Moreland46e0da72019-09-05 15:52:02 -07001/*
2 * Copyright (C) 2019 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 <iostream>
18#include <sstream>
19#include <string>
20#include <vector>
21
22#ifndef FUZZ_LOG_TAG
23#error "Must define FUZZ_LOG_TAG"
24#endif
25
Steven Morelande8a57c12019-10-10 11:20:28 -070026// for local debugging
27#define ENABLE_LOG_FUZZ 0
Steven Moreland46e0da72019-09-05 15:52:02 -070028
Steven Morelande8a57c12019-10-10 11:20:28 -070029#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG).log()
30
31#if ENABLE_LOG_FUZZ == 1
Steven Moreland46e0da72019-09-05 15:52:02 -070032class FuzzLog {
33public:
Steven Morelande8a57c12019-10-10 11:20:28 -070034 FuzzLog(const char* tag) : mTag(tag) {}
35 ~FuzzLog() { std::cout << mTag << ": " << mOs.str() << std::endl; }
Steven Moreland46e0da72019-09-05 15:52:02 -070036
Steven Morelande8a57c12019-10-10 11:20:28 -070037 std::stringstream& log() { return mOs; }
Steven Moreland46e0da72019-09-05 15:52:02 -070038
39private:
Steven Morelande8a57c12019-10-10 11:20:28 -070040 const char* mTag = nullptr;
Steven Moreland46e0da72019-09-05 15:52:02 -070041 std::stringstream mOs;
42};
Steven Morelande8a57c12019-10-10 11:20:28 -070043#else
44class FuzzLog {
45public:
46 FuzzLog(const char* /*tag*/) {}
47 template <typename T>
48 FuzzLog& operator<<(const T& /*t*/) {
49 return *this;
50 }
51 FuzzLog& log() { return *this; }
52};
53#endif
Steven Moreland46e0da72019-09-05 15:52:02 -070054
Steven Moreland6065c052019-09-30 18:22:44 -070055std::string hexString(const void* bytes, size_t len);
56std::string hexString(const std::vector<uint8_t>& bytes);