This commit is contained in:
2025-12-11 08:08:53 +07:00
parent f3a5c1f658
commit ff6e412049
5 changed files with 327 additions and 378 deletions

View File

@@ -1,60 +1,61 @@
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g
LDFLAGS_MQ = -lrt
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g
LDFLAGS_MQ = -lrt # POSIX message queues on Linux
# SERVER_ARGS: <total_honey> <portion> <period_ms> <starvation_ms>
# WORKER_ARGS: <honey_portion>
SERVER_ARGS = 1000 15 500 500
WORKER_ARGS = 7
TEST_INPUT = test_input.txt
TEST_OUTPUT = test_output.txt
all: msg
# ===== POSIX MQ targets =====
msg: msg_server msg_worker
msg: mq_server mq_client
msg_server: server.c common.h
mq_server: server.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS_MQ)
msg_worker: worker.c common.h
mq_client: client.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS_MQ)
# ===== Tests =====
test_msg_server: msg
@echo "=== Запуск сервера POSIX MQ ==="
@echo "В другом терминале выполните: make test_msg_workers"
./msg_server $(SERVER_ARGS)
# ===== Ручные тесты =====
test_msg_workers: msg
@echo "=== Запуск нескольких пчёл ==="
./msg_worker 7 & \
./msg_worker 9 & \
./msg_worker 5 & \
wait
test_server: msg
@echo "=== Запуск MQ сервера ==="
@echo "В другом терминале выполните: make test_client_manual"
./mq_server
test_client_manual: msg
@echo "=== Запуск MQ клиента (ручной тест) ==="
./mq_client $(TEST_INPUT) $(TEST_OUTPUT)
# ===== Автотест: сервер в фоне + клиент =====
# Автотест: сервер в фоне, несколько пчёл
test_all: msg
@echo "=== Автотест POSIX MQ ==="
./msg_server $(SERVER_ARGS) & \
@echo "=== Автотест MQ (server + client) ==="
@echo "Создание тестового входного файла..."
echo "aabbccddeeff" > $(TEST_INPUT)
@echo "Старт сервера в фоне..."
./mq_server & \
SRV=$$!; \
sleep 2; \
./msg_worker $(WORKER_ARGS) & \
./msg_worker $(WORKER_ARGS) & \
./msg_worker $(WORKER_ARGS) & \
wait; \
wait $$SRV
sleep 1; \
echo "Запуск клиента..."; \
./mq_client $(TEST_INPUT) $(TEST_OUTPUT); \
echo "Остановка сервера..."; \
kill $$SRV || true; \
wait $$SRV 2>/dev/null || true; \
echo "=== Содержимое $(TEST_OUTPUT) ==="; \
cat $(TEST_OUTPUT)
# Очистка
clean:
@echo "Очистка..."
rm -f msg_server msg_worker
rm -f mq_server mq_client *.o $(TEST_INPUT) $(TEST_OUTPUT)
help:
@echo "Available targets:"
@echo " msg - Build POSIX message queue programs"
@echo " test_msg_server - Run MQ server (use workers in another terminal)"
@echo " test_msg_workers - Run several worker processes"
@echo " test_all - Automatic end-to-end test"
@echo " clean - Remove built files"
@echo " help - Show this help"
@echo " msg - Build POSIX MQ programs"
@echo " test_server - Run MQ server (client separately)"
@echo " test_client_manual- Run client (server must be running)"
@echo " test_all - Automatic end-to-end test (server+client)"
@echo " clean - Remove built and test files"
@echo " help - Show this help"
.PHONY: all msg test_msg_server test_msg_workers test_all clean help
.PHONY: all msg test_server test_client_manual test_all clean help