-
Notifications
You must be signed in to change notification settings - Fork 179
[onert] Add MockSycallManager for customized system call mocking #16333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "mock_syscalls.h" | ||
|
|
||
| int open(const char *pathname, int flags, ...) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous form of open() was, int open(const char *, int, ...) { return 0; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
|
|
||
| // Handle variable arguments for open() | ||
| if (flags & O_CREAT) | ||
| { | ||
| if (auto creatHook = manager.getOpenCreatHook()) | ||
| { | ||
| va_list args; | ||
| va_start(args, flags); | ||
| mode_t mode = va_arg(args, mode_t); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter 'mode' is only required when a file is created (O_CREAT). |
||
| va_end(args); | ||
| return creatHook(pathname, flags, mode); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (auto hook = manager.getOpenHook()) | ||
| { | ||
| return hook(pathname, flags); | ||
| } | ||
| } | ||
| return 0; // Default mock return value | ||
| } | ||
|
|
||
| void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous definition of mmap() was, void *mmap(void *, size_t, int, int, int, off_t) { return (void *)0x1; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getMmapHook()) | ||
| { | ||
| return hook(addr, length, prot, flags, fd, offset); | ||
| } | ||
| return (void *)0x1; // Default mock return value | ||
| } | ||
|
|
||
| int munmap(void *addr, size_t length) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous definition of munmap() was, int munmap(void *, size_t) { return 0; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getMunmapHook()) | ||
| { | ||
| return hook(addr, length); | ||
| } | ||
| return 0; // Default mock return value | ||
| } | ||
|
|
||
| int close(int fd) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous definition of close(), int close(int) { return 0; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getCloseHook()) | ||
| { | ||
| return hook(fd); | ||
| } | ||
| return 0; // Default mock return value | ||
| } | ||
|
|
||
| int ioctl(int fd, unsigned long request, ...) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous definition of ioctl(), int ioctl(int, unsigned long, ...) { return 0; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getIoctlHook()) | ||
| { | ||
| va_list args; | ||
| va_start(args, request); | ||
| void *arg = va_arg(args, void *); | ||
| va_end(args); | ||
| return hook(fd, request, arg); | ||
| } | ||
| return 0; // Default mock return value | ||
| } | ||
|
|
||
| FILE *fopen(const char *path, const char *mode) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous definition of fopen() size_t fread(void *, size_t, size_t, FILE *) { return 1; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getFopenHook()) | ||
| { | ||
| return hook(path, mode); | ||
| } | ||
| return (FILE *)0x1; // Default mock return value | ||
| } | ||
|
|
||
| int fclose(FILE *stream) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fclose() is newly added. |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getFcloseHook()) | ||
| { | ||
| return hook(stream); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous definition of fread() size_t fread(void *, size_t, size_t, FILE *) { return 1; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getFreadHook()) | ||
| { | ||
| return hook(ptr, size, nmemb, stream); | ||
| } | ||
| return 1; // Default mock return value | ||
| } | ||
|
|
||
| int fseek(FILE *stream, long offset, int whence) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous definition of fseek() int fseek(FILE *, long, int) { return 0; } |
||
| { | ||
| auto &manager = onert::backend::trix::ops::test::MockSyscallsManager::getInstance(); | ||
| if (auto hook = manager.getFseekHook()) | ||
| { | ||
| return hook(stream, offset, whence); | ||
| } | ||
| return 0; // Default mock return value | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update on next PR