Skip to content

Commit 8f2a43f

Browse files
committed
Fix GTest Death Style Tests and LoadDirectory test in conda (#5469)
- GTest Death Style Tests clone the current process but don't follow the PATH to discover the executed binary. As in conda, we use relative path and the tests are installed in bin this fails. This change makes sure that tests are invoked with the full path specified. - LoadDirectory tests assume that the plugins are located next to the test binary while in conda they are copied to the global lib dir. This PR accounts for that. Signed-off-by: Janusz Lisiecki <[email protected]>
1 parent 280616a commit 8f2a43f

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

dali/test/dali_plugin_manager_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ TEST(DummyTest, TestPluginGPU) {
7979
TEST(DummyTest, LoadDirectory) {
8080
GTEST_FLAG_SET(death_test_style, "threadsafe");
8181
::dali::PluginManager::LoadDirectory(dali::test::CurrentExecutableDir());
82+
// in conda we place plugins into main lib director, not app specific
83+
::dali::PluginManager::LoadDirectory(dali::test::DefaultGlobalLibPath());
8284
// This is crucial so that each test case has a chance to load the plugin (new process).
8385
EXPECT_EXIT(TestPlugin("cpu"), testing::ExitedWithCode(0), "");
8486
}

dali/test/dali_test_utils.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@
1414

1515
#include "dali/test/dali_test_utils.h"
1616
#include <gtest/gtest.h>
17+
#include <dlfcn.h>
1718
#include <libgen.h>
1819
#include <limits.h>
1920
#include <unistd.h>
2021
#include <limits>
2122
#include <opencv2/opencv.hpp>
2223
#include <random>
2324
#include <string>
25+
#include <filesystem>
2426
#include "dali/core/common.h"
2527
#include "dali/core/error_handling.h"
2628
#include "dali/pipeline/data/backend.h"
2729
#include "dali/pipeline/data/views.h"
2830
#include "dali/pipeline/workspace/workspace.h"
2931
#include "dali/test/tensor_test_utils.h"
3032

33+
namespace fs = std::filesystem;
34+
3135
namespace dali {
3236
namespace test {
3337

@@ -40,6 +44,21 @@ std::string CurrentExecutableDir() {
4044
return {};
4145
}
4246

47+
const std::string& DefaultGlobalLibPath() {
48+
static const std::string path = [&]() -> std::string {
49+
Dl_info info;
50+
if (dladdr((const void*)dali::DALISetLastError, &info)) {
51+
fs::path path(info.dli_fname);
52+
// use the directory of the plugin manager shared object to detect the potential
53+
// plugin default directory
54+
path = path.parent_path();
55+
return path.string();
56+
}
57+
return {};
58+
}();
59+
return path;
60+
}
61+
4362
void MakeRandomBatch(TensorList<CPUBackend> &data, int N,
4463
const TensorShape<> &min_sh,
4564
const TensorShape<> &max_sh) {

dali/test/dali_test_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace test {
3232

3333
std::string CurrentExecutableDir();
3434

35+
const std::string& DefaultGlobalLibPath();
36+
3537
/**
3638
* @brief Produces a batch of ND random data
3739
* with random shapes between a minimum and a maximum shape

qa/TL1_self-test_conda/test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ test_body() {
3030
"dali_test.bin" \
3131
"dali_operator_test.bin"
3232
do
33-
# DecodeJPEGHost doesn't work well for Conda as OpenCV there uses libjpeg that returns a bit different
3433
# results that libturbo-jpeg DALI uses, also OpenCV conflicts with FFMpeg >= 4.2 which is reguired
3534
# to handle PackedBFrames
36-
"$BINNAME" --gtest_filter="*:-*Vp9*"
35+
# use `which` to invoke test binary with full path so
36+
# https://google.github.io/googletest/advanced.html#death-test-styles which runs tests in
37+
# a separate process don't use PATH to discover the file location and fails
38+
$(which $BINNAME) --gtest_filter="*:-*Vp9*"
3739
done
3840
}
3941

0 commit comments

Comments
 (0)