Skip to content

Commit 512163f

Browse files
committed
Integration tests: Pass config to OIL tests on the command line
Instead of using an environment variable, pass the path to the config file as a command line argument. This makes it possible to directly copy the command being run (as show with --verbose) and run it in a debugger outside of the test framework. Old verbose output: Running: /home/ajor/src/object-introspection3/build/test/integration/integration_test_target oil cycles_unique_ptr New verbose output: Running: /home/ajor/src/object-introspection3/build/test/integration/integration_test_target oil cycles_unique_ptr /home/ajor/src/object-introspection3/build/testing.oid.toml
1 parent 56f7147 commit 512163f

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

test/integration/gen_tests.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def define_traceable_func(name, params, body):
131131
oil_func_body = (
132132
f"\n"
133133
f"ObjectIntrospection::options opts{{\n"
134-
f' .configFilePath = std::getenv("CONFIG_FILE_PATH"),\n'
134+
f" .configFilePath = configFile,\n"
135135
f" .debugLevel = 3,\n"
136136
f' .sourceFileDumpPath = "oil_jit_code.cpp",\n'
137137
f"}};"
@@ -160,21 +160,36 @@ def define_traceable_func(name, params, body):
160160
def add_common_code(f):
161161
f.write(
162162
"""
163+
void usage(const std::string &argv0) {
164+
std::cerr << "usage: " << argv0 << " oid CASE ITERATIONS" << std::endl;
165+
std::cerr << " " << argv0 << " oil CASE CONFIG_FILE" << std::endl;
166+
}
167+
163168
int main(int argc, char *argv[]) {
164-
if (argc < 3 || argc > 4) {
165-
std::cerr << "usage: " << argv[0] << " oid/oil CASE [ITER]" << std::endl;
169+
if (argc != 4) {
170+
usage(argv[0]);
166171
return -1;
167172
}
168173
169174
std::string mode = argv[1];
170175
std::string test_case = argv[2];
171176
172-
int iterations = 1000;
173-
if (argc == 4) {
177+
int iterations = 1;
178+
179+
if (mode == "oid") {
174180
std::istringstream iss(argv[3]);
175181
iss >> iterations;
176-
if (iss.fail())
177-
iterations = 1000;
182+
if (iss.fail()) {
183+
usage(argv[0]);
184+
return -1;
185+
}
186+
}
187+
else if (mode == "oil") {
188+
configFile = argv[3];
189+
}
190+
else {
191+
usage(argv[0]);
192+
return -1;
178193
}
179194
180195
"""
@@ -224,6 +239,7 @@ def gen_target(output_target_name, test_configs):
224239
f"thrift/annotation/gen-cpp2/{config['suite']}_types.h"
225240
]
226241
add_headers(f, sorted(headers), thrift_headers)
242+
f.write("std::string configFile;")
227243

228244
for config in test_configs:
229245
add_test_setup(f, config)
@@ -334,7 +350,7 @@ def add_oil_integration_test(f, config, case_name, case):
334350
f" ba::io_context ctx;\n"
335351
f" auto target = runOilTarget({{\n"
336352
f" .ctx = ctx,\n"
337-
f' .targetArgs = "oil {case_str} 1",\n'
353+
f' .targetArgs = "oil {case_str}",\n'
338354
f" }}, std::move(configOptions));\n\n"
339355
f" ASSERT_EQ(exit_code(target), {exit_code});\n"
340356
f"\n"

test/integration/runner_common.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ OidProc OidIntegration::runOidOnProcess(OidOpts opts,
172172
std::vector<std::string> extra_args,
173173
std::string extra_config) {
174174
// Binary paths are populated by CMake
175-
std::string targetExe = std::string(TARGET_EXE_PATH) + " " + opts.targetArgs;
175+
std::string targetExe =
176+
std::string(TARGET_EXE_PATH) + " " + opts.targetArgs + " 1000";
176177

177178
/* Spawn the target process with all IOs redirected to /dev/null to not polute
178179
* the terminal */
@@ -256,8 +257,8 @@ OidProc OidIntegration::runOidOnProcess(OidOpts opts,
256257
// clang-format off
257258
bp::child oidProcess(
258259
oidExe,
259-
bp::env["OID_METRICS_TRACE"] = "time",
260260
bp::args(oid_args),
261+
bp::env["OID_METRICS_TRACE"] = "time",
261262
bp::std_in < bp::null,
262263
bp::std_out > std_out_pipe,
263264
bp::std_err > std_err_pipe,
@@ -337,7 +338,10 @@ std::string OilIntegration::TmpDirStr() {
337338
}
338339

339340
Proc OilIntegration::runOilTarget(OidOpts opts, std::string extra_config) {
340-
std::string targetExe = std::string(TARGET_EXE_PATH) + " " + opts.targetArgs;
341+
fs::path thisConfig = createCustomConfig(extra_config);
342+
343+
std::string targetExe = std::string(TARGET_EXE_PATH) + " " + opts.targetArgs +
344+
" " + thisConfig.string();
341345

342346
if (verbose) {
343347
std::cerr << "Running: " << targetExe << std::endl;
@@ -375,8 +379,6 @@ Proc OilIntegration::runOilTarget(OidOpts opts, std::string extra_config) {
375379
// clang-format on
376380
}
377381

378-
fs::path thisConfig = createCustomConfig(extra_config);
379-
380382
/* Spawn target with tracing on and IOs redirected in custom pipes to be read
381383
* later */
382384
// clang-format off
@@ -385,7 +387,6 @@ Proc OilIntegration::runOilTarget(OidOpts opts, std::string extra_config) {
385387
bp::std_in < bp::null,
386388
bp::std_out > std_out_pipe,
387389
bp::std_err > std_err_pipe,
388-
bp::env["CONFIG_FILE_PATH"] = thisConfig.string(),
389390
opts.ctx);
390391
// clang-format on
391392

0 commit comments

Comments
 (0)