Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Remove logfile after test (#88)
Browse files Browse the repository at this point in the history
* Made the unit tests create the logfile in /tmp

* Clarified the test code
  • Loading branch information
pboothe authored Mar 28, 2017
1 parent aeaf958 commit b410a92
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/web100srv_unit_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ void make_certificate_files(char *private_key_file, char *certificate_file) {
CHECK(system(create_certificate_command_line) == 0);
}


#define LOGFILE_TEMPLATE "/tmp/web100srv.log-XXXXXX"

/** Starts the web100srv process. Either args must be NULL or the last element
* of **args must be NULL. */
pid_t start_server(int port, char **extra_args) {
Expand All @@ -66,10 +69,17 @@ pid_t start_server(int port, char **extra_args) {
siginfo_t server_status;
char port_string[6]; // 32767 is the max port, so must hold 5 digits + \0
int rv;
char *args_for_exec[256] = {"./web100srv", "--snaplog", "--tcpdump", "--cputime", "--log_dir", "/tmp", "--port", NULL};
char *args_for_exec[256] = {"./web100srv", "--snaplog", "--tcpdump",
"--cputime", "--log_dir", "/tmp", "-l", LOGFILE_TEMPLATE, "--port", NULL};
int exec_args_index = 0;
// Should be set to the first index of args_for_exec that is NULL
while (args_for_exec[exec_args_index] != NULL) exec_args_index++;
// set exec_args_index to the first index of args_for_exec that is NULL
while (args_for_exec[exec_args_index] != NULL) {
// along the way, fill in the template for the test logs
if (strcmp(args_for_exec[exec_args_index], LOGFILE_TEMPLATE) == 0) {
mkstemp(args_for_exec[exec_args_index]);
}
exec_args_index++;
}
log_println(1, "Starting the server");
if ((server_pid = fork()) == 0) {
sprintf(port_string, "%d", port);
Expand Down

0 comments on commit b410a92

Please sign in to comment.