From dcae07bbed1b99c751771e3dc757fb258b014fd2 Mon Sep 17 00:00:00 2001
From: Brian Sullivan <briansul@microsoft.com>
Date: Fri, 8 Jan 2021 11:44:09 -0800
Subject: [PATCH 1/3] Fix Ilasm Round Trip script by adding retry logic Fix
 bash syntax Update bash syntax to use while true

---
 src/tests/Common/CLRTest.Jit.targets | 46 ++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets
index c80452618d0439..322d0bfecda883 100644
--- a/src/tests/Common/CLRTest.Jit.targets
+++ b/src/tests/Common/CLRTest.Jit.targets
@@ -109,13 +109,32 @@ then
     echo EXECUTION OF ILDASM - FAILED $ERRORLEVEL
     exit 1
   fi
+  if [ ! -f "$(DisassemblyName)" ]
+  then
+    echo "EXECUTION OF ILDASM - FAILED $(DisassemblyName) is missing"
+    exit 1
+  fi
+
+  ilasm_count=1
+  while true
+  do
+    echo "$CORE_ROOT/ilasm" -output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
+    "$CORE_ROOT/ilasm" -output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
+    ERRORLEVEL=$?
+    if [ $ERRORLEVEL -eq 0 ]
+    then
+      break
+    fi
+    echo EXECUTION $ilasm_count OF ILASM - FAILED with $ERRORLEVEL
+    if [ $ilasm_count -eq 3 ]
+    then
+      break
+    fi
+    echo Trying again
+    sleep 10
+  done
 
-  echo "$CORE_ROOT/ilasm" -output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
-  "$CORE_ROOT/ilasm" -output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
-  ERRORLEVEL=$?
   if [ $ERRORLEVEL -ne 0 ]
-  then
-    echo EXECUTION OF ILASM - FAILED $ERRORLEVEL
     exit 1
   fi
 fi
@@ -163,14 +182,29 @@ IF NOT DEFINED DoLink (
   IF DEFINED RunningIlasmRoundTrip (
     ECHO %CORE_ROOT%\ildasm.exe /raweh /out=$(DisassemblyName) $(InputAssemblyName)
     %CORE_ROOT%\ildasm.exe /raweh /out=$(DisassemblyName) $(InputAssemblyName)
+
     IF NOT "!ERRORLEVEL!"=="0" (
       ECHO EXECUTION OF ILDASM - FAILED !ERRORLEVEL!
       Exit /b 1
     )
+    IF NOT EXIST $(DisassemblyName) (
+      ECHO EXECUTION OF ILDASM - FAILED $(DisassemblyName) is missing
+      Exit /b 1
+    )
+
+   set ilasm_count=1
+:Try_ilasm
     ECHO %CORE_ROOT%\ilasm.exe /output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
     %CORE_ROOT%\ilasm.exe /output=$(TargetAssemblyName) $(_IlasmSwitches) $(DisassemblyName)
     IF NOT "!ERRORLEVEL!"=="0" (
-      ECHO EXECUTION OF ILASM - FAILED !ERRORLEVEL!
+      ECHO EXECUTION OF ILASM - Try !ilasm_count! FAILED with status !ERRORLEVEL! 
+      IF !ilasm_count! LEQ 3 (
+        ECHO Trying again
+        set /A ilasm_count=ilasm_count+1
+        timeout /t 10 /nobreak
+        goto :Try_ilasm
+      )
+      ECHO EXECUTION OF ILASM - FAILED
       Exit /b 1
     )
   )

From 260090bd25b7078c3441a707a1ad2bc2c7e85e10 Mon Sep 17 00:00:00 2001
From: Brian Sullivan <briansul@microsoft.com>
Date: Sun, 10 Jan 2021 21:56:40 -0800
Subject: [PATCH 2/3] Fix bash syntax error missing then

---
 src/tests/Common/CLRTest.Jit.targets | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets
index 322d0bfecda883..4965c51ab803e4 100644
--- a/src/tests/Common/CLRTest.Jit.targets
+++ b/src/tests/Common/CLRTest.Jit.targets
@@ -125,7 +125,9 @@ then
     then
       break
     fi
+
     echo EXECUTION $ilasm_count OF ILASM - FAILED with $ERRORLEVEL
+
     if [ $ilasm_count -eq 3 ]
     then
       break
@@ -135,6 +137,7 @@ then
   done
 
   if [ $ERRORLEVEL -ne 0 ]
+  then
     exit 1
   fi
 fi

From fa483aae02fdcee207bc3bc6ae6ae629366106ca Mon Sep 17 00:00:00 2001
From: Brian Sullivan <briansul@microsoft.com>
Date: Tue, 12 Jan 2021 09:06:46 -0800
Subject: [PATCH 3/3] bash - increment ilasm_count

---
 src/tests/Common/CLRTest.Jit.targets | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets
index 4965c51ab803e4..ef2ea293589fe9 100644
--- a/src/tests/Common/CLRTest.Jit.targets
+++ b/src/tests/Common/CLRTest.Jit.targets
@@ -132,6 +132,8 @@ then
     then
       break
     fi
+
+    ((ilasm_count++))
     echo Trying again
     sleep 10
   done
