Skip to content

Commit 910f4ed

Browse files
committed
autotester: save old CWD before chdir, and restore it afterwards.
1 parent 1aa39a3 commit 910f4ed

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

tests/autotester/autotester.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ namespace autotester
5151
/* The global config variable */
5252
config_t config;
5353

54+
std::string oldCWD;
55+
5456
bool debugMode = true;
5557
bool ignoreROMfield = false;
5658
bool configLoaded = false;

tests/autotester/autotester.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ namespace autotester
5151
std::unordered_map<std::string, hash_params_t> hashes;
5252
};
5353

54+
extern std::string oldCWD;
55+
5456
/*
5557
* Constants usable in the "start" and "size" parameters of the JSON config for the hash params
5658
* See http://wikiti.brandonw.net/index.php?title=Category:84PCE:RAM:By_Address

tests/autotester/autotester_cli.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
1818
#include <direct.h>
1919
#define chdir _chdir
20+
#define getcwd _getcwd
2021
#else
2122
#include <unistd.h>
2223
#endif
@@ -83,6 +84,12 @@ int main(int argc, char* argv[])
8384
return -1;
8485
}
8586

87+
char* oldCWD = getcwd(nullptr, 0);
88+
if (oldCWD != nullptr && oldCWD[0] != '\0')
89+
{
90+
autotester::oldCWD = std::string{oldCWD} + '/';
91+
}
92+
8693
// Go to the json file's dir to allow relative paths from there
8794
if (chdir(jsonPath.substr(0, jsonPath.find_last_of("/\\")).c_str())) {
8895
std::cerr << "[Error] Couldn't change directory path" << std::endl;
@@ -134,6 +141,11 @@ int main(int argc, char* argv[])
134141
}
135142

136143
cleanExit:
144+
if (oldCWD)
145+
{
146+
chdir(oldCWD);
147+
free(oldCWD);
148+
}
137149
cemucore::emu_exit();
138150
cemucore::asic_free();
139151

0 commit comments

Comments
 (0)