Skip to content

Commit

Permalink
(#1006) Extend attach test with execv and execve
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbiesek committed Jul 5, 2022
1 parent 2498d1d commit b7402cf
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
6 changes: 6 additions & 0 deletions test/integration/attach/Dockerfile.glibc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ RUN apt update \
&& apt install -y \
curl \
emacs \
gcc \
gdb \
lsof \
openjdk-13-jdk-headless \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*

# Tests
Expand All @@ -18,6 +20,10 @@ RUN mkdir -p /opt/java_http
COPY ./java/SimpleHttpServer.java /opt/java_http/SimpleHttpServer.java
RUN javac -d /opt/java_http/ /opt/java_http/SimpleHttpServer.java

RUN mkdir -p /opt/exec_test
COPY ./attach/hello_exec.c /opt/exec_test/hello_exec.c
RUN gcc -O0 -g -o /opt/exec_test/exec_test /opt/exec_test/hello_exec.c

ENV SCOPE_CRIBL_ENABLE=false
ENV SCOPE_LOG_LEVEL=error
ENV SCOPE_METRIC_VERBOSITY=4
Expand Down
6 changes: 5 additions & 1 deletion test/integration/attach/Dockerfile.musl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:latest

RUN apk add bash curl gdb openjdk11 python3
RUN apk add bash curl gcc gdb musl-dev openjdk11 python3 wget

# Tests
COPY ./attach/test_attach.sh /opt/test/bin/test_attach.sh
Expand All @@ -9,6 +9,10 @@ RUN mkdir -p /opt/java_http
COPY ./java/SimpleHttpServer.java /opt/java_http/SimpleHttpServer.java
RUN javac -d /opt/java_http/ /opt/java_http/SimpleHttpServer.java

RUN mkdir -p /opt/exec_test
COPY ./attach/hello_exec.c /opt/exec_test/hello_exec.c
RUN gcc -O0 -g -o /opt/exec_test/exec_test /opt/exec_test/hello_exec.c

ENV SCOPE_CRIBL_ENABLE=false
ENV SCOPE_LOG_LEVEL=debug
ENV SCOPE_METRIC_VERBOSITY=4
Expand Down
47 changes: 47 additions & 0 deletions test/integration/attach/hello_exec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>

#define EXECVE_VAR 0
#define EXECV_VAR 1
#define ATTACH_TIME 10

extern char **environ;

int main(int argc, char *argv[]) {
int res;
if (argc != 2) {
return EXIT_FAILURE;
}
int sleep_time = 0;
// provide a time to attach
while(sleep_time < ATTACH_TIME) {
sleep(1);
sleep_time++;
fprintf(stderr, "Waiting to attach %d sec.\n", sleep_time);
}
int variant = atoi(argv[1]);

res = fork();
if (res < 0) {
return EXIT_FAILURE;
} else if (res == 0) {
switch (variant) {
case EXECVE_VAR: {
char* args[] = {"/usr/bin/curl", "-I", "https://cribl.io", NULL};
return execve("/usr/bin/curl", args, environ);
}
case EXECV_VAR: {
char* args[] = {"/usr/bin/wget", "-S", "--spider", "--no-check-certificate", "https://cribl.io", NULL};
return execv("/usr/bin/wget", args);
}
}
} else {
wait(&res);
return EXIT_SUCCESS;
}

return EXIT_FAILURE;
}
44 changes: 44 additions & 0 deletions test/integration/attach/test_attach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ grep -q http.resp $EVT_FILE > /dev/null
ERR+=$?

kill -9 `pidof python3` > /dev/null

endtest

#
Expand Down Expand Up @@ -122,8 +123,51 @@ ERR+=$?

kill -9 `pidof java`

sleep 1

endtest

#
# attach execve_test
#

starttest execve_test

cd /opt/exec_test/
./exec_test 0 &
EXEC_TEST_PID=`pidof exec_test`

ldscope --attach ${EXEC_TEST_PID}
ERR+=$?

wait ${EXEC_TEST_PID}

egrep '"cmd":"/usr/bin/curl -I https://cribl.io"' $EVT_FILE > /dev/null
ERR+=$?

endtest

#
# attach execv_test
#

starttest execv_test

cd /opt/exec_test/
./exec_test 1 &
EXEC_TEST_PID=`pidof exec_test`

ldscope --attach ${EXEC_TEST_PID}
ERR+=$?

wait ${EXEC_TEST_PID}

egrep '"cmd":"/usr/bin/wget -S --spider --no-check-certificate https://cribl.io"' $EVT_FILE > /dev/null
ERR+=$?

endtest


if (( $FAILED_TEST_COUNT == 0 )); then
echo ""
echo ""
Expand Down

0 comments on commit b7402cf

Please sign in to comment.