Skip to content

Commit

Permalink
Fix GTest Death Style Tests and LoadDirectory test in conda (#5469)
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
JanuszL committed May 15, 2024
1 parent 280616a commit 8f2a43f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dali/test/dali_plugin_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ TEST(DummyTest, TestPluginGPU) {
TEST(DummyTest, LoadDirectory) {
GTEST_FLAG_SET(death_test_style, "threadsafe");
::dali::PluginManager::LoadDirectory(dali::test::CurrentExecutableDir());
// in conda we place plugins into main lib director, not app specific
::dali::PluginManager::LoadDirectory(dali::test::DefaultGlobalLibPath());
// This is crucial so that each test case has a chance to load the plugin (new process).
EXPECT_EXIT(TestPlugin("cpu"), testing::ExitedWithCode(0), "");
}
Expand Down
19 changes: 19 additions & 0 deletions dali/test/dali_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@

#include "dali/test/dali_test_utils.h"
#include <gtest/gtest.h>
#include <dlfcn.h>
#include <libgen.h>
#include <limits.h>
#include <unistd.h>
#include <limits>
#include <opencv2/opencv.hpp>
#include <random>
#include <string>
#include <filesystem>
#include "dali/core/common.h"
#include "dali/core/error_handling.h"
#include "dali/pipeline/data/backend.h"
#include "dali/pipeline/data/views.h"
#include "dali/pipeline/workspace/workspace.h"
#include "dali/test/tensor_test_utils.h"

namespace fs = std::filesystem;

namespace dali {
namespace test {

Expand All @@ -40,6 +44,21 @@ std::string CurrentExecutableDir() {
return {};
}

const std::string& DefaultGlobalLibPath() {
static const std::string path = [&]() -> std::string {
Dl_info info;
if (dladdr((const void*)dali::DALISetLastError, &info)) {
fs::path path(info.dli_fname);
// use the directory of the plugin manager shared object to detect the potential
// plugin default directory
path = path.parent_path();
return path.string();
}
return {};
}();
return path;
}

void MakeRandomBatch(TensorList<CPUBackend> &data, int N,
const TensorShape<> &min_sh,
const TensorShape<> &max_sh) {
Expand Down
2 changes: 2 additions & 0 deletions dali/test/dali_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace test {

std::string CurrentExecutableDir();

const std::string& DefaultGlobalLibPath();

/**
* @brief Produces a batch of ND random data
* with random shapes between a minimum and a maximum shape
Expand Down
6 changes: 4 additions & 2 deletions qa/TL1_self-test_conda/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ test_body() {
"dali_test.bin" \
"dali_operator_test.bin"
do
# DecodeJPEGHost doesn't work well for Conda as OpenCV there uses libjpeg that returns a bit different
# results that libturbo-jpeg DALI uses, also OpenCV conflicts with FFMpeg >= 4.2 which is reguired
# to handle PackedBFrames
"$BINNAME" --gtest_filter="*:-*Vp9*"
# use `which` to invoke test binary with full path so
# https://google.github.io/googletest/advanced.html#death-test-styles which runs tests in
# a separate process don't use PATH to discover the file location and fails
$(which $BINNAME) --gtest_filter="*:-*Vp9*"
done
}

Expand Down

0 comments on commit 8f2a43f

Please sign in to comment.