pmt: add memory test function and some new functions to libhelper

This commit is contained in:
2025-08-13 10:58:48 +03:00
parent 0bc5f70294
commit bf0df8cc83
7 changed files with 33 additions and 13 deletions

View File

@@ -81,12 +81,14 @@ private:
std::vector<uint8_t *> _ptrs_u;
std::vector<FILE *> _fps;
std::vector<int> _fds;
std::vector<std::string_view> _files;
public:
~garbageCollector();
void delAfterProgress(char *&_ptr);
void delAfterProgress(uint8_t *&_ptr);
void delFileAfterProgress(std::string_view path);
void closeAfterProgress(FILE *&_fp);
void closeAfterProgress(int _fd);
};
@@ -151,6 +153,7 @@ std::string runCommandWithOutput(std::string_view cmd);
std::string pathJoin(std::string base, std::string relative);
std::string pathBasename(std::string_view entry);
std::string pathDirname(std::string_view entry);
uint64_t getRandomOffset(uint64_t size, uint64_t bufferSize);
// Android
std::string getProperty(std::string_view prop);

View File

@@ -95,6 +95,8 @@ garbageCollector::~garbageCollector() {
close(fd);
for (const auto &fp : _fps)
fclose(fp);
for (const auto &file: _files)
eraseEntry(file);
}
void garbageCollector::delAfterProgress(char *&_ptr) {
@@ -103,6 +105,9 @@ void garbageCollector::delAfterProgress(char *&_ptr) {
void garbageCollector::delAfterProgress(uint8_t *&_ptr) {
_ptrs_u.push_back(_ptr);
}
void garbageCollector::delFileAfterProgress(const std::string_view path) {
_files.push_back(path);
}
void garbageCollector::closeAfterProgress(const int _fd) {
_fds.push_back(_fd);
}

View File

@@ -216,5 +216,11 @@ bool reboot(const std::string_view arg) {
return android_reboot(cmd, 0, arg.empty() ? nullptr : arg.data()) != -1;
}
uint64_t getRandomOffset(const uint64_t size, const uint64_t bufferSize) {
if (size <= bufferSize) return 0;
const uint64_t maxOffset = size - bufferSize;
return rand() % maxOffset;
}
std::string getLibVersion() { MKVERSION("libhelper"); }
} // namespace Helper