mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 16:46:16 +00:00
Add Node.js tests (#207)
This commit is contained in:
57
.github/workflows/build.yml
vendored
57
.github/workflows/build.yml
vendored
@@ -161,7 +161,8 @@ jobs:
|
||||
- iOS arm64
|
||||
- Android x86_64
|
||||
- Android arm64-v8a
|
||||
- Emscripten
|
||||
- Emscripten Web
|
||||
- Emscripten Node.js
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
@@ -202,9 +203,12 @@ jobs:
|
||||
abi: arm64-v8a
|
||||
rust-target: aarch64-linux-android
|
||||
cmake-options: "-DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/cmake/toolchain/android-ndk.cmake"
|
||||
- platform: Emscripten
|
||||
- platform: Emscripten Web
|
||||
runner: ubuntu-24.04
|
||||
cmake-options: "-DMOMO_ENABLE_RUST_CODE=Off -DCMAKE_TOOLCHAIN_FILE=$(dirname $(which emcc))/cmake/Modules/Platform/Emscripten.cmake"
|
||||
- platform: Emscripten Node.js
|
||||
runner: ubuntu-24.04
|
||||
cmake-options: "-DMOMO_EMSCRIPTEN_SUPPORT_NODEJS=On -DMOMO_ENABLE_RUST_CODE=Off -DCMAKE_TOOLCHAIN_FILE=$(dirname $(which emcc))/cmake/Modules/Platform/Emscripten.cmake"
|
||||
steps:
|
||||
- name: Checkout Source
|
||||
uses: actions/checkout@v4
|
||||
@@ -219,7 +223,7 @@ jobs:
|
||||
run: rustup target add ${{ matrix.rust-target }}
|
||||
|
||||
- name: Install Emscripten
|
||||
if: "${{ matrix.platform == 'Emscripten' }}"
|
||||
if: "${{ startsWith(matrix.platform, 'Emscripten') }}"
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
|
||||
- name: Install Clang
|
||||
@@ -248,6 +252,7 @@ jobs:
|
||||
add-to-path: false
|
||||
|
||||
- name: Setup Environment Variables
|
||||
shell: bash
|
||||
if: ${{ startsWith(matrix.platform, 'Android') }}
|
||||
run: |
|
||||
echo "ANDROID_NDK_ROOT=${{ steps.setup-ndk.outputs.ndk-path }}" >> $GITHUB_ENV
|
||||
@@ -320,6 +325,7 @@ jobs:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup Environment Variables
|
||||
shell: bash
|
||||
run: |
|
||||
echo "RUST_BACKTRACE=1" >> $GITHUB_ENV
|
||||
echo "ASAN_OPTIONS=detect_odr_violation=0" >> $GITHUB_ENV
|
||||
@@ -382,6 +388,7 @@ jobs:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup Environment Variables
|
||||
shell: bash
|
||||
run: |
|
||||
echo "RUST_BACKTRACE=1" >> $GITHUB_ENV
|
||||
echo "ASAN_OPTIONS=detect_odr_violation=0" >> $GITHUB_ENV
|
||||
@@ -416,6 +423,44 @@ jobs:
|
||||
ANALYSIS_SAMPLE: ${{github.workspace}}/build/release/artifacts/test-sample.exe
|
||||
|
||||
|
||||
smoke-test-node:
|
||||
name: Smoke Test Node.js
|
||||
runs-on: ubuntu-24.04
|
||||
needs: [create-emulation-root, build]
|
||||
steps:
|
||||
- name: Checkout Source
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Download Artifacts
|
||||
uses: pyTooling/download-artifact@v4
|
||||
with:
|
||||
name: Emscripten Node.js Release Artifacts
|
||||
path: build/release/artifacts
|
||||
|
||||
- name: Download Windows Artifacts
|
||||
uses: pyTooling/download-artifact@v4
|
||||
with:
|
||||
name: Windows x86_64 Release Artifacts
|
||||
path: build/release/artifacts
|
||||
|
||||
- name: Download Emulation Root
|
||||
uses: pyTooling/download-artifact@v4
|
||||
with:
|
||||
name: Windows 2022 Emulation Root
|
||||
path: build/release/artifacts/root
|
||||
|
||||
- name: Copy Test Sample
|
||||
run: cp build/release/artifacts/test-sample.exe build/release/artifacts/root/filesys/c/
|
||||
|
||||
- name: CMake Test
|
||||
run: cd build/release/artifacts && node ./windows-emulator-test.js
|
||||
env:
|
||||
EMULATOR_ROOT: ${{github.workspace}}/build/release/artifacts/root
|
||||
EMULATOR_VERBOSE: ${{ github.event.inputs.verbose }}
|
||||
|
||||
|
||||
smoke-test-android:
|
||||
name: Smoke Test Android
|
||||
runs-on: ${{ matrix.runner }}
|
||||
@@ -495,10 +540,10 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Download Emscripten Artifacts
|
||||
- name: Download Emscripten Web Artifacts
|
||||
uses: pyTooling/download-artifact@v4
|
||||
with:
|
||||
name: Emscripten Release Artifacts
|
||||
name: Emscripten Web Release Artifacts
|
||||
path: build/release/artifacts
|
||||
|
||||
- name: Download Windows Artifacts
|
||||
@@ -562,7 +607,7 @@ jobs:
|
||||
summary:
|
||||
name: Pipeline Summary
|
||||
runs-on: ubuntu-24.04
|
||||
needs: [build-page, clang-tidy, build-apiset-dumper, smoke-test-android, create-emulation-root, build, test, win-test, verify-formatting]
|
||||
needs: [build-page, clang-tidy, build-apiset-dumper, smoke-test-node, smoke-test-android, create-emulation-root, build, test, win-test, verify-formatting]
|
||||
if: always()
|
||||
steps:
|
||||
- uses: geekyeggo/delete-artifact@v5
|
||||
|
||||
@@ -6,6 +6,7 @@ option(MOMO_ENABLE_AVX2 "Enable AVX2 support" ON)
|
||||
option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF)
|
||||
option(MOMO_ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF)
|
||||
option(MOMO_ENABLE_RUST_CODE "Enable code parts written in rust" ON)
|
||||
option(MOMO_EMSCRIPTEN_SUPPORT_NODEJS "Enable Node.js filesystem for emscripten compilation" OFF)
|
||||
option(MOMO_BUILD_AS_LIBRARY "Configure and Build the emulator as a shared library (without the samples and tests)" OFF)
|
||||
|
||||
set(MOMO_REFLECTION_LEVEL "0" CACHE STRING "Reflection level for the build")
|
||||
|
||||
@@ -89,8 +89,9 @@ endif()
|
||||
##########################################
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
|
||||
add_compile_options(
|
||||
momo_add_c_and_cxx_compile_options(
|
||||
-fexceptions
|
||||
-ftrivial-auto-var-init=zero
|
||||
)
|
||||
|
||||
add_link_options(
|
||||
@@ -98,13 +99,24 @@ if(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
|
||||
-sALLOW_MEMORY_GROWTH=1
|
||||
-sASSERTIONS
|
||||
-sWASM_BIGINT
|
||||
-sENVIRONMENT=web
|
||||
-sUSE_OFFSET_CONVERTER
|
||||
#-sEXCEPTION_CATCHING_ALLOWED=[..]
|
||||
-sEXIT_RUNTIME
|
||||
#-lnodefs.js -sNODERAWFS=1
|
||||
#-sASYNCIFY
|
||||
)
|
||||
)
|
||||
|
||||
if(MOMO_EMSCRIPTEN_SUPPORT_NODEJS)
|
||||
add_link_options(
|
||||
-lnodefs.js -sNODERAWFS=1
|
||||
-sENVIRONMENT=node
|
||||
-sMAXIMUM_MEMORY=4gb
|
||||
--pre-js ${CMAKE_CURRENT_LIST_DIR}/misc/node-pre-script.js
|
||||
)
|
||||
else()
|
||||
add_link_options(
|
||||
-sENVIRONMENT=worker
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
##########################################
|
||||
|
||||
3
cmake/misc/node-pre-script.js
Normal file
3
cmake/misc/node-pre-script.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Module['preRun'] = () => {
|
||||
ENV = process.env;
|
||||
};
|
||||
2
deps/unicorn
vendored
2
deps/unicorn
vendored
Submodule deps/unicorn updated: 6b32965144...a19ae94cbf
@@ -1,91 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include <utils/object.hpp>
|
||||
|
||||
template <typename T, size_t N>
|
||||
T resolve_indexed_argument_internal(const std::array<size_t, N>& args, size_t& index)
|
||||
{
|
||||
const auto a1 = args[index++];
|
||||
|
||||
if constexpr (sizeof(T) <= sizeof(a1) || sizeof(size_t) > 4)
|
||||
{
|
||||
return T(a1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto a2 = args[index++];
|
||||
|
||||
const auto arg = (a1 | (static_cast<uint64_t>(a2) << 32));
|
||||
return T(arg);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, size_t N>
|
||||
T resolve_indexed_argument(const std::array<size_t, N>& args, size_t& index)
|
||||
{
|
||||
auto arg = resolve_indexed_argument_internal<T, N>(args, index);
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <typename ReturnType, typename... Args>
|
||||
class function_wrapper_tcg : public utils::object
|
||||
{
|
||||
public:
|
||||
using user_data_pointer = void*;
|
||||
using c_function_type = ReturnType(Args..., user_data_pointer);
|
||||
using functor_type = std::function<ReturnType(Args...)>;
|
||||
|
||||
function_wrapper_tcg() = default;
|
||||
|
||||
function_wrapper_tcg(functor_type functor)
|
||||
: functor_(std::make_unique<functor_type>(std::move(functor)))
|
||||
{
|
||||
}
|
||||
|
||||
c_function_type* get_c_function() const
|
||||
{
|
||||
auto* func = +[](const size_t a1, const size_t a2, const size_t a3, const size_t a4, const size_t a5,
|
||||
const size_t a6, const size_t a7, const size_t a8, const size_t a9, const size_t a10,
|
||||
const size_t a11, const size_t a12) -> uint64_t {
|
||||
const std::array arguments = {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12};
|
||||
|
||||
const auto lambda = +[](Args... args, user_data_pointer user_data) -> ReturnType {
|
||||
return (*static_cast<functor_type*>(user_data))(std::forward<Args>(args)...);
|
||||
};
|
||||
|
||||
size_t index = 0;
|
||||
std::tuple<Args..., user_data_pointer> func_args{
|
||||
resolve_indexed_argument<std::remove_cv_t<std::remove_reference_t<Args>>>(arguments, index)...,
|
||||
resolve_indexed_argument<user_data_pointer>(arguments, index)};
|
||||
|
||||
(void)index;
|
||||
|
||||
if constexpr (!std::is_void_v<ReturnType>)
|
||||
{
|
||||
return uint64_t(std::apply(lambda, std::move(func_args)));
|
||||
}
|
||||
|
||||
std::apply(lambda, std::move(func_args));
|
||||
return 0;
|
||||
};
|
||||
|
||||
return reinterpret_cast<c_function_type*>(reinterpret_cast<void*>(func));
|
||||
}
|
||||
|
||||
void* get_function() const
|
||||
{
|
||||
return reinterpret_cast<void*>(this->get_c_function());
|
||||
}
|
||||
|
||||
user_data_pointer get_user_data() const
|
||||
{
|
||||
return this->functor_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<functor_type> functor_{};
|
||||
};
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "unicorn_hook.hpp"
|
||||
|
||||
#include "function_wrapper.hpp"
|
||||
#include "function_wrapper_tcg.hpp"
|
||||
#include <ranges>
|
||||
|
||||
namespace unicorn
|
||||
@@ -550,7 +549,7 @@ namespace unicorn
|
||||
c(address); //
|
||||
};
|
||||
|
||||
function_wrapper_tcg<void, uc_engine*, uint64_t, uint32_t> wrapper(std::move(exec_wrapper));
|
||||
function_wrapper<void, uc_engine*, uint64_t, uint32_t> wrapper(std::move(exec_wrapper));
|
||||
|
||||
unicorn_hook hook{*this};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user