diff --git a/CMakeLists.txt b/CMakeLists.txt index a56137c..9f17473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.1) #///////////////////////////////////////////////////////////////////# project(nvtop VERSION 2.0.1 - LANGUAGES C) + LANGUAGES C CXX) set(default_build_type "Release") # Default build type @@ -87,6 +87,12 @@ add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +#///////////////////////////////////////////////////////////////////# +# TESTING # +#///////////////////////////////////////////////////////////////////# + +include(CTest) +add_subdirectory(tests) #///////////////////////////////////////////////////////////////////# # PACKAGING # diff --git a/include/nvtop/interface_options.h b/include/nvtop/interface_options.h index d0c226a..fec274f 100644 --- a/include/nvtop/interface_options.h +++ b/include/nvtop/interface_options.h @@ -54,9 +54,8 @@ inline bool plot_isset_draw_info(enum plot_information check_info, inline unsigned plot_count_draw_info(plot_info_to_draw to_draw) { unsigned count = 0; - for (enum plot_information i = plot_gpu_rate; i < plot_information_count; - ++i) { - count += plot_isset_draw_info(i, to_draw); + for (int i = plot_gpu_rate; i < plot_information_count; ++i) { + count += plot_isset_draw_info((enum plot_information)i, to_draw); } return count; } @@ -108,9 +107,8 @@ process_add_field_to_display(enum process_field field, inline process_field_displayed process_default_displayed_field(void) { process_field_displayed to_display = 0; - for (enum process_field field = process_pid; field < process_field_count; - ++field) { - to_display = process_add_field_to_display(field, to_display); + for (int field = process_pid; field < process_field_count; ++field) { + to_display = process_add_field_to_display((enum process_field)field, to_display); } to_display = process_remove_field_to_display(process_enc_rate, to_display); to_display = process_remove_field_to_display(process_dec_rate, to_display); @@ -120,9 +118,8 @@ inline process_field_displayed process_default_displayed_field(void) { inline unsigned process_field_displayed_count(process_field_displayed fields_displayed) { unsigned displayed_count = 0; - for (enum process_field field = process_pid; field < process_field_count; - ++field) { - if (process_is_field_displayed(field, fields_displayed)) + for (int field = process_pid; field < process_field_count; ++field) { + if (process_is_field_displayed((enum process_field)field, fields_displayed)) displayed_count++; } return displayed_count; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..6078428 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,21 @@ +find_package(GTest) +if (BUILD_TESTING AND GTest_FOUND) + # Create a library for testing + add_library(testLib + ${PROJECT_SOURCE_DIR}/src/interface_layout_selection.c + ${PROJECT_SOURCE_DIR}/src/interface_options.c + ${PROJECT_SOURCE_DIR}/src/ini.c + ) + target_include_directories(testLib PUBLIC + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_BINARY_DIR}/include) + + # Tests + add_executable( + interfaceTests + interfaceTests.cpp + ) + target_link_libraries(interfaceTests PRIVATE testLib GTest::gtest_main) + gtest_discover_tests(interfaceTests) + +endif() diff --git a/tests/interfaceTests.cpp b/tests/interfaceTests.cpp new file mode 100644 index 0000000..14b1413 --- /dev/null +++ b/tests/interfaceTests.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (C) 2022 Maxime Schmitt + * + * This file is part of Nvtop. + * + * Nvtop is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Nvtop is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with nvtop. If not, see . + * + */ + +#include + +extern "C" { +#include "nvtop/interface_layout_selection.h" +} + +TEST(InterfaceLayour, LayoutSelection_issue_147) { + plot_info_to_draw to_draw_default = plot_default_draw_info(); + unsigned nGpu = 8; + plot_info_to_draw plot_display[8]; + for (unsigned i = 0; i < nGpu; ++i) + plot_display[i] = to_draw_default; + process_field_displayed proc_display = process_default_displayed_field(); + struct window_position dev_positions[8]; + struct window_position plot_positions[MAX_CHARTS]; + unsigned num_plots = 0; + unsigned map_dev_to_plot[8]; + struct window_position process_position; + struct window_position setup_position; + compute_sizes_from_layout(8, 3, 78, 26, 189, plot_display, proc_display, dev_positions, &num_plots, plot_positions, + map_dev_to_plot, &process_position, &setup_position); +}