Skip to content

Add tests for processes and endpoints integration test suite #1340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration-tests/container/QA_TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
2.1.0-jv
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
FROM ubuntu:jammy

COPY process-listening-on-ports.c /process-listening-on-ports.c
COPY change-process-name.c /change-process-name.c
COPY change-executable-file-path.c /change-executable-file-path.c
COPY listening-endpoint-child-process.c /listening-endpoint-child-process.c
COPY listening-endpoint-child-process-no-exec.c /listening-endpoint-child-process-no-exec.c
COPY listening-endpoint-child-process-no-fork.c /listening-endpoint-child-process-no-fork.c
COPY so_reuseport.py /so_reuseport.py
COPY so_reuseport.sh /so_reuseport.sh

RUN apt update -y && apt install gcc lsof -y
RUN apt update -y && apt install gcc lsof net-tools python3 -y
RUN gcc process-listening-on-ports.c -o process-listening-on-ports
RUN gcc change-process-name.c -o change-process-name
RUN gcc change-executable-file-path.c -o change-executable-file-path
RUN gcc listening-endpoint-child-process.c -o listening-endpoint-child-process
RUN gcc listening-endpoint-child-process-no-exec.c -o listening-endpoint-child-process-no-exec
RUN gcc listening-endpoint-child-process-no-fork.c -o listening-endpoint-child-process-no-fork

RUN ln -s /process-listening-on-ports plop

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <netinet/in.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/types.h>

int main(int argc, char* argv[]) {
int sockfd;

sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}

// Bind the socket to a port
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8082);
server_addr.sin_addr.s_addr = INADDR_ANY;

if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
perror("Binding failed");
close(sockfd);
exit(EXIT_FAILURE);
}

// Listen for incoming connections
if (listen(sockfd, 5) == -1) {
perror("Listening failed");
close(sockfd);
exit(EXIT_FAILURE);
}

printf("Listening on port 8082...\n");

sleep(10);

// Change the process name
argv[0][0] = 'a';

printf("Process name changed to: %s\n", argv[0]);

sleep(10000);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <netinet/in.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/types.h>

int main(int argc, char* argv[]) {
int sockfd;

sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}

// Bind the socket to a port
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8082);
server_addr.sin_addr.s_addr = INADDR_ANY;

if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
perror("Binding failed");
close(sockfd);
exit(EXIT_FAILURE);
}

// Listen for incoming connections
if (listen(sockfd, 5) == -1) {
perror("Listening failed");
close(sockfd);
exit(EXIT_FAILURE);
}

printf("Listening on port 8082...\n");

sleep(10);

char newName[] = "NewProcessName";

// Change the process name
if (prctl(PR_SET_NAME, newName) == 0) {
printf("Process name changed to: %s\n", newName);
} else {
perror("prctl");
return 1;
}

sleep(10000);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>

int main(int argc, char* argv[]) {
int sockfd;

// Create a socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}

// Bind the socket to a port
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8082);
server_addr.sin_addr.s_addr = INADDR_ANY;

if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
perror("Binding failed");
close(sockfd);
exit(EXIT_FAILURE);
}

// Listen for incoming connections
if (listen(sockfd, 5) == -1) {
perror("Listening failed");
close(sockfd);
exit(EXIT_FAILURE);
}

printf("Listening on port 8082...\n");

// Create a child process
pid_t child_pid = fork();
if (child_pid == -1) {
perror("Fork failed");
close(sockfd);
exit(EXIT_FAILURE);
}

sleep(10000);
close(sockfd);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>

int main(int argc, char* argv[]) {
int sockfd;
int sleep_before_child;
bool is_parent = true;

sleep_before_child = atoi(argv[1]);

// Check if sockfd is provided as a command line argument
if (argc == 3) {
sockfd = atoi(argv[2]);
is_parent = false;
} else {
// Create a socket if sockfd is not provided as an argument
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}

// Bind the socket to a port
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8082);
server_addr.sin_addr.s_addr = INADDR_ANY;

if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
perror("Binding failed");
close(sockfd);
exit(EXIT_FAILURE);
}
}

// Listen for incoming connections
if (listen(sockfd, 5) == -1) {
perror("Listening failed");
close(sockfd);
exit(EXIT_FAILURE);
}

printf("Listening on port 8082...\n");

sleep(sleep_before_child);

if (is_parent) {
// Pass the socket file descriptor to the child
char sockfd_str[32];
snprintf(sockfd_str, sizeof(sockfd_str), "%d", sockfd);
char sleep_before_child_str[32];
sprintf(sleep_before_child_str, "%d", sleep_before_child);
char* const child_args[] = {"listening-endpoint-child-process-no-fork", sleep_before_child_str, sockfd_str, NULL};

// Replace the child process with a new program
if (execve("./listening-endpoint-child-process-no-fork", child_args, NULL) == -1) {
perror("Execve failed");
close(sockfd);
exit(EXIT_FAILURE);
}

sleep(10000);

// Close the socket in the parent process
close(sockfd);
}

sleep(10000);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>

int main(int argc, char* argv[]) {
int sockfd;
bool is_parent = true;

// Check if sockfd is provided as a command line argument
if (argc == 2) {
sockfd = atoi(argv[1]);
is_parent = false;
} else {
// Create a socket if sockfd is not provided as an argument
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}

// Bind the socket to a port
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8082);
server_addr.sin_addr.s_addr = INADDR_ANY;

if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
perror("Binding failed");
close(sockfd);
exit(EXIT_FAILURE);
}
}

// Listen for incoming connections
if (listen(sockfd, 5) == -1) {
perror("Listening failed");
close(sockfd);
exit(EXIT_FAILURE);
}

printf("Listening on port 8082...\n");

if (is_parent) {
// Create a child process
pid_t child_pid = fork();
if (child_pid == -1) {
perror("Fork failed");
close(sockfd);
exit(EXIT_FAILURE);
}

if (child_pid == 0) {
// This is the child process

// Pass the socket file descriptor to the child
char sockfd_str[32];
snprintf(sockfd_str, sizeof(sockfd_str), "%d", sockfd);
char* const child_args[] = {"listening-endpoint-child-process", sockfd_str, NULL};

// Replace the child process with a new program
if (execve("./listening-endpoint-child-process", child_args, NULL) == -1) {
perror("Execve failed");
close(sockfd);
exit(EXIT_FAILURE);
}
} else {
sleep(10000);

// Close the socket in the parent process
close(sockfd);
}
}

sleep(10000);

return 0;
}
1 change: 1 addition & 0 deletions integration-tests/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ qa:
qa-schedule-curls: quay.io/rhacs-eng/qa-multi-arch:collector-schedule-curls
qa-alpine-curl: quay.io/rhacs-eng/qa-multi-arch:alpine-curl
qa-perf-event-open: quay.io/rhacs-eng/qa-multi-arch:collector-perf-event-open
qa-change-process-name: quay.io/rhacs-eng/qa-multi-arch:collector-change-process-name

non_qa:
nginx: nginx:1.14-alpine
Loading