diff --git a/.github/workflows/jsruntime_L1tests.yml b/.github/workflows/jsruntime_L1tests.yml new file mode 100644 index 0000000..fd7d3c4 --- /dev/null +++ b/.github/workflows/jsruntime_L1tests.yml @@ -0,0 +1,106 @@ +name: L1 Unit Tests for rdkNativeScript +permissions: + contents: read + checks: write + +on: + push: + branches: [develop] + pull_request: + branches: [develop] + workflow_dispatch: + +env: + AUTOMATICS_UNAME: ${{ secrets.AUTOMATICS_UNAME }} + AUTOMATICS_PASSCODE: ${{ secrets.AUTOMATICS_PASSCODE }} + +jobs: + build-and-test-l1: + runs-on: ubuntu-latest + + steps: + - name: Checkout source repository + uses: actions/checkout@v3 + + - name: Checkout rdkNativeScript_tests repository + uses: actions/checkout@v3 + with: + repository: rdk-e/rdkNativeScript_tests + ref: topic/RDKEMW-5610 + path: rdkNativeScript_tests + token: ${{ secrets.GH_PAT }} + + - name: Install dependencies + run: | + sudo apt-get update && sudo apt-get install -y \ + g++ \ + cmake \ + build-essential \ + libcurl4-openssl-dev \ + libcjson-dev \ + libgtest-dev \ + libssl-dev \ + zlib1g-dev \ + libuv1-dev \ + lcov \ + libglib2.0-dev + + - name: Build Google Test and Google Mock + run: | + cd /usr/src/googletest + sudo cmake -S . -B build + sudo cmake --build build + sudo cp build/lib/libgmock.a /usr/lib + sudo cp build/lib/libgmock_main.a /usr/lib + sudo cp build/lib/libgtest.a /usr/lib + sudo cp build/lib/libgtest_main.a /usr/lib + + - name: Configure and Build L1 + run: | + mkdir -p build_l1 + cd build_l1 + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DRUN_L1=ON \ + -DRUN_L2=OFF \ + -DENABLE_JSRUNTIME_ESSOS=ON \ + -DENABLE_JSRUNTIME_PLAYER=ON \ + -DENABLE_AAMP_JSBINDINGS=ON \ + -DENABLE_AAMP_JSBINDINGS_DYNAMIC=ON \ + -DENABLE_AAMP_JSBINDINGS_STATIC=OFF \ + -DJSRUNTIME_ENGINE_NAME=jsc \ + -Djsruntime_source=.. ../rdkNativeScript_tests + make -j$(nproc) + + - name: Run L1 Tests and Generate JUnit Results + run: | + cd build_l1 + #ctest -R RunL1Tests --output-on-failure --no-compress-output --output-junit ctest-results.xml + ./L1_tests --gtest_output=xml:ctest-results.xml + + - name: Publish L1 test results + uses: dorny/test-reporter@v1 + with: + name: Unit Test Results + path: build_l1/ctest-results.xml + reporter: java-junit + + - name: Generate coverage report + run: | + cd build_l1 + lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch --rc geninfo_unexecuted_blocks=1 + lcov --remove coverage.info '/usr/*' '*/test/*' '*/tests/*' '*/L1/*' '*/mocks/*' '*/gtest/*' '*/gmock/*' '*/googletest/*' '*/include/*' --output-file coverage.cleaned.info --ignore-errors unused + lcov --extract coverage.cleaned.info '*/src/*' --output-file coverage.final.info + genhtml coverage.final.info --output-directory html_coverage_report + + - name: Upload test result file (JUnit XML) + uses: actions/upload-artifact@v4 + with: + name: ctest-results-l1-${{ github.run_id }} + path: build_l1/ctest-results.xml + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: l1-html-coverage-report + path: build_l1/html_coverage_report + if-no-files-found: warn diff --git a/include/EssosInstance.h b/include/EssosInstance.h index caf1973..7b94e28 100644 --- a/include/EssosInstance.h +++ b/include/EssosInstance.h @@ -20,7 +20,12 @@ #ifndef NativeJS_ESSOS_INSTANCE_H #define NativeJS_ESSOS_INSTANCE_H +#ifdef USE_ESSOS_MOCK +#include "essos_mock.h" +#else #include +#endif + #include class EssosInstance diff --git a/include/JSRuntimeClient.h b/include/JSRuntimeClient.h index 2c9ec61..586223a 100644 --- a/include/JSRuntimeClient.h +++ b/include/JSRuntimeClient.h @@ -18,9 +18,14 @@ **/ #pragma once + +#ifdef USE_WEBSOCKET_MOCK +#include "websocketpp.hpp" +#else #include #include #include +#endif #include #include diff --git a/include/JSRuntimeServer.h b/include/JSRuntimeServer.h index 9df8115..e6850cc 100644 --- a/include/JSRuntimeServer.h +++ b/include/JSRuntimeServer.h @@ -19,8 +19,13 @@ #pragma once #include + +#ifdef USE_WEBSOCKET_MOCK +#include "websocketpp.hpp" +#else #include #include +#endif #include #include diff --git a/include/jsc/JavaScriptEngine.h b/include/jsc/JavaScriptEngine.h index 4a2924f..7e830ba 100644 --- a/include/jsc/JavaScriptEngine.h +++ b/include/jsc/JavaScriptEngine.h @@ -22,6 +22,7 @@ #include #include +#include //#include #include diff --git a/src/JSRuntimeClient.cpp b/src/JSRuntimeClient.cpp index d640c29..65e4c73 100644 --- a/src/JSRuntimeClient.cpp +++ b/src/JSRuntimeClient.cpp @@ -18,7 +18,13 @@ **/ #include #include + +#ifdef USE_JSCLIB_MOCK +#include "jsc_lib_mock.h" +#else #include "jsc_lib.h" +#endif + #include #include #include @@ -143,6 +149,7 @@ void JSRuntimeClient::onClose(websocketpp::connection_hdl hdl) setState("close"); } +#ifndef UNIT_TEST_BUILD int main(int argc, char **argv) { std::string command; @@ -178,3 +185,4 @@ int main(int argc, char **argv) return 0; } +#endif diff --git a/src/JSRuntimeServer.cpp b/src/JSRuntimeServer.cpp index 44438ad..340a070 100644 --- a/src/JSRuntimeServer.cpp +++ b/src/JSRuntimeServer.cpp @@ -17,7 +17,12 @@ * limitations under the License. **/ +#ifdef USE_JSCLIB_MOCK +#include "jsc_lib_mock.h" +#else #include "jsc_lib.h" +#endif + #include #include #include diff --git a/src/jsc/JavaScriptContext.cpp b/src/jsc/JavaScriptContext.cpp index 29a8602..ddca18a 100644 --- a/src/jsc/JavaScriptContext.cpp +++ b/src/jsc/JavaScriptContext.cpp @@ -146,10 +146,10 @@ void JavaScriptContext::loadAAMPJSBindingsLib() gAAMPJSBindings->PlayerLibHandle = aampJSBindingsLibHandle; gAAMPJSBindings->fnLoadJS = - reinterpret_cast( + reinterpret_cast( dlsym(aampJSBindingsLibHandle, "_Z17AAMPPlayer_LoadJSPv")); gAAMPJSBindings->fnUnloadJS = - reinterpret_cast( + reinterpret_cast( dlsym(aampJSBindingsLibHandle, "_Z19AAMPPlayer_UnloadJSPv")); } else diff --git a/src/jsc/JavaScriptUtils.cpp b/src/jsc/JavaScriptUtils.cpp index 836aa23..6ac3397 100644 --- a/src/jsc/JavaScriptUtils.cpp +++ b/src/jsc/JavaScriptUtils.cpp @@ -20,7 +20,13 @@ #include "JavaScriptUtils.h" #include "JavaScriptWrapper.h" #include "rtLog.h" + +#ifdef USE_JSCLIB_MOCK +#include "jsc_lib_mock.h" +#else #include "jsc_lib.h" +#endif + #include #include #include diff --git a/src/jsc/JavaScriptWrapper.cpp b/src/jsc/JavaScriptWrapper.cpp index 66d15e9..c363973 100644 --- a/src/jsc/JavaScriptWrapper.cpp +++ b/src/jsc/JavaScriptWrapper.cpp @@ -17,7 +17,12 @@ * limitations under the License. **/ +#ifdef USE_JSCLIB_MOCK +#include "jsc_lib_mock.h" +#else #include "jsc_lib.h" +#endif + #include "JavaScriptEngine.h" #include "JavaScriptWrapper.h" #include diff --git a/src/jsc/PlayerWrapper.cpp b/src/jsc/PlayerWrapper.cpp index 17a4cc3..e1a748c 100644 --- a/src/jsc/PlayerWrapper.cpp +++ b/src/jsc/PlayerWrapper.cpp @@ -141,7 +141,7 @@ void PlayerWrapper::clearCallbackForAllAdIds() for (std::map::iterator it = mPromiseCallbacks.begin(); it != mPromiseCallbacks.end(); ) { JSValueUnprotect(ctx, it->second); - mPromiseCallbacks.erase(it); + it = mPromiseCallbacks.erase(it); } } } @@ -344,7 +344,7 @@ JSValueRef AAMPMediaPlayerJS_initConfig (JSContextRef ctx, JSObjectRef function, } if (!success) { - NativeJSLogger::log(ERROR, "Failed to parse JSON string [%s]\n", configData.c_str()); + NativeJSLogger::log(ERROR, "Failed to parse JSON string [%s]\n", configData); fflush(stdout); } if (configData) diff --git a/src/jsc/jsc_lib/jsc_lib.cpp b/src/jsc/jsc_lib/jsc_lib.cpp index c2a8757..8972922 100644 --- a/src/jsc/jsc_lib/jsc_lib.cpp +++ b/src/jsc/jsc_lib/jsc_lib.cpp @@ -15,7 +15,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef USE_JSCLIB_MOCK +#include "jsc_lib_mock.h" +#else #include "jsc_lib.h" +#endif + #include "NativeJSLogger.h" using namespace JSC; diff --git a/src/jsc/rtScriptJSCPrivate.cpp b/src/jsc/rtScriptJSCPrivate.cpp index 2d68a55..f5f36bd 100644 --- a/src/jsc/rtScriptJSCPrivate.cpp +++ b/src/jsc/rtScriptJSCPrivate.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/jsruntime.cpp b/src/jsruntime.cpp index 8bfbaa0..0f6390c 100644 --- a/src/jsruntime.cpp +++ b/src/jsruntime.cpp @@ -34,6 +34,7 @@ using namespace std; using namespace JsRuntime; +#ifndef UNIT_TEST_BUILD int main(int argc, char* argv[]) { if (argc < 2) @@ -155,3 +156,5 @@ int main(int argc, char* argv[]) return 0; } + +#endif