Commit 77a0a45f authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Add test

parent 1cee1e4d
Pipeline #26382 failed with stages
in 8 minutes and 29 seconds
......@@ -5,6 +5,11 @@ pybind11_add_module(pylena_test pylena_test.cpp)
target_link_libraries(pylena_test PRIVATE Pylene pylena_numpy)
target_include_directories(pylena_test PRIVATE ${CMAKE_SOURCE_DIR}/pylene-python/include)
# Dummy extension for testing
pybind11_add_module(pylena_extension extension_pylena_numpy.cpp)
target_link_libraries(pylena_extension PRIVATE Pylene pylena_numpy)
target_include_directories(pylena_extension PRIVATE ${CMAKE_SOURCE_DIR}/pylene-python/include)
# Sanitizer (clang linked statically asan by default unlike gcc)
if ((SANITIZE_ADDRESS OR SANITIZE_UNDEFINED OR SANITIZE_MEMORY OR SANITIZE_THREAD))
if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
......
#include <pln/core/image_cast.hpp>
namespace pln::test
{
PYBIND11_MODULE(pylena_extension, m)
{
init_pylena_numpy(m);
m.def("id", [](const mln::ndbuffer_image& img) { return img; });
m.def("generate_iota", []() {
mln::ndbuffer_image img(mln::sample_type_id::UINT8, 10, 15, {0, 0});
for (std::size_t y = 0; y < 15; y++)
{
std::uint8_t* lineptr = reinterpret_cast<std::uint8_t*>(img.buffer()) + y * 10;
for (std::size_t x = 0; x < 10; x++)
{
lineptr[x] = 20 + y * 10 + x;
}
}
return img;
});
}
} // namespace pln::test
\ No newline at end of file
......@@ -57,5 +57,19 @@ class TestNumpyImage(unittest.TestCase):
self.assertTrue(res.strides[1] == res2.strides[1] == 2)
self.assertTrue(res.data == res2.data)
def test_several_pylena_numpy_extension(self):
"""
Just check there are no memory leaks or runtime error, not a precise result
"""
import pylena_extension as ext
img1 = pln.iota()
img2 = ext.generate_iota()
res1 = pln.id(img2)
res2 = ext.id(img1)
expected1 = np.arange(10, 10 + 10 * 15).reshape((15, 10))
expected2 = np.arange(10 * 15).reshape((10, 15))
self.assertTrue(np.all(res1 == expected1))
self.assertTrue(np.all(res2 == expected2))
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment