Skip to content

Commit

Permalink
autotester: save old CWD before chdir, and restore it afterwards.
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Dec 4, 2024
1 parent 1aa39a3 commit 910f4ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/autotester/autotester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace autotester
/* The global config variable */
config_t config;

std::string oldCWD;

bool debugMode = true;
bool ignoreROMfield = false;
bool configLoaded = false;
Expand Down
2 changes: 2 additions & 0 deletions tests/autotester/autotester.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace autotester
std::unordered_map<std::string, hash_params_t> hashes;
};

extern std::string oldCWD;

/*
* Constants usable in the "start" and "size" parameters of the JSON config for the hash params
* See http://wikiti.brandonw.net/index.php?title=Category:84PCE:RAM:By_Address
Expand Down
12 changes: 12 additions & 0 deletions tests/autotester/autotester_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <direct.h>
#define chdir _chdir
#define getcwd _getcwd
#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -83,6 +84,12 @@ int main(int argc, char* argv[])
return -1;
}

char* oldCWD = getcwd(nullptr, 0);
if (oldCWD != nullptr && oldCWD[0] != '\0')
{
autotester::oldCWD = std::string{oldCWD} + '/';
}

// Go to the json file's dir to allow relative paths from there
if (chdir(jsonPath.substr(0, jsonPath.find_last_of("/\\")).c_str())) {
std::cerr << "[Error] Couldn't change directory path" << std::endl;
Expand Down Expand Up @@ -134,6 +141,11 @@ int main(int argc, char* argv[])
}

cleanExit:
if (oldCWD)
{
chdir(oldCWD);
free(oldCWD);
}
cemucore::emu_exit();
cemucore::asic_free();

Expand Down

0 comments on commit 910f4ed

Please sign in to comment.