Skip to content

Update core library to add support for generics <T> #242

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

Merged
merged 75 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
0b4d241
Bump version to 2.0
josesimoes Mar 13, 2023
7d53a44
Remove empty file
josesimoes Mar 13, 2023
18ec78d
Clean-up ghost linked files
josesimoes Mar 13, 2023
256c8a3
Update test framework sub-module @0928fa9
josesimoes Apr 3, 2023
270c8c3
Update Unit test projects
josesimoes Apr 3, 2023
7704536
Move runsetting to nano version
josesimoes Apr 27, 2023
2c9a590
Update test dummy adapter
josesimoes Apr 27, 2023
465b6fe
Move runsettings to dummy test adapter
josesimoes Apr 27, 2023
fb9cd1d
remove wrong file
josesimoes Apr 27, 2023
fb3230c
Fix unit test project
josesimoes Apr 27, 2023
9d81efc
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes May 29, 2023
e0ceaab
Add unit tests to cover typeof (#205)
josesimoes Jun 9, 2023
5a6ebe1
Add Unit Tests for GC (#206)
josesimoes Oct 20, 2023
41507de
Work CI-CD
josesimoes Oct 30, 2023
0defde4
Adding nanoFramework.Graphics and nanoFramework.Graphics.Core to frie…
CoryCharlton Nov 3, 2023
971ed70
Add Unit Tests for GC and strings (#209)
josesimoes Nov 7, 2023
76efe86
Switching MathInternal.Min/Max to managed implementations (#208)
CoryCharlton Nov 9, 2023
b971f34
Work CI-CD
josesimoes Nov 8, 2023
9341cb1
Work CI-CD
josesimoes Nov 9, 2023
2a13f16
Work CI-CD
josesimoes Nov 9, 2023
bfce1d7
Fix GC Unit Tests project (#210)
josesimoes Nov 9, 2023
e862eb6
Adding some unit tests for `string` (#211)
CoryCharlton Nov 11, 2023
bc3b302
Add unit test for hash code of class objects (#212)
josesimoes Dec 7, 2023
4e0f337
Work CI-CD
josesimoes Jan 29, 2024
05c5f5e
Rework Unit Tests and Test Framework (#213)
CoryCharlton Jun 13, 2024
f468ea6
Enable destructor and finalizer tests (#215)
josesimoes Sep 20, 2024
b5ce979
Fixed order of parameters in several Unit Tests (#216)
josesimoes Oct 3, 2024
cb42176
Code style fixes
josesimoes Oct 23, 2024
1c9e00b
Add `String.Concat` tests (#217)
josesimoes Oct 23, 2024
136e65d
Improve attribute constructor handling when calling `Type.GetCustomAt…
CoryCharlton Jan 17, 2025
24e4ab8
Add gitattributes file
josesimoes Jan 24, 2025
1dc6ded
Normalize files
josesimoes Jan 24, 2025
37c85de
Add `ExcludeFromStubs` attribute (#220)
CoryCharlton Jan 29, 2025
cce6f77
Rework datetime handling in Convert (#222)
josesimoes Jan 29, 2025
0051e0f
Fix `UtcNow` and `Today` (#221)
josesimoes Jan 29, 2025
6789454
Remove unused files
josesimoes Jan 29, 2025
cd5be82
Work CI-CD
josesimoes Jan 29, 2025
c33f1ea
Moving attributes from System.Runtime (#219)
CoryCharlton Jan 29, 2025
65a78a0
Add null helpers to argument exceptions (#223)
CoryCharlton Jan 29, 2025
1f779f1
Add editor config and spelling exclusion dic
josesimoes Feb 3, 2025
60fbb7c
Rename attribute to exclude types (#226)
josesimoes Feb 3, 2025
5bc6ee8
Add NativeProfiled attribute (#227)
josesimoes Feb 3, 2025
76cc31b
Fix message for `ArgumentException` (#228)
josesimoes Feb 3, 2025
b4fd960
Add unit tests for new nullable attributes (#225)
CoryCharlton Feb 3, 2025
8b7a24c
Work and improvements in unit tests (#232)
josesimoes Feb 6, 2025
5a19047
Rework `Guid` (#233)
josesimoes Feb 25, 2025
2925e1b
Remove types to exclude from project file (#234)
josesimoes Feb 25, 2025
0fef780
Rework ArgumentNullException (#235)
josesimoes Feb 25, 2025
b34f233
Fix inclusion of DefaultMemberAttribute in no reflection version (#239)
josesimoes Feb 28, 2025
a26c479
Fix TestFramework clone project (#238)
josesimoes Feb 28, 2025
d51b036
Fix `Guid.TryParseGuidWithDashes()` and `Guid` constructor with strin…
josesimoes Mar 10, 2025
4f1e809
Update test framework sub-module @5182f1f
josesimoes Mar 14, 2025
778672c
Fix types wrongly excluded from metadata
josesimoes Mar 17, 2025
67abf19
Fix missing source file in project
josesimoes Mar 18, 2025
2b3ec89
Update test framework sub-module @c0a77fd
josesimoes Mar 19, 2025
601e5d7
Add extra output to unit test to help debug
josesimoes Mar 21, 2025
40ce642
Fix UnitTestReflectionType tests
josesimoes Mar 21, 2025
d3d1dac
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes Mar 31, 2025
c228f9f
Fix types wrongly excluded from metadata
josesimoes Mar 17, 2025
674924b
Rename TryParse Guid
josesimoes Mar 31, 2025
d24d148
Rename runsetting file
josesimoes Apr 1, 2025
912cb27
Fix merge
josesimoes Apr 1, 2025
fb57d7f
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes Apr 2, 2025
bf70ecc
Work on `GC` APIs (#243)
josesimoes Apr 2, 2025
7ed9467
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes Apr 3, 2025
c5a581c
Merge branch 'main' of https://github.com/nanoframework/CoreLibrary i…
josesimoes Apr 4, 2025
f437d54
Bump native assembly version
josesimoes Apr 4, 2025
6fbdec2
Add preview to nbgv version config
josesimoes Apr 4, 2025
d520712
Work CI-CD
josesimoes Apr 4, 2025
6abe4b8
Work CI-CD
josesimoes Apr 4, 2025
530fb99
Fix nuspec to package with nano TFM
josesimoes Apr 16, 2025
b262767
Work CI-CD
josesimoes Apr 16, 2025
1a7c138
Update test sub-module @18e4b3d
josesimoes Apr 17, 2025
aee2353
Update runsettings to use preview CLR
josesimoes Apr 17, 2025
b114fb7
Remove "generics" from branch trigger
josesimoes Apr 17, 2025
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
5 changes: 3 additions & 2 deletions .runsettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
Expand All @@ -12,5 +12,6 @@
<Logging>Verbose</Logging>
<IsRealHardware>False</IsRealHardware>
<RunnerExtraArguments> --forcegc </RunnerExtraArguments>
<UsePreviewClr>True</UsePreviewClr>
</nanoFrameworkAdapter>
</RunSettings>
</RunSettings>
36 changes: 31 additions & 5 deletions Tests/NFUnitTestGC/TestGC.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.


using System;
using nanoFramework.TestFramework;

namespace NFUnitTestGC
Expand All @@ -15,16 +16,14 @@ public void TestGCStress()
int maxArraySize = 1024 * 32;
object[] arrays = new object[600];

// Starting TestGCStress

for (int loop = 0; loop < 100; loop++)
{
OutputHelper.WriteLine($"Running iteration {loop}");

for (int i = 0; i < arrays.Length - 1;)
{
OutputHelper.WriteLine($"Alloc array of {maxArraySize} bytes @ pos {i}");
arrays[i++] = new byte[maxArraySize]; ;
arrays[i++] = new byte[maxArraySize];

OutputHelper.WriteLine($"Alloc array of 64 bytes @ pos {i}");
arrays[i++] = new byte[64];
Expand All @@ -37,8 +36,35 @@ public void TestGCStress()
arrays[i] = null;
}
}
}

[TestMethod]
public void TestGetTotalMemory()
{
// create several objects
object[] objects = new object[100];

for (int i = 0; i < objects.Length; i++)
{
objects[i] = new object();
}

// get total memory
long totalMemory = GC.GetTotalMemory(false);
OutputHelper.WriteLine($"Total memory: {totalMemory} bytes");

// release objects
for (int i = 0; i < objects.Length; i++)
{
objects[i] = null;
}

// get total memory, forcing full collection
long totalMemoryAfterCollection = GC.GetTotalMemory(true);
OutputHelper.WriteLine($"Total memory: {totalMemoryAfterCollection} bytes");

// Completed TestGCStress
// check if memory was released
Assert.IsTrue(totalMemory > totalMemoryAfterCollection, "Memory was not released");
}
}
}
85 changes: 35 additions & 50 deletions Tests/NFUnitTestSystemLib/UnitTestGCTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace NFUnitTestSystemLib
[TestClass]
public class UnitTestGCTest
{
#pragma warning disable S1215 // this is intended to test the GC
#pragma warning disable S1854 // this is intended to test the GC
#pragma warning disable S2696 // this is intended to test the GC
#pragma warning disable S3971 // this is intended to test the GC

internal class FinalizeObject
{
public static FinalizeObject m_currentInstance = null;
Expand Down Expand Up @@ -54,17 +59,20 @@ public void SystemGC1_Test()
/// 6. Verify that object has been collected
/// </summary>
///
// Tests ReRegisterForFinalize
// Create a FinalizeObject.

OutputHelper.WriteLine("Tests ReRegisterForFinalize");
OutputHelper.WriteLine("Create a FinalizeObject.");

FinalizeObject mfo = new FinalizeObject();
m_hasFinalized1 = false;
m_hasFinalized2 = false;

// Release reference
OutputHelper.WriteLine("Release reference");
mfo = null;

// Allow GC
GC.WaitForPendingFinalizers();
OutputHelper.WriteLine("Allow GC");
GC.Collect();

int sleepTime = 1000;
int slept = 0;
Expand All @@ -85,10 +93,10 @@ public void SystemGC1_Test()
// FinalizeObject.m_currentInstance field. Setting this value
// to null and forcing another garbage collection will now
// cause the object to Finalize permanently.
// Reregister and allow for GC
FinalizeObject.m_currentInstance = null;

GC.WaitForPendingFinalizers();
OutputHelper.WriteLine("Reregister and allow for GC");
FinalizeObject.m_currentInstance = null;
GC.Collect();

sleepTime = 1000;
slept = 0;
Expand Down Expand Up @@ -119,26 +127,27 @@ public void SystemGC2_Test()
/// 6. Verify that object has not been collected
/// </summary>
///
// Tests SuppressFinalize
// Create a FinalizeObject.

OutputHelper.WriteLine("Tests SuppressFinalize");
OutputHelper.WriteLine("Create a FinalizeObject");
FinalizeObject mfo = new FinalizeObject();
m_hasFinalized1 = false;
m_hasFinalized2 = false;

// Releasing
OutputHelper.WriteLine("Releasing");
GC.SuppressFinalize(mfo);
mfo = null;

// Allow GC
GC.WaitForPendingFinalizers();
OutputHelper.WriteLine("Allow GC");
GC.Collect();

int sleepTime = 1000;
int slept = 0;

while (!m_hasFinalized1 && slept < sleepTime)
{
// force GC run caused by memory allocation
var dummyArray = new byte[1024 * 1024 * 1];
_ = new byte[1024 * 1024 * 1];

System.Threading.Thread.Sleep(10);
slept += 10;
Expand All @@ -161,59 +170,35 @@ public void SystemGC3_Test()
/// </summary>
///

// Tests WaitForPendingFinalizers, dependant on test 1
// will auto-fail if test 1 fails.
OutputHelper.Write("Tests WaitForPendingFinalizers, dependant on test 1");
OutputHelper.WriteLine("will auto-fail if test 1 fails.");
OutputHelper.WriteLine("will fail if test 1 fails.");

Assert.IsTrue(m_Test1Result);
Assert.IsTrue(m_Test1Result, "Can't run this test as SystemGC1_Test has failed.");

// Create a FinalizeObject.
OutputHelper.WriteLine("Create a FinalizeObject");
FinalizeObject mfo = new FinalizeObject();
m_hasFinalized1 = false;
m_hasFinalized2 = false;

// Releasing
OutputHelper.WriteLine("Releasing");
mfo = null;

int sleepTime = 1000;
int slept = 0;

while (!m_hasFinalized1 && slept < sleepTime)
{
// force GC run caused by memory allocation
var dummyArray = new byte[1024 * 1024 * 1];

System.Threading.Thread.Sleep(10);
slept += 10;
}

OutputHelper.WriteLine($"GC took {slept}");

// Wait for GC
OutputHelper.WriteLine("Wait for GC");
GC.Collect();
GC.WaitForPendingFinalizers();

// Releasing again
OutputHelper.WriteLine("Releasing again");
FinalizeObject.m_currentInstance = null;

sleepTime = 1000;
slept = 0;

while (!m_hasFinalized2 && slept < sleepTime)
{
// force GC run caused by memory allocation
var dummyArray = new byte[1024 * 1024 * 1];

System.Threading.Thread.Sleep(10);
slept += 10;
}

OutputHelper.WriteLine($"GC took {slept}");

// Wait for GC
OutputHelper.WriteLine("Wait for GC");
GC.Collect();
GC.WaitForPendingFinalizers();

Assert.IsTrue(m_hasFinalized2);
}
}
#pragma warning restore S1215 // "GC.Collect" should not be called
#pragma warning restore S1854 // Unused assignments should be removed
#pragma warning restore S2696 // Instance members should not write to "static" fields
#pragma warning restore S3971 // "GC.SuppressFinalize" should not be called
}
27 changes: 25 additions & 2 deletions Tests/NFUnitTestSystemLib/UnitTestInitLocalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void SystemType1_GetType_Test()
// ConstructorInfo)
// NOTE: We add the reflection items to the ArrayList to assure that they can be properly
// assigned to a object container (this used to lead to a access violation)

OutputHelper.WriteLine("Testing Int32");

Type type = typeof(int);
list.Add(type);
string name = ((Type)list[i]).Name;
Expand All @@ -68,33 +71,43 @@ public void SystemType1_GetType_Test()
//fRes &= name.ToLower() == "mscorlib";
//i++;

OutputHelper.WriteLine("Testing NFUnitTestSystemLib.UnitTestInitLocalTests+TestObj");

type = Type.GetType("NFUnitTestSystemLib.UnitTestInitLocalTests+TestObj");
list.Add(type);
name = ((Type)list[i]).Name;
Assert.AreEqual(name, "TestObj");
i++;

OutputHelper.WriteLine("Testing IEmptyInterface");

Type iface = type.GetInterfaces()[0];
list.Add(iface);
name = ((Type)list[i]).Name;
Assert.AreEqual(name, "IEmptyInterface");
Assert.AreEqual(iface.Name, "IEmptyInterface");
i++;

OutputHelper.WriteLine("Testing FieldInfo");

FieldInfo fi = type.GetField("Field1");
list.Add(fi);
name = ((FieldInfo)list[i]).Name;
Assert.AreEqual(name, "Field1");
Assert.AreEqual(fi.Name, "Field1");
i++;

OutputHelper.WriteLine("Testing MethodInfo");

MethodInfo mi = type.GetMethod("Method1");
list.Add(mi);
name = ((MethodInfo)list[i]).Name;
Assert.AreEqual(name, "Method1");
Assert.AreEqual(mi.Name, "Method1");
i++;

OutputHelper.WriteLine("Testing ConstructorInfo");

ConstructorInfo ci = type.GetConstructor(new Type[] { });
list.Add(ci);
name = ((ConstructorInfo)list[i]).Name;
Expand All @@ -104,7 +117,10 @@ public void SystemType1_GetType_Test()

//
// Now test arrays of reflection types
//
//

OutputHelper.WriteLine("Testing Array of Type");

Type[] types = new Type[] { typeof(int), typeof(bool), Type.GetType("NFUnitTestSystemLib.UnitTestInitLocalTests+TestObj") };
list.Add(types[2]);
name = ((Type)list[i]).Name;
Expand All @@ -127,27 +143,35 @@ public void SystemType1_GetType_Test()
//fRes &= asms[0].GetName().Name == "Microsoft.SPOT.Platform.Tests.Systemlib2";
//i++;

OutputHelper.WriteLine("Testing Array of FieldInfo");

FieldInfo[] fis = new FieldInfo[] { types[2].GetField("Field1"), type.GetFields()[0] };
list.Add(fis[0]);
name = ((FieldInfo)list[i]).Name;
Assert.AreEqual(name, "Field1");
Assert.AreEqual(fis[0].Name, "Field1");
i++;

OutputHelper.WriteLine("Testing Array of MethodInfo");

MethodInfo[] mis = new MethodInfo[] { type.GetMethods()[2], types[2].GetMethod("Method2", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) };
list.Add(mis[1]);
name = ((MethodInfo)list[i]).Name;
Assert.AreEqual(name, "Method2");
Assert.AreEqual(mis[1].Name, "Method2");
i++;

OutputHelper.WriteLine("Testing Array of ConstructorInfo");

ConstructorInfo[] cis = new ConstructorInfo[] { types[2].GetConstructor(new Type[] { }), typeof(TestObj).GetConstructor(new Type[] { typeof(int) }) };
list.Add(cis[0]);
name = ((ConstructorInfo)list[i]).Name;
Assert.AreEqual(name, ".ctor");
Assert.AreEqual(cis[0].Name, ".ctor");
i++;

OutputHelper.WriteLine("Testing Array of System.Collections.ArrayList");

Array ar = Array.CreateInstance(typeof(Type), 3);
((IList)ar)[0] = typeof(Type);
((IList)ar)[1] = Type.GetType("System.Collections.ArrayList");
Expand All @@ -157,7 +181,6 @@ public void SystemType1_GetType_Test()
Assert.AreEqual(name, "ArrayList");
Assert.AreEqual(((Type)((IList)ar)[0]).Name, "Type");
Assert.AreEqual(((Type)ar.GetValue(1)).Name, "ArrayList");
i++;

list.Clear();
}
Expand Down
Loading
Loading