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

Tests and warnings #174

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 16 additions & 2 deletions src/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,33 @@ static void set_current_error(int err)
errno = err;
}

#ifdef __clang__
#pragma clang diagnostic push
#ifdef __arm__
// warning: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes)
#pragma clang diagnostic ignored "-Watomic-alignment"
#endif // __arm__
#endif // __clang__

static void enter_lock(dnne_lock_handle* lock)
{
while (__sync_val_compare_and_swap(lock, DNNE_LOCK_OPEN, -1) != DNNE_LOCK_OPEN)
long tmp = DNNE_LOCK_OPEN;
while (!__atomic_compare_exchange_n(lock, &tmp, -1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
{
(void)sched_yield(); // Yield instead of sleeping.
tmp = DNNE_LOCK_OPEN;
}
}

static void exit_lock(dnne_lock_handle* lock)
{
__atomic_exchange_n(lock, DNNE_LOCK_OPEN, __ATOMIC_ACQ_REL);
__atomic_exchange_n(lock, DNNE_LOCK_OPEN, __ATOMIC_SEQ_CST);
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif // __clang__

#endif // !DNNE_WINDOWS

static failure_fn failure_fptr;
Expand Down
2 changes: 1 addition & 1 deletion test/DNNE.UnitTests/Consumption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void InstanceExports()

Assert.Equal(num, ExportingAssembly.InstanceExports.MyClass_getNumber(inst));

ExportingAssembly.InstanceExports.MyClass_printNumber(inst);
Assert.Equal(num * 2, ExportingAssembly.InstanceExports.MyClass_doubleNumber(inst));
ExportingAssembly.InstanceExports.MyClass_dtor(inst);
}

Expand Down
2 changes: 1 addition & 1 deletion test/DNNE.UnitTests/ExportingAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static class InstanceExports
public static extern void MyClass_setNumber(IntPtr inst, int number);

[DllImport(nameof(ExportingAssemblyNE))]
public static extern void MyClass_printNumber(IntPtr inst);
public static extern int MyClass_doubleNumber(IntPtr inst);
}

public static class IntExports
Expand Down
5 changes: 3 additions & 2 deletions test/ExportingAssembly/ExportingAssembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<Import Condition="'$(TestNuPkg)' != 'true'" Project="$(PseudoPackage)build/DNNE.props" />

<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net472</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RollForward>Major</RollForward>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -22,7 +23,7 @@
<DnneCompilerCommand Condition="'$(BuildWithClangPP)'=='true'">clang++</DnneCompilerCommand>

<!-- Include the override option for dnne_abort() -->
<DnneCompilerUserFlags>$(DnneCompilerUserFlags)$(MSBuildThisFileDirectory)override.c</DnneCompilerUserFlags>
<DnneCompilerUserFlags>$(DnneCompilerUserFlags) $(MSBuildThisFileDirectory)override.c</DnneCompilerUserFlags>

<!-- When targeting .NET Framework we only use a subset of files -->
<EnableDefaultCompileItems Condition="$(TargetFramework.StartsWith('net4'))">false</EnableDefaultCompileItems>
Expand Down
17 changes: 7 additions & 10 deletions test/ExportingAssembly/InstanceExports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ExportingAssembly
/// class MyClass
/// {
/// intptr_t _inst;
///
///
/// public:
/// MyClass()
/// {
Expand All @@ -56,9 +56,9 @@ namespace ExportingAssembly
/// {
/// MyClass_setNumber(_inst, num);
/// }
/// void printNumber()
/// int32_t doubleNumber()
/// {
/// MyClass_printNumber(_inst);
/// return MyClass_doubleNumber(_inst);
/// }
/// // Delete copy functions since a copy export isn't defined.
/// MyClass(const MyClass&) = delete;
Expand Down Expand Up @@ -94,10 +94,10 @@ public static void MyClassSetNumber(IntPtr inst, int number)
As<MyClass>(inst).Number = number;
}

[UnmanagedCallersOnly(EntryPoint = "MyClass_printNumber")]
public static void MyClassPrintNumber(IntPtr inst)
[UnmanagedCallersOnly(EntryPoint = "MyClass_doubleNumber")]
public static int MyClassDoubleNumber(IntPtr inst)
{
As<MyClass>(inst).PrintNumber();
return As<MyClass>(inst).DoubleNumber();
}

private static T As<T>(IntPtr ptr) where T : class
Expand All @@ -111,15 +111,12 @@ private static T As<T>(IntPtr ptr) where T : class
/// </summary>
public class MyClass
{
private int number;

public MyClass()
{
this.number = 0;
}

public int Number { get; set; }

public void PrintNumber() => Console.WriteLine(this.number);
public int DoubleNumber() => 2 * this.Number;
}
}
Loading