Skip to content

Commit

Permalink
improvement(sdk): add sdk code coverage (#808)
Browse files Browse the repository at this point in the history
* feat(doc): add CI

* CI(sdk): add sdk coverage

* style(test): code format

* fix(CI): update coverage.info path

* improvement(CI): use internal image

* improvement(CI): push coverage info once
  • Loading branch information
tpoisonooo authored Jul 29, 2022
1 parent 2c18fbd commit f54da4e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
37 changes: 33 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:
cancel-in-progress: true

jobs:
build_cpu:
build_cpu_model_convert:
runs-on: ubuntu-18.04
strategy:
matrix:
Expand Down Expand Up @@ -53,12 +53,41 @@ jobs:
pip install -U numpy
- name: Build and install
run: rm -rf .eggs && pip install -e .
- name: Run unittests and generate coverage report
- name: Run python unittests and generate coverage report
run: |
coverage run --branch --source mmdeploy -m pytest -rsE tests
coverage xml
coverage report -m
build_cpu_sdk:
runs-on: ubuntu-18.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: update
run: sudo apt update
- name: gcc-multilib
run: |
sudo apt install gcc-multilib g++-multilib wget libprotobuf-dev protobuf-compiler
sudo apt update
sudo apt install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev libc++1-9 libc++abi1-9
sudo add-apt-repository ppa:ignaciovizzo/opencv3-nonfree
sudo apt install libopencv-dev lcov wget
pkg-config --libs opencv
- name: Build and run SDK unit test without backend
run: |
mkdir -p build && pushd build
cmake .. -DCMAKE_CXX_COMPILER=g++-7 -DMMDEPLOY_CODEBASES=all -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=OFF -DMMDEPLOY_TARGET_DEVICES=cpu -DMMDEPLOY_COVERAGE=ON -DMMDEPLOY_BUILD_TEST=ON
make -j2
mkdir -p mmdeploy_test_resources/transform
cp ../tests/data/tiger.jpeg mmdeploy_test_resources/transform/
./bin/mmdeploy_tests
lcov --capture --directory . --output-file coverage.info
ls -lah coverage.info
cp coverage.info ../
build_cuda102:
runs-on: ubuntu-18.04
container:
Expand Down Expand Up @@ -153,8 +182,8 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
file: ./coverage.xml
file: ./coverage.xml,./coverage.info
flags: unittests
env_vars: OS,PYTHON
env_vars: OS,PYTHON,CPLUS
name: codecov-umbrella
fail_ci_if_error: false
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ option(MMDEPLOY_BUILD_SDK_JAVA_API "build SDK JAVA API" OFF)
option(MMDEPLOY_BUILD_EXAMPLES "build examples" OFF)
option(MMDEPLOY_SPDLOG_EXTERNAL "use external spdlog" OFF)
option(MMDEPLOY_ZIP_MODEL "support SDK model in zip format" OFF)
option(MMDEPLOY_COVERAGE "build SDK for coverage" OFF)

set(MMDEPLOY_TARGET_DEVICES "cpu" CACHE STRING "target devices to support")
set(MMDEPLOY_TARGET_BACKENDS "" CACHE STRING "target inference engines to support")
set(MMDEPLOY_CODEBASES "all" CACHE STRING "select OpenMMLab codebases")
Expand All @@ -49,6 +51,11 @@ endif ()

set(MMDEPLOY_TASKS "" CACHE INTERNAL "")

if (MMDEPLOY_COVERAGE)
add_compile_options(-coverage -fprofile-arcs -ftest-coverage)
add_link_options(-coverage -lgcov)
endif ()

# when CUDA devices are enabled, the environment variable ASAN_OPTIONS=protect_shadow_gap=0
# must be set at runtime
if (MMDEPLOY_ASAN_ENABLE)
Expand Down
3 changes: 1 addition & 2 deletions csrc/mmdeploy/preprocess/transform/collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ Result<Value> CollectImpl::Process(const Value &input) {
}
for (auto &key : arg_.keys) {
if (!input.contains(key)) {
MMDEPLOY_ERROR("missed key '{}' in input", key);
// return Status(eInvalidArgument);
MMDEPLOY_INFO("missed key '{}' in input", key);
return Status(eInvalidArgument);
} else {
output[key] = input[key];
Expand Down
16 changes: 8 additions & 8 deletions tests/test_csrc/core/test_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST_CASE("test basic execution", "[execution]") {
static_assert(std::is_same_v<decltype(GetCompletionScheduler(b)), InlineScheduler>);
auto c = Then(b, [](Value v) -> Value { return {{"c", v["a"].get<int>() + v["b"].get<int>()}}; });
auto d = SyncWait(c);
MMDEPLOY_ERROR("{}", d);
MMDEPLOY_INFO("{}", d);
}

template <class Sender>
Expand All @@ -45,7 +45,7 @@ TEST_CASE("test split", "[execution]") {
auto y = GetKey(s, "y");
auto x_v = SyncWait(x);
auto y_v = SyncWait(y);
MMDEPLOY_ERROR("x = {}, y = {}", x_v, y_v);
MMDEPLOY_INFO("x = {}, y = {}", x_v, y_v);
}

TEST_CASE("test when_all", "[execution]") {
Expand All @@ -56,7 +56,7 @@ TEST_CASE("test when_all", "[execution]") {
auto e = Just(500);
auto t = WhenAll(a, b, c, d, e);
auto v = SyncWait(t);
MMDEPLOY_ERROR("v = {}", v);
MMDEPLOY_INFO("v = {}", v);
}

void Func() {
Expand All @@ -65,7 +65,7 @@ void Func() {
LetValue(a, [](int& x, int& y) { return Then(Just(x + y), [](int v) { return v * v; }); });
auto v = SyncWait(b);
static_assert(std::is_same_v<decltype(v), std::tuple<int>>);
MMDEPLOY_ERROR("v = {}", v);
MMDEPLOY_INFO("v = {}", v);
}

TEST_CASE("test let_value", "[execution]") { Func(); }
Expand All @@ -78,7 +78,7 @@ TEST_CASE("test fork-join", "[execution]") {
auto xy = WhenAll(x, y);
auto v = SyncWait(xy);
static_assert(std::is_same_v<decltype(v), std::tuple<Value, Value>>);
MMDEPLOY_ERROR("v = {}", v);
MMDEPLOY_INFO("v = {}", v);
}

TEST_CASE("test ensure_started", "[execution]") {
Expand All @@ -97,7 +97,7 @@ TEST_CASE("test ensure_started", "[execution]") {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
MMDEPLOY_INFO("ensure_started sync_wait");
auto v = SyncWait(c);
MMDEPLOY_ERROR("ensure_started: {}", v);
MMDEPLOY_INFO("ensure_started: {}", v);
}

TEST_CASE("test start_detached", "[execution]") {
Expand All @@ -119,7 +119,7 @@ TEST_CASE("test on", "[execution]") {
auto b = On(pool.GetScheduler(), a);
auto c = SyncWait(b);
static_assert(std::is_same_v<decltype(c), std::tuple<int, int>>);
MMDEPLOY_ERROR("c = {}", c);
MMDEPLOY_INFO("c = {}", c);
}

mmdeploy_value_t f(mmdeploy_value_t v, void*) {
Expand Down Expand Up @@ -246,7 +246,7 @@ TEST_CASE("test executor C API", "[execution]") {
REQUIRE(b);
auto c = mmdeploy_executor_sync_wait(b);
REQUIRE(c);
MMDEPLOY_CRITICAL("{}", *(Value*)c);
MMDEPLOY_INFO("{}", *(Value*)c);
mmdeploy_value_destroy(c);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_csrc/preprocess/test_resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ void TestResizeWithScaleFactor(const Value& cfg, const std::string& device_name,
auto transform = CreateTransform(cfg, device, stream);
REQUIRE(transform != nullptr);

auto [dst_height, dst_width] = make_tuple(mat.rows * scale_factor, mat.cols * scale_factor);
// keep round policy with resize.cpp
const int dst_height = static_cast<int>(mat.rows * scale_factor + 0.5);
const int dst_width = static_cast<int>(mat.cols * scale_factor + 0.5);
auto interpolation = cfg["interpolation"].get<string>();
auto ref_mat = mmdeploy::cpu::Resize(mat, dst_height, dst_width, interpolation);

Expand Down

0 comments on commit f54da4e

Please sign in to comment.