@@ -57,6 +57,8 @@ if (Qt5Widgets_FOUND)
endif (Qt5Widgets_FOUND)
+find_package (Boost COMPONENTS unit_test_framework)
+
set(LIBRARY_OUTPUT_PATH "${KS_DIR}/lib")
set(EXECUTABLE_OUTPUT_PATH "${KS_DIR}/bin")
@@ -109,6 +111,13 @@ message(STATUS "Linker flags : " ${CMAKE_EXE_LINKER_FLAGS})
add_subdirectory(${KS_DIR}/src)
add_subdirectory(${KS_DIR}/examples)
+if (Boost_FOUND)
+
+ enable_testing()
+ add_subdirectory(${KS_DIR}/tests)
+
+endif()
+
if (_DOXYGEN_DOC AND DOXYGEN_FOUND)
message("\n doxygen documentation ...")
@@ -2,9 +2,13 @@ make clean
rm CMakeCache.txt
rm cmake_install.cmake
rm Makefile
+rm CTestTestfile.cmake
+rm -f DartConfiguration.tcl
rm -rf CMakeFiles/
rm -rf src/
rm -rf examples/
+rm -rf tests/
+rm -rf Testing/
rm -f ../lib/*
rm ../kernelshark.desktop
rm ../org.freedesktop.kshark-record.policy
new file mode 100644
@@ -0,0 +1,14 @@
+message("\n tests ...")
+
+set(KS_TEST_DIR "${KS_DIR}/tests")
+set(EXECUTABLE_OUTPUT_PATH ${KS_TEST_DIR})
+
+add_executable(kshark-tests libkshark-tests.cpp)
+target_include_directories(kshark-tests PRIVATE ${Boost_INCLUDE_DIRS})
+target_compile_definitions(kshark-tests PRIVATE "BOOST_TEST_DYN_LINK=1")
+target_link_libraries(kshark-tests kshark
+ ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+
+add_test(NAME "libkshark_tests"
+ COMMAND ${KS_TEST_DIR}/kshark-tests --log_format=HRF
+ WORKING_DIRECTORY ${KS_TEST_DIR})
new file mode 100644
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: LGPL-2.1
+
+/*
+ * Copyright (C) 2020 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+ */
+
+// Boost
+#define BOOST_TEST_MODULE KernelSharkTests
+#include <boost/test/unit_test.hpp>
+
+// KernelShark
+#include "libkshark.h"
+
+#define N_TEST_STREAMS 1000
+
+BOOST_AUTO_TEST_CASE(add_remove_streams)
+{
+ struct kshark_context *kshark_ctx = NULL;
+ int sd, free = 0, i;
+
+ kshark_instance(&kshark_ctx);
+
+ for (i = 0; i < N_TEST_STREAMS; ++i) {
+ sd = kshark_add_stream(kshark_ctx);
+ BOOST_CHECK_EQUAL(sd, free);
+
+ kshark_add_stream(kshark_ctx);
+
+ free = i / 2;
+ kshark_remove_stream(kshark_ctx, free);
+ sd = kshark_add_stream(kshark_ctx);
+ BOOST_CHECK_EQUAL(sd, free);
+
+ free = i / 2 + 1;
+ kshark_remove_stream(kshark_ctx, free);
+ }
+
+ BOOST_CHECK_EQUAL(kshark_ctx->n_streams, N_TEST_STREAMS);
+
+ while (sd > 0)
+ sd = kshark_add_stream(kshark_ctx);
+
+ BOOST_CHECK_EQUAL(kshark_ctx->n_streams, INT16_MAX + 1);
+ BOOST_CHECK_EQUAL(kshark_ctx->stream_info.array_size, INT16_MAX + 1);
+ BOOST_CHECK_EQUAL(sd, -ENODEV);
+
+ kshark_close_all(kshark_ctx);
+}
The tasting infrastructure is based on GTest (CMake-provided feature for automated testing) and Boost Test Library. In the patch we also provide a very simple test of adding/removing Data streams. For the moment this single test is used mainly to validate the proper functioning of the tasting infrastructure itself. A proper test coverage of the libraries is yet to be implemented. In a following patch we will integrate the tasting infrastructure into a "github Actions" workflow that will help the CI process. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- CMakeLists.txt | 9 ++++++++ build/cmake_clean.sh | 4 ++++ tests/CMakeLists.txt | 14 ++++++++++++ tests/libkshark-tests.cpp | 48 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/libkshark-tests.cpp