From 5739414d9757164ccf54cf92fd556f7ae6a16402 Mon Sep 17 00:00:00 2001 From: Russ Keldorph Date: Sat, 2 Mar 2019 21:00:34 -0800 Subject: [PATCH] Fix JIT/Directed/pinvoke/tail Remove dependency on Windows user32 library and enable test for all platforms. Fixes #13048 --- tests/issues.targets | 3 - tests/src/JIT/Directed/pinvoke/CMakeLists.txt | 13 +++ tests/src/JIT/Directed/pinvoke/tail.il | 16 ++-- tests/src/JIT/Directed/pinvoke/tail.ilproj | 7 +- tests/src/JIT/Directed/pinvoke/user32menu.cpp | 114 ++++++++++++++++++++++++++ 5 files changed, 137 insertions(+), 16 deletions(-) create mode 100644 tests/src/JIT/Directed/pinvoke/CMakeLists.txt create mode 100644 tests/src/JIT/Directed/pinvoke/user32menu.cpp diff --git a/tests/issues.targets b/tests/issues.targets index d3d48ef..38c2b2b 100644 --- a/tests/issues.targets +++ b/tests/issues.targets @@ -75,9 +75,6 @@ Issue building native components for the test. - - 13048 - 22975 diff --git a/tests/src/JIT/Directed/pinvoke/CMakeLists.txt b/tests/src/JIT/Directed/pinvoke/CMakeLists.txt new file mode 100644 index 0000000..7fc8f06 --- /dev/null +++ b/tests/src/JIT/Directed/pinvoke/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 2.6) +project(pinvoke_user32menu) + +set(CMAKE_SHARED_LIBRARY_PREFIX "") + +add_library(user32menu SHARED user32menu.cpp) +SET_TARGET_PROPERTIES(user32menu PROPERTIES COMPILE_FLAGS "-c") + +# add the install targets (this "installs" the native file on Windows systems) +install(TARGETS user32menu DESTINATION bin) + +# This "installs" the native file on System V systems +set_target_properties(user32menu PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/user32menu) diff --git a/tests/src/JIT/Directed/pinvoke/tail.il b/tests/src/JIT/Directed/pinvoke/tail.il index 748accd..542bc34 100644 --- a/tests/src/JIT/Directed/pinvoke/tail.il +++ b/tests/src/JIT/Directed/pinvoke/tail.il @@ -15,22 +15,22 @@ .class private auto ansi beforefieldinit Test extends [mscorlib]System.Object { - .method private hidebysig static pinvokeimpl("user32" ansi winapi) + .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) native uint CreatePopupMenu() cil managed preservesig { } - .method private hidebysig static pinvokeimpl("user32" ansi winapi) + .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) bool DestroyMenu(native uint hMenu) cil managed preservesig { } - .method private hidebysig static pinvokeimpl("user32" ansi winapi) + .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) bool AppendMenu(native uint hMenu, unsigned int32 uFlags, unsigned int32 uID, string item) cil managed preservesig { } - .method private hidebysig static pinvokeimpl("user32" ansi winapi) + .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) int32 GetMenuString(native uint hMenu, unsigned int32 uIDItem, class [mscorlib]System.Text.StringBuilder data, @@ -38,7 +38,7 @@ unsigned int32 uFlag) cil managed preservesig { } - + .method private hidebysig static native uint __CreatePopupMenu() cil managed { tail. call native uint JitTest.Test::CreatePopupMenu() @@ -93,8 +93,8 @@ int32, unsigned int32) } - - .method private hidebysig static int32 + + .method private hidebysig static int32 Main() cil managed { .entrypoint @@ -211,7 +211,7 @@ IL_00b0: ret } // end of method Test::Main - .method public hidebysig specialname rtspecialname + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { .maxstack 8 diff --git a/tests/src/JIT/Directed/pinvoke/tail.ilproj b/tests/src/JIT/Directed/pinvoke/tail.ilproj index 45e12b0..a81ed69 100644 --- a/tests/src/JIT/Directed/pinvoke/tail.ilproj +++ b/tests/src/JIT/Directed/pinvoke/tail.ilproj @@ -11,10 +11,6 @@ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ..\..\ true - - - true - true @@ -34,7 +30,8 @@ + - \ No newline at end of file + diff --git a/tests/src/JIT/Directed/pinvoke/user32menu.cpp b/tests/src/JIT/Directed/pinvoke/user32menu.cpp new file mode 100644 index 0000000..f3a2c54 --- /dev/null +++ b/tests/src/JIT/Directed/pinvoke/user32menu.cpp @@ -0,0 +1,114 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// This file fakes a few Windows APIs to enable the tail.il test on all platforms. + +#include +#include +#include + +#if defined(_MSC_VER) +#define EXPORT_API extern "C" __declspec(dllexport) +#else +#define EXPORT_API extern "C" __attribute__((visibility("default"))) + +#ifdef BIT64 +#define __int64 long +#else // BIT64 +#define __int64 long long +#endif // BIT64 + +#define __int32 int +#define __int16 short int +#define __int8 char // assumes char is signed + +#endif + +#include + +typedef std::vector MENU; +typedef MENU * HMENU; + +EXPORT_API +HMENU +CreatePopupMenu() +{ + return new MENU(); +} + +EXPORT_API +unsigned __int32 +DestroyMenu( + HMENU hMenu + ) +{ + delete hMenu; + + return 1; +} + +EXPORT_API +unsigned __int32 +AppendMenuA( + HMENU hMenu, + unsigned __int32 uFlags, + unsigned __int32 uID, + const char * item + ) +{ + if (uFlags != 0) + { + throw "AppendMenu: only MF_STRING (0) supported for uFlags"; + } + + hMenu->push_back(std::string(item)); + + return 1; +} + +EXPORT_API +__int32 +GetMenuStringA( + HMENU hMenu, + unsigned __int32 uIDItem, + char * lpString, + __int32 cchMax, + unsigned __int32 flags + ) +{ + if (flags != 0x400) + { + throw "GetMenuStringA: only MF_BYPOSITION (0x400) supported for flags"; + } + + if (cchMax < 0) + { + throw "GetMenuStringA: invalid argument (cchMax)"; + } + + if (uIDItem >= hMenu->size()) + { + return 0; + } + + const std::string & str = (*hMenu)[uIDItem]; + + __int32 cch = (__int32)str.size(); + + if ((cchMax == 0) || (lpString == nullptr)) + { + return cch; + } + + if (cch >= cchMax) + { + cch = cchMax - 1; + } + + memcpy(lpString, str.c_str(), cch); + lpString[cch] = '\0'; + + return cch; +} + -- 2.7.4