mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 00:24:58 +08:00
Functions: fileExists and loadDataToFile use IO functions from namespace IoFunctions Now tests that use these functions are mocked by default, but some still require access to real files and have been restored the ability to read files. They will be mocked in next PRs. Related-To: NEO-7006 Signed-off-by: Marcel Skierkowski <marcel.skierkowski@intel.com>
41 lines
2.7 KiB
C++
41 lines
2.7 KiB
C++
/*
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "shared/source/helpers/stdio.h"
|
|
#include "shared/source/utilities/io_functions.h"
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
std::unique_ptr<char[]> loadDataFromFile(
|
|
const char *filename,
|
|
size_t &retSize);
|
|
|
|
size_t writeDataToFile(
|
|
const char *filename,
|
|
const void *pData,
|
|
size_t dataSize);
|
|
|
|
bool fileExists(const std::string &fileName);
|
|
bool fileExistsHasSize(const std::string &fileName);
|
|
void dumpFileIncrement(const char *data, size_t dataSize, const std::string &filename, const std::string &extension);
|
|
|
|
#define USE_REAL_FILE_SYSTEM() \
|
|
VariableBackup<decltype(NEO::IoFunctions::fopenPtr)> mockFopen(&NEO::IoFunctions::fopenPtr, [](const char *filename, const char *mode) -> FILE * { \
|
|
FILE *pFile = nullptr; \
|
|
fopen_s(&pFile, filename, mode); \
|
|
return pFile; \
|
|
}); \
|
|
VariableBackup<decltype(NEO::IoFunctions::fseekPtr)> mockFseek(&NEO::IoFunctions::fseekPtr, [](FILE *stream, long int offset, int origin) -> int { return fseek(stream, offset, origin); }); \
|
|
VariableBackup<decltype(NEO::IoFunctions::ftellPtr)> mockFtell(&NEO::IoFunctions::ftellPtr, [](FILE *stream) -> long int { return ftell(stream); }); \
|
|
VariableBackup<decltype(NEO::IoFunctions::freadPtr)> mockFread(&NEO::IoFunctions::freadPtr, [](void *ptr, size_t size, size_t count, FILE *stream) -> size_t { return fread(ptr, size, count, stream); }); \
|
|
VariableBackup<decltype(NEO::IoFunctions::fclosePtr)> mockFclose(&NEO::IoFunctions::fclosePtr, [](FILE *stream) -> int { return fclose(stream); });
|