-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add emitUnitTests.sh #96064
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
Merged
Add emitUnitTests.sh #96064
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,115 @@ | ||
| #!/bin/bash | ||
|
|
||
| # On Linux/Mac, run the emit unit tests and compare the output against capstone. | ||
| # | ||
| # args: | ||
| # -s : Setup the tools. Checkout and build capstone. Build the dummy app. | ||
| # -c : Sets CORE_ROOT used to run the tests. | ||
| # -g : The Group of tests to run. Used for DOTNET_JitDumpEmitUnitTests. | ||
| # -v : Use regex to search the generated clr output. Useful when adding new instructions during development. | ||
| # | ||
|
|
||
| # Show all commands run and exit on any errors | ||
|
|
||
| set -xeuo pipefail | ||
|
|
||
| # Parse command line | ||
|
|
||
| usage="$0 [-s] [-c core_root] [-g group] [-v ins_regex]" | ||
| group=all | ||
| search= | ||
| setup= | ||
| verbose= | ||
| while getopts sc:g:v: line | ||
| do | ||
| case $line in | ||
| c) export CORE_ROOT=$OPTARG;; | ||
| g) group=$OPTARG;; | ||
| s) setup=1;; | ||
| v) verbose=$OPTARG;; | ||
| *) echo $usage; exit 2;; | ||
| esac | ||
| done | ||
|
|
||
| arch=$(uname -m) | ||
| if [ "$arch" == 'aarch64' ]; then | ||
| clr_arch=arm64 | ||
| elif [ "$arch" == 'x86_64' ]; then | ||
| arch=x64 | ||
| clr_arch=x64 | ||
| fi | ||
|
|
||
| artifacts_dir="$(pwd)/../../../artifacts/bin/emitUnitTests" | ||
|
|
||
| # Setup capstone | ||
|
|
||
| capstone_directory=$artifacts_dir/capstone | ||
|
|
||
| if [ -n "$setup" ] || [ ! -d "$capstone_directory" ]; then | ||
| rm -fr "$capstone_directory" | ||
| git clone --quiet --depth 1 -b capstone-jit2-formatting https://github.com/TIHan/capstone.git "$capstone_directory" | ||
| cd "$capstone_directory" | ||
| ./make.sh | ||
| cd - | ||
| fi | ||
|
|
||
| cstool=$(realpath "$capstone_directory/cstool/cstool") | ||
|
|
||
| # Setup dummy app | ||
|
|
||
| app_dir="$artifacts_dir/$clr_arch/Release/publish" | ||
|
|
||
| if [ -n "$setup" ] || [ ! -d "$app_dir" ]; then | ||
| cd emitUnitTests | ||
| dotnet publish -c Release | ||
| cd - | ||
| fi | ||
|
|
||
| app_dll="$app_dir/emitUnitTests.dll" | ||
| app_dll=$(realpath $app_dll) | ||
|
|
||
| # Set env | ||
|
|
||
| output_dir=$(mktemp -d) | ||
|
|
||
| export DOTNET_JitRawHexCode=Main | ||
| export DOTNET_JitRawHexCodeFile=$output_dir/clr_hex.txt | ||
| export DOTNET_JitDump=Main | ||
| export DOTNET_JitDumpEmitUnitTests=$group | ||
|
|
||
| # Run the dummy app in clr | ||
|
|
||
| $CORE_ROOT/corerun $app_dll > $output_dir/clr_output.txt | ||
|
|
||
| # Extract the instructions from the clr output, from the first NOP to the first set of 2 NOPS. | ||
|
|
||
| egrep "IN.*: 00" $output_dir/clr_output.txt \ | ||
| | cut -f 8- -d ' ' | tr -s ' \t' ' ' \ | ||
| | awk '{ if ($1=="nop") { go=1; if (prev=="nop") fin=1; } if (go && !fin) print $0; prev=$1 }' \ | ||
| > $output_dir/clr_instrs.txt | ||
|
|
||
| # Run the raw hex through capstone | ||
|
|
||
| $cstool $arch $output_dir/clr_hex.txt > $output_dir/capstone_output.txt | ||
|
|
||
| # Extract the instructions from the capstone output, from the first NOP to the first set of 2 NOPS. | ||
|
|
||
| cat $output_dir/capstone_output.txt \ | ||
| | cut -f 3- -d ' ' | tr -s ' \t' ' ' \ | ||
| | awk '{ if ($1=="nop") { go=1; if (prev=="nop") fin=1; } if (go && !fin) print $0; prev=$1 }' \ | ||
| > $output_dir/capstone_instrs.txt | ||
|
|
||
| # Show some of the output | ||
|
|
||
| if [ -n "$verbose" ]; then | ||
| egrep "$verbose" $output_dir/clr_instrs.txt | ||
| else | ||
| (head -n 5; tail -n 5) < $output_dir/clr_instrs.txt | ||
| fi | ||
|
|
||
| # Diff capstone and clr | ||
|
|
||
| diff $output_dir/clr_instrs.txt $output_dir/capstone_instrs.txt | ||
|
|
||
| rm -fr $output_dir | ||
| echo PASSED | ||
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,12 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace EmitUnitTests | ||
| { | ||
| public class EmitUnitTests | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| } | ||
| } | ||
| } |
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,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
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.
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.
Thanks for doing this @a74nh . Perhaps, we should have a python script instead, so it can be used on all platforms.
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.
That should be possible to just convert across. this might be a good time to try the Arm64 Windows box we've got.
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.
yes, but IMO having 2 copies for different platform, makes us remember to make changes on both the scripts and soon one might get outdated with respect to other.
with
python, you might not even have to do it ;)