Skip to content

Commit

Permalink
vcs: fix resources deallocation of simulation (#300)
Browse files Browse the repository at this point in the history
When running with --workload-lilst, simv_init is reinitialized multiple times in a single launch, and the pointer from the last simv_init request needs to be destroyed before doing so. 

This commit fixed an issue with incomplete memory deallocation when exiting the program, and release the list file correctly when using the workload list
  • Loading branch information
xiaokamikami authored Mar 5, 2024
1 parent 260b9cd commit 1b3c3aa
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ int switch_workload() {
set_max_instrs(num);
} else if (feof(fp)) {
printf("Workload list is completed\n");
fclose(fp);
return 1;
} else {
printf("Unknown workload list format\n");
fclose(fp);
return 1;
}
} else {
Expand Down Expand Up @@ -177,12 +179,21 @@ void difftest_deferred_result(uint8_t result) {
}
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT

void simv_finish() {
common_finish();
flash_finish();
if (enable_difftest) {
goldenmem_finish();
difftest_finish();
}
delete simMemory;
simMemory = nullptr;
}

static uint8_t simv_result = SIMV_RUN;
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
extern "C" void simv_nstep(uint8_t step) {
if (simv_result == SIMV_FAIL)
return;
if (difftest == NULL)
if (simv_result == SIMV_FAIL || difftest == NULL)
return;
#else
extern "C" uint8_t simv_nstep(uint8_t step) {
Expand All @@ -200,7 +211,7 @@ extern "C" uint8_t simv_nstep(uint8_t step) {
int ret = simv_step();
if (ret) {
simv_result = ret;
difftest_finish();
simv_finish();
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
difftest_deferred_result(ret);
return;
Expand Down

0 comments on commit 1b3c3aa

Please sign in to comment.