Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/sync_to_tencent_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: mirror-repository
uses: spyoungtech/mirror-action@v0.4.3
with:
Expand Down
91 changes: 79 additions & 12 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ on:
push:
branches:
- main
- 'feature/*'
- 'bugfix/*'

jobs:
mac-build:
mac-clang-run:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
backends: [ V8, JavaScriptCore, Lua, Empty ]
build_type: [ Debug, Release ]
build_type:
- Debug
# mac runner seems to be slow and less
# - Release
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down Expand Up @@ -43,13 +44,15 @@ jobs:
cd build
./UnitTests

windows-build:
windows-msvc-run:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
backends: [ V8, JavaScriptCore, Lua, Empty ]
build_type: [ Debug, Release ]
build_type:
- Debug
- Release
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -68,7 +71,6 @@ jobs:
run: |
mkdir -Force build
cd build
ls dependencies
cmake ../test -A X64 -DSCRIPTX_BACKEND=${{ matrix.backends }}
- name: Configure cmake X86
if: matrix.backends == 'JavaScriptCore'
Expand All @@ -91,8 +93,76 @@ jobs:
cd build
${{ matrix.build_type }}/UnitTests

ubuntu-gcc-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
backends: [ V8, JavaScriptCore, Lua, Empty ]
build_type:
- Debug
#- Release
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
key: build-dependencies-macos
path: |
build/ScriptXTestLibs
build/googletest-src
- name: Configure cmake
env:
SCRIPTX_TEST_FORCE_UPDATE_DEPS: ON
SCRIPTX_TEST_BUILD_ONLY: ON
run: |
mkdir -p build && cd build
cmake ../test \
-DSCRIPTX_BACKEND=${{ matrix.backends }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
- name: Compile UnitTests
run: |
cd build
cmake --build . -j $(nproc) --target UnitTests

android-clang-build:
# disable for now
# 1. we don't have android libraries
# 2. -undefined dynamic_lookup not work with NDK
if: ${{ false }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
backends: [ V8, JavaScriptCore, Lua, Empty ]
build_type:
- Debug
#- Release
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
key: build-dependencies-macos
path: |
build/ScriptXTestLibs
build/googletest-src
- name: Configure cmake
env:
SCRIPTX_TEST_FORCE_UPDATE_DEPS: ON
SCRIPTX_TEST_BUILD_ONLY: ON
run: |
mkdir -p build && cd build
cmake ../test \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-21 \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DSCRIPTX_BACKEND=${{ matrix.backends }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
- name: Compile UnitTests
run: |
cd build
cmake --build . -j $(nproc) --target UnitTests

node-js:
node-gcc-run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -115,7 +185,7 @@ jobs:
cd test/node_addon
npm run test

Webassembly:
webassembly-emscripten-run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -151,6 +221,3 @@ jobs:
cd build
# exclude failed tests
node UnitTests.js '--gtest_filter=-ThreadPool.*:EngineScopeTest.ExitEngine:EngineScopeTest.TwoThreads:EngineScopeTest.ThreadLocal:MessageQueue.Interrupt:MessageQueue.Shutdown:MessageQueue.ShutdownNow:MessageQueue.FullAndPostInsideLoopQueue:ReferenceTest.WeakGc:ReferenceTest.WeakGc:ReferenceTest.GlobalNotClear:ReferenceTest.GlobalOnEngineDestroy:ReferenceTest.WeakOnEngineDestroy:ReferenceTest.WeakNotClrear:ManagedObjectTest.EngineDispose:ManagedObjectTest.FunctionCallback:PressureTest.All'

# todo: add NDK build?
# todo: add linux build?
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ They have all licensed their contributions to this project under the
licensing terms detailed in LICENSE, while still keep copyright of their contributions.
People who commit code to this project are encouraged to append their names here.

| name | email | copyright |
| :--: | :---: | :---: |
| Yang Chao | <taylorcyang@tencent.com> | THL A29 Limited, a Tencent company. |
| Yang Chao | <landerlyoung@gmail.com> | |
| name | email | copyright | note |
| :--: | :---: | :---: | |
| Yang Chao | <taylorcyang@tencent.com> | THL A29 Limited, a Tencent company. | |
| Yang Chao | <landerlyoung@gmail.com> | | |
3 changes: 2 additions & 1 deletion backend/JavaScriptCore/JscEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ JSClassRef JscEngine::externalClass_{};

// When we link against high-version library
// but run with a low-version one, macOS/iOS linker just set the undefined symbols to nullptr.
bool JscEngine::hasByteBufferAPI_ = &JSValueGetTypedArrayType != nullptr;
// cast to void* to suppress g++ -Werror=address
bool JscEngine::hasByteBufferAPI_ = reinterpret_cast<void*>(&JSValueGetTypedArrayType) != nullptr;

JscEngine::JscEngine(std::shared_ptr<utils::MessageQueue> mq)
: messageQueue_(mq ? std::move(mq) : std::make_shared<utils::MessageQueue>()) {
Expand Down
2 changes: 1 addition & 1 deletion backend/JavaScriptCore/JscNative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool Arguments::hasThiz() const { return callbackInfo_.thisObject != nullptr; }
size_t Arguments::size() const { return callbackInfo_.size; }

Local<Value> Arguments::operator[](size_t i) const {
if (i < 0 || i >= size()) {
if (i >= size()) {
return {};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
Expand Down
28 changes: 14 additions & 14 deletions backend/Lua/LuaByteBufferImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class LuaByteBuffer : public ScriptClass {
return;
}
}
throw Exception(
(std::ostringstream() << "ByteBuffer should be created like ByteBuffer(n) n >= 0").str());

throw Exception(std::string("ByteBuffer should be created like ByteBuffer(n) n >= 0"));
}

const std::shared_ptr<void> &getNativeBuffer() const { return nativeBuffer_; }
Expand All @@ -62,22 +62,22 @@ class LuaByteBuffer : public ScriptClass {
using ScriptClass::getScriptObject;

template <typename T>
Local<Value> write(uint32_t pos, T data) {
Local<Value> write(int32_t pos, T data) {
writePtr<T>(pos) = data;
return getScriptObject();
}

template <typename T>
T read(uint32_t pos) {
T read(int32_t pos) {
return readPtr<T>(pos);
}

private:
template <typename T>
T &writePtr(uint32_t pos) {
T &writePtr(int32_t pos) {
// lua use 1-based index
pos--;
if (pos < 0 || pos + sizeof(T) >= size_) {
if (pos < 0 || pos + sizeof(T) > size_) {
throwIndexOutOfRange(pos + 1);
}
if (pos % sizeof(T) != 0) {
Expand All @@ -87,10 +87,10 @@ class LuaByteBuffer : public ScriptClass {
}

template <typename T>
T readPtr(uint32_t pos) {
T readPtr(int32_t pos) {
// lua use 1-based index
pos--;
if (pos < 0 || pos >= size_) {
if (pos < 0 || pos + sizeof(T) > size_) {
throwIndexOutOfRange(pos + 1);
}
if (pos % sizeof(T) != 0) {
Expand All @@ -100,15 +100,15 @@ class LuaByteBuffer : public ScriptClass {
}

void throwIndexOutOfRange(uint32_t pos) const {
throw Exception((std::ostringstream()
<< "ByteBuffer index out of range size:" << size_ << " position:" << pos)
.str());
std::ostringstream msg;
msg << "ByteBuffer index out of range size:" << size_ << " position:" << pos;
throw Exception(msg.str());
}

void throwNotAlignedMemoryAccess(uint32_t pos, uint32_t size) const {
throw Exception((std::ostringstream() << "ByteBuffer access memory at: [" << pos
<< "] is not aligned with: [" << size << "]")
.str());
std::ostringstream msg;
msg << "ByteBuffer access memory at: [" << pos << "] is not aligned with: [" << size << "]";
throw Exception(msg.str());
}
};

Expand Down
2 changes: 1 addition & 1 deletion backend/Lua/LuaNative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool Arguments::hasThiz() const {
size_t Arguments::size() const { return callbackInfo_.size; }

Local<Value> Arguments::operator[](size_t i) const {
if (i >= 0 && i < size()) {
if (i < size()) {
return lua_backend::LuaEngine::make<Local<Value>>(
static_cast<int>(callbackInfo_.stackBase + i));
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Tracer;
// using SFINA technology.

// android ndk can't compile follow declare until NDK r21
// #define StringLikeConcept(StringLike) \
// #define StringLikeConcept(StringLike)
// typename = std::void_t<decltype(::script::String::newString(std::declval<StringLike>()))>

#ifdef __cpp_lib_char8_t
Expand Down
2 changes: 1 addition & 1 deletion src/utils/MessageQueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ std::unique_ptr<InplaceMessage> MessageQueue::obtainInplaceMessage(
auto msg = messagePool_.obtain();
// InplaceMessage is essentially a Message with some extra non-virtual method.
// so it's safe to cast
msg->handlerProc = reinterpret_cast<void (*)(Message&)>(handlerProc);
msg->handlerProc = reinterpret_cast<void (*)(Message&)>(reinterpret_cast<void*>(handlerProc));
return std::unique_ptr<InplaceMessage>(reinterpret_cast<InplaceMessage*>(msg));
}

Expand Down
10 changes: 10 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ target_link_libraries(UnitTests gtest ScriptX)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# using clang or gcc
target_compile_options(ScriptX PRIVATE -Werror -Wall -Wextra -Wno-unused-parameter)

if (SCRIPTX_TEST_BUILD_ONLY)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_options(UnitTests PRIVATE -Wl,-undefined,dynamic_lookup)
else ()
target_link_options(UnitTests PRIVATE -Wl,--unresolved-symbols=ignore-in-object-files)
endif ()
message(WARNING "SCRIPTX_TEST_BUILD_ONLY is ON, the compiled UnitTests won't run properly. "
"Compiler is ${CMAKE_CXX_COMPILER_ID}")
endif ()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# using Visual Studio C++
target_compile_options(ScriptX PRIVATE /W4 /WX /Zc:__cplusplus /utf-8 /MP
Expand Down
Loading