No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

080-TestSystemThreading.cs 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Threading;
  3. using UnityBenchShared;
  4. namespace Burst.Compiler.IL.Tests
  5. {
  6. /// <summary>
  7. /// Tests of the <see cref="System.Threading"/> functions.
  8. /// </summary>
  9. internal class TestSystemThreading
  10. {
  11. [TestCompiler]
  12. public static void TestMemoryBarrier()
  13. {
  14. Thread.MemoryBarrier();
  15. }
  16. [TestCompiler]
  17. public static int TestReadBool()
  18. {
  19. var data = false;
  20. return (Volatile.Read(ref data) ? 1 : 0) + (Volatile.Read(ref data) ? 1 : 0);
  21. }
  22. [TestCompiler((byte)42)]
  23. public static int TestReadByte(ref byte data)
  24. {
  25. return Volatile.Read(ref data) + Volatile.Read(ref data);
  26. }
  27. [TestCompiler((sbyte)42)]
  28. public static int TestReadSByte(ref sbyte data)
  29. {
  30. return Volatile.Read(ref data) + Volatile.Read(ref data);
  31. }
  32. [TestCompiler((short)42)]
  33. public static int TestReadShort(ref short data)
  34. {
  35. return Volatile.Read(ref data) + Volatile.Read(ref data);
  36. }
  37. [TestCompiler((ushort)42)]
  38. public static int TestReadUShort(ref ushort data)
  39. {
  40. return Volatile.Read(ref data) + Volatile.Read(ref data);
  41. }
  42. [TestCompiler(42)]
  43. public static int TestReadInt(ref int data)
  44. {
  45. return Volatile.Read(ref data) + Volatile.Read(ref data);
  46. }
  47. [TestCompiler(42u)]
  48. public static uint TestReadUInt(ref uint data)
  49. {
  50. return Volatile.Read(ref data) + Volatile.Read(ref data);
  51. }
  52. [TestCompiler((long)42)]
  53. public static long TestReadLong(ref long data)
  54. {
  55. return Volatile.Read(ref data) + Volatile.Read(ref data);
  56. }
  57. [TestCompiler((ulong)42)]
  58. public static ulong TestReadULong(ref ulong data)
  59. {
  60. return Volatile.Read(ref data) + Volatile.Read(ref data);
  61. }
  62. [TestCompiler(42.0f)]
  63. public static float TestReadFloat(ref float data)
  64. {
  65. return Volatile.Read(ref data);
  66. }
  67. [TestCompiler(42.0)]
  68. public static double TestReadDouble(ref double data)
  69. {
  70. return Volatile.Read(ref data);
  71. }
  72. public struct UIntPtrProvider : IArgumentProvider
  73. {
  74. public object Value => UIntPtr.Zero;
  75. }
  76. [TestCompiler(typeof(UIntPtrProvider))]
  77. public static UIntPtr TestReadUIntPtr(ref UIntPtr data)
  78. {
  79. return Volatile.Read(ref data);
  80. }
  81. [TestCompiler]
  82. public static int TestWriteBool()
  83. {
  84. var data = false;
  85. Volatile.Write(ref data, true);
  86. return data ? 1 : 0;
  87. }
  88. [TestCompiler((byte)42)]
  89. public static int TestWriteByte(ref byte data)
  90. {
  91. var result = data;
  92. Volatile.Write(ref data, 1);
  93. return result + data;
  94. }
  95. [TestCompiler((sbyte)42)]
  96. public static int TestWriteSByte(ref sbyte data)
  97. {
  98. var result = data;
  99. Volatile.Write(ref data, 2);
  100. return result + data;
  101. }
  102. [TestCompiler((short)42)]
  103. public static int TestWriteShort(ref short data)
  104. {
  105. var result = data;
  106. Volatile.Write(ref data, 3);
  107. return result + data;
  108. }
  109. [TestCompiler((ushort)42)]
  110. public static int TestWriteUShort(ref ushort data)
  111. {
  112. var result = data;
  113. Volatile.Write(ref data, 4);
  114. return result + data;
  115. }
  116. [TestCompiler(42)]
  117. public static int TestWriteInt(ref int data)
  118. {
  119. var result = data;
  120. Volatile.Write(ref data, 5);
  121. return result + data;
  122. }
  123. #if BURST_TESTS_ONLY || UNITY_2019_4_OR_NEWER
  124. [TestCompiler(42u)]
  125. public static uint TestWriteUInt(ref uint data)
  126. {
  127. var result = data;
  128. Volatile.Write(ref data, 6);
  129. return result + data;
  130. }
  131. #endif
  132. [TestCompiler((long)42)]
  133. public static long TestWriteLong(ref long data)
  134. {
  135. var result = data;
  136. Volatile.Write(ref data, 7);
  137. return result + data;
  138. }
  139. #if BURST_TESTS_ONLY || UNITY_2019_4_OR_NEWER
  140. [TestCompiler((ulong)42)]
  141. public static ulong TestWriteULong(ref ulong data)
  142. {
  143. var result = data;
  144. Volatile.Write(ref data, 8);
  145. return result + data;
  146. }
  147. #endif
  148. [TestCompiler(42.0f)]
  149. public static float TestWriteFloat(ref float data)
  150. {
  151. var result = data;
  152. Volatile.Write(ref data, 9);
  153. return result + data;
  154. }
  155. [TestCompiler(42.0)]
  156. public static double TestWriteDouble(ref double data)
  157. {
  158. var result = data;
  159. Volatile.Write(ref data, 10);
  160. return result + data;
  161. }
  162. [TestCompiler(typeof(UIntPtrProvider))]
  163. public static UIntPtr TestWriteUIntPtr(ref UIntPtr data)
  164. {
  165. var result = data;
  166. Volatile.Write(ref data, new UIntPtr(11));
  167. return result;
  168. }
  169. }
  170. }