diff options
author | Yordan Karadzhov (VMware) <y.karadz@gmail.com> | 2020-12-11 17:07:55 +0200 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2020-12-21 19:13:16 -0500 |
commit | e30c3057770e0b646b51762fead9ace4a0a00453 (patch) | |
tree | 15b55cc3706cbda83396200b42a2b00d526b86c7 | |
parent | e143a886b344ef3f9434c278f82db3b2539cb704 (diff) | |
download | kernel-shark-e30c3057770e0b646b51762fead9ace4a0a00453.tar.gz |
kernel-shark: Add basic infrastructure for testing
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.
Link: https://lore.kernel.org/linux-trace-devel/20201211150756.577366-32-y.karadz@gmail.com
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rwxr-xr-x | build/cmake_clean.sh | 4 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 14 | ||||
-rw-r--r-- | tests/libkshark-tests.cpp | 48 |
4 files changed, 75 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 44071a6f..303e47e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,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") @@ -93,6 +95,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 ...") diff --git a/build/cmake_clean.sh b/build/cmake_clean.sh index 2e7c8f94..f70b5453 100755 --- a/build/cmake_clean.sh +++ b/build/cmake_clean.sh @@ -2,9 +2,13 @@ make clean rm CMakeCache.txt rm cmake_install.cmake rm Makefile +rm CTestTestfile.cmake +rm 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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..a1e3085e --- /dev/null +++ b/tests/CMakeLists.txt @@ -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}) diff --git a/tests/libkshark-tests.cpp b/tests/libkshark-tests.cpp new file mode 100644 index 00000000..27c11717 --- /dev/null +++ b/tests/libkshark-tests.cpp @@ -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); +} |