Skip to content

Commit

Permalink
ram: disable accessed memory statistics when not fuzzing (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
poemonsense authored Sep 12, 2023
1 parent 44cbcb7 commit 0121689
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/test/csrc/common/ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ InputReader *SimMemory::createInputReader(const char *image) {
}

void SimMemory::display_stats() {
#ifdef FUZZING
uint64_t req_in_range = 0;
auto const img_indices = get_img_size() / sizeof(uint64_t);
for (auto index : accessed_indices) {
Expand All @@ -235,6 +236,7 @@ void SimMemory::display_stats() {
}
auto req_all = accessed_indices.size();
printf("SimMemory: img_size %lu, req_all %lu, req_in_range %lu\n", img_indices, req_all, req_in_range);
#endif // FUZZING
}

MmapMemory::MmapMemory(const char *image, uint64_t n_bytes) : SimMemory(n_bytes) {
Expand Down
4 changes: 4 additions & 0 deletions src/test/csrc/common/ram.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ class SimMemory {

protected:
uint64_t memory_size; // in bytes
#ifdef FUZZING
std::set<uint64_t> accessed_indices;
#endif
InputReader *createInputReader(const char *image);
virtual uint64_t get_img_size() = 0;
void inline on_access(uint64_t index) {
#ifdef FUZZING
accessed_indices.insert(index);
#endif
}

public:
Expand Down
2 changes: 0 additions & 2 deletions src/test/csrc/verilator/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ Emulator::~Emulator() {
stats.update(&(difftest[0]->dut));
#endif // CONFIG_NO_DIFFTEST

#ifdef FUZZING
simMemory->display_stats();
#endif
delete simMemory;
simMemory = nullptr;

Expand Down

0 comments on commit 0121689

Please sign in to comment.