Obsolete
/
libipc-old
Archived
3
0
Fork 0

Read-write loop test.

more_to_read
Philippe PITTOLI 2020-01-28 13:41:09 +01:00
parent 75b407538b
commit ac9e329cec
3 changed files with 133 additions and 30 deletions

View File

@ -7,16 +7,16 @@ LIBDIR := $(PREFIX)/lib
SHAREDIR := $(PREFIX)/share SHAREDIR := $(PREFIX)/share
INCLUDEDIR := $(PREFIX)/include INCLUDEDIR := $(PREFIX)/include
MANDIR := $(SHAREDIR)/man MANDIR := $(SHAREDIR)/man
CC := cc
AR := ar
RANLIB := ranlib
CFLAGS := -Wall -Wextra -g CFLAGS := -Wall -Wextra -g
LDFLAGS := -I../src -L../ ../src/ipc.h -lipc LDFLAGS := -I../src -L../ ../src/ipc.h -lipc
CC := cc
CXX := c++
LD := ${CC}
CXXFLAGS :=
Q := @ Q := @
all: func_01_connection_establishment func_01_connection_establishmentd func_02_pong func_02_pongd func_03_multiple-communications-client func_03_multiple-communications-server func_04_empty_message unit_01_service-path unit_02_usock-remove unit_03_connection-add-remove all: func_01_connection_establishment func_01_connection_establishmentd func_02_pong func_02_pongd func_03_multiple-communications-client func_03_multiple-communications-server func_04_empty_message func_05_read-write-loop unit_01_service-path unit_02_usock-remove unit_03_connection-add-remove
@: @:
func_01_connection_establishment: func_01_connection_establishment.o func_01_connection_establishment: func_01_connection_establishment.o
@ -131,6 +131,22 @@ func_04_empty_message.uninstall:
@echo ' RM > $(BINDIR)/func_04_empty_message' @echo ' RM > $(BINDIR)/func_04_empty_message'
$(Q)rm -f '$(DESTDIR)$(BINDIR)/func_04_empty_message' $(Q)rm -f '$(DESTDIR)$(BINDIR)/func_04_empty_message'
func_05_read-write-loop: func_05_read-write-loop.o
@echo ' LD > func_05_read-write-loop'
$(Q)$(CC) -o func_05_read-write-loop func_05_read-write-loop.o $(LDFLAGS)
func_05_read-write-loop.install: func_05_read-write-loop
@echo ' IN > $(BINDIR)/func_05_read-write-loop'
$(Q)mkdir -p '$(DESTDIR)$(BINDIR)'
$(Q)install -m0755 func_05_read-write-loop $(DESTDIR)$(BINDIR)/func_05_read-write-loop
func_05_read-write-loop.clean: func_05_read-write-loop.o.clean
@echo ' RM > func_05_read-write-loop'
$(Q)rm -f func_05_read-write-loop
func_05_read-write-loop.uninstall:
@echo ' RM > $(BINDIR)/func_05_read-write-loop'
$(Q)rm -f '$(DESTDIR)$(BINDIR)/func_05_read-write-loop'
unit_01_service-path: unit_01_service-path.o unit_01_service-path: unit_01_service-path.o
@echo ' LD > unit_01_service-path' @echo ' LD > unit_01_service-path'
$(Q)$(CC) -o unit_01_service-path unit_01_service-path.o $(LDFLAGS) $(Q)$(CC) -o unit_01_service-path unit_01_service-path.o $(LDFLAGS)
@ -263,6 +279,18 @@ func_04_empty_message.o.clean:
func_04_empty_message.o.uninstall: func_04_empty_message.o.uninstall:
func_05_read-write-loop.o: func_05_read-write-loop.c ./../src/ipc.h
@echo ' CC > func_05_read-write-loop.o'
$(Q)$(CC) $(CFLAGS) -std=c11 -c func_05_read-write-loop.c -std=c11 -o func_05_read-write-loop.o
func_05_read-write-loop.o.install:
func_05_read-write-loop.o.clean:
@echo ' RM > func_05_read-write-loop.o'
$(Q)rm -f func_05_read-write-loop.o
func_05_read-write-loop.o.uninstall:
unit_01_service-path.o: unit_01_service-path.c ./../src/ipc.h unit_01_service-path.o: unit_01_service-path.c ./../src/ipc.h
@echo ' CC > unit_01_service-path.o' @echo ' CC > unit_01_service-path.o'
$(Q)$(CC) $(CFLAGS) -std=c11 -c unit_01_service-path.c -std=c11 -o unit_01_service-path.o $(Q)$(CC) $(CFLAGS) -std=c11 -c unit_01_service-path.c -std=c11 -o unit_01_service-path.o
@ -317,25 +345,14 @@ $(DESTDIR)$(INCLUDEDIR):
$(DESTDIR)$(MANDIR): $(DESTDIR)$(MANDIR):
@echo ' DIR > $(MANDIR)' @echo ' DIR > $(MANDIR)'
$(Q)mkdir -p $(DESTDIR)$(MANDIR) $(Q)mkdir -p $(DESTDIR)$(MANDIR)
install: subdirs.install func_01_connection_establishment.install func_01_connection_establishmentd.install func_02_pong.install func_02_pongd.install func_03_multiple-communications-client.install func_03_multiple-communications-server.install func_04_empty_message.install unit_01_service-path.install unit_02_usock-remove.install unit_03_connection-add-remove.install func_01_connection_establishment.o.install func_01_connection_establishmentd.o.install func_02_pong.o.install func_02_pongd.o.install func_03_multiple-communications-client.o.install func_03_multiple-communications-server.o.install func_04_empty_message.o.install unit_01_service-path.o.install unit_02_usock-remove.o.install unit_03_connection-add-remove.o.install install: func_01_connection_establishment.install func_01_connection_establishmentd.install func_02_pong.install func_02_pongd.install func_03_multiple-communications-client.install func_03_multiple-communications-server.install func_04_empty_message.install func_05_read-write-loop.install unit_01_service-path.install unit_02_usock-remove.install unit_03_connection-add-remove.install func_01_connection_establishment.o.install func_01_connection_establishmentd.o.install func_02_pong.o.install func_02_pongd.o.install func_03_multiple-communications-client.o.install func_03_multiple-communications-server.o.install func_04_empty_message.o.install func_05_read-write-loop.o.install unit_01_service-path.o.install unit_02_usock-remove.o.install unit_03_connection-add-remove.o.install
@: @:
subdirs.install: uninstall: func_01_connection_establishment.uninstall func_01_connection_establishmentd.uninstall func_02_pong.uninstall func_02_pongd.uninstall func_03_multiple-communications-client.uninstall func_03_multiple-communications-server.uninstall func_04_empty_message.uninstall func_05_read-write-loop.uninstall unit_01_service-path.uninstall unit_02_usock-remove.uninstall unit_03_connection-add-remove.uninstall func_01_connection_establishment.o.uninstall func_01_connection_establishmentd.o.uninstall func_02_pong.o.uninstall func_02_pongd.o.uninstall func_03_multiple-communications-client.o.uninstall func_03_multiple-communications-server.o.uninstall func_04_empty_message.o.uninstall func_05_read-write-loop.o.uninstall unit_01_service-path.o.uninstall unit_02_usock-remove.o.uninstall unit_03_connection-add-remove.o.uninstall
uninstall: subdirs.uninstall func_01_connection_establishment.uninstall func_01_connection_establishmentd.uninstall func_02_pong.uninstall func_02_pongd.uninstall func_03_multiple-communications-client.uninstall func_03_multiple-communications-server.uninstall func_04_empty_message.uninstall unit_01_service-path.uninstall unit_02_usock-remove.uninstall unit_03_connection-add-remove.uninstall func_01_connection_establishment.o.uninstall func_01_connection_establishmentd.o.uninstall func_02_pong.o.uninstall func_02_pongd.o.uninstall func_03_multiple-communications-client.o.uninstall func_03_multiple-communications-server.o.uninstall func_04_empty_message.o.uninstall unit_01_service-path.o.uninstall unit_02_usock-remove.o.uninstall unit_03_connection-add-remove.o.uninstall
@: @:
subdirs.uninstall: clean: func_01_connection_establishment.clean func_01_connection_establishmentd.clean func_02_pong.clean func_02_pongd.clean func_03_multiple-communications-client.clean func_03_multiple-communications-server.clean func_04_empty_message.clean func_05_read-write-loop.clean unit_01_service-path.clean unit_02_usock-remove.clean unit_03_connection-add-remove.clean func_01_connection_establishment.o.clean func_01_connection_establishmentd.o.clean func_02_pong.o.clean func_02_pongd.o.clean func_03_multiple-communications-client.o.clean func_03_multiple-communications-server.o.clean func_04_empty_message.o.clean func_05_read-write-loop.o.clean unit_01_service-path.o.clean unit_02_usock-remove.o.clean unit_03_connection-add-remove.o.clean
test: all subdirs subdirs.test
@:
subdirs.test:
clean: func_01_connection_establishment.clean func_01_connection_establishmentd.clean func_02_pong.clean func_02_pongd.clean func_03_multiple-communications-client.clean func_03_multiple-communications-server.clean func_04_empty_message.clean unit_01_service-path.clean unit_02_usock-remove.clean unit_03_connection-add-remove.clean func_01_connection_establishment.o.clean func_01_connection_establishmentd.o.clean func_02_pong.o.clean func_02_pongd.o.clean func_03_multiple-communications-client.o.clean func_03_multiple-communications-server.o.clean func_04_empty_message.o.clean unit_01_service-path.o.clean unit_02_usock-remove.o.clean unit_03_connection-add-remove.o.clean
distclean: clean distclean: clean
dist: dist-gz dist-xz dist-bz2 dist: dist-gz dist-xz dist-bz2
$(Q)rm -- $(PACKAGE)-$(VERSION) $(Q)rm -- $(PACKAGE)-$(VERSION)
@ -356,6 +373,7 @@ $(PACKAGE)-$(VERSION).tar.gz: distdir
$(PACKAGE)-$(VERSION)/func_01_connection_establishment.c \ $(PACKAGE)-$(VERSION)/func_01_connection_establishment.c \
$(PACKAGE)-$(VERSION)/func_03_multiple-communications-server.c \ $(PACKAGE)-$(VERSION)/func_03_multiple-communications-server.c \
$(PACKAGE)-$(VERSION)/unit_03_connection-add-remove.c \ $(PACKAGE)-$(VERSION)/unit_03_connection-add-remove.c \
$(PACKAGE)-$(VERSION)/func_05_read-write-loop.c \
$(PACKAGE)-$(VERSION)/func_03_multiple-communications-client.c \ $(PACKAGE)-$(VERSION)/func_03_multiple-communications-client.c \
$(PACKAGE)-$(VERSION)/unit_02_usock-remove.c \ $(PACKAGE)-$(VERSION)/unit_02_usock-remove.c \
$(PACKAGE)-$(VERSION)/func_01_connection_establishmentd.c $(PACKAGE)-$(VERSION)/func_01_connection_establishmentd.c
@ -373,6 +391,7 @@ $(PACKAGE)-$(VERSION).tar.xz: distdir
$(PACKAGE)-$(VERSION)/func_01_connection_establishment.c \ $(PACKAGE)-$(VERSION)/func_01_connection_establishment.c \
$(PACKAGE)-$(VERSION)/func_03_multiple-communications-server.c \ $(PACKAGE)-$(VERSION)/func_03_multiple-communications-server.c \
$(PACKAGE)-$(VERSION)/unit_03_connection-add-remove.c \ $(PACKAGE)-$(VERSION)/unit_03_connection-add-remove.c \
$(PACKAGE)-$(VERSION)/func_05_read-write-loop.c \
$(PACKAGE)-$(VERSION)/func_03_multiple-communications-client.c \ $(PACKAGE)-$(VERSION)/func_03_multiple-communications-client.c \
$(PACKAGE)-$(VERSION)/unit_02_usock-remove.c \ $(PACKAGE)-$(VERSION)/unit_02_usock-remove.c \
$(PACKAGE)-$(VERSION)/func_01_connection_establishmentd.c $(PACKAGE)-$(VERSION)/func_01_connection_establishmentd.c
@ -390,6 +409,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
$(PACKAGE)-$(VERSION)/func_01_connection_establishment.c \ $(PACKAGE)-$(VERSION)/func_01_connection_establishment.c \
$(PACKAGE)-$(VERSION)/func_03_multiple-communications-server.c \ $(PACKAGE)-$(VERSION)/func_03_multiple-communications-server.c \
$(PACKAGE)-$(VERSION)/unit_03_connection-add-remove.c \ $(PACKAGE)-$(VERSION)/unit_03_connection-add-remove.c \
$(PACKAGE)-$(VERSION)/func_05_read-write-loop.c \
$(PACKAGE)-$(VERSION)/func_03_multiple-communications-client.c \ $(PACKAGE)-$(VERSION)/func_03_multiple-communications-client.c \
$(PACKAGE)-$(VERSION)/unit_02_usock-remove.c \ $(PACKAGE)-$(VERSION)/unit_02_usock-remove.c \
$(PACKAGE)-$(VERSION)/func_01_connection_establishmentd.c $(PACKAGE)-$(VERSION)/func_01_connection_establishmentd.c
@ -406,10 +426,12 @@ help:
@echo ' - uninstall  Deinstalls the project.' @echo ' - uninstall  Deinstalls the project.'
@echo '' @echo ''
@echo 'CLI-modifiable variables:' @echo 'CLI-modifiable variables:'
@echo ' - CC  ${CC}'
@echo ' - CFLAGS  ${CFLAGS}' @echo ' - CFLAGS  ${CFLAGS}'
@echo ' - LDFLAGS  ${LDFLAGS}' @echo ' - LDFLAGS  ${LDFLAGS}'
@echo ' - DESTDIR  ${DESTDIR}' @echo ' - CC  ${CC}'
@echo ' - CXX  ${CXX}'
@echo ' - LD  ${LD}'
@echo ' - CXXFLAGS  ${CXXFLAGS}'
@echo ' - PREFIX  ${PREFIX}' @echo ' - PREFIX  ${PREFIX}'
@echo ' - BINDIR  ${BINDIR}' @echo ' - BINDIR  ${BINDIR}'
@echo ' - LIBDIR  ${LIBDIR}' @echo ' - LIBDIR  ${LIBDIR}'
@ -420,14 +442,15 @@ help:
@echo 'Project targets: ' @echo 'Project targets: '
@echo ' - func_01_connection_establishment binary' @echo ' - func_01_connection_establishment binary'
@echo ' - func_01_connection_establishmentd binary' @echo ' - func_01_connection_establishmentd binary'
@echo ' - func_02_pong  binary' @echo ' - func_02_pong  binary'
@echo ' - func_02_pongd  binary' @echo ' - func_02_pongd  binary'
@echo ' - func_03_multiple-communications-client binary' @echo ' - func_03_multiple-communications-client binary'
@echo ' - func_03_multiple-communications-server binary' @echo ' - func_03_multiple-communications-server binary'
@echo ' - func_04_empty_message binary' @echo ' - func_04_empty_message  binary'
@echo ' - unit_01_service-path binary' @echo ' - func_05_read-write-loop  binary'
@echo ' - unit_02_usock-remove binary' @echo ' - unit_01_service-path  binary'
@echo ' - unit_03_connection-add-remove binary' @echo ' - unit_02_usock-remove  binary'
@echo ' - unit_03_connection-add-remove  binary'
@echo '' @echo ''
@echo 'Makefile options:' @echo 'Makefile options:'
@echo ' - gnu: false' @echo ' - gnu: false'
@ -435,5 +458,5 @@ help:
@echo '' @echo ''
@echo 'Rebuild the Makefile with:' @echo 'Rebuild the Makefile with:'
@echo ' zsh ./build.zsh -c' @echo ' zsh ./build.zsh -c'
.PHONY: all subdirs clean distclean dist install uninstall help .PHONY: all clean distclean dist install uninstall help

View File

@ -0,0 +1,77 @@
#define _BSD_SOURCE
#include "../src/ipc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#define SERVICE_NAME "pong"
#define SECURE_MALLOC(p, s, wat) p = malloc (s); if (p == NULL) { wat; }
#define DEFAULT_MSG "coucou"
int main(int argc, char * argv[], char **env)
{
SECURE_DECLARATION(struct ipc_connection_info,srv);
SECURE_DECLARATION(struct ipc_event, event);
SECURE_DECLARATION (struct ipc_message, write_m);
SECURE_DECLARATION (struct ipc_message, read_m);
// timing the exchange duration
struct timeval tval_before, tval_after, tval_result;
size_t nb_rounds = 1000;
char *message_str = NULL;
if (argc > 1 && strncmp(argv[1], "-h", 2) == 0) {
fprintf (stderr, "usage: %s [nb-rounds [message]]\n", argv[0]);
fprintf (stderr, "default: nb-rounds = 1000, message='coucou'\n");
exit(0);
}
if (argc > 1) {
nb_rounds = (size_t) atoi(argv[1]);
}
if (argc > 2) {
message_str = argv[2];
}
if (message_str == NULL) {
// message par defaut
SECURE_MALLOC (message_str, strlen(DEFAULT_MSG) +1, exit(EXIT_FAILURE));
memcpy(message_str, DEFAULT_MSG, strlen(DEFAULT_MSG));
}
TEST_IPC_Q (ipc_connection (env, &srv, SERVICE_NAME), EXIT_FAILURE);
SECURE_MALLOC (write_m.payload, strlen(message_str), exit(EXIT_FAILURE));
memcpy (write_m.payload, message_str, strlen(message_str));
write_m.type = MSG_TYPE_DATA;
write_m.user_type = 42;
write_m.length = strlen(message_str);
gettimeofday(&tval_before, NULL);
for (size_t i = 0 ; i < nb_rounds ; i++) {
ipc_write (&srv, &write_m);
// reading
TEST_IPC_Q(ipc_read (&srv, &read_m), EXIT_FAILURE);
// printf ("received message (%d bytes): %*s\n", read_m.length, read_m.length, read_m.payload);
// ipc_message_empty (&read_m);
}
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &tval_result);
printf("Time elapsed: %ld.%06ld\n", (long int)tval_result.tv_sec, (long int)tval_result.tv_usec);
// disconnection
TEST_IPC_Q (ipc_close (&srv), EXIT_FAILURE);
return EXIT_SUCCESS;
}

View File

@ -2,8 +2,10 @@
package=ipc-tests package=ipc-tests
version=0.5.0 version=0.5.0
CFLAGS="-Wall -Wextra -g" variables+=(
LDFLAGS="-I../src -L../ ../src/ipc.h -lipc" CFLAGS "-Wall -Wextra -g"
LDFLAGS "-I../src -L../ ../src/ipc.h -lipc"
)
targets=( targets=(
func_01_connection_establishment func_01_connection_establishment
@ -13,6 +15,7 @@ targets=(
func_03_multiple-communications-client func_03_multiple-communications-client
func_03_multiple-communications-server func_03_multiple-communications-server
func_04_empty_message func_04_empty_message
func_05_read-write-loop
unit_01_service-path unit_01_service-path
unit_02_usock-remove unit_02_usock-remove
unit_03_connection-add-remove unit_03_connection-add-remove