Skip to content

Commit 4101d5d

Browse files
authored
tests: add jak3 typeconsistency test and ensure offline tests are working (#3310)
1 parent 0742779 commit 4101d5d

File tree

14 files changed

+86
-28
lines changed

14 files changed

+86
-28
lines changed

.vs/launch.vs.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@
6868
"jak2"
6969
]
7070
},
71+
{
72+
"type": "default",
73+
"project": "CMakeLists.txt",
74+
"projectTarget": "offline-test.exe (bin\\offline-test.exe)",
75+
"name": "Tests - Offline Tests - Jak 3",
76+
"args": [
77+
"--iso_data_path",
78+
"${workspaceRoot}/iso_data/jak3",
79+
"--game",
80+
"jak3"
81+
]
82+
},
7183
{
7284
"type": "default",
7385
"project": "CMakeLists.txt",

Taskfile.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ tasks:
9090
- cmd: python ./scripts/cpp/format-includes.py
9191
- cmd: python ./third-party/run-clang-format/run-clang-format.py -r common decompiler game goalc test tools lsp -i
9292
- task: format-json
93-
93+
9494
# DECOMPILING
9595
decomp:
9696
cmds:
@@ -165,9 +165,6 @@ tasks:
165165
ignore_error: true
166166
- python ./scripts/update_decomp_reference.py ./failures ./test/decompiler/reference/ --game {{.GAME}}
167167
- task: offline-test-file
168-
type-test-jak1:
169-
cmds:
170-
- cmd: '{{.GOALCTEST_BIN_RELEASE_DIR}}/goalc-test --gtest_brief=0 --gtest_filter="*Jak1TypeConsistency*" --gtest_break_on_failure'
171168
type-test:
172169
cmds:
173-
- cmd: '{{.GOALCTEST_BIN_RELEASE_DIR}}/goalc-test --gtest_brief=0 --gtest_filter="*Jak2TypeConsistency*" --gtest_break_on_failure'
170+
- cmd: '{{.GOALCTEST_BIN_RELEASE_DIR}}/goalc-test --gtest_brief=0 --gtest_filter="*{{.TYPE_CONSISTENCY_TEST_FILTER}}*" --gtest_break_on_failure'

common/goos/Reader.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,14 @@ Object Reader::read_from_string(const std::string& str,
238238
* Read a file
239239
*/
240240
Object Reader::read_from_file(const std::vector<std::string>& file_path, bool check_encoding) {
241-
std::string joined_path = fmt::format("{}", fmt::join(file_path, "/"));
241+
std::string file_descriptor = fmt::format("{}", fmt::join(file_path, "/"));
242+
const auto joined_file_path = file_util::get_file_path(file_path);
242243

243-
auto textFrag = std::make_shared<FileText>(file_util::get_file_path(file_path), joined_path);
244+
if (!fs::exists(joined_file_path)) {
245+
throw std::runtime_error(fmt::format("Cannot read {}, file doesn't exist", joined_file_path));
246+
}
247+
248+
auto textFrag = std::make_shared<FileText>(joined_file_path, file_descriptor);
244249
db.insert(textFrag);
245250

246251
auto result = internal_read(textFrag, check_encoding);

common/goos/TextDB.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ std::pair<int, int> SourceText::get_containing_line(int offset) {
8585
/*!
8686
* Read text from a file.
8787
*/
88-
FileText::FileText(const std::string& filename, const std::string& description_name)
89-
: m_filename(filename), m_desc_name(description_name) {
90-
m_text = file_util::read_text_file(m_filename);
88+
FileText::FileText(const std::string& file_path, const std::string& description_name)
89+
: m_filepath(file_path), m_desc_name(description_name) {
90+
m_text = file_util::read_text_file(m_filepath);
9191
build_offsets();
9292
}
9393

common/goos/TextDB.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ class ProgramString : public SourceText {
8080
*/
8181
class FileText : public SourceText {
8282
public:
83-
FileText(const std::string& filename, const std::string& description_name);
83+
FileText(const std::string& file_path, const std::string& description_name);
8484

8585
std::string get_description() { return m_desc_name; }
8686
~FileText() = default;
8787

8888
private:
89-
std::string m_filename;
89+
std::string m_filepath;
9090
std::string m_desc_name;
9191
};
9292

common/util/FileUtil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ std::vector<fs::path> find_files_in_dir(const fs::path& dir, const std::regex& p
636636

637637
std::vector<fs::path> find_files_recursively(const fs::path& base_dir, const std::regex& pattern) {
638638
std::vector<fs::path> files = {};
639+
if (!fs::exists(base_dir)) {
640+
return files;
641+
}
639642
for (auto& p : fs::recursive_directory_iterator(base_dir)) {
640643
if (p.is_regular_file()) {
641644
if (std::regex_match(p.path().filename().string(), pattern)) {

decompiler/config/jak1/all-types.gc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(z float :offset 64)
1414
(w float :offset 96))
1515
:method-count-assert 9
16-
:size-assert #x10
16+
:size-assert #x10
1717
:flag-assert #x900000010
1818
)
1919

decompiler/config/jak3/all-types.gc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
;; (define-extern lognot function) ;; (function int int)
253253
;; (define-extern false-func function) ;; (function symbol)
254254
;; (define-extern true-func function) ;; (function symbol)
255-
;; (define-extern format object) ;; (function _varargs_ object)
255+
(define-extern format (function _varargs_ object))
256256
;; (define-extern basic-type? function) ;; (function basic type symbol)
257257
;; (define-extern type-type? function) ;; (function type type symbol)
258258
;; (define-extern type? function) ;; (function object type symbol)
@@ -2826,12 +2826,11 @@
28262826
(basic-reserved-method-28 () none) ;; 28
28272827
)
28282828
)
2829-
|#
28302829

2831-
;; (deftype part-id (uint32)
2832-
;; ()
2833-
;; :flag-assert #x900000004
2834-
;; )
2830+
(deftype part-id (uint32)
2831+
()
2832+
:flag-assert #x900000004
2833+
)
28352834

28362835

28372836
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

scripts/tasks/.env.default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
GAME=jak1
22
DECOMP_CONFIG=jak1/jak1_config.jsonc
33
DECOMP_CONFIG_VERSION=ntsc_v1
4+
TYPE_CONSISTENCY_TEST_FILTER=Jak1TypeConsistency

scripts/tasks/update-env.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
"jak3": "ntsc_v1"
7070
}
7171

72+
type_consistency_filter_map = {
73+
"jak1": "Jak1TypeConsistency",
74+
"jak2": "Jak2TypeConsistency",
75+
"jak3": "Jak3TypeConsistency"
76+
}
77+
7278
if args.game:
7379
if args.game not in valid_games:
7480
print("Unsupported game '{}'".format(args.game))
@@ -78,12 +84,14 @@
7884
if (curr != file["GAME"]) or file["DECOMP_CONFIG_VERSION"] not in decomp_config_version_map[file["GAME"]]:
7985
file["DECOMP_CONFIG"] = decomp_config_map[file["GAME"]]
8086
file["DECOMP_CONFIG_VERSION"] = default_config_version_map[file["GAME"]]
87+
file["TYPE_CONSISTENCY_TEST_FILTER"] = type_consistency_filter_map[file["GAME"]]
8188
if args.decomp_config:
8289
if args.decomp_config not in decomp_config_version_map[file["GAME"]]:
8390
print("Unsupported decomp config '{}' for game '{}'".format(args.decomp_config, file["GAME"]))
8491
sys.exit(1)
8592
file["DECOMP_CONFIG"] = decomp_config_map[file["GAME"]]
8693
file["DECOMP_CONFIG_VERSION"] = decomp_config_version_map[file["GAME"]][args.decomp_config]
94+
file["TYPE_CONSISTENCY_TEST_FILTER"] = type_consistency_filter_map[file["GAME"]]
8795

8896
with open(env_path, 'w') as env_file:
8997
for item in file.items():

0 commit comments

Comments
 (0)