Skip to content
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

Add zoneinfo data for System.Runtime.TimeZoneInfoTests #38219

Merged
merged 13 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>629993236116221fba87fe1de6d7893dd02c3722</Sha>
</Dependency>
<Dependency Name="System.Runtime.TestData" Version="5.0.0-beta.20319.2">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>629993236116221fba87fe1de6d7893dd02c3722</Sha>
</Dependency>
<Dependency Name="System.Private.Runtime.UnicodeData" Version="5.0.0-beta.20319.2">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>629993236116221fba87fe1de6d7893dd02c3722</Sha>
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<SystemPrivateRuntimeUnicodeDataVersion>5.0.0-beta.20319.2</SystemPrivateRuntimeUnicodeDataVersion>
<SystemSecurityCryptographyX509CertificatesTestDataVersion>5.0.0-beta.20319.2</SystemSecurityCryptographyX509CertificatesTestDataVersion>
<SystemWindowsExtensionsTestDataVersion>5.0.0-beta.20319.2</SystemWindowsExtensionsTestDataVersion>
<SystemRuntimeTestDataVersion>5.0.0-beta.20319.2</SystemRuntimeTestDataVersion>
tqiu8 marked this conversation as resolved.
Show resolved Hide resolved
<!-- Standard dependencies -->
<NETStandardLibraryVersion>2.2.0-prerelease.19564.1</NETStandardLibraryVersion>
<!-- dotnet-optimization dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@
<Compile Include="$(CommonTestPath)System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs"
Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.TestData" Version="$(SystemRuntimeTestDataVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="TestLoadAssembly\TestLoadAssembly.csproj" />
<ProjectReference Include="TestCollectibleAssembly\TestCollectibleAssembly.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/mono/netcore/sample/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ clean:
rm -rf bin

run:
cd bin/$(CONFIG)/publish && ~/.jsvu/v8 --expose_wasm runtime.js -- --enable-gc --run WasmSample.dll
cd bin/$(CONFIG)/publish && ~/.jsvu/v8 --expose_wasm runtime.js -- --enable-gc --enable-zoneinfo --run WasmSample.dll
safern marked this conversation as resolved.
Show resolved Hide resolved

runtimepack:
EMSDK_PATH=$(abspath $(TOP)/src/mono/wasm/emsdk) $(TOP)/build.sh -c $(CONFIG) -os Browser -arch wasm -subset Mono+Libs
129 changes: 129 additions & 0 deletions src/mono/netcore/sample/wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,139 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading.Tasks;
tqiu8 marked this conversation as resolved.
Show resolved Hide resolved
using System.Threading;
using System.Collections;
using System.Globalization;
using Xunit;

public class Test
{
private const int NumberOfElements = 100;
private static Stack _stackDaughter;
private static Stack _stackGrandDaughter;
public static async Task GetSyncRootBasic () {
var stackMother = new Stack ();
for (int i = 0; i < NumberOfElements; i++)
{
stackMother.Push(i);
}

Assert.IsType<Stack>(stackMother.SyncRoot);
Stack stackSon = Stack.Synchronized(stackMother);
_stackGrandDaughter = Stack.Synchronized(stackSon);
_stackDaughter = Stack.Synchronized(stackMother);

Assert.Equal(stackSon.SyncRoot, stackMother.SyncRoot);
Assert.Equal(_stackGrandDaughter.SyncRoot, stackMother.SyncRoot);
Assert.Equal(_stackDaughter.SyncRoot, stackMother.SyncRoot);
Assert.Equal(stackSon.SyncRoot, stackMother.SyncRoot);

Action ts1 = SortElements;
Action ts2 = ReverseElements;
var tasks = new Task[4];
for (int iThreads = 0; iThreads < tasks.Length; iThreads += 2)
{
tasks[iThreads] = Task.Run(ts1);
tasks[iThreads + 1] = Task.Run(ts2);
}

await Task.WhenAll(tasks);
}

private static void SortElements()
{
_stackGrandDaughter.Clear();
for (int i = 0; i < NumberOfElements; i++)
{
_stackGrandDaughter.Push(i);
}
}

private static void ReverseElements()
{
_stackDaughter.Clear();
for (int i = 0; i < NumberOfElements; i++)
{
_stackDaughter.Push(i);
}
}

public static async Task ThreadPoolTest () {
bool min = ThreadPool.SetMinThreads(1,1);
bool max = ThreadPool.SetMaxThreads(1,1);

int workerThreads;
int portThreads;

Console.WriteLine("SetMinThreads returns: {0} \nSetMaxThreads returns {1}",
min, max);

ThreadPool.GetMaxThreads(out workerThreads, out portThreads);
Console.WriteLine("\nMaximum worker threads: \t{0}" +
"\nMaximum completion port threads: {1}",
workerThreads, portThreads);

ThreadPool.GetMinThreads(out workerThreads,
out portThreads);
Console.WriteLine("\nMinimum worker threads: \t{0}" +
"\nAvailable completion port threads: {1}\n",
workerThreads, portThreads);

ThreadPool.GetAvailableThreads(out workerThreads,
out portThreads);
Console.WriteLine("\nAvailable worker threads: \t{0}" +
"\nAvailable completion port threads: {1}\n",
workerThreads, portThreads);

await GetSyncRootBasic ();
}

private static TimeZoneInfo CreateCustomLondonTimeZone()
{
TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 1, 0, 0), 3, 5, DayOfWeek.Sunday);
TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 10, 5, DayOfWeek.Sunday);
TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan(1, 0, 0), start, end);
return TimeZoneInfo.CreateCustomTimeZone("Europe/London", new TimeSpan(0), "Europe/London", "British Standard Time", "British Summer Time", new TimeZoneInfo.AdjustmentRule[] { rule });
}

public static void ConvertTimeFromToUtc () {
TimeZoneInfo london = CreateCustomLondonTimeZone ();

DateTime utc = DateTime.UtcNow;
Assert.Equal(DateTimeKind.Utc, utc.Kind);

DateTime converted = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Utc);
Assert.Equal(DateTimeKind.Utc, converted.Kind);
DateTime back = TimeZoneInfo.ConvertTimeToUtc(converted, TimeZoneInfo.Utc);
Assert.Equal(DateTimeKind.Utc, back.Kind);
Assert.Equal(utc, back);

Console.WriteLine("converted date {0}", converted);

converted = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Local);
DateTimeKind expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc) ? DateTimeKind.Utc : DateTimeKind.Local;
Assert.Equal(expectedKind, converted.Kind);
back = TimeZoneInfo.ConvertTimeToUtc(converted, TimeZoneInfo.Local);
Assert.Equal(DateTimeKind.Utc, back.Kind);
Assert.Equal(utc, back);
}

public static void HasSameRules_RomeAndVatican()
{
TimeZoneInfo rome = TimeZoneInfo.FindSystemTimeZoneById("Europe/Rome");
TimeZoneInfo vatican = TimeZoneInfo.FindSystemTimeZoneById("Europe/Vatican");
Console.WriteLine("ROME: {0}", rome.StandardName);
// Assert.True(rome.HasSameRules(vatican));
}

public static void Main (String[] args) {
Console.WriteLine ("Hello, World!");

// ConvertTimeFromToUtc ();
TimeZoneInfo.FindSystemTimeZoneById("Europe/London");
HasSameRules_RomeAndVatican ();


}
}
11 changes: 9 additions & 2 deletions src/mono/netcore/sample/wasm/WasmSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Targets="Build;Publish"/>
</Target>

<UsingTask TaskName="WasmAppBuilder"
<UsingTask TaskName="WasmAppBuilder"
AssemblyFile="$(ArtifactsBinDir)WasmAppBuilder\$(Configuration)\$(NetCoreAppCurrent)\publish\WasmAppBuilder.dll"/>

<Target Name="BuildApp" DependsOnTargets="RebuildWasmAppBuilder;Build">
Expand All @@ -39,11 +39,18 @@
MicrosoftNetCoreAppRuntimePackDir="$(MicrosoftNetCoreAppRuntimePackDir)"
MainAssembly="bin\WasmSample.dll"
MainJS="$(MonoProjectRoot)wasm\runtime-test.js"
AssemblySearchPaths="@(AssemblySearchPaths)"/>
AssemblySearchPaths="@(AssemblySearchPaths)"
FilesToIncludeInFileSystem="@(WasmFilesToIncludeInFileSystem)"
/>
<Exec Command="chmod a+x $(AppDir)/run-v8.sh" />
</Target>

<ItemGroup>
<PackageReference Include="System.Runtime.TestData" Version="$(SystemRuntimeTestDataVersion)" />
tqiu8 marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
</Project>

74 changes: 38 additions & 36 deletions src/mono/wasm/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ function fail_exec (reason) {
}

function inspect_object (o) {
var r = "";
for(var p in o) {
var t = typeof o[p];
r += "'" + p + "' => '" + t + "', ";
}
return r;
var r = "";
for(var p in o) {
var t = typeof o[p];
r += "'" + p + "' => '" + t + "', ";
}
return r;
}

// Preprocess arguments
Expand Down Expand Up @@ -132,7 +132,7 @@ while (true) {
args = args.slice (1);
} else if (args [0] == "--enable-zoneinfo") {
enable_zoneinfo = true;
args = args.slice (1);
args = args.slice (1);
} else {
break;
}
Expand All @@ -149,7 +149,7 @@ function writeContentToFile(content, path)
if (typeof window == "undefined")
load ("mono-config.js");

var Module = {
var Module = {
mainScriptUrlOrBlob: "dotnet.js",

print: function(x) { print ("WASM: " + x) },
Expand Down Expand Up @@ -206,35 +206,37 @@ var Module = {
f ();
}
if (enable_zoneinfo) {
// Load the zoneinfo data into the VFS rooted at /zoneinfo
FS.mkdir("zoneinfo");
Module['FS_createPath']('/', 'zoneinfo', true, true);
Module['FS_createPath']('/zoneinfo', 'Indian', true, true);
Module['FS_createPath']('/zoneinfo', 'Atlantic', true, true);
Module['FS_createPath']('/zoneinfo', 'US', true, true);
Module['FS_createPath']('/zoneinfo', 'Brazil', true, true);
Module['FS_createPath']('/zoneinfo', 'Pacific', true, true);
Module['FS_createPath']('/zoneinfo', 'Arctic', true, true);
Module['FS_createPath']('/zoneinfo', 'America', true, true);
Module['FS_createPath']('/zoneinfo/America', 'Indiana', true, true);
Module['FS_createPath']('/zoneinfo/America', 'Argentina', true, true);
Module['FS_createPath']('/zoneinfo/America', 'Kentucky', true, true);
Module['FS_createPath']('/zoneinfo/America', 'North_Dakota', true, true);
Module['FS_createPath']('/zoneinfo', 'Australia', true, true);
Module['FS_createPath']('/zoneinfo', 'Etc', true, true);
Module['FS_createPath']('/zoneinfo', 'Asia', true, true);
Module['FS_createPath']('/zoneinfo', 'Antarctica', true, true);
Module['FS_createPath']('/zoneinfo', 'Europe', true, true);
Module['FS_createPath']('/zoneinfo', 'Mexico', true, true);
Module['FS_createPath']('/zoneinfo', 'Africa', true, true);
Module['FS_createPath']('/zoneinfo', 'Chile', true, true);
Module['FS_createPath']('/zoneinfo', 'Canada', true, true);
var zoneInfoData = read ('zoneinfo.data', 'binary');
var metadata = JSON.parse(read ("mono-webassembly-zoneinfo-fs-smd.js.metadata", 'utf-8'));
FS.mkdir("usr");
Module['FS_createPath']('/', 'usr', true, true);
FS.mkdir("share");
Module['FS_createPath']('/usr', 'share', true, true);
FS.mkdir("/usr/share/zoneinfo")
Module['FS_createPath']('/usr/share/zoneinfo', 'Indian', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Atlantic', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'US', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Brazil', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Pacific', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Arctic', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'America', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'Indiana', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'Argentina', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'Kentucky', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'North_Dakota', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Australia', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Etc', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Asia', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Antarctica', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Europe', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Mexico', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Africa', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Chile', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Canada', true, true);
var zoneInfoData = new Uint8Array(read ('supportFiles/zoneinfo/zoneinfo.data', 'binary'));
var metadata = JSON.parse(read ("supportFiles/zoneinfo/mono-webassembly-zoneinfo-fs-smd.js.metadata", 'utf-8'));
var files = metadata.files;
for (var i = 0; i < files.length; ++i) {
var byteArray = zoneInfoData.subarray(files[i].start, files[i].end);
writeContentToFile(byteArray, files[i].filename);
writeContentToFile(byteArray, `/usr/share${files[i].filename}`);
}
}
MONO.mono_load_runtime_and_bcl (
Expand Down Expand Up @@ -283,7 +285,7 @@ if (typeof window == "undefined")
const IGNORE_PARAM_COUNT = -1;

var App = {
init: function () {
init: function () {

var assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string'])
var find_class = Module.cwrap ('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string'])
Expand Down Expand Up @@ -400,5 +402,5 @@ var App = {
} else {
fail_exec ("Unhanded argument: " + args [0]);
}
},
},
};