runtime
runtime copied to clipboard
[ARM/Linux] Unittest JIT.jit64.hfa.main.testB.hfa_nd2B_d.hfa_nd2B_d failure
On ARM/Linux, JIT.jit64.hfa.main.testB.hfa_nd2B_d.hfa_nd2B_d fails.
I analyze the testcase and can simplify it into the following native and managed code. Here is the native code:
#include <stdio.h>
#define HFADLL_API extern "C" __attribute__((visibility("default")))
struct HFA01 {
double f1;
};
HFADLL_API void init_HFA01(HFA01& hfa) {
hfa.f1 = static_cast<double>(1);
}
HFADLL_API double get_EXPECTED_SUM_HFA01() {
return static_cast<double>(1);
}
HFADLL_API double sum5_HFA01(long v1, double v2, int v3, signed char v4, HFA01 hfa) {
printf("v1 = %ld; v2 = %f; v3 = %d; v4 = %d\n", v1, v2, v3, v4);
return static_cast<float>(v1)
+ static_cast<float>(v2)
+ static_cast<float>(v3)
+ static_cast<float>(v4)
+ hfa.f1;
}
Here is the managed code:
using System;
using System.Runtime.InteropServices;
namespace HFATest {
[StructLayout(LayoutKind.Sequential)]
public struct HFA01 { public double f1; }
}
namespace HFATest { public class TestMan {
public const string DllName = "hfa_native";
[DllImport(DllName, EntryPoint = "get_EXPECTED_SUM_HFA01", CallingConvention = CallingConvention.StdCall)]
public static extern double Get_EXPECTED_SUM_HFA01();
[DllImport(DllName, EntryPoint = "init_HFA01", CallingConvention = CallingConvention.StdCall)]
public static extern void Init_HFA01(out HFA01 hfa);
[DllImport(DllName, EntryPoint = "sum5_HFA01", CallingConvention = CallingConvention.StdCall)]
public static extern double Sum5_HFA01(long v1, double v2, int v3, sbyte v4, HFA01 hfa);
public static readonly double EXPECTED_SUM_HFA01 = Get_EXPECTED_SUM_HFA01();
} }
namespace HFATest { public class TestCase {
const sbyte CONST_INT8 = (sbyte)-128;
const int CONST_INT32 = (int)-128;
const long CONST_INT64 = (long)-128;
const float CONST_FLOAT32 = (float)-128.0;
const double CONST_FLOAT64 = (double)-128.0;
public static void Main() {
HFA01 hfa01;
TestMan.Init_HFA01(out hfa01);
Common.Check(TestMan.Sum5_HFA01(-128, 128.0, 128, -128, hfa01), TestMan.EXPECTED_SUM_HFA01);
}
} }
namespace HFATest { public class Common {
public const float tolerance = (float)1.0E-15;
private static void Show(double actual, double expected, bool result) {
System.Console.Write("expected = {0}, actual = {1}, status = {2}", expected, actual, result ? "PASSED" : "FAILED");
}
public static void Check(double actual, double expected)
{
Show(actual, expected, Math.Abs(expected - actual) <= tolerance);
}
} }
It is expected to show the following output:
v1 = -128; v2 = 128.000000; v3 = 128; v4 = -128
expected = 1, actual = 1, status = PASSED
Currently, however, it shows the following output:
v1 = -128; v2 = 128.000000; v3 = -1; v4 = -128
expected = 1, actual = -128, status = FAILED
I found why the above simplified example fails. In C#, long always represents 64-bit signed integer, but represents 32-bit signed integer in C for ARM arch.
It looks like JIT.jit64.hfa.main.testB.hfa_nd2B_d.hfa_nd2B_d failed for another reason.