Skip to content

Commit

Permalink
Use capture and strace-log-watch in the test-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Nov 1, 2022
1 parent a7015ee commit 5bf06e8
Show file tree
Hide file tree
Showing 5 changed files with 738 additions and 54 deletions.
1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib
capture
strace-log-watch
8 changes: 5 additions & 3 deletions tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
CC = gcc

CFLAGS = -Wall -Werror -O2
LDFLAGS =
LOG_LEVEL ?= WARN
EXTRA_CFLAGS ?= -DLOG_LEVEL=LOG_$(LOG_LEVEL)
EXTRA_LDFLAGS ?=

.PHONY: all
all: bpf lib capture
all: bpf lib capture strace-log-watch

.PHONY: bpf
bpf:
Expand All @@ -14,10 +16,10 @@ bpf:
lib: lib.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -o "$@" "$<" $(LDFLAGS) -ldl $(EXTRA_LDFLAGS)

capture: capture.c
%: %.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -o "$@" "$<" $(LDFLAGS) $(EXTRA_LDFLAGS)

.PHONY: clean
clean:
rm -f lib capture
rm -f lib capture strace-log-watch
$(MAKE) -C bpf clean
31 changes: 30 additions & 1 deletion tools/capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ struct options {
const char* stdout_fn;
int silence_stderr;
const char* stderr_fn;

const char* returncode_fn;
};

static void print_usage(int fd, const char* prog)
Expand All @@ -22,6 +24,7 @@ static void print_usage(int fd, const char* prog)
dprintf(fd, " -o FILE write stdout to FILE\n");
dprintf(fd, " -E do not output stderr\n");
dprintf(fd, " -e FILE write stderr to FILE\n");
dprintf(fd, " -r FILE write returncode to FILE (-SIG if signaled)\n");
dprintf(fd, " -h print this message\n");
}

Expand All @@ -33,7 +36,7 @@ static int parse_options(struct options* o, int argc, char* argv[])
o->stderr_fn = "/dev/null";

int res;
while((res = getopt(argc, argv, "Oo:Ee:h-")) != -1) {
while((res = getopt(argc, argv, "Oo:Ee:r:h-")) != -1) {
switch(res) {
case 'O':
o->silence_stdout = 1;
Expand All @@ -49,6 +52,10 @@ static int parse_options(struct options* o, int argc, char* argv[])
o->stderr_fn = strdup(optarg);
CHECK_NOT(o->stderr_fn, NULL, "strdup(%s)", optarg);
break;
case 'r':
o->returncode_fn = strdup(optarg);
CHECK_NOT(o->returncode_fn, NULL, "strdup(%s)", optarg);
break;
case '-':
goto opt_end;
case 'h':
Expand Down Expand Up @@ -257,5 +264,27 @@ int main(int argc, char* argv[])
}

info("child returncode: %d", state.returncode);

if(o.returncode_fn) {
debug("writing returncode to: %s", o.returncode_fn);
int fd = open(o.returncode_fn, O_WRONLY|O_EXCL|O_CREAT);
CHECK(fd, "open(%s)", o.returncode_fn);

char buf[48];
ssize_t s = snprintf(LIT(buf), "%d", state.returncode);
if(s >= sizeof(buf)) {
failwith("buffer too small");
}

size_t i = 0;
while(i != s) {
int r = write(fd, &buf[i], s-i);
CHECK(r, "write(%s)", o.returncode_fn);
i += r;
}

int r = close(fd); CHECK(r, "close");
}

return state.returncode != 0;
}
Loading

0 comments on commit 5bf06e8

Please sign in to comment.