Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
test: add memory check for unit tests in ci#558
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
Merged
Miou-zora
merged 7 commits into
main
from
447-feature-add-memory-checks-valgrind-leaks-for-unit-tests-in-ciApr 5, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
496aa72
tests(memory): add memory leak checks for unit tests
Miou-zora ee98c6e
ci: add memory leak checks for macOS in CI workflow
Miou-zora 3ad8b45
ci: add memory cleanup step before running tests
Miou-zora ae09e0d
ci: add memory cleanup step for Linux in test workflow
Miou-zora c9e1a9b
ci: update checkout action to v6 in commit norm checker
Miou-zora 6c1bfe1
ci: add debug flag for tests
Miou-zora 8d51a1a
ci: remove debug print statement from memory leak check
Miou-zora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| includes(os.scriptdir() .. "/groups.lua") | ||
| local TestGroupName = TEST_GROUP_NAME | ||
| local function check_leaks_macos(targets, leaks_tool, project, os) | ||
| local failing_targets = {} | ||
| for _, target in pairs(targets) do | ||
| local target_name = target:name() | ||
| local bin_path = path.join(os.projectdir(), target:targetdir(), "debug", target:filename()) | ||
Miou-zora marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if not os.isfile(bin_path) then | ||
| print("Executable not found for target: " .. target_name) | ||
| goto continue | ||
| end | ||
| print("Running leaks check on: " .. bin_path) | ||
| local return_value = os.execv(leaks_tool, {"--atExit", "--", bin_path}, {try = true, stdout = os.nuldev(), stderr = os.nuldev()}) | ||
| if return_value ~= 0 then | ||
| table.insert(failing_targets, target_name) | ||
| end | ||
| ::continue:: | ||
| end | ||
| return failing_targets | ||
| end | ||
| task("check_leaks") | ||
| on_run(function () | ||
| import("core.base.option") | ||
| import("core.project.project") | ||
| import("core.project.config") | ||
| import("lib.detect.find_program") | ||
| local targets = option.get("targets") or {} | ||
| if #targets == 0 then | ||
| -- If no targets specified, check all test targets | ||
| targets = {} | ||
| for _, target in pairs(project:targets()) do | ||
| local name = target:name() | ||
| local group = target:info().group | ||
| local kind = target:kind() | ||
| if kind == "binary" and group == TestGroupName then | ||
| table.insert(targets, target) | ||
| end | ||
| end | ||
| end | ||
| local failing_targets = {} | ||
| if os.host() == "macosx" then | ||
| local leaks_tool = find_program("leaks", { check = "--help" }) | ||
| if not leaks_tool then | ||
| print("leaks tool not found!") | ||
| return | ||
| end | ||
| failing_targets = check_leaks_macos(targets, leaks_tool, project, os) | ||
| else | ||
| print("Memory leak checking is currently only implemented for macOS.") | ||
| end | ||
| if #failing_targets > 0 then | ||
| print("Targets with memory leaks found:") | ||
| for _, target in ipairs(failing_targets) do | ||
| print(" - " .. target) | ||
| end | ||
| else | ||
| print("No memory leaks found.") | ||
| end | ||
Miou-zora marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| end) | ||
| set_menu { | ||
| usage = "xmake check_leaks", | ||
| description = "Check for memory leaks", | ||
| options = { | ||
| {nil, "targets", "vs", nil, "Targets to check for leaks (default: all test targets)"} | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| TEST_GROUP_NAME = "UnitTests" | ||
| PLUGINS_GROUP_NAME = "Plugins" | ||
| UTILS_GROUP_NAME = "Utils" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.