Skip to content

Commit

Permalink
initial commit for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yczhang-nv committed Sep 25, 2024
1 parent 52ccfbe commit 83c5b35
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ class MonitorController
{
public:
MonitorController(const std::string& description,
std::optional<std::function<int(MessageT)>> determin_count_fn = std::nullopt);
std::optional<std::function<int(MessageT)>> determine_count_fn = std::nullopt);

private:
MessageT progress_sink(MessageT msg);
auto auto_count_fn(MessageT msg) -> std::optional<std::function<int(MessageT)>>;

MessageT progress_sink(MessageT msg);
void sink_on_completed();

private:
const std::string& m_description;
size_t m_count;

indicators::ProgressBar m_progress_bar;

std::optional<std::function<int(MessageT)>> m_determine_count_fn;

indicators::ProgressBar m_progress_bar;
static indicators::DynamicProgress<indicators::ProgressBar> m_progress_bars;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ namespace morpheus {

template <typename MessageT>
MonitorController<MessageT>::MonitorController(const std::string& description,
std::optional<std::function<int(MessageT)>> determin_count_fn) :
std::optional<std::function<int(MessageT)>> determine_count_fn) :
m_description(description),
m_determine_count_fn(determin_count_fn),
m_determine_count_fn(determine_count_fn),
m_count(0)
{
m_progress_bar.set_option(indicators::option::BarWidth{50});
Expand Down
6 changes: 6 additions & 0 deletions python/morpheus/morpheus/_lib/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ add_morpheus_test(
test_multi_slices.cpp
)

add_morpheus_test(
NAME controllers
FILES
controllers/test_monitor_controller.cpp
)

add_morpheus_test(
NAME stages
FILES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "../test_utils/common.hpp" // for get_morpheus_root, TEST_CLASS_WITH_PYTHON, morpheus

#include "morpheus/controllers/monitor_controller.hpp" // for MonitorController

#include <cudf/column/column.hpp>
#include <cudf/column/column_factories.hpp>
#include <cudf/column/column_view.hpp>
#include <cudf/filling.hpp>
#include <cudf/scalar/scalar.hpp>
#include <cudf/table/table.hpp>
#include <cudf/types.hpp>
#include <gtest/gtest.h>
#include <rmm/device_buffer.hpp>
#include <rmm/device_uvector.hpp>

#include <memory>
#include <numeric>
#include <vector>

using namespace morpheus;

TEST_CLASS(MonitorController);

std::unique_ptr<cudf::table> create_cudf_table(int rows, int cols)
{
std::vector<std::unique_ptr<cudf::column>> columns;

for (int i = 0; i < cols; ++i)
{
// Create a numeric column of type INT32 with 'rows' elements
auto col = cudf::make_numeric_column(cudf::data_type{cudf::type_id::INT32}, rows);
auto col_view = col->mutable_view();

// Fill the column with range [0, rows - 1]
std::vector<int32_t> data(rows);
std::iota(data.begin(), data.end(), 0);
cudaMemcpy(col_view.data<int32_t>(), data.data(), data.size() * sizeof(int32_t), cudaMemcpyHostToDevice);

// Add the column to the vector
columns.push_back(std::move(col));
}

// Create and return the table
return std::make_unique<cudf::table>(std::move(columns));
}

TEST_F(TestMonitorController, TestAutoCountFn)
{
auto mc_1 = MonitorController<cudf::table>("mc_1 progress_bar");
}

0 comments on commit 83c5b35

Please sign in to comment.