https://git.reactos.org/?p=reactos.git;a=commitdiff;h=759bdedc1efc3b45b0cbc…
commit 759bdedc1efc3b45b0cbc981ff95c00c33183ec0
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Wed Jul 28 22:38:21 2021 +0300
Commit: Stanislav Motylkov <x86corez(a)gmail.com>
CommitDate: Thu Jul 29 13:37:07 2021 +0300
[CRT_APITEST] Add tests for __rt_sdiv/udiv/sdiv64/udiv64 on ARM
Addendum to f2bc1f0e and f1e2c6cb.
CORE-17607 CORE-17614 CORE-17604
---
modules/rostests/apitests/crt/__rt_div.c | 175 +++++++++++++++++++++
.../rostests/apitests/crt/msvcrt_crt_apitest.cmake | 4 +
modules/rostests/apitests/crt/testlist.c | 3 +
3 files changed, 182 insertions(+)
diff --git a/modules/rostests/apitests/crt/__rt_div.c
b/modules/rostests/apitests/crt/__rt_div.c
new file mode 100644
index 00000000000..72c7460ce60
--- /dev/null
+++ b/modules/rostests/apitests/crt/__rt_div.c
@@ -0,0 +1,175 @@
+/*
+ * PROJECT: ReactOS API tests
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Tests for statically linked __rt_sdiv/udiv/sdiv64/udiv64 on ARM
+ * COPYRIGHT: Copyright 2021 Stanislav Motylkov <x86corez(a)gmail.com>
+ */
+
+#include <apitest.h>
+
+typedef struct _SDIV_TEST_DATA
+{
+ LONG dividend;
+ LONG divisor;
+ LONG expected_div;
+ LONG expected_mod;
+} SDIV_TEST_DATA;
+
+typedef struct _UDIV_TEST_DATA
+{
+ ULONG dividend;
+ ULONG divisor;
+ ULONG expected_div;
+ ULONG expected_mod;
+} UDIV_TEST_DATA;
+
+typedef struct _SDIV64_TEST_DATA
+{
+ LONGLONG dividend;
+ LONGLONG divisor;
+ LONGLONG expected_div;
+ LONGLONG expected_mod;
+} SDIV64_TEST_DATA;
+
+typedef struct _UDIV64_TEST_DATA
+{
+ ULONGLONG dividend;
+ ULONGLONG divisor;
+ ULONGLONG expected_div;
+ ULONGLONG expected_mod;
+} UDIV64_TEST_DATA;
+
+START_TEST(__rt_div)
+{
+ SDIV_TEST_DATA sdiv[] =
+ {
+ /* Dividend is larger than divisor */
+ { 3425, 400, 8, 225 },
+ { -3425, 400, -8, -225 },
+ { 3425, -400, -8, 225 },
+ { -3425, -400, 8, -225 },
+ /* Divisor is larger than dividend */
+ { 12, 42, 0, 12 },
+ { -12, 42, 0, -12 },
+ { 12, -42, 0, 12 },
+ { -12, -42, 0, -12 },
+ /* Division without remainder */
+ { 16777216, 65536, 256, 0 },
+ { -16777216, 65536, -256, 0 },
+ { 16777216, -65536, -256, 0 },
+ { -16777216, -65536, 256, 0 },
+ };
+ UDIV_TEST_DATA udiv[] =
+ {
+ /* Dividend is larger than divisor */
+ { 3425, 400, 8, 225 },
+ /* Divisor is larger than dividend */
+ { 12, 42, 0, 12 },
+ /* Division without remainder */
+ { 16777216, 65536, 256, 0 },
+ };
+ SDIV64_TEST_DATA sdiv64[] =
+ {
+ /* Dividend is larger than divisor */
+ { 34918215, 7, 4988316, 3 },
+ { -34918215, 7, -4988316, -3 },
+ { 34918215, -7, -4988316, 3 },
+ { -34918215, -7, 4988316, -3 },
+ /* Divisor is larger than dividend */
+ { 12, 42, 0, 12 },
+ { -12, 42, 0, -12 },
+ { 12, -42, 0, 12 },
+ { -12, -42, 0, -12 },
+ /* Division without remainder */
+ { 16777216, 65536, 256, 0 },
+ { -16777216, 65536, -256, 0 },
+ { 16777216, -65536, -256, 0 },
+ { -16777216, -65536, 256, 0 },
+
+ /* Big 64-bit numbers */
+
+ /* Dividend is larger than divisor */
+ { 0x2AFFFFFFFLL * 100, 400, 2885681151LL, 300 },
+ { -0x2AFFFFFFFLL * 100, 400, -2885681151LL, -300 },
+ { 0x2AFFFFFFFLL * 100, -400, -2885681151LL, 300 },
+ { -0x2AFFFFFFFLL * 100, -400, 2885681151LL, -300 },
+ /* Divisor is larger than dividend */
+ { 0x2AFFFFFFFLL * 50, 0x2AFFFFFFFLL * 100, 0, 0x2AFFFFFFFLL * 50 },
+ { -0x2AFFFFFFFLL * 50, 0x2AFFFFFFFLL * 100, 0, -0x2AFFFFFFFLL * 50 },
+ { 0x2AFFFFFFFLL * 50, -0x2AFFFFFFFLL * 100, 0, 0x2AFFFFFFFLL * 50 },
+ { -0x2AFFFFFFFLL * 50, -0x2AFFFFFFFLL * 100, 0, -0x2AFFFFFFFLL * 50 },
+ /* Division without remainder */
+ { 0x2AFFFFFFFLL * 100, 100, 0x2AFFFFFFFLL, 0 },
+ { -0x2AFFFFFFFLL * 100, 100, -0x2AFFFFFFFLL, 0 },
+ { 0x2AFFFFFFFLL * 100, -100, -0x2AFFFFFFFLL, 0 },
+ { -0x2AFFFFFFFLL * 100, -100, 0x2AFFFFFFFLL, 0 },
+ };
+ UDIV64_TEST_DATA udiv64[] =
+ {
+ /* Dividend is larger than divisor */
+ { 34918215, 7, 4988316, 3 },
+ /* Divisor is larger than dividend */
+ { 12, 42, 0, 12 },
+ /* Division without remainder */
+ { 16777216, 65536, 256, 0 },
+
+ /* Big 64-bit numbers */
+
+ /* Dividend is larger than divisor */
+ { 0x2AFFFFFFFULL * 100, 400, 2885681151ULL, 300 },
+ /* Divisor is larger than dividend */
+ { 0x2AFFFFFFFULL * 50, 0x2AFFFFFFFULL * 100, 0, 0x2AFFFFFFFULL * 50 },
+ /* Division without remainder */
+ { 0x2AFFFFFFFULL * 100, 100, 0x2AFFFFFFFULL, 0 },
+ };
+ INT i;
+
+ for (i = 0; i < _countof(sdiv); i++)
+ {
+ LONG test_div, test_mod;
+
+ test_div = sdiv[i].dividend / sdiv[i].divisor;
+ test_mod = sdiv[i].dividend % sdiv[i].divisor;
+ ok(test_div == sdiv[i].expected_div, "(sdiv) %d: Expected %ld, got %ld / %ld
= %ld\n",
+ i, sdiv[i].expected_div, sdiv[i].dividend, sdiv[i].divisor, test_div);
+ ok(test_mod == sdiv[i].expected_mod, "(sdiv) %d: Expected %ld, got %ld %%
%ld = %ld\n",
+ i, sdiv[i].expected_mod, sdiv[i].dividend, sdiv[i].divisor, test_mod);
+ }
+
+ for (i = 0; i < _countof(udiv); i++)
+ {
+ ULONG test_div, test_mod;
+
+ test_div = udiv[i].dividend / udiv[i].divisor;
+ test_mod = udiv[i].dividend % udiv[i].divisor;
+ ok(test_div == udiv[i].expected_div, "(udiv) %d: Expected %lu, got %lu / %lu
= %lu\n",
+ i, udiv[i].expected_div, udiv[i].dividend, udiv[i].divisor, test_div);
+ ok(test_mod == udiv[i].expected_mod, "(udiv) %d: Expected %lu, got %lu %%
%lu = %lu\n",
+ i, udiv[i].expected_mod, udiv[i].dividend, udiv[i].divisor, test_mod);
+ }
+
+ for (i = 0; i < _countof(sdiv64); i++)
+ {
+ LONGLONG test_div, test_mod;
+
+ test_div = sdiv64[i].dividend / sdiv64[i].divisor;
+ test_mod = sdiv64[i].dividend % sdiv64[i].divisor;
+ ok(test_div == sdiv64[i].expected_div, "(sdiv64) %d: Expected %lld, got %lld
/ %lld = %lld\n",
+ i, sdiv64[i].expected_div, sdiv64[i].dividend, sdiv64[i].divisor, test_div);
+ ok(test_mod == sdiv64[i].expected_mod, "(sdiv64) %d: Expected %lld, got %lld
%% %lld = %lld\n",
+ i, sdiv64[i].expected_mod, sdiv64[i].dividend, sdiv64[i].divisor, test_mod);
+ }
+
+ for (i = 0; i < _countof(udiv64); i++)
+ {
+ ULONGLONG test_div, test_mod;
+
+ test_div = udiv64[i].dividend / udiv64[i].divisor;
+ test_mod = udiv64[i].dividend % udiv64[i].divisor;
+ ok(test_div == udiv64[i].expected_div, "(udiv64) %d: Expected %llu, got %llu
/ %llu = %llu\n",
+ i, udiv64[i].expected_div, udiv64[i].dividend, udiv64[i].divisor, test_div);
+ ok(test_mod == udiv64[i].expected_mod, "(udiv64) %d: Expected %llu, got %llu
%% %llu = %llu\n",
+ i, udiv64[i].expected_mod, udiv64[i].dividend, udiv64[i].divisor, test_mod);
+ }
+}
+
diff --git a/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
b/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
index 9e76ba0202c..2375f59472a 100644
--- a/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
+++ b/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake
@@ -1371,6 +1371,10 @@ elseif(ARCH STREQUAL "amd64")
# sinf.c
# sqrtf.c
)
+elseif(ARCH STREQUAL "arm")
+ list(APPEND SOURCE_MSVCRT
+ __rt_div.c
+ )
endif()
# Startup code doesn't go together well with the static CRT... too much __imp_
diff --git a/modules/rostests/apitests/crt/testlist.c
b/modules/rostests/apitests/crt/testlist.c
index 9516d540be0..ca76ebbf593 100644
--- a/modules/rostests/apitests/crt/testlist.c
+++ b/modules/rostests/apitests/crt/testlist.c
@@ -4,6 +4,7 @@
#include <apitest.h>
#if defined(TEST_MSVCRT)
+extern void func___rt_div(void);
extern void func__vscprintf(void);
extern void func__vscwprintf(void);
extern void func_atexit(void);
@@ -59,6 +60,8 @@ const struct test winetest_testlist[] =
{ "atexit", func_atexit },
#if defined(_M_IX86)
{ "__getmainargs", func___getmainargs },
+#elif defined(_M_ARM)
+ { "__rt_div", func___rt_div },
#endif
{ "_vscprintf", func__vscprintf },
{ "_vscwprintf", func__vscwprintf },