Skip to content

Commit

Permalink
Fix add_test calls and change temporary file creation. (#1522)
Browse files Browse the repository at this point in the history
* * Fix add_test in cmake files. This notation allows it to understand that the command portion is a target and to translate it to the proper executable.
* Remove starting backslash if present from temporary filename. A starting backslash mean that it is safe to create it in the current working directory.
* Implement a public TempFile class.
* Change relevant tests to use TempFile class.

Signed-off-by: Patrick Northon <northon_patrick3@yahoo.ca>

* * Revert back changes for TempFile class.
* Add comment on temporary file functions fix.

Signed-off-by: Patrick Northon <northon_patrick3@yahoo.ca>

* Add FIXME comments.

Signed-off-by: Patrick Northon <northon_patrick3@yahoo.ca>

* Add -C flag to ctest commands.

Signed-off-by: Patrick Northon <northon_patrick3@yahoo.ca>

* Add `-C Release` to ctest commands in `analysis_workflow.yml`.

Signed-off-by: Patrick Northon <northon_patrick3@yahoo.ca>

Co-authored-by: Patrick Hodoul <patrick.hodoul@autodesk.com>
Co-authored-by: Rémi Achard <remiachard@gmail.com>
  • Loading branch information
3 people authored Nov 4, 2021
1 parent b2e88b1 commit ce85939
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/analysis_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
-- -j$(nproc)
working-directory: _build
- name: Test
run: ctest -V
run: ctest -V -C Release
working-directory: _build

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
run: build-wrapper-linux-x86-64 --out-dir bw_output make clean all
working-directory: _build
- name: Test
run: ctest -V
run: ctest -V -C Release
working-directory: _build
- name: Generate code coverage report
run: share/ci/scripts/linux/run_gcov.sh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ jobs:
-- -j$(nproc)
working-directory: _build
- name: Test
run: ctest -V
run: ctest -V -C ${{ matrix.build-type }}
working-directory: _build
- name: Test CMake Consumer
if: matrix.build-shared == 'ON'
Expand Down Expand Up @@ -407,7 +407,7 @@ jobs:
-- -j$(sysctl -n hw.ncpu)
working-directory: _build
- name: Test
run: ctest -V
run: ctest -V -C ${{ matrix.build-type }}
working-directory: _build
- name: Test CMake Consumer
if: matrix.build-shared == 'ON'
Expand Down Expand Up @@ -549,7 +549,7 @@ jobs:
shell: bash
working-directory: _build
- name: Test
run: ctest -V
run: ctest -V -C ${{ matrix.build-type }}
shell: bash
working-directory: _build
- name: Test CMake Consumer
Expand Down
4 changes: 3 additions & 1 deletion src/OpenColorIO/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ std::string CreateTempFilename(const std::string & filenameExt)
throw Exception("Could not create a temporary file.");
}

filename = tmpFilename;
// Note that when a file name is pre-pended with a backslash and no path information, such as \fname21, this
// indicates that the name is valid for the current working directory.
filename = tmpFilename[0] == '\\' ? tmpFilename + 1 : tmpFilename;

#else

Expand Down
1 change: 1 addition & 0 deletions src/OpenColorIO/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void AlignedFree(void * memBlock);
// Note: Temporary files should be at some point deleted by the OS (depending of the OS
// and various platform specific settings). To be safe, add some code to remove
// the file if created.
// FIXME: Implement a function or class for temporary file creation useable by all tests.
std::string CreateTempFilename(const std::string & filenameExt);

// Create an input file stream (std::ifstream) using a UTF-8 filename on any platform.
Expand Down
2 changes: 1 addition & 1 deletion tests/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function(add_ocio_test NAME SOURCES PRIVATE_INCLUDES)
set_target_properties(${TEST_BINARY} PROPERTIES
COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS}")

add_test(${TEST_NAME} ${TEST_BINARY})
add_test(NAME ${TEST_NAME} COMMAND ${TEST_BINARY})
endfunction(add_ocio_test)

# Eventually we will factor out each test into it's own executable
Expand Down
2 changes: 1 addition & 1 deletion tests/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ target_link_libraries(test_gpu_exec
unittest_data
)

add_test(test_gpu test_gpu_exec)
add_test(NAME test_gpu COMMAND test_gpu_exec)

# Note: To avoid changing PATH from outside the cmake files.
if(MSVC AND BUILD_SHARED_LIBS)
Expand Down
4 changes: 3 additions & 1 deletion tests/gpu/GPUHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ std::string createTempFile(const std::string& fileExt, const std::string& fileCo
throw OCIO::Exception("Could not create a temporary file");
}

filename = tmpFilename;
// Note that when a file name is pre-pended with a backslash and no path information, such as \fname21, this
// indicates that the name is valid for the current working directory.
filename = tmpFilename[0] == '\\' ? tmpFilename + 1 : tmpFilename;
filename += fileExt;

#else
Expand Down
3 changes: 2 additions & 1 deletion tests/gpu/GPUHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include <string>


// FIXME: Duplicate function implemented in `src/OpenColorIO/Platform.h and cpp`.
// Implement a function or class for temporary file creation useable by all tests.
std::string createTempFile(const std::string& fileExt, const std::string& fileContent);


Expand Down
2 changes: 1 addition & 1 deletion tests/osl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ target_link_libraries(test_osl_exec
OpenImageIO::OpenImageIO
)

add_test(test_osl test_osl_exec)
add_test(NAME test_osl COMMAND test_osl_exec)

list(APPEND ENVS "OSL_SHADERS_DIR=${OSL_SHADERS_DIR}")
list(APPEND ENVS "TMP_SHADERS_DIR=${CMAKE_CURRENT_BINARY_DIR}")
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ target_link_libraries(test_utils_exec
set_target_properties(test_utils_exec PROPERTIES
COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS}")

add_test(test_utils_exec test_utils_exec)
add_test(NAME test_utils_exec COMMAND test_utils_exec)

0 comments on commit ce85939

Please sign in to comment.