summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Sadov <vsadov@microsoft.com>2019-03-28 10:25:25 -0700
committerGitHub <noreply@github.com>2019-03-28 10:25:25 -0700
commite5bfd7d89ad0704a23545ac1e6d6a80918e2dbe5 (patch)
tree279c8f38f24104c0f62c8991148adb5e981add1f
parent7c4717e01baf2cc5f4f6a73fc56109b527311c2d (diff)
parent743b42a782651d5f3b14ef5643684b9f31890389 (diff)
downloadcoreclr-e5bfd7d89ad0704a23545ac1e6d6a80918e2dbe5.tar.gz
coreclr-e5bfd7d89ad0704a23545ac1e6d6a80918e2dbe5.tar.bz2
coreclr-e5bfd7d89ad0704a23545ac1e6d6a80918e2dbe5.zip
Merge pull request #23325 from VSadov/CmpExchA64
Resolve 22303 (interlocked failures on ARM64)
-rw-r--r--tests/issues.targets18
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj2
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj2
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs70
-rw-r--r--tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs3
-rw-r--r--tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs61
6 files changed, 62 insertions, 94 deletions
diff --git a/tests/issues.targets b/tests/issues.targets
index 96c3d5241c..0e518744df 100644
--- a/tests/issues.targets
+++ b/tests/issues.targets
@@ -571,24 +571,6 @@
<ExcludeList Include="$(XunitTestBinBase)/GC/Scenarios/Dynamo/dynamo/*">
<Issue>17129</Issue>
</ExcludeList>
- <ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass/*">
- <Issue>22303</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass_1/*">
- <Issue>22303</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/interlocked/exchange/ExchangeTClass/*">
- <Issue>22303</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/interlocked/exchange/ExchangeTString/*">
- <Issue>22303</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/interlocked/exchange/ExchangeTString_1/*">
- <Issue>22303</Issue>
- </ExcludeList>
- <ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/interlocked/exchange/ExchangeTString_2/*">
- <Issue>22303</Issue>
- </ExcludeList>
</ItemGroup>
<!-- Unix arm32 specific -->
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj
index a3db344e61..3b30552d0c 100644
--- a/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj
@@ -10,7 +10,7 @@
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestExecutionArguments>null</CLRTestExecutionArguments>
+ <CLRTestExecutionArguments>""</CLRTestExecutionArguments>
<CLRTestPriority>1</CLRTestPriority>
<GCStressIncompatible>true</GCStressIncompatible>
</PropertyGroup>
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj b/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj
index 2e34b48f8b..b0cb6f0e20 100644
--- a/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj
@@ -12,7 +12,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLRTestKind>BuildAndRun</CLRTestKind>
<CLRTestPriority>1</CLRTestPriority>
- <CLRTestExecutionArguments>empty</CLRTestExecutionArguments>
+ <CLRTestExecutionArguments>"hello"</CLRTestExecutionArguments>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs
index a119d6b8da..956efba686 100644
--- a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs
@@ -6,7 +6,7 @@ using System.Threading;
class Class1
{
-
+
static int Main(string[] args)
{
int rValue = 0;
@@ -21,21 +21,21 @@ class Class1
threads[i] = new Thread(new ParameterizedThreadStart(tsi.ThreadWorker));
threads[i].Start(kcIn);
}
-
+
tsi.Signal();
Console.WriteLine("Joining threads");
- for(int i=0;i<threads.Length;i++)
+ for (int i = 0; i < threads.Length; i++)
threads[i].Join();
-
+
// Build the expected string
- KrisClass kcExpected = new KrisClass("hello world! ");
- for(int i=0;i<threads.Length * 100;i++)
+ KrisClass kcExpected = new KrisClass("hello world! ");
+ for (int i = 0; i < threads.Length * 100; i++)
kcExpected = kcExpected + kcIn;
- if(kcExpected == tsi.GetValue)
+ if (kcExpected == tsi.GetValue)
rValue = 100;
- Console.WriteLine("Test Expected {0}, but found {1}", kcExpected, tsi.GetValue);
+ Console.WriteLine("Test Expected {0}, but found {1}", kcExpected, tsi.GetValue);
Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
return rValue;
}
@@ -44,9 +44,9 @@ class Class1
public class ThreadSafe
{
ManualResetEvent signal;
- public KrisClass Val = new KrisClass("hello world! ");
+ public KrisClass Val = new KrisClass("hello world! ");
private int numberOfIterations;
- public ThreadSafe(): this(100) { }
+ public ThreadSafe() : this(100) { }
public ThreadSafe(int loops)
{
signal = new ManualResetEvent(false);
@@ -62,21 +62,23 @@ public class ThreadSafe
{
KrisClass kcIn = (KrisClass)objIn;
signal.WaitOne();
- for(int i=0;i<numberOfIterations;i++)
+ for (int i = 0; i < numberOfIterations; i++)
AddToTotal(kcIn);
}
private KrisClass AddToTotal(KrisClass addend)
{
- KrisClass initialValue = new KrisClass(string.Empty);
- KrisClass newValue = new KrisClass(string.Empty);
+ KrisClass initialValue;
+ KrisClass newValue;
+
do
{
initialValue = Val;
newValue = initialValue + addend;
- }
- while (initialValue != Interlocked.CompareExchange<KrisClass>(
+ }
+ while ((object)initialValue != Interlocked.CompareExchange<KrisClass>(
ref Val, newValue, initialValue));
+
return newValue;
}
@@ -104,7 +106,7 @@ public class KrisClass
return retVal;
}
}
-
+
public static KrisClass operator +(KrisClass kc1, KrisClass kc2)
{
return new KrisClass(kc1.ClassVal + kc2.ClassVal);
@@ -112,7 +114,7 @@ public class KrisClass
public static bool operator ==(KrisClass kc1, KrisClass kc2)
{
- if(kc1.ClassVal == kc2.ClassVal)
+ if (kc1.ClassVal == kc2.ClassVal)
return true;
else
return false;
@@ -120,26 +122,26 @@ public class KrisClass
public static bool operator !=(KrisClass kc1, KrisClass kc2)
{
- if(kc1.ClassVal != kc2.ClassVal)
+ if (kc1.ClassVal != kc2.ClassVal)
return true;
else
return false;
}
- public override bool Equals(object o)
- {
- try
- {
- return (bool) (this == (KrisClass) o);
- }
- catch
- {
- return false;
- }
- }
-
- public override int GetHashCode()
- {
- return 0;
- }
+ public override bool Equals(object o)
+ {
+ try
+ {
+ return (bool)(this == (KrisClass)o);
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return 0;
+ }
} \ No newline at end of file
diff --git a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs
index 82f1520fb2..386b081157 100644
--- a/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs
+++ b/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs
@@ -95,8 +95,9 @@ public class ThreadSafe
initialValue = Val;
newValue = initialValue + addend;
}
- while (initialValue != Interlocked.CompareExchange<string>(
+ while ((object)initialValue != Interlocked.CompareExchange<string>(
ref Val, newValue, initialValue));
+
return newValue;
}
}
diff --git a/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs b/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs
index 6c6f4865e8..26cfe38bf9 100644
--- a/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs
+++ b/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs
@@ -6,7 +6,7 @@ using System.Threading;
using System.Collections;
class Class1
-{
+{
static int Main(string[] args)
{
int rValue = 0;
@@ -17,10 +17,10 @@ class Class1
for (int i = 0; i < threads.Length - 1; i++)
{
if (i % 2 == 0)
- threads[i] = new Thread(new
+ threads[i] = new Thread(new
ParameterizedThreadStart(tsi.ThreadWorkerA));
else
- threads[i] = new Thread(new
+ threads[i] = new Thread(new
ParameterizedThreadStart(tsi.ThreadWorkerB));
threads[i].Start(args);
@@ -30,12 +30,6 @@ class Class1
threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker));
threads[threads.Length - 1].Start();
- //Added to prevent races where Checker does not get to Wait before ManualEvent is Set
- while(tsi.ThreadCount < 100)
- {
- Thread.Sleep(100);
- }
- Thread.Sleep(100);
tsi.Signal();
Console.WriteLine("Joining threads");
@@ -57,11 +51,8 @@ public class ThreadSafe
private string newValueA = "hello";
private string newValueB = "world";
private bool success;
- public volatile int ThreadCount = 0;
- private volatile static object syncroot = new object();
-
- public ThreadSafe(): this(10000) { }
+ public ThreadSafe() : this(10000) { }
public ThreadSafe(int loops)
{
@@ -81,28 +72,23 @@ public class ThreadSafe
string ret = null;
// get the value
- if(0 < str.Length)
+ if (0 < str.Length)
{
- if("null" == str[0])
+ if ("null" == str[0])
newValueA = null;
- else if("empty" == str[0])
+ else if ("empty" == str[0])
newValueA = string.Empty;
else
newValueA = str[0];
}
-
- lock(syncroot)
- {
- ThreadCount++;
- }
-
+
signal.WaitOne();
for (int i = 0; i < numberOfIterations; i++)
{
ret = Interlocked.Exchange<string>(ref curVal, newValueA);
-
+
// Check return value
- if(ret != newValueB && ret != newValueA && ret != "start string")
+ if (ret != newValueB && ret != newValueA && ret != "start string")
{
Console.WriteLine(ret + "," + newValueB + "," + newValueA);
success = false;
@@ -117,28 +103,24 @@ public class ThreadSafe
string ret = null;
// get the value
- if(2 == str.Length)
+ if (2 == str.Length)
{
- if("null" == str[1])
+ if ("null" == str[1])
newValueB = null;
- else if("empty" == str[1])
+ else if ("empty" == str[1])
newValueB = string.Empty;
else
newValueB = str[1];
}
- lock(syncroot)
- {
- ThreadCount++;
- }
+ signal.WaitOne();
- signal.WaitOne();
for (int i = 0; i < numberOfIterations; i++)
{
ret = Interlocked.Exchange<string>(ref curVal, newValueB);
// Check return value
- if(ret != newValueB && ret != newValueA && ret != "start string")
+ if (ret != newValueB && ret != newValueA && ret != "start string")
{
Console.WriteLine(ret + "," + newValueB + "," + newValueA);
success = false;
@@ -148,17 +130,18 @@ public class ThreadSafe
public void ThreadChecker()
{
- lock(syncroot)
- {
- ThreadCount++;
- }
-
signal.WaitOne();
+
+ while(curVal == "start string")
+ {
+ Thread.Sleep(0);
+ }
+
string tmpVal;
for (int i = 0; i < numberOfIterations; i++)
{
tmpVal = curVal;
- if (tmpVal != newValueB && tmpVal != newValueA && tmpVal != "start string")
+ if (tmpVal != newValueB && tmpVal != newValueA)
{
Console.WriteLine(tmpVal + "," + newValueB + "," + newValueA);
success = false;