Skip to content

Commit 71b7ed0

Browse files
authored
Increase coverage (#321)
Part of #178
1 parent 535cbda commit 71b7ed0

File tree

18 files changed

+73
-24
lines changed

18 files changed

+73
-24
lines changed

.github/workflows/static-analysis-pr.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
id: review
2222
with:
2323
build_dir: build
24-
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind
24+
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind,libopencv-dev
2525
cmake_command: >
2626
cmake -S . -B build
2727
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
@@ -30,6 +30,7 @@ jobs:
3030
-D USE_SEQ=ON -D USE_MPI=ON
3131
-D USE_OMP=ON -D USE_TBB=ON -D USE_STL=ON
3232
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
33+
-D USE_SYSTEM_OPENCV=ON
3334
config_file: .clang-tidy
3435
exclude: 3rdparty
3536
split_workflow: true
@@ -56,7 +57,7 @@ jobs:
5657
id: review
5758
with:
5859
build_dir: build
59-
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind
60+
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind,libopencv-dev
6061
cmake_command: >
6162
cmake -S . -B build
6263
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
@@ -65,6 +66,7 @@ jobs:
6566
-D USE_SEQ=ON -D USE_MPI=ON
6667
-D USE_OMP=ON -D USE_TBB=ON -D USE_STL=ON
6768
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
69+
-D USE_SYSTEM_OPENCV=ON
6870
config_file: .clang-tidy
6971
exclude: 3rdparty
7072
split_workflow: true

cmake/opencv.cmake

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ if(NOT USE_SEQ AND NOT USE_MPI AND NOT USE_OMP AND NOT USE_TBB AND NOT USE_STL)
66
endif()
77

88
include(ExternalProject)
9-
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv/include)
9+
option(USE_SYSTEM_OPENCV OFF)
10+
if( USE_SYSTEM_OPENCV )
11+
find_package(OpenCV REQUIRED)
12+
include_directories(${OpenCV_INCLUDE_DIRS})
13+
else ()
14+
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv/include)
15+
endif ()
16+
1017
if(WIN32)
1118
ExternalProject_Add(ppc_opencv
1219
SOURCE_DIR "${CMAKE_SOURCE_DIR}/3rdparty/opencv"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <cstdlib>
4+
#include <string>
5+
#include <thread>
6+
7+
#include "core/util/include/util.hpp"
8+
9+
TEST(util_tests, check_unset_env) {
10+
#ifndef _WIN32
11+
int save_var = ppc::util::GetPPCNumThreads();
12+
13+
unsetenv("OMP_NUM_THREADS"); // NOLINT(misc-include-cleaner)
14+
15+
EXPECT_EQ(ppc::util::GetPPCNumThreads(), 1);
16+
17+
setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(misc-include-cleaner)
18+
#else
19+
GTEST_SKIP();
20+
#endif
21+
}
22+
23+
TEST(util_tests, check_set_env) {
24+
#ifndef _WIN32
25+
int save_var = ppc::util::GetPPCNumThreads();
26+
27+
const int num_threads = static_cast<int>(std::thread::hardware_concurrency());
28+
setenv("OMP_NUM_THREADS", std::to_string(num_threads).c_str(), 1); // NOLINT(misc-include-cleaner)
29+
30+
EXPECT_EQ(ppc::util::GetPPCNumThreads(), num_threads);
31+
32+
setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(misc-include-cleaner)
33+
#else
34+
GTEST_SKIP();
35+
#endif
36+
}

modules/core/util/include/util.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#include <string>
3+
4+
namespace ppc::util {
5+
6+
std::string GetAbsolutePath(const std::string &relative_path);
7+
int GetPPCNumThreads();
8+
9+
} // namespace ppc::util

modules/core/util/util.hpp modules/core/util/src/util.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#include "core/util/include/util.hpp"
22

33
#include <cstdlib>
44
#ifdef _WIN32
@@ -11,14 +11,12 @@
1111
#include <filesystem>
1212
#include <string>
1313

14-
namespace ppc::util {
15-
16-
inline std::string GetAbsolutePath(const std::string &relative_path) {
14+
std::string ppc::util::GetAbsolutePath(const std::string &relative_path) {
1715
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
1816
return path.string();
1917
}
2018

21-
inline int GetPPCNumThreads() {
19+
int ppc::util::GetPPCNumThreads() {
2220
#ifdef _WIN32
2321
size_t len;
2422
char omp_env[100];
@@ -32,5 +30,3 @@ inline int GetPPCNumThreads() {
3230
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;
3331
return num_threads;
3432
}
35-
36-
} // namespace ppc::util

tasks/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ foreach(TASK_TYPE ${LIST_OF_TASKS})
9090
endif (USE_PERF_TESTS)
9191

9292
foreach (EXEC_FUNC ${LIST_OF_EXEC_TESTS})
93-
target_link_libraries(${EXEC_FUNC} PUBLIC core_module_lib ${exec_func_lib})
93+
target_link_libraries(${EXEC_FUNC} PUBLIC ${exec_func_lib} core_module_lib)
9494

9595
if ("${MODULE_NAME}" STREQUAL "stl")
9696
target_link_libraries(${EXEC_FUNC} PUBLIC Threads::Threads)

tasks/all/example/func_tests/func_all.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "all/example/include/ops_all.hpp"
1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212

1313
TEST(nesterov_a_test_task_all, test_matmul_50) {
1414
constexpr size_t kCount = 50;

tasks/all/example/src/ops_all.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <thread>
77
#include <vector>
88

9-
#include "core/util/util.hpp"
9+
#include "core/util/include/util.hpp"
1010
#include "oneapi/tbb/task_arena.h"
1111
#include "oneapi/tbb/task_group.h"
1212

tasks/all/runner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <string>
1010
#include <utility>
1111

12-
#include "core/util/util.hpp"
12+
#include "core/util/include/util.hpp"
1313
#include "oneapi/tbb/global_control.h"
1414

1515
class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {

tasks/mpi/example/func_tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212
#include "mpi/example/include/ops_mpi.hpp"
1313

1414
TEST(nesterov_a_test_task_mpi, test_matmul_50) {

tasks/omp/example/func_tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212
#include "omp/example/include/ops_omp.hpp"
1313

1414
TEST(nesterov_a_test_task_omp, test_matmul_50) {

tasks/seq/broken_example_disabled/func_tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212
#include "seq/example/include/ops_seq.hpp"
1313

1414
TEST(nesterov_a_test_task_seq, test_matmul_50) {

tasks/seq/example/func_tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212
#include "seq/example/include/ops_seq.hpp"
1313

1414
TEST(nesterov_a_test_task_seq, test_matmul_50) {

tasks/stl/example/func_tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212
#include "stl/example/include/ops_stl.hpp"
1313

1414
TEST(nesterov_a_test_task_stl, test_matmul_50) {

tasks/stl/example/src/ops_stl.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
#include <cmath>
44
#include <cstddef>
5-
#include <functional>
65
#include <thread>
76
#include <vector>
87

9-
#include "core/util/util.hpp"
8+
#include "core/util/include/util.hpp"
109

1110
namespace {
1211
void MatMul(const std::vector<int> &in_vec, int rc_size, std::vector<int> &out_vec) {

tasks/tbb/example/func_tests/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include "core/task/include/task.hpp"
11-
#include "core/util/util.hpp"
11+
#include "core/util/include/util.hpp"
1212
#include "tbb/example/include/ops_tbb.hpp"
1313

1414
TEST(nesterov_a_test_task_tbb, test_matmul_50) {

tasks/tbb/example/src/ops_tbb.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <tbb/tbb.h>
44

55
#include <cmath>
6-
#include <core/util/util.hpp>
6+
#include <core/util/include/util.hpp>
77
#include <cstddef>
88
#include <vector>
99

tasks/tbb/runner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <gtest/gtest.h>
22
#include <tbb/global_control.h>
33

4-
#include "core/util/util.hpp"
4+
#include "core/util/include/util.hpp"
55
#include "oneapi/tbb/global_control.h"
66

77
int main(int argc, char** argv) {

0 commit comments

Comments
 (0)