summaryrefslogtreecommitdiff
path: root/simpleperf/libsimpleperf_report_fuzzer.cpp
blob: f448af8779522acf7cde92e1ac7bc61c8c8d8ef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#include <android-base/file.h>

#include "command.h"
#include "report_lib_interface.cpp"
#include "test_util.h"

using namespace simpleperf;

namespace {

class CommandRegister {
 public:
  CommandRegister() { RegisterDumpRecordCommand(); }
};

CommandRegister command_register;

void TestReportLib(const char* record_file) {
  ReportLib* report_lib = CreateReportLib();
  SetRecordFile(report_lib, record_file);
  while (true) {
    Sample* sample = GetNextSample(report_lib);
    if (sample == nullptr) {
      break;
    }
  }
  DestroyReportLib(report_lib);
}

void TestDumpCmd(const char* record_file) {
  std::unique_ptr<Command> dump_cmd = CreateCommandInstance("dump");
  CaptureStdout capture;
  capture.Start();
  dump_cmd->Run({"-i", record_file, "--dump-etm", "raw,packet,element"});
}

}  // namespace

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  TemporaryFile tmpfile;
  android::base::WriteFully(tmpfile.fd, data, size);
  TestReportLib(tmpfile.path);
  TestDumpCmd(tmpfile.path);
  return 0;
}