Skip to content

Commit 0b51ab9

Browse files
committed
reapi unit test: add shrink
1 parent 08255dd commit 0b51ab9

File tree

2 files changed

+135
-11
lines changed

2 files changed

+135
-11
lines changed

resource/reapi/test/reapi_cli_test_c.cpp

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define CATCH_CONFIG_MAIN
1+
#define CATCH_CONFIG_MAIN
22

33
#include <catch2/catch_test_macros.hpp>
44
#include <resource/reapi/bindings/c/reapi_cli.h>
@@ -7,7 +7,8 @@
77

88
namespace Flux::resource_model::detail {
99

10-
TEST_CASE( "Initialize REAPI CLI", "[initialize C]" ) {
10+
TEST_CASE ("Initialize REAPI CLI", "[initialize C]")
11+
{
1112
const std::string options = "{}";
1213
std::stringstream buffer;
1314
std::ifstream inputFile ("../../../t/data/resource/jgfs/tiny.json");
@@ -24,7 +25,8 @@ TEST_CASE( "Initialize REAPI CLI", "[initialize C]" ) {
2425
REQUIRE (ctx);
2526
}
2627

27-
TEST_CASE( "Match basic jobspec", "[match C]" ) {
28+
TEST_CASE ("Match basic jobspec", "[match C]")
29+
{
2830
int rc = -1;
2931
const std::string options = "{}";
3032
std::stringstream gbuffer, jbuffer;
@@ -58,14 +60,65 @@ TEST_CASE( "Match basic jobspec", "[match C]" ) {
5860
uint64_t jobid = 1;
5961
double ov = 0.0;
6062
int64_t at = 0;
61-
63+
6264
rc = reapi_cli_match (ctx, match_op, jobspec.c_str (), &jobid, &reserved, &R, &at, &ov);
6365
REQUIRE (rc == 0);
6466
REQUIRE (reserved == false);
6567
REQUIRE (at == 0);
6668
}
6769

68-
}
70+
TEST_CASE ("Match shrink basic jobspec", "[match shrink C]")
71+
{
72+
int rc = -1;
73+
const std::string options = "{\"load_format\": \"rv1exec\"}";
74+
std::stringstream gbuffer, jbuffer, cbuffer;
75+
std::ifstream graphfile ("../../../t/data/resource/rv1exec/tiny_rv1exec.json");
76+
std::ifstream jobspecfile ("../../../t/data/resource/jobspecs/cancel/test018.yaml");
77+
std::ifstream cancelfile ("../../../t/data/resource/rv1exec/cancel/rank1_cancel.json");
78+
79+
if (!graphfile.is_open ()) {
80+
std::cerr << "Error opening file!" << std::endl;
81+
}
82+
83+
if (!jobspecfile.is_open ()) {
84+
std::cerr << "Error opening file!" << std::endl;
85+
}
6986

87+
if (!cancelfile.is_open ()) {
88+
std::cerr << "Error opening file!" << std::endl;
89+
}
90+
91+
gbuffer << graphfile.rdbuf ();
92+
std::string rgraph = gbuffer.str ();
93+
jbuffer << jobspecfile.rdbuf ();
94+
std::string jobspec = jbuffer.str ();
95+
cbuffer << cancelfile.rdbuf ();
96+
std::string cancel_string = cbuffer.str ();
7097

98+
reapi_cli_ctx_t *ctx = nullptr;
99+
ctx = reapi_cli_new ();
100+
REQUIRE (ctx);
101+
102+
rc = reapi_cli_initialize (ctx, rgraph.c_str (), options.c_str ());
103+
REQUIRE (rc == 0);
104+
105+
match_op_t match_op = match_op_t::MATCH_ALLOCATE;
106+
bool reserved = false;
107+
char *R;
108+
uint64_t jobid = 1;
109+
double ov = 0.0;
110+
int64_t at = 0;
111+
112+
rc = reapi_cli_match (ctx, match_op, jobspec.c_str (), &jobid, &reserved, &R, &at, &ov);
113+
REQUIRE (rc == 0);
114+
REQUIRE (reserved == false);
115+
REQUIRE (at == 0);
116+
117+
bool noent_ok = false;
118+
bool full_removal = true;
119+
rc = reapi_cli_partial_cancel (ctx, jobid, cancel_string.c_str (), noent_ok, &full_removal);
120+
REQUIRE (rc == 0);
121+
REQUIRE (full_removal == false);
122+
}
71123

124+
} // namespace Flux::resource_model::detail

resource/reapi/test/reapi_cli_test_cxx.cpp

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#define CATCH_CONFIG_MAIN
1+
#define CATCH_CONFIG_MAIN
22

33
#include <catch2/catch_test_macros.hpp>
44
#include <resource/reapi/bindings/c++/reapi_cli.hpp>
55
#include <fstream>
66

77
namespace Flux::resource_model::detail {
88

9-
TEST_CASE( "Initialize REAPI CLI", "[initialize C++]" ) {
9+
TEST_CASE ("Initialize REAPI CLI", "[initialize C++]")
10+
{
1011
const std::string options = "{}";
1112
std::stringstream buffer;
1213
std::ifstream inputFile ("../../../t/data/resource/jgfs/tiny.json");
@@ -23,7 +24,8 @@ TEST_CASE( "Initialize REAPI CLI", "[initialize C++]" ) {
2324
REQUIRE (ctx);
2425
}
2526

26-
TEST_CASE( "Match basic jobspec", "[match grow C++]" ) {
27+
TEST_CASE ("Match and basic jobspec", "[match grow C++]")
28+
{
2729
int rc = -1;
2830
const std::string options = "{}";
2931
std::stringstream gbuffer, jbuffer;
@@ -55,20 +57,89 @@ TEST_CASE( "Match basic jobspec", "[match grow C++]" ) {
5557
double ov = 0.0;
5658
int64_t at = 0;
5759

58-
rc = detail::reapi_cli_t::match_allocate (ctx.get (), match_op, jobspec, jobid, reserved, R, at, ov);
60+
rc = detail::reapi_cli_t::match_allocate (ctx.get (),
61+
match_op,
62+
jobspec,
63+
jobid,
64+
reserved,
65+
R,
66+
at,
67+
ov);
5968
REQUIRE (rc == 0);
6069
REQUIRE (reserved == false);
6170
REQUIRE (at == 0);
6271

6372
R = "";
6473
match_op = match_op_t::MATCH_GROW_ALLOCATION;
65-
rc = detail::reapi_cli_t::match_allocate (ctx.get (), match_op, jobspec, jobid, reserved, R, at, ov);
74+
rc = detail::reapi_cli_t::match_allocate (ctx.get (),
75+
match_op,
76+
jobspec,
77+
jobid,
78+
reserved,
79+
R,
80+
at,
81+
ov);
6682
REQUIRE (rc == 0);
6783
REQUIRE (reserved == false);
6884
REQUIRE (at == 0);
6985
}
7086

71-
}
87+
TEST_CASE ("Match shrink basic jobspec", "[match shrink C++]")
88+
{
89+
int rc = -1;
90+
const std::string options = "{\"load_format\": \"rv1exec\"}";
91+
std::stringstream gbuffer, jbuffer, cbuffer;
92+
std::ifstream graphfile ("../../../t/data/resource/rv1exec/tiny_rv1exec.json");
93+
std::ifstream jobspecfile ("../../../t/data/resource/jobspecs/cancel/test018.yaml");
94+
std::ifstream cancelfile ("../../../t/data/resource/rv1exec/cancel/rank1_cancel.json");
95+
96+
if (!graphfile.is_open ()) {
97+
std::cerr << "Error opening file!" << std::endl;
98+
}
99+
100+
if (!jobspecfile.is_open ()) {
101+
std::cerr << "Error opening file!" << std::endl;
102+
}
103+
104+
if (!cancelfile.is_open ()) {
105+
std::cerr << "Error opening file!" << std::endl;
106+
}
107+
108+
gbuffer << graphfile.rdbuf ();
109+
std::string rgraph = gbuffer.str ();
110+
jbuffer << jobspecfile.rdbuf ();
111+
std::string jobspec = jbuffer.str ();
112+
cbuffer << cancelfile.rdbuf ();
113+
std::string cancel_string = cbuffer.str ();
72114

115+
std::shared_ptr<resource_query_t> ctx = nullptr;
116+
ctx = std::make_shared<resource_query_t> (rgraph, options);
117+
REQUIRE (ctx);
73118

119+
match_op_t match_op = match_op_t::MATCH_ALLOCATE;
120+
bool reserved = false;
121+
std::string R = "";
122+
uint64_t jobid = 1;
123+
double ov = 0.0;
124+
int64_t at = 0;
125+
126+
rc = detail::reapi_cli_t::match_allocate (ctx.get (),
127+
match_op,
128+
jobspec,
129+
jobid,
130+
reserved,
131+
R,
132+
at,
133+
ov);
134+
REQUIRE (rc == 0);
135+
REQUIRE (reserved == false);
136+
REQUIRE (at == 0);
137+
138+
bool noent_ok = false;
139+
bool full_removal = true;
140+
rc = detail::reapi_cli_t::cancel (ctx.get (), jobid, cancel_string, noent_ok, full_removal);
141+
REQUIRE (rc == 0);
142+
REQUIRE (full_removal == false);
143+
}
74144

145+
} // namespace Flux::resource_model::detail

0 commit comments

Comments
 (0)