Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5da0bde

Browse files
committed
Add a browser functional test for hot reload
Just check that the capabilities are non-empty which is a good proxy for hotreload being enabled in the runtime.
1 parentaa89d4c commit5da0bde

File tree

9 files changed

+302
-0
lines changed

9 files changed

+302
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<ProjectSdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TestRuntime>true</TestRuntime>
4+
<DeltaScript>deltascript.json</DeltaScript>
5+
<OutputType>library</OutputType>
6+
<IsTestProject>false</IsTestProject>
7+
<IsTestSupportProject>true</IsTestSupportProject>
8+
<!-- to call AsssemblyExtensions.ApplyUpdate we need Optimize=false, EmitDebugInformation=true in all configurations-->
9+
<Optimize>false</Optimize>
10+
<EmitDebugInformation>true</EmitDebugInformation>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<CompileInclude="MethodBody1.cs" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<!-- This package from https://github.com/dotnet/hotreload-utils provides
19+
targets that read the json delta script and generates deltas based on the baseline assembly and the modified sources.
20+
21+
Projects must define the DeltaScript property that specifies the (relative) path to the json script.
22+
Deltas will be emitted next to the output assembly. Deltas will be copied when the current
23+
project is referenced from other other projects.
24+
-->
25+
<PackageReferenceInclude="Microsoft.DotNet.HotReload.Utils.Generator.BuildTool"Version="$(MicrosoftDotNetHotReloadUtilsGeneratorBuildToolVersion)" />
26+
</ItemGroup>
27+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
4+
namespaceApplyUpdateReferencedAssembly
5+
{
6+
publicclassMethodBody1{
7+
publicstaticstringStaticMethod1(){
8+
return"OLD STRING";
9+
}
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
4+
namespaceApplyUpdateReferencedAssembly
5+
{
6+
publicclassMethodBody1{
7+
publicstaticstringStaticMethod1(){
8+
return"NEW STRING";
9+
}
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
4+
namespaceApplyUpdateReferencedAssembly
5+
{
6+
publicclassMethodBody1{
7+
publicstaticstringStaticMethod1(){
8+
return"NEWEST STRING";
9+
}
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"changes": [
3+
{"document":"MethodBody1.cs","update":"MethodBody1_v1.cs"},
4+
{"document":"MethodBody1.cs","update":"MethodBody1_v2.cs"},
5+
]
6+
}
7+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
4+
usingSystem;
5+
usingSystem.Reflection;
6+
usingSystem.Runtime.CompilerServices;
7+
8+
namespaceSample
9+
{
10+
publicclassTest
11+
{
12+
publicstaticvoidMain(string[]args)
13+
{
14+
Console.WriteLine("Hello, World!");
15+
}
16+
17+
[MethodImpl(MethodImplOptions.NoInlining)]
18+
publicstaticintTestMeaning()
19+
{
20+
constintsuccess=42;
21+
constintfailure=1;
22+
23+
varty=typeof(System.Reflection.Metadata.AssemblyExtensions);
24+
varmi=ty.GetMethod("GetApplyUpdateCapabilities",BindingFlags.NonPublic|BindingFlags.Static,Array.Empty<Type>());
25+
26+
if(mi==null)
27+
returnfailure;
28+
29+
varcaps=mi.Invoke(null,null)asstring;
30+
31+
if(String.IsNullOrEmpty(caps))
32+
returnfailure;
33+
34+
varassm=typeof(ApplyUpdateReferencedAssembly.MethodBody1).Assembly;
35+
36+
varr=ApplyUpdateReferencedAssembly.MethodBody1.StaticMethod1();
37+
if("OLD STRING"!=r)
38+
returnfailure;
39+
40+
ApplyUpdate(assm);
41+
42+
r=ApplyUpdateReferencedAssembly.MethodBody1.StaticMethod1();
43+
if("NEW STRING"!=r)
44+
returnfailure;
45+
46+
ApplyUpdate(assm);
47+
48+
r=ApplyUpdateReferencedAssembly.MethodBody1.StaticMethod1();
49+
if("NEWEST STRING"!=r)
50+
returnfailure;
51+
52+
returnsuccess;
53+
}
54+
55+
56+
privatestaticSystem.Collections.Generic.Dictionary<Assembly,int>assembly_count=new();
57+
58+
internalstaticvoidApplyUpdate(System.Reflection.Assemblyassm)
59+
{
60+
intcount;
61+
if(!assembly_count.TryGetValue(assm,outcount))
62+
count=1;
63+
else
64+
count++;
65+
assembly_count[assm]=count;
66+
67+
/* FIXME WASM: Location is empty on wasm. Make up a name based on Name */
68+
stringbasename=assm.Location;
69+
if(basename=="")
70+
basename=assm.GetName().Name+".dll";
71+
Console.Error.WriteLine($"Apply Delta Update for{basename}, revision{count}");
72+
73+
stringdmeta_name=$"{basename}.{count}.dmeta";
74+
stringdil_name=$"{basename}.{count}.dil";
75+
byte[]dmeta_data=System.IO.File.ReadAllBytes(dmeta_name);
76+
byte[]dil_data=System.IO.File.ReadAllBytes(dil_name);
77+
byte[]dpdb_data=null;// TODO also use the dpdb data
78+
79+
System.Reflection.Metadata.AssemblyExtensions.ApplyUpdate(assm,dmeta_data,dil_data,dpdb_data);
80+
}
81+
}
82+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<ProjectSdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<MonoForceInterpreter>true</MonoForceInterpreter>
4+
<RunAOTCompilation>false</RunAOTCompilation>
5+
<TestRuntime>true</TestRuntime>
6+
<Scenario>WasmTestOnBrowser</Scenario>
7+
<ExpectedExitCode>42</ExpectedExitCode>
8+
<WasmMainJSPath>runtime.js</WasmMainJSPath>
9+
<EnableDefaultItems>false</EnableDefaultItems>
10+
<!-- setting WasmXHarnessMonoArgs doesn't work here, but see runtime.js-->
11+
<!-- <WasmXHarnessMonoArgs>- -setenv=DOTNET_MODIFIABLE_ASSEMBLIES=debug</WasmXHarnessMonoArgs>-->
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<CompileInclude="Program.cs" />
15+
<ContentInclude="index.html">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</Content>
18+
<ProjectReferenceInclude="ApplyUpdateReferencedAssembly\ApplyUpdateReferencedAssembly.csproj" />
19+
</ItemGroup>
20+
21+
<TargetName="AfterWasmBuildApp"AfterTargets="WasmBuildApp">
22+
<CopySourceFiles="$(OutDir)\index.html"DestinationFolder="$(WasmAppDir)" />
23+
</Target>
24+
25+
<TargetName="PreserveEnCAssembliesFromLinking"
26+
Condition="'$(TargetOS)' == 'Browser' and '$(EnableAggressiveTrimming)' == 'true'"
27+
BeforeTargets="ConfigureTrimming">
28+
<ItemGroup>
29+
<!-- Don't modify EnC test assemblies-->
30+
<TrimmerRootAssembly
31+
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('ApplyUpdateReferencedAssembly.dll'))"
32+
Include="%(ResolvedFileToPublish.FullPath)" />
33+
</ItemGroup>
34+
</Target>
35+
36+
<TargetName="IncludeDeltasInWasmBundle"
37+
BeforeTargets="PrepareForWasmBuildApp"
38+
Condition="'$(TargetOS)' == 'Browser'">
39+
<ItemGroup>
40+
<!-- FIXME: this belongs in eng/testing/tests.wasm.targets-->
41+
<!-- FIXME: Can we do something on the Content items in the referenced projects themselves to get this for free?-->
42+
<WasmFilesToIncludeInFileSystemInclude="@(PublishItemsOutputGroupOutputs)"
43+
Condition="$([System.String]::new('%(PublishItemsOutputGroupOutputs.Identity)').EndsWith('.dmeta'))" />
44+
<WasmFilesToIncludeInFileSystemInclude="@(PublishItemsOutputGroupOutputs)"
45+
Condition="$([System.String]::new('%(PublishItemsOutputGroupOutputs.Identity)').EndsWith('.dil'))" />
46+
<WasmFilesToIncludeInFileSystemInclude="@(PublishItemsOutputGroupOutputs)"
47+
Condition="$([System.String]::new('%(PublishItemsOutputGroupOutputs.Identity)').EndsWith('.dpdb'))" />
48+
</ItemGroup>
49+
</Target>
50+
51+
</Project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<!-- Licensed to the .NET Foundation under one or more agreements. -->
3+
<!-- The .NET Foundation licenses this file to you under the MIT license. -->
4+
<html>
5+
<head>
6+
<title>TESTS</title>
7+
<metacharset="UTF-8">
8+
<metaname="viewport"content="width=device-width, initial-scale=1.0">
9+
</head>
10+
<bodyonload="onLoad()">
11+
<h3id="header">Wasm Browser Sample</h3>
12+
Result from Sample.Test.TestMeaning:<spanid="out"></span>
13+
<scripttype='text/javascript'>
14+
varis_testing=false;
15+
varonLoad=function(){
16+
varurl=newURL(decodeURI(window.location));
17+
letargs=url.searchParams.getAll('arg');
18+
is_testing=args!==undefined&&(args.find(arg=>arg=='--testing')!==undefined);
19+
};
20+
21+
vartest_exit=function(exit_code)
22+
{
23+
if(!is_testing){
24+
console.log(`test_exit:${exit_code}`);
25+
return;
26+
}
27+
28+
/* Set result in a tests_done element, to be read by xharness */
29+
vartests_done_elem=document.createElement("label");
30+
tests_done_elem.id="tests_done";
31+
tests_done_elem.innerHTML=exit_code.toString();
32+
document.body.appendChild(tests_done_elem);
33+
34+
console.log(`WASM EXIT${exit_code}`);
35+
};
36+
37+
varApp={
38+
init:function(){
39+
varexit_code=BINDING.call_static_method("[WebAssembly.Browser.HotReload.Test] Sample.Test:TestMeaning",[]);
40+
document.getElementById("out").innerHTML=exit_code;
41+
42+
if(is_testing)
43+
{
44+
console.debug(`exit_code:${exit_code}`);
45+
test_exit(exit_code);
46+
}
47+
},
48+
};
49+
</script>
50+
<scripttype="text/javascript"src="runtime.js"></script>
51+
52+
<scriptdefersrc="dotnet.js"></script>
53+
54+
</body>
55+
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
4+
varModule={
5+
6+
config:null,
7+
8+
preInit:asyncfunction(){
9+
Module.config=awaitMONO.mono_wasm_load_config("./mono-config.json");
10+
},
11+
12+
onRuntimeInitialized:function(){
13+
if(!Module.config||Module.config.error){
14+
console.log("No config found");
15+
test_exit(1);
16+
throw(Module.config.error);
17+
}
18+
19+
Module.config.loaded_cb=function(){
20+
try{
21+
App.init();
22+
}catch(error){
23+
test_exit(1);
24+
throw(error);
25+
}
26+
};
27+
Module.config.fetch_file_cb=function(asset){
28+
returnfetch(asset,{credentials:'same-origin'});
29+
}
30+
31+
if(Module.config.environment_variables!==undefined){
32+
console.log("expected environment variables to be undefined, but they're: ",Module.config.environment_variables);
33+
test_exit(1);
34+
}
35+
Module.config.environment_variables={
36+
"DOTNET_MODIFIABLE_ASSEMBLIES":"debug"
37+
};
38+
39+
try
40+
{
41+
MONO.mono_load_runtime_and_bcl_args(Module.config);
42+
}catch(error){
43+
test_exit(1);
44+
throw(error);
45+
}
46+
},
47+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp