manual testing
Test and Deploy / test (push) Failing after 10s Details
Test and Deploy / docs (push) Has been skipped Details

This commit is contained in:
Evan Burkey 2024-07-07 20:05:32 -07:00
parent 1424925cbf
commit c52712471f
5 changed files with 43 additions and 14 deletions

View File

@ -14,15 +14,11 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y libbsd-dev cmake build-essential sudo apt-get install -y libbsd-dev build-essential
- name: Build and test - name: Build and test
run: | run: |
mkdir build make tests
cd build
cmake ..
make
./tests
docs: docs:
runs-on: ubuntu-latest runs-on: ubuntu-latest

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ test
tcptest tcptest
testrunner testrunner
.idea .idea
netmanual

View File

@ -1,4 +1,4 @@
.PHONY : clean tests all .PHONY : clean tests all manual
CFLAGS = -std=c99 -Iinclude -pedantic CFLAGS = -std=c99 -Iinclude -pedantic
WARNINGS= -Wall -Wextra WARNINGS= -Wall -Wextra
@ -30,6 +30,7 @@ clean:
rm -f $(TARGET) rm -f $(TARGET)
rm -f testrunner rm -f testrunner
rm -f tcptest rm -f tcptest
rm -f netmanual
rm -f compile_commands.json rm -f compile_commands.json
tests: tests:
@ -37,3 +38,5 @@ tests:
cc $(CFLAGS) -o tcptest tests/tcptest.c src/*.c cc $(CFLAGS) -o tcptest tests/tcptest.c src/*.c
./run_tests.sh ./run_tests.sh
manual:
cc $(CFLAGS) -o netmanual tests/netmanual.c src/*.c

View File

@ -1,4 +1,5 @@
#include <errno.h> #include <errno.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
@ -115,13 +116,26 @@ void handler_tcp_echo(Server *s) {
printf("Received connection from %s\n", buf); printf("Received connection from %s\n", buf);
// Start child process // Start child process
if (!fork()) { if (!fork()) {
close(s->fd); // Child doesn't need the initial socket close(s->fd); // Child doesn't need the initial socket
if (send(new_fd, "Hello, world!", 13, 0) == -1) {
fprintf(stderr, "Failed to send hello world\n"); char recv_buf[256];
} int r = recv(new_fd, recv_buf, 256, 0);
close(new_fd); if (r == -1) {
_exit(0); fprintf(stderr, "Failed to recv. Errno: %d\n", errno);
goto CHILD_END;
} else if (r == 0) {
fprintf(stderr, "Client closed connection\n");
goto CHILD_END;
}
if (send(new_fd, recv_buf, strlen(recv_buf), 0) == -1) {
fprintf(stderr, "Failed to send echo\n");
}
CHILD_END:
close(new_fd);
_exit(0);
} }
// End child process // End child process

15
tests/netmanual.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include "lfnetwork.h"
int main(int argc, char **argv) {
Server *server = new_server(SERVERTYPE_TCP, "18632", handler_tcp_echo);
serve(server, DEFAULT_BACKLOG);
delete_server(server);
}