Skip to content

Commit 1543694

Browse files
committed
debugging with github
1 parent 2f5172a commit 1543694

7 files changed

Lines changed: 65 additions & 16 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030

3131
- name: Test
3232
working-directory: ${{github.workspace}}/build
33-
run: ctest -C ${{matrix.build_type}} --output-on-failure
33+
run: ctest -C ${{matrix.build_type}} --output-on-failure -V

src/cpp/subprocess/ProcessBuilder.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "shell_utils.hpp"
2323
#include "utf8_to_utf16.hpp"
2424

25+
#define HERE(format, ...) \
26+
printf("[%s:%d] " format "\n", __FILE__, __LINE__, ##__VA_ARGS__)
2527

2628
using std::nullptr_t;
2729

@@ -206,7 +208,7 @@ namespace subprocess {
206208
}
207209
void Popen::init(CommandLine& command, RunOptions& options) {
208210
ProcessBuilder builder;
209-
211+
HERE("initializing builder");
210212
builder.cin_option = get_pipe_option(options.cin);
211213
builder.cout_option = get_pipe_option(options.cout);
212214
builder.cerr_option = get_pipe_option(options.cerr);
@@ -230,19 +232,22 @@ namespace subprocess {
230232
builder.new_process_group = options.new_process_group;
231233
builder.env = options.env;
232234
builder.cwd = options.cwd;
233-
235+
HERE("running builder");
234236
*this = builder.run_command(command);
235237

238+
HERE("setting up redirects");
236239
cin_thread = setup_redirect_stream(options.cin, cin);
237240
cout_thread = setup_redirect_stream(cout, options.cout);
238241
cerr_thread = setup_redirect_stream(cerr, options.cerr);
242+
HERE("closing unused pipes");
239243
// the background thread will take ownership and auto close the pipe
240244
if (cin_thread.joinable())
241245
cin = kBadPipeValue;
242246
if (cout_thread.joinable())
243247
cout = kBadPipeValue;
244248
if (cerr_thread.joinable())
245249
cerr = kBadPipeValue;
250+
HERE("done start");
246251
}
247252

248253
Popen::Popen(Popen&& other) {
@@ -586,10 +591,13 @@ namespace subprocess {
586591
}
587592

588593
CompletedProcess run(CommandLine command, RunOptions options) {
594+
HERE("starting command");
589595
Popen popen(command, std::move(options));
596+
HERE("it started");
590597
CompletedProcess completed;
591598
std::thread cout_thread;
592599
std::thread cerr_thread;
600+
HERE("starting threads\n");
593601
if (popen.cout != kBadPipeValue) {
594602
cout_thread = std::thread([&]() {
595603
try {
@@ -611,6 +619,7 @@ namespace subprocess {
611619
});
612620
}
613621

622+
HERE("joining threads");
614623
if (cout_thread.joinable()) {
615624
cout_thread.join();
616625
}
@@ -619,26 +628,33 @@ namespace subprocess {
619628
}
620629

621630
try {
631+
HERE("waiting for timeout");
622632
popen.wait(options.timeout);
623633
} catch (subprocess::TimeoutExpired& expired) {
634+
HERE("caught signal");
624635
popen.send_signal(subprocess::SigNum::PSIGTERM);
625636
/* python source code sends SIGKILL, we'll be a bit more nice.
626637
give it a bit of time to terminate. This is more practical.
627638
*/
628639
try {
640+
HERE("graceful wait");
629641
popen.wait(1.0/20.0);
630642
} catch (subprocess::TimeoutExpired& expired) {
643+
HERE("dirty kill");
631644
popen.kill();
632645
}
646+
HERE("final wait");
633647
popen.wait();
634648
subprocess::TimeoutExpired timeout("subprocess::run timeout reached");
635649
timeout.cmd = command;
636650
timeout.timeout = options.timeout;
637651
timeout.cout = std::move(completed.cout);
638652
timeout.cerr = std::move(completed.cerr);
653+
HERE("second throw");
639654
throw timeout;
640655
}
641656

657+
HERE("all good");
642658
completed.returncode = popen.returncode;
643659
completed.args = command;
644660
if (options.check && completed.returncode != 0) {
@@ -647,6 +663,7 @@ namespace subprocess {
647663
error.returncode = completed.returncode;
648664
error.cout = std::move(completed.cout);
649665
error.cerr = std::move(completed.cerr);
666+
HERE("check bad");
650667
throw error;
651668
}
652669
return completed;

test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ function(cxx_test source)
4747
# this is only a gcc option
4848
#set_target_properties(${target} PROPERTIES COMPILE_FLAGS "-Wno-effc++")
4949
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND MINGW)
50-
add_test(NAME ${target} COMMAND wine ${RUNTIME_OUTPUT_DIRECTORY}/${target}.exe)
50+
add_test(NAME ${target} COMMAND wine ${RUNTIME_OUTPUT_DIRECTORY}/${target}.exe -v)
5151
else()
52-
add_test(NAME ${target} COMMAND ${RUNTIME_OUTPUT_DIRECTORY}/${target})
52+
add_test(NAME ${target} COMMAND ${RUNTIME_OUTPUT_DIRECTORY}/${target} -v)
5353
endif()
5454
#add_custom_command(TARGET test_all
5555
# COMMAND $<TARGET_FILE:${target}>

test/basic_test.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ using subprocess::CompletedProcess;
1212
using subprocess::PipeOption;
1313
using subprocess::RunBuilder;
1414

15-
#ifdef _WIN32
16-
#define EOL "\r\n"
15+
// github CI on windows uses LF
16+
#if defined(_WIN32) && !defined(EOL_IS_LF)
17+
#define EOL "\n"
1718
#else
1819
#define EOL "\n"
1920
#endif
@@ -113,7 +114,7 @@ class BasicSuite : public CxxTest::TestSuite {
113114
text.resize(32);
114115
double start = subprocess::monotonic_seconds();
115116

116-
ssize_t transferred = subprocess::pipe_read_some(
117+
subprocess::ssize_t transferred = subprocess::pipe_read_some(
117118
pipe.input, text.data(), text.size()
118119
);
119120

@@ -302,45 +303,61 @@ class BasicSuite : public CxxTest::TestSuite {
302303
++count;
303304
TS_TRACE("poll did " + std::to_string(count) + " iterations");
304305
TS_ASSERT(count > 100);
305-
306+
TS_TRACE("HERE");
306307
popen.close();
307-
308+
TS_TRACE("HERE");
308309
double timeout = timer.seconds();
310+
printf("timeout is %f\n", timeout);
309311
TS_ASSERT_DELTA(timeout, 3, 0.5);
312+
TS_TRACE("HERE");
310313
}
311314

312315
void testRunTimeout() {
316+
TS_TRACE("HERE");
313317
subprocess::EnvGuard guard;
314318
prepend_this_to_path();
315319
subprocess::StopWatch timer;
316320
bool didThrow = false;
321+
TS_TRACE("HERE");
317322
try {
323+
TS_TRACE("HERE");
318324
auto completedProcess = subprocess::run({"sleep", "3"}, {.timeout = 1});
325+
TS_TRACE("HERE");
319326
} catch (subprocess::TimeoutExpired& error) {
320327
didThrow = true;
328+
TS_TRACE("HERE");
329+
} catch (std::exception& error) {
330+
TS_TRACE("HERE");
331+
printf("OMG: %s\n", error.what());
332+
} catch (...) {
333+
TS_TRACE("catch all here :O");
321334
}
335+
TS_TRACE("HERE");
322336
double timeout = timer.seconds();
323337
TS_ASSERT_EQUALS(didThrow, true);
324338
TS_ASSERT_DELTA(timeout, 1, 0.5);
339+
TS_TRACE("HERE");
325340
}
326341

327342
void testWaitTimeout() {
343+
TS_TRACE("HERE");
328344
subprocess::EnvGuard guard;
329345
prepend_this_to_path();
330346
auto popen = RunBuilder({"sleep", "10"}).new_process_group(true).popen();
331347
subprocess::StopWatch timer;
332-
348+
TS_TRACE("HERE");
333349
TS_ASSERT_THROWS(popen.wait(3), subprocess::TimeoutExpired)
334350

335351
popen.terminate();
336352
popen.close();
337-
353+
TS_TRACE("HERE");
338354
double timeout = timer.seconds();
339355
TS_ASSERT_DELTA(timeout, 3, 0.5);
340356

341357
}
342358

343359
void test2ProcessConnect() {
360+
TS_TRACE("HERE");
344361
subprocess::EnvGuard guard;
345362
prepend_this_to_path();
346363

@@ -502,7 +519,7 @@ class BasicSuite : public CxxTest::TestSuite {
502519
TS_ASSERT_DIFFERS(handle, subprocess::kBadPipeValue);
503520
std::vector<char> data;
504521
data.resize(1024);
505-
ssize_t transferred = subprocess::pipe_read(handle, data.data(), data.size());
522+
subprocess::ssize_t transferred = subprocess::pipe_read(handle, data.data(), data.size());
506523
TS_ASSERT_EQUALS(transferred, str.size());
507524
std::string str2 = data.data();
508525
TS_ASSERT_EQUALS(str, str2);

test/cat_child.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <string>
44
#ifdef _WIN32
55
#include <io.h>
6-
//const auto& read = _read;
6+
#include <fcntl.h>
77
#else
88
#include <unistd.h>
99
#endif
@@ -25,6 +25,10 @@ enum ExitCode {
2525
};
2626
int main(int argc, char** argv) {
2727
std::vector<std::string> args;
28+
#ifdef _WIN32
29+
setmode(fileno(stdout), O_BINARY);
30+
setmode(fileno(stderr), O_BINARY);
31+
#endif
2832
for (int i = 1; i < argc; ++i)
2933
args.push_back(argv[i]);
3034

test/echo_main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <subprocess.hpp>
44

55
#ifdef _WIN32
6-
#include <io.h>
7-
#include <fcntl.h>
6+
#include <io.h>
7+
#include <fcntl.h>
88
#endif
99

1010
// no echo on windows, so we make this to help test the library
@@ -15,7 +15,10 @@ int main(int argc, char** argv) {
1515
if (binary.size() > 0 && binary != "0" && binary != "false") {
1616
setmode(fileno(stdout), O_BINARY);
1717
}
18+
setmode(fileno(stdout), O_BINARY);
19+
setmode(fileno(stderr), O_BINARY);
1820
#endif
21+
1922
std::string use_cerr_str = subprocess::cenv["USE_CERR"];
2023
bool use_cerr = use_cerr_str == "1";
2124
auto output_file = use_cerr? stderr : stdout;

test/printenv_main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#include <iostream>
22
#include <subprocess.hpp>
33

4+
#ifdef _WIN32
5+
#include <io.h>
6+
#include <fcntl.h>
7+
#endif
8+
49
// no echo on windows, so we make this to help test the library
510
int main(int argc, char** argv) {
11+
#ifdef _WIN32
12+
setmode(fileno(stdout), O_BINARY);
13+
#endif
614
if (argc != 2) {
715
std::cout << "printenv <var-name>\n Will print out contents of that variable\n";
816
std::cout << " Returns failure code if variable was not found.\n";

0 commit comments

Comments
 (0)