Skip to content
Draft
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include $(ALL_MAKES)
# by default compile all tests, but allow custom values on per-TARGET_FAMILY basys
# TODO: prepare tool which will read YAML files and return the components which should be compiled for a given platform
# for now getting all components and removing tests working only on certain targets
DEFAULT_COMPONENTS := $(filter-out test_meterfs_% test_virtio test-grlib-multi test-grspw2, $(ALL_COMPONENTS))
DEFAULT_COMPONENTS := $(filter-out test_meterfs_% test_virtio test-grlib-multi test-grspw2 test-msg, $(ALL_COMPONENTS))
-include Makefile.$(TARGET_FAMILY)

# create generic targets
Expand Down
1 change: 1 addition & 0 deletions Makefile.host
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ DEFAULT_COMPONENTS += $(LIBC_UNIT_TESTS)
DEFAULT_COMPONENTS += test-mprotect
DEFAULT_COMPONENTS += test-libtinyaes
DEFAULT_COMPONENTS += test-libalgo
DEFAULT_COMPONENTS += test-msg
14 changes: 14 additions & 0 deletions msg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
NAME := msg-server
LOCAL_SRCS := msg_server.c
LIBS := libphoenix
DEP_LIBS := unity

include $(binary.mk)

NAME := test-msg
LOCAL_SRCS := test_msg.c
LIBS := libphoenix
DEP_LIBS := unity
DEPS := msg-server

include $(binary.mk)
161 changes: 161 additions & 0 deletions msg/msg_server.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Phoenix-RTOS
*
* Message (PC version) tests utility
*
* Copyright 2025 Phoenix Systems
* Author: Mateusz Piasecki
*
*
* %LICENSE%
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pthread.h>

#include <sys/msg.h>


void *echoPortThread(void *arg)
{
char *name = (char *)arg;
msg_rid_t rid;

Check failure on line 25 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

unknown type name 'msg_rid_t'
uint32_t port;

Check failure on line 26 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

unknown type name 'uint32_t'
oid_t oid;

Check failure on line 27 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

unknown type name 'oid_t'; did you mean 'id_t'?
msg_t msg;

Check failure on line 28 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

unknown type name 'msg_t'; did you mean 'msglen_t'?

portCreate(&port);

Check failure on line 30 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

implicit declaration of function 'portCreate' [-Werror=implicit-function-declaration]

oid = (oid_t) { port, 1 };

Check failure on line 32 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

expected ';' before '{' token

Check failure on line 32 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

'oid_t' undeclared (first use in this function); did you mean 'id_t'?
portRegister(port, name, &oid);

Check failure on line 33 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

implicit declaration of function 'portRegister' [-Werror=implicit-function-declaration]

while (1) {
if (msgRecv(port, &msg, &rid) < 0) {

Check failure on line 36 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

implicit declaration of function 'msgRecv'; did you mean 'msgrcv'? [-Werror=implicit-function-declaration]
printf("Error in msgRecv occurred\n");
continue;
}

if (msgRespond(port, &msg, rid) < 0) {

Check failure on line 41 in msg/msg_server.c

View workflow job for this annotation

GitHub Actions / call-ci / build (host-generic-pc)

implicit declaration of function 'msgRespond'; did you mean 'msgsnd'? [-Werror=implicit-function-declaration]
printf("Error in msgRespond occurred\n");
continue;
}
}

return NULL;
}


void *dataGreetPortThread(void *arg)
{
char *name = (char *)arg;
char *message;
char *greeting = "Hello from ";
size_t messageSize;
msg_rid_t rid;
uint32_t port;
oid_t oid;
msg_t msg;

messageSize = strlen(greeting) + strlen(name) + 1;
message = malloc(messageSize);

if (message == NULL) {
perror("malloc");
exit(1);
}

strcpy(message, greeting);
strcpy(message + strlen(greeting), name);

portCreate(&port);

oid = (oid_t) { port, 1 };
portRegister(port, name, &oid);

while (1) {
if (msgRecv(port, &msg, &rid) < 0) {
printf("Error in msgRecv occurred\n");
continue;
}

if (msg.o.size >= messageSize) {
strcpy(msg.o.data, message);
}

if (msgRespond(port, &msg, rid) < 0) {
printf("Error in msgRespond occurred\n");
continue;
}
}

return NULL;
}

void *rawGreetPortThread(void *arg)
{
char *name = (char *)arg;
char *message;
char *greeting = "Hello from ";
size_t messageSize;
msg_rid_t rid;
uint32_t port;
oid_t oid;
msg_t msg;

messageSize = strlen(greeting) + strlen(name) + 1;
message = malloc(messageSize);

if (message == NULL) {
perror("malloc");
exit(1);
}

strcpy(message, greeting);
strcpy(message + strlen(greeting), name);

portCreate(&port);

oid = (oid_t) { port, 1 };
portRegister(port, name, &oid);

while (1) {
if (msgRecv(port, &msg, &rid) < 0) {
printf("Error in msgRecv occurred\n");
continue;
}

strcpy((char *)msg.o.raw, message);

if (msgRespond(port, &msg, rid) < 0) {
printf("Error in msgRespond occurred\n");
continue;
}
}

return NULL;
}


int main(void)
{
pthread_t thread[5];

setbuf(stdout, NULL);

pthread_create(&thread[0], NULL, echoPortThread, "/testport");
pthread_create(&thread[1], NULL, echoPortThread, "testport");
pthread_create(&thread[2], NULL, echoPortThread, "/");
pthread_create(&thread[3], NULL, dataGreetPortThread, "greetport");
pthread_create(&thread[3], NULL, rawGreetPortThread, "rawTinker");

pthread_join(thread[0], NULL);
pthread_join(thread[1], NULL);
pthread_join(thread[2], NULL);
pthread_join(thread[3], NULL);
pthread_join(thread[4], NULL);

return 0;
}
Loading
Loading