Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 9378be6

Browse files
committed
Merge pull request #3563 from adityamandaleeka/threading_test_port_2
Open source even more threading tests
2 parents 18579f6 + 7c0cefd commit 9378be6

File tree

397 files changed

+23639
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+23639
-517
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Threading;
7+
8+
public class Test
9+
{
10+
11+
public static int Main()
12+
{
13+
int retVal = 100;
14+
15+
int val = 20;
16+
int adder= 5;
17+
int foo = Interlocked.Add(ref val, adder);
18+
Console.WriteLine("NewValue: " + val);
19+
Console.WriteLine("OldValue: " + foo);
20+
//if(foo != 20 && val != 25)
21+
if ((val != 25) || (foo != val))
22+
retVal = -1;
23+
24+
long val1 = 20;
25+
long adder1= 5;
26+
long foo1 = Interlocked.Add(ref val1, adder1);
27+
Console.WriteLine("NewValue: " + val1);
28+
Console.WriteLine("OldValue: " + foo1);
29+
//if(foo1 != 20 && val1 != 25)
30+
if ((val1 != 25) || (foo1 != val1))
31+
retVal = -1;
32+
33+
if (retVal == 100)
34+
Console.WriteLine("Test passed");
35+
else
36+
Console.WriteLine("Test failed");
37+
38+
return retVal;
39+
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<FileAlignment>512</FileAlignment>
12+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
15+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
16+
<CLRTestPriority>1</CLRTestPriority>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<!-- Add Compile Object Here -->
30+
<Compile Include="add.cs" />
31+
</ItemGroup>
32+
<ItemGroup>
33+
<None Include="app.config" />
34+
<None Include="project.json" />
35+
</ItemGroup>
36+
<ItemGroup>
37+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
38+
</ItemGroup>
39+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
40+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
41+
</PropertyGroup>
42+
</Project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Threading;
7+
//Regression for DevDiv Bugs 48020
8+
namespace ExchangeAdd
9+
{
10+
class InterlockedAddInt
11+
{
12+
static int Main(string[] args)
13+
{
14+
// Check number of args
15+
if(args.Length != 2)
16+
{
17+
Console.WriteLine("USAGE: InterlockedAddIntWithSubtract " +
18+
"/loops:<int> /addVal:<int>");
19+
return -1;
20+
}
21+
22+
// Get the args
23+
int loops=100;
24+
int valueToAdd = 0;
25+
26+
for(int i=0;i<args.Length;i++)
27+
{
28+
if(args[i].ToLower().StartsWith("/loops:"))
29+
{
30+
loops = Convert.ToInt32(args[i].Substring(7));
31+
continue;
32+
}
33+
34+
if(args[i].ToLower().StartsWith("/addval:"))
35+
{
36+
valueToAdd = Convert.ToInt32(args[i].Substring(8));
37+
continue;
38+
}
39+
}
40+
41+
int rValue = 0;
42+
Thread[] threads = new Thread[100];
43+
ThreadSafe tsi = new ThreadSafe(loops, valueToAdd);
44+
for (int i = 0; i < threads.Length; i++)
45+
{
46+
threads[i] = new Thread(new ThreadStart(tsi.ThreadWorker));
47+
threads[i].Start();
48+
}
49+
50+
tsi.Signal();
51+
52+
for (int i = 0; i < threads.Length; i++)
53+
threads[i].Join();
54+
55+
if (tsi.Total == tsi.Expected * threads.Length)
56+
rValue = 100;
57+
Console.WriteLine("Expected: " + (tsi.Expected * threads.Length));
58+
Console.WriteLine("Actual: " + tsi.Total);
59+
Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
60+
return rValue;
61+
}
62+
}
63+
64+
public class ThreadSafe
65+
{
66+
ManualResetEvent signal;
67+
private int totalValue = 0;
68+
private int numberOfIterations;
69+
private int valueToAdd;
70+
private int valueToSubtract;
71+
public ThreadSafe(): this(100,100) { }
72+
public ThreadSafe(int loops, int iAdd)
73+
{
74+
signal = new ManualResetEvent(false);
75+
numberOfIterations = loops;
76+
valueToAdd = iAdd;
77+
valueToSubtract = 0-iAdd;
78+
}
79+
80+
public void Signal()
81+
{
82+
signal.Set();
83+
}
84+
85+
public void ThreadWorker()
86+
{
87+
signal.WaitOne();
88+
for (int i = 0; i < numberOfIterations; i++)
89+
{
90+
Interlocked.Add(ref totalValue, valueToAdd);
91+
Interlocked.Add(ref totalValue, valueToSubtract);
92+
}
93+
94+
}
95+
public int Expected
96+
{
97+
get
98+
{
99+
return (0);
100+
}
101+
}
102+
public int Total
103+
{
104+
get { return totalValue; }
105+
}
106+
}
107+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<FileAlignment>512</FileAlignment>
12+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
15+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
16+
<CLRTestPriority>1</CLRTestPriority>
17+
<CLRTestExecutionArguments>/loops:500000 /addVal:1</CLRTestExecutionArguments>
18+
</PropertyGroup>
19+
<!-- Default configurations to help VS understand the configurations -->
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
</PropertyGroup>
24+
<ItemGroup>
25+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
26+
<Visible>False</Visible>
27+
</CodeAnalysisDependentAssemblyPaths>
28+
</ItemGroup>
29+
<ItemGroup>
30+
<!-- Add Compile Object Here -->
31+
<Compile Include="InterlockedAddIntWithSubtract.cs" />
32+
</ItemGroup>
33+
<ItemGroup>
34+
<None Include="app.config" />
35+
<None Include="project.json" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
39+
</ItemGroup>
40+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
41+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
42+
</PropertyGroup>
43+
</Project>

tests/src/baseservices/threading/readerwriterlockslim/app.config renamed to tests/src/baseservices/threading/interlocked/checkreturn/app.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
2323
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
2424
</dependentAssembly>
25+
<dependentAssembly>
26+
<assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
27+
<bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
28+
</dependentAssembly>
2529
</assemblyBinding>
2630
</runtime>
27-
</configuration>
31+
</configuration>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Threading;
7+
8+
namespace InterlockedTest
9+
{
10+
class InterlockTest
11+
{
12+
13+
public static int Main(string[] Args)
14+
{
15+
int rValue;
16+
IntTest testInt = new IntTest(100, 10);
17+
18+
Console.WriteLine("Check Inc Returnt: {0}", rValue = testInt.CheckDecReturn());
19+
Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
20+
return rValue;
21+
}
22+
}
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<FileAlignment>512</FileAlignment>
12+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
15+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
16+
<CLRTestPriority>1</CLRTestPriority>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<!-- Add Compile Object Here -->
30+
<Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
31+
<Compile Include="IntDecCheckReturn.cs" />
32+
</ItemGroup>
33+
<ItemGroup>
34+
<None Include="app.config" />
35+
<None Include="project.json" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
39+
</ItemGroup>
40+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
41+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
42+
</PropertyGroup>
43+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Threading;
7+
8+
namespace InterlockedTest
9+
{
10+
class InterlockTest
11+
{
12+
13+
public static int Main(string[] Args)
14+
{
15+
int rValue;
16+
IntTest testInt = new IntTest(100, 10);
17+
18+
Console.WriteLine("Check Inc Returnt: {0}", rValue = testInt.CheckIncReturn());
19+
Console.WriteLine("Test {0}", 100 == rValue ? "Passed" : "Failed");
20+
return rValue;
21+
}
22+
}
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<FileAlignment>512</FileAlignment>
12+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
15+
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
16+
<CLRTestPriority>1</CLRTestPriority>
17+
</PropertyGroup>
18+
<!-- Default configurations to help VS understand the configurations -->
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
</PropertyGroup>
23+
<ItemGroup>
24+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
25+
<Visible>False</Visible>
26+
</CodeAnalysisDependentAssemblyPaths>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<!-- Add Compile Object Here -->
30+
<Compile Include="..\common\InterlockedHelper_CoreCLR.cs" />
31+
<Compile Include="IntIncCheckReturn.cs" />
32+
</ItemGroup>
33+
<ItemGroup>
34+
<None Include="app.config" />
35+
<None Include="project.json" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
39+
</ItemGroup>
40+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
41+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
42+
</PropertyGroup>
43+
</Project>

0 commit comments

Comments
 (0)