blob: 45e8c571a8a35dcb2d3a05331ecb2b4e03c8dab5 [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 */
Steven Moreland5e561af2020-10-08 02:16:03 +000016#pragma once
Steven Moreland46e0da72019-09-05 15:52:02 -070017
18#include <iostream>
19#include <sstream>
20#include <string>
21#include <vector>
22
23#ifndef FUZZ_LOG_TAG
24#error "Must define FUZZ_LOG_TAG"
25#endif
26
Steven Morelande8a57c12019-10-10 11:20:28 -070027#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG).log()
28
Steven Moreland5da8f922019-10-11 13:01:48 -070029#ifdef ENABLE_LOG_FUZZ
Steven Moreland46e0da72019-09-05 15:52:02 -070030class FuzzLog {
31public:
Steven Morelande8a57c12019-10-10 11:20:28 -070032 FuzzLog(const char* tag) : mTag(tag) {}
33 ~FuzzLog() { std::cout << mTag << ": " << mOs.str() << std::endl; }
Steven Moreland46e0da72019-09-05 15:52:02 -070034
Steven Morelande8a57c12019-10-10 11:20:28 -070035 std::stringstream& log() { return mOs; }
Steven Moreland46e0da72019-09-05 15:52:02 -070036
37private:
Steven Morelande8a57c12019-10-10 11:20:28 -070038 const char* mTag = nullptr;
Steven Moreland46e0da72019-09-05 15:52:02 -070039 std::stringstream mOs;
40};
Steven Morelande8a57c12019-10-10 11:20:28 -070041#else
42class FuzzLog {
43public:
44 FuzzLog(const char* /*tag*/) {}
45 template <typename T>
46 FuzzLog& operator<<(const T& /*t*/) {
47 return *this;
48 }
49 FuzzLog& log() { return *this; }
50};
51#endif
Steven Moreland46e0da72019-09-05 15:52:02 -070052
Steven Moreland6065c052019-09-30 18:22:44 -070053std::string hexString(const void* bytes, size_t len);
54std::string hexString(const std::vector<uint8_t>& bytes);