mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 07:08:04 +08:00
Enhance mocking env variables
Change-Id: I2d0659b6f608467f9c1bc5746742ac5e3454582d Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
cb6777ee73
commit
8daf71070d
@@ -19,9 +19,7 @@ uint32_t mockVfptrinfCalled = 0;
|
||||
uint32_t mockFcloseCalled = 0;
|
||||
uint32_t mockGetenvCalled = 0;
|
||||
|
||||
bool returnMockEnvValue = false;
|
||||
std::string mockEnvValue = "1";
|
||||
std::set<std::string> notMockableEnvValues = {""};
|
||||
std::unordered_map<std::string, std::string> *mockableEnvValues = nullptr;
|
||||
|
||||
} // namespace IoFunctions
|
||||
} // namespace NEO
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include "shared/source/utilities/io_functions.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace NEO {
|
||||
namespace IoFunctions {
|
||||
@@ -19,9 +19,7 @@ extern uint32_t mockVfptrinfCalled;
|
||||
extern uint32_t mockFcloseCalled;
|
||||
extern uint32_t mockGetenvCalled;
|
||||
|
||||
extern bool returnMockEnvValue;
|
||||
extern std::string mockEnvValue;
|
||||
extern std::set<std::string> notMockableEnvValues;
|
||||
extern std::unordered_map<std::string, std::string> *mockableEnvValues;
|
||||
|
||||
inline FILE *mockFopen(const char *filename, const char *mode) {
|
||||
mockFopenCalled++;
|
||||
@@ -40,10 +38,8 @@ inline int mockFclose(FILE *stream) {
|
||||
|
||||
inline char *mockGetenv(const char *name) noexcept {
|
||||
mockGetenvCalled++;
|
||||
if (notMockableEnvValues.find(name) == notMockableEnvValues.end()) {
|
||||
if (returnMockEnvValue) {
|
||||
return const_cast<char *>(mockEnvValue.c_str());
|
||||
}
|
||||
if (mockableEnvValues != nullptr && mockableEnvValues->find(name) != mockableEnvValues->end()) {
|
||||
return const_cast<char *>(mockableEnvValues->find(name)->second.c_str());
|
||||
}
|
||||
return getenv(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user