diff --git a/src/Makefile.am b/src/Makefile.am index 4b452022..cdba7431 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,7 +47,8 @@ fairness_libweighted_tree_la_CXXFLAGS = \ TESTS = \ weighted_tree_test01.t \ data_reader_db_test01.t \ - data_writer_db_test01.t + data_writer_db_test01.t \ + accounting_test01.t check_PROGRAMS = $(TESTS) TEST_EXTENSIONS = .t @@ -94,6 +95,14 @@ data_writer_db_test01_t_LDADD = \ fairness/libweighted_tree.la \ common/libtap/libtap.la +accounting_test01_t_SOURCES = \ + plugins/test/accounting_test01.cpp \ + plugins/accounting.cpp \ + plugins/accounting.hpp +accounting_test01_t_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir) +accounting_test01_t_LDADD = \ + common/libtap/libtap.la + noinst_PROGRAMS = \ cmd/flux-account-update-fshare \ cmd/flux-account-shares diff --git a/src/plugins/test/accounting_test01.cpp b/src/plugins/test/accounting_test01.cpp new file mode 100644 index 00000000..650a69ff --- /dev/null +++ b/src/plugins/test/accounting_test01.cpp @@ -0,0 +1,100 @@ +/************************************************************\ + * Copyright 2024 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +extern "C" { +#if HAVE_CONFIG_H +#include "config.h" +#endif +} + +#include +#include +#include +#include +#include + +#include "src/plugins/accounting.hpp" +#include "src/common/libtap/tap.h" + +// define a test users map to run tests on +std::map> users; +std::map users_def_bank; + + +/* + * helper function to add a user/bank to the users map + */ +void add_user_to_map ( + std::map> &users, + int userid, + const std::string& bank, + Association a) +{ + // insert user to users map + users[userid][bank] = { + a.bank_name, + a.fairshare, + a.max_run_jobs, + a.cur_run_jobs, + a.max_active_jobs, + a.cur_active_jobs, + a.held_jobs, + a.queues, + a.queue_factor, + a.active + }; +} + + +/* + * helper function to add test users to the users map + */ +void initialize_map ( + std::map> &users) +{ + Association user1 = {"bank_A", 0.5, 5, 0, 7, 0, {}, {}, 0, 1}; + Association user2 = {"bank_A", 0.5, 5, 0, 7, 0, {}, {}, 0, 1}; + + add_user_to_map (users, 1001, "bank_A", user1); + users_def_bank[1001] = "bank_A"; + + // purposely do not add user2 to the def_bank_map + add_user_to_map (users, 1002, "bank_A", user2); +} + + +// ensure we can access a user/bank in the users map +static void test_direct_map_access ( + std::map> &users) +{ + ok (users[1001]["bank_A"].bank_name == "bank_A", + "a user/bank from users map can be accessed directly"); +} + + +int main (int argc, char* argv[]) +{ + // declare the number of tests that we plan to run + plan (1); + + // add users to the test map + initialize_map (users); + + test_direct_map_access (users); + + // indicate we are done testing + done_testing (); + + return EXIT_SUCCESS; +} + +/* + * vi:tabstop=4 shiftwidth=4 expandtab + */