blob: aa504d29f28b9875c170572619373eb5d584bef5 [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#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG).log()
27
Steven Moreland5da8f922019-10-11 13:01:48 -070028#ifdef ENABLE_LOG_FUZZ
Steven Moreland46e0da72019-09-05 15:52:02 -070029class FuzzLog {
30public:
Steven Morelande8a57c12019-10-10 11:20:28 -070031 FuzzLog(const char* tag) : mTag(tag) {}
32 ~FuzzLog() { std::cout << mTag << ": " << mOs.str() << std::endl; }
Steven Moreland46e0da72019-09-05 15:52:02 -070033
Steven Morelande8a57c12019-10-10 11:20:28 -070034 std::stringstream& log() { return mOs; }
Steven Moreland46e0da72019-09-05 15:52:02 -070035
36private:
Steven Morelande8a57c12019-10-10 11:20:28 -070037 const char* mTag = nullptr;
Steven Moreland46e0da72019-09-05 15:52:02 -070038 std::stringstream mOs;
39};
Steven Morelande8a57c12019-10-10 11:20:28 -070040#else
41class FuzzLog {
42public:
43 FuzzLog(const char* /*tag*/) {}
44 template <typename T>
45 FuzzLog& operator<<(const T& /*t*/) {
46 return *this;
47 }
48 FuzzLog& log() { return *this; }
49};
50#endif
Steven Moreland46e0da72019-09-05 15:52:02 -070051
Steven Moreland6065c052019-09-30 18:22:44 -070052std::string hexString(const void* bytes, size_t len);
53std::string hexString(const std::vector<uint8_t>& bytes);