-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Merge-on-Red] - Implement Test Process Watcher #78742
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
be9867e
Started the draft for the watch tower.
ivdiazsa e79ae66
Parsing command-line arguments done.
ivdiazsa b17eef2
Removed auto-generated file.
ivdiazsa d40ad9e
Added an example I made on how to run processes from C/C++ :)
ivdiazsa 6cc9e9e
Perfect arg parsing done!
ivdiazsa fcd9f1a
Seems to be working?
ivdiazsa 1c7f46c
Watchdog is functional now!
ivdiazsa ec90d1e
Fixed a nuisance with the Windows compiler messing with Linux code, b…
ivdiazsa b157904
Got the Windows draft working, at long last.
ivdiazsa 36a75f0
Added initial linking of the watcher to the repo's build scripts. Not…
ivdiazsa c4f2009
Moved the watcher to the CoreCLR project. Not yet functional though...
ivdiazsa e8b13a5
Got it to build on Windows!
ivdiazsa b476ad2
Builds and Works on Linux!
ivdiazsa f74fb2e
Fixed a slowdown with the watcher.
ivdiazsa 958dc29
Forgot to not leak memory :)
ivdiazsa 67e25fe
This is C++, not C.
ivdiazsa 7ef09b2
Bash scripts now call the watcher, but watcher still crashes when bui…
ivdiazsa 226ea36
Renamed variable.
ivdiazsa 5fbd787
FIXED THE LINUX PART!
ivdiazsa 0ff6b8d
Started implementing the constant flow of logs. Had to save my progress.
ivdiazsa 8f21b9c
TEMP LOG BUILDS!
ivdiazsa c7fc541
TEMP LOGS WORK!
ivdiazsa 4f658e2
Updated with main.
ivdiazsa a88e48c
Test Watcher seems to be working on Linux and MacOS.
ivdiazsa 8fceb44
Updated the Helix Commands with the watcher now included, and removed…
ivdiazsa 064b9b0
Fixed build issue in the watcher's Windows version.
ivdiazsa 2cb9270
Apparently works on Windows now too?
ivdiazsa 450eba9
Fixed build issue with Windows x86.
ivdiazsa eba2bcd
Fixed issue where we were not building the watcher in certain subsets…
ivdiazsa d68d16c
Fixed yet another Windows issue.
ivdiazsa 998965c
Used ExeSuffix instead of recomputing it and excluded Browser-Wasm
ivdiazsa 7cb4e89
Changed the Helix Correlation Payloads to bundle the whole watchdog d…
ivdiazsa 2ba916a
Changed the scripts to use the test watcher in the Core_Root, instead…
ivdiazsa a712352
Fixed undeclared variable in Windows test scripts.
ivdiazsa 0cc8875
Addressed PR feedback comments.
ivdiazsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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,4 @@ | ||
add_executable_clr(watchdog ${CMAKE_CURRENT_LIST_DIR}/watchdog.cpp) | ||
install_clr(TARGETS watchdog DESTINATIONS . COMPONENT hosts) | ||
install_clr(TARGETS watchdog DESTINATIONS . COMPONENT nativeaot) | ||
|
This file contains 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,136 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <errno.h> | ||
#include <signal.h> | ||
|
||
#ifdef TARGET_WINDOWS | ||
|
||
#include <windows.h> | ||
#include <string> | ||
|
||
#else // !TARGET_WINDOWS | ||
|
||
#include <chrono> | ||
#include <sys/wait.h> | ||
#include <thread> | ||
#include <unistd.h> | ||
#include <vector> | ||
|
||
#endif // TARGET_WINDOWS | ||
|
||
int run_timed_process(const long, const int, const char *[]); | ||
|
||
#ifdef TARGET_X86 | ||
int __cdecl main(const int argc, const char *argv[]) | ||
#else | ||
int main(const int argc, const char *argv[]) | ||
#endif | ||
{ | ||
if (argc < 3) | ||
{ | ||
printf("There are missing arguments. Got %d instead of 3+ :(\n", argc); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
const long timeout_sec = strtol(argv[1], nullptr, 10); | ||
int exit_code = run_timed_process(timeout_sec * 1000L, argc-2, &argv[2]); | ||
|
||
printf("App Exit Code: %d\n", exit_code); | ||
return exit_code; | ||
} | ||
|
||
int run_timed_process(const long timeout_ms, const int proc_argc, const char *proc_argv[]) | ||
{ | ||
#ifdef TARGET_WINDOWS | ||
std::string cmdline(proc_argv[0]); | ||
|
||
for (int i = 1; i < proc_argc; i++) | ||
{ | ||
cmdline.append(" "); | ||
cmdline.append(proc_argv[i]); | ||
} | ||
|
||
STARTUPINFOA startup_info; | ||
PROCESS_INFORMATION proc_info; | ||
unsigned long exit_code; | ||
|
||
ZeroMemory(&startup_info, sizeof(startup_info)); | ||
startup_info.cb = sizeof(startup_info); | ||
ZeroMemory(&proc_info, sizeof(proc_info)); | ||
|
||
if (!CreateProcessA(NULL, &cmdline[0], NULL, NULL, FALSE, 0, NULL, NULL, | ||
&startup_info, &proc_info)) | ||
{ | ||
int error_code = GetLastError(); | ||
printf("Process creation failed... Code %d.\n", error_code); | ||
return error_code; | ||
} | ||
|
||
WaitForSingleObject(proc_info.hProcess, timeout_ms); | ||
GetExitCodeProcess(proc_info.hProcess, &exit_code); | ||
|
||
CloseHandle(proc_info.hProcess); | ||
CloseHandle(proc_info.hThread); | ||
return exit_code; | ||
|
||
#else // !TARGET_WINDOWS | ||
|
||
const int check_interval_ms = 25; | ||
int check_count = 0; | ||
std::vector<const char*> args; | ||
|
||
pid_t child_pid; | ||
int child_status; | ||
int wait_code; | ||
|
||
for (int i = 0; i < proc_argc; i++) | ||
{ | ||
args.push_back(proc_argv[i]); | ||
} | ||
args.push_back(NULL); | ||
|
||
child_pid = fork(); | ||
|
||
if (child_pid < 0) | ||
{ | ||
// Fork failed. No memory remaining available :( | ||
printf("Fork failed... Returning ENOMEM.\n"); | ||
return ENOMEM; | ||
} | ||
else if (child_pid == 0) | ||
{ | ||
// Instructions for child process! | ||
execv(args[0], const_cast<char* const*>(args.data())); | ||
} | ||
else | ||
{ | ||
do | ||
{ | ||
// Instructions for the parent process! | ||
wait_code = waitpid(child_pid, &child_status, WNOHANG); | ||
|
||
if (wait_code == -1) | ||
return EINVAL; | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(check_interval_ms)); | ||
|
||
if (wait_code) | ||
{ | ||
if (WIFEXITED(child_status)) | ||
return WEXITSTATUS(child_status); | ||
} | ||
check_count++; | ||
|
||
} while (check_count < (timeout_ms / check_interval_ms)); | ||
} | ||
|
||
printf("Child process took too long. Timed out... Exiting...\n"); | ||
kill(child_pid, SIGKILL); | ||
|
||
#endif // TARGET_WINDOWS | ||
return ETIMEDOUT; | ||
} | ||
|
This file contains 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 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 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 |
---|---|---|
|
@@ -411,8 +411,8 @@ | |
<HelixCommandLines Condition="'$(TestWrapperTargetsWindows)' != 'true'" Include="export TEST_HARNESS_STRIPE_TO_EXECUTE=.0.1" /> | ||
<HelixCommandLines Condition="'$(TestWrapperTargetsWindows)' != 'true'" Include="chmod +x $(_MergedWrapperRunScriptRelative)" /> | ||
<!-- Force assemblies to lazy-load for LLVM AOT test runs to enable using tests that fail at AOT time (and as a result can't be AOTd) --> | ||
<HelixCommandLines Condition="'$(RuntimeVariant)' == 'llvmfullaot'" Include="$(_MergedWrapperRunScriptPrefix)$(_MergedWrapperRunScriptRelative) --aot-lazy-assembly-load" /> | ||
<HelixCommandLines Condition="'$(RuntimeVariant)' != 'llvmfullaot'" Include="$(_MergedWrapperRunScriptPrefix)$(_MergedWrapperRunScriptRelative)" /> | ||
<HelixCommandLines Condition="'$(RuntimeVariant)' == 'llvmfullaot'" Include="$(_MergedWrapperRunScriptPrefix)$(_MergedWrapperRunScriptRelative) -usewatcher --aot-lazy-assembly-load" /> | ||
<HelixCommandLines Condition="'$(RuntimeVariant)' != 'llvmfullaot'" Include="$(_MergedWrapperRunScriptPrefix)$(_MergedWrapperRunScriptRelative) -usewatcher" /> | ||
<HelixCommandLines Include="$(XUnitLogCheckerCommand)" /> | ||
</ItemGroup> | ||
|
||
|
@@ -720,7 +720,9 @@ | |
|
||
<ItemGroup Condition=" '$(UsesHelixSdk)' == 'true' "> | ||
<HelixCorrelationPayload Include="$(CoreRootDirectory)" /> | ||
<HelixCorrelationPayload Include="$(XUnitLogCheckerDirectory)" /> | ||
|
||
<!-- Browser-Wasm follows a very different workflow, which is currently out of scope of the Log Checker. --> | ||
<HelixCorrelationPayload Include="$(XUnitLogCheckerDirectory)" Condition="'$(TargetsBrowser)' != 'true'" /> | ||
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. Does this change the current behavior for wasm logs then? 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. Not at all. Wasm is out of scope of this project for the time being, hence we are excluding it. So wasm tests will remain unaffected. |
||
|
||
<LegacyPayloads Include="$([System.IO.Directory]::GetDirectories($(LegacyPayloadsRootDirectory)))" Condition="Exists('$(LegacyPayloadsRootDirectory)')" /> | ||
<LegacyPayloads Update="@(LegacyPayloads)"> | ||
|
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.
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.
Nit: Add license header