manual testing
This commit is contained in:
parent
1424925cbf
commit
c52712471f
|
@ -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
|
||||||
|
|
|
@ -8,3 +8,4 @@ test
|
||||||
tcptest
|
tcptest
|
||||||
testrunner
|
testrunner
|
||||||
.idea
|
.idea
|
||||||
|
netmanual
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue