Skip to content

Commit 0ad777f

Browse files
authored
Feature test read to uninit mem (#15)
* Return 0 if memory uninitialized * Fix segmentation fault in failed test cases
1 parent d42e5b4 commit 0ad777f

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

include/test/test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "test/test_total_result.h"
43
#include "test/test_result.h"
54
#include "nlohmann/json.hpp"
65

@@ -10,6 +9,7 @@ using json = nlohmann::json;
109

1110
class args_parser;
1211
class emulation_devices;
12+
class test_total_result;
1313
class debug_info;
1414

1515
class test
@@ -21,7 +21,7 @@ class test
2121
vector<json> test_scinarios;
2222

2323
json read_json(string path);
24-
void traverse(test_total_result &total_result, json test_target, json test_template, json testcase, string path);
24+
void traverse(emulation_devices *device, test_total_result *total_result, json test_target, json test_template, json testcase, string path);
2525
test_result do_test(string id, json test_target, json test_template, json testcase);
2626
void print_call_stack();
2727

include/test/test_total_result.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ class args_parser;
99
class test_total_result
1010
{
1111
private:
12-
emulation_devices *device;
1312
args_parser *args;
1413
int total;
1514
vector<test_result> results;
1615
map<test_result_type, int> test_result_map;
1716

1817
public:
19-
test_total_result(emulation_devices *_device, args_parser *_args);
20-
void add_and_print_result(test_result result);
18+
test_total_result(args_parser *_args);
19+
void add_and_print_result(emulation_devices *device, test_result result);
2120
bool is_success();
2221
void set_total(int total);
2322
void print_summary();

src/emulation/memory_device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ uint8_t memory_device::read(uint16_t address)
152152
}
153153
}
154154

155-
return ram[address];
155+
return ram.count(address) == 0 ? 0 : ram[address];
156156
}
157157

158158
uint8_t memory_device::read_raw(uint16_t address)

src/test/test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44

55
#include "test/test.h"
6+
#include "test/test_total_result.h"
67
#include "test/test_result.h"
78
#include "test/test_setup.h"
89
#include "test/test_assert.h"
@@ -56,15 +57,16 @@ test::test(args_parser *_args)
5657

5758
bool test::execute()
5859
{
59-
test_total_result total_result{device, args};
60+
test_total_result total_result{args};
6061
int num_cases = 0;
6162

6263
for (auto test_scinario : test_scinarios)
6364
{
6465
num_cases += test_scinario["cases"].size();
6566
device = new emulation_devices(args, test_scinario["config"], debug);
6667
traverse(
67-
total_result,
68+
device,
69+
&total_result,
6870
test_scinario["target"],
6971
test_scinario["definitions"]["templates"],
7072
test_scinario["cases"],
@@ -80,7 +82,7 @@ bool test::execute()
8082
return total_result.is_success();
8183
}
8284

83-
void test::traverse(test_total_result &total_result, json test_target, json test_template, json test_case, string path)
85+
void test::traverse(emulation_devices *device, test_total_result *total_result, json test_target, json test_template, json test_case, string path)
8486
{
8587
for (auto &element : test_case.items())
8688
{
@@ -91,14 +93,15 @@ void test::traverse(test_total_result &total_result, json test_target, json test
9193

9294
if (test_id_path.ends_with("/"))
9395
{
94-
traverse(total_result, test_target, test_template, sub_test_case, test_id_path);
96+
traverse(device, total_result, test_target, test_template, sub_test_case, test_id_path);
9597
continue;
9698
}
9799

98100
if (!args->get_test_id().empty() && args->get_test_id() != test_id_path)
99101
continue;
100102

101-
total_result.add_and_print_result(
103+
total_result->add_and_print_result(
104+
device,
102105
do_test(test_id_path, test_target, test_template, sub_test_case));
103106
}
104107
}

src/test/test_total_result.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "test/test_total_result.h"
22
#include "args_parser.h"
33

4-
test_total_result::test_total_result(emulation_devices *_device, args_parser *_args)
4+
test_total_result::test_total_result(args_parser *_args)
55
{
6-
device = _device;
76
args = _args;
87
}
98

10-
void test_total_result::add_and_print_result(test_result result)
9+
void test_total_result::add_and_print_result(emulation_devices *device, test_result result)
1110
{
1211
test_result_map[result.get_result_type()]++;
1312

0 commit comments

Comments
 (0)