[tests] include more information in error message

This commit is contained in:
Timothy Stack 2021-03-20 13:39:35 -07:00
parent 5d4f08b1b4
commit 4f4d90a65d
3 changed files with 24 additions and 6 deletions

View File

@ -1112,7 +1112,10 @@ void load_config(const vector<ghc::filesystem::path> &extra_paths, vector<string
auto fd = auto_fd(openp(sample_path, O_WRONLY|O_TRUNC|O_CREAT, 0644));
auto sf = bsf.to_string_fragment();
if (fd == -1 || write(fd.get(), sf.data(), sf.length()) == -1) {
perror("error: unable to write default config file");
fprintf(stderr,
"error:unable to write default config file: %s -- %s\n",
sample_path.c_str(),
strerror(errno));
}
}

View File

@ -767,7 +767,10 @@ static void write_sample_file()
O_WRONLY | O_TRUNC | O_CREAT,
0644)) == -1 ||
(write(sample_fd.get(), sf.data(), sf.length()) == -1)) {
perror("error: unable to write default format file");
fprintf(stderr,
"error:unable to write default format file: %s -- %s\n",
sample_path.c_str(),
strerror(errno));
}
}
@ -778,7 +781,10 @@ static void write_sample_file()
if ((sh_fd = openp(sh_path, O_WRONLY|O_TRUNC|O_CREAT, 0755)) == -1 ||
write(sh_fd.get(), sf.data(), sf.length()) == -1) {
perror("error: unable to write default text file");
fprintf(stderr,
"error:unable to write default text file: %s -- %s\n",
sh_path.c_str(),
strerror(errno));
}
}
@ -798,7 +804,10 @@ static void write_sample_file()
}
if ((script_fd = openp(script_path, O_WRONLY|O_TRUNC|O_CREAT, 0755)) == -1 ||
write(script_fd.get(), sf.data(), sf.length()) == -1) {
perror("error: unable to write default text file");
fprintf(stderr,
"error:unable to write default text file: %s -- %s\n",
script_path.c_str(),
strerror(errno));
}
}
}

View File

@ -982,6 +982,7 @@ int main(int argc, char *argv[])
struct timeval last, now;
fd_set read_fds;
term_machine tm(ct);
size_t last_replay_size = scripty_data.sd_replay.size();
scripty_data.sd_child_pid = ct.get_child_pid();
signal(SIGINT, sigpass);
@ -1012,6 +1013,7 @@ int main(int argc, char *argv[])
gettimeofday(&now, nullptr);
timersub(&now, &last, &diff);
if (diff.tv_sec > 10) {
fprintf(stderr, "%s:replay timed out!\n", tstamp());
scripty_data.sd_looping = false;
kill(ct.get_child_pid(), SIGKILL);
retval = EXIT_FAILURE;
@ -1054,8 +1056,9 @@ int main(int argc, char *argv[])
if (rc <= 0) {
scripty_data.sd_looping = false;
} else {
if (passout)
if (passout) {
log_perror(write(STDOUT_FILENO, buffer, rc));
}
if (scripty_data.sd_from_child != nullptr) {
for (size_t lpc = 0; lpc < rc; lpc++) {
#if 0
@ -1064,8 +1067,11 @@ int main(int argc, char *argv[])
buffer[lpc] & 0xff);
#endif
tm.new_input(buffer[lpc]);
if (!tm.tm_waiting_on_input) {
if (scripty_data.sd_replay.size() !=
last_replay_size) {
last = now;
last_replay_size =
scripty_data.sd_replay.size();
}
}
}