Skip to content

Commit

Permalink
tests: posix: common: separate posix message passing to standalone test
Browse files Browse the repository at this point in the history
posix.common contains testsuites that can be separated into smaller
groups of tests. This change moves mqueue into a singular
testsuite at tests/posix/message_passing app directory.

Signed-off-by: Marvin Ouma <[email protected]>
  • Loading branch information
Pancakem committed Jan 6, 2025
1 parent 1a578eb commit c5fa3a2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
9 changes: 9 additions & 0 deletions tests/posix/message_passing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(posix_message_passing)

target_sources(app PRIVATE src/main.c)

target_compile_options(app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L)
5 changes: 5 additions & 0 deletions tests/posix/message_passing/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_POSIX_API=y
CONFIG_ZTEST=y

CONFIG_POSIX_AEP_CHOICE_BASE=y
CONFIG_POSIX_MESSAGE_PASSING=y
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

#include <fcntl.h>
#include <mqueue.h>
#include <message_passing.h>
#include <pthread.h>

#include <zephyr/sys/util.h>
#include <zephyr/ztest.h>

#define N_THR 2
#define MESSAGE_SIZE 16
#define MESSAGE_SIZE 16
#define MESG_COUNT_PERMQ 4

static char queue[16] = "server";
Expand All @@ -40,13 +40,11 @@ static void *sender_thread(void *p1)
zassert_false(mq_timedsend(mqd, send_data, MESSAGE_SIZE, 0, &curtime),
"Not able to send message in timer");
usleep(USEC_PER_MSEC);
zassert_false(mq_close(mqd),
"unable to close message queue descriptor.");
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
pthread_exit(p1);
return NULL;
}


static void *receiver_thread(void *p1)
{
mqd_t mqd;
Expand All @@ -59,13 +57,12 @@ static void *receiver_thread(void *p1)
zassert_false(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);
usleep(USEC_PER_MSEC);
zassert_false(mq_close(mqd),
"unable to close message queue descriptor.");
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
pthread_exit(p1);
return NULL;
}

ZTEST(mqueue, test_mqueue)
ZTEST(message_passing, test_message_passing)
{
mqd_t mqd;
struct mq_attr attrs;
Expand All @@ -91,8 +88,7 @@ ZTEST(mqueue, test_mqueue)
pthread_join(newthread[i], &retval);
}

zassert_false(mq_close(mqd),
"unable to close message queue descriptor.");
zassert_false(mq_close(mqd), "unable to close message queue descriptor.");
zassert_false(mq_unlink(queue), "Not able to unlink Queue");
}

Expand All @@ -106,15 +102,15 @@ void notify_function_basic(union sigval val)
mqd = mq_open(queue, O_RDONLY);

mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
zassert_ok(strcmp(rec_data, send_data),
"Error in data reception. exp: %s act: %s", send_data, rec_data);
zassert_ok(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);

zassert_ok(mq_close(mqd), "Unable to close message queue descriptor.");

*executed = true;
}

ZTEST(mqueue, test_mqueue_notify_basic)
ZTEST(message_passing, test_message_passing_notify_basic)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand All @@ -134,7 +130,7 @@ ZTEST(mqueue, test_mqueue_notify_basic)

mqd = mq_open(queue, flags, mode, &attrs);

zassert_ok(mq_notify(mqd, &not), "Unable to set notification.");
zassert_ok(mq_notify(mqd, &not ), "Unable to set notification.");

Check failure on line 133 in tests/posix/message_passing/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/posix/message_passing/src/main.c:133 space prohibited before that close parenthesis ')'

zassert_ok(mq_send(mqd, send_data, MESSAGE_SIZE, 0), "Unable to send message");

Expand All @@ -155,15 +151,15 @@ void notify_function_thread(union sigval val)
mqd = mq_open(queue, O_RDONLY);

mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
zassert_ok(strcmp(rec_data, send_data),
"Error in data reception. exp: %s act: %s", send_data, rec_data);
zassert_ok(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);

zassert_ok(mq_close(mqd), "Unable to close message queue descriptor.");

notification_executed = true;
}

ZTEST(mqueue, test_mqueue_notify_thread)
ZTEST(message_passing, test_message_passing_notify_thread)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand All @@ -183,7 +179,7 @@ ZTEST(mqueue, test_mqueue_notify_thread)

mqd = mq_open(queue, flags, mode, &attrs);

zassert_ok(mq_notify(mqd, &not), "Unable to set notification.");
zassert_ok(mq_notify(mqd, &not ), "Unable to set notification.");

Check failure on line 182 in tests/posix/message_passing/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/posix/message_passing/src/main.c:182 space prohibited before that close parenthesis ')'

zassert_ok(mq_send(mqd, send_data, MESSAGE_SIZE, 0), "Unable to send message");

Expand All @@ -195,7 +191,7 @@ ZTEST(mqueue, test_mqueue_notify_thread)
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
}

ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
ZTEST(message_passing, test_message_passing_notify_non_empty_queue)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand All @@ -217,13 +213,13 @@ ZTEST(mqueue, test_mqueue_notify_non_empty_queue)

zassert_ok(mq_send(mqd, send_data, MESSAGE_SIZE, 0), "Unable to send message");

zassert_ok(mq_notify(mqd, &not), "Unable to set notification.");
zassert_ok(mq_notify(mqd, &not ), "Unable to set notification.");

Check failure on line 216 in tests/posix/message_passing/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/posix/message_passing/src/main.c:216 space prohibited before that close parenthesis ')'

zassert_false(notification_executed, "Notification shouldn't be processed.");

mq_receive(mqd, rec_data, MESSAGE_SIZE, 0);
zassert_false(strcmp(rec_data, send_data),
"Error in data reception. exp: %s act: %s", send_data, rec_data);
zassert_false(strcmp(rec_data, send_data), "Error in data reception. exp: %s act: %s",
send_data, rec_data);

memset(rec_data, 0, MESSAGE_SIZE);

Expand All @@ -235,7 +231,7 @@ ZTEST(mqueue, test_mqueue_notify_non_empty_queue)
zassert_ok(mq_unlink(queue), "Unable to unlink queue");
}

ZTEST(mqueue, test_mqueue_notify_errors)
ZTEST(message_passing, test_message_passing_notify_errors)
{
mqd_t mqd;
struct mq_attr attrs = {
Expand All @@ -258,15 +254,15 @@ ZTEST(mqueue, test_mqueue_notify_errors)
zassert_not_ok(mq_notify(mqd, NULL), "Should return -1 and set errno to EINVAL.");
zassert_equal(errno, EINVAL);

zassert_not_ok(mq_notify(mqd, &not), "SIGEV_SIGNAL not supported should return -1.");
zassert_not_ok(mq_notify(mqd, &not ), "SIGEV_SIGNAL not supported should return -1.");

Check failure on line 257 in tests/posix/message_passing/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/posix/message_passing/src/main.c:257 space prohibited before that close parenthesis ')'
zassert_equal(errno, ENOSYS);

not.sigev_notify = SIGEV_NONE;
not .sigev_notify = SIGEV_NONE;

zassert_ok(mq_notify(mqd, &not),
zassert_ok(mq_notify(mqd, &not ),

Check failure on line 262 in tests/posix/message_passing/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/posix/message_passing/src/main.c:262 space prohibited before that close parenthesis ')'
"Unexpected error while asigning notification to the queue.");

zassert_not_ok(mq_notify(mqd, &not),
zassert_not_ok(mq_notify(mqd, &not ),

Check failure on line 265 in tests/posix/message_passing/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/posix/message_passing/src/main.c:265 space prohibited before that close parenthesis ')'
"Can't assign notification when there is another assigned.");
zassert_equal(errno, EBUSY);

Expand All @@ -286,4 +282,4 @@ static void before(void *arg)
}
}

ZTEST_SUITE(mqueue, NULL, NULL, before, NULL, NULL);
ZTEST_SUITE(message_passing, NULL, NULL, before, NULL, NULL);
25 changes: 25 additions & 0 deletions tests/posix/message_passing/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
common:
filter: not CONFIG_NATIVE_LIBC
tags:
- posix
- message_passing
# 1 tier0 platform per supported architecture
platform_key:
- arch
- simulation
min_flash: 64
min_ram: 32
tests:
portability.posix.message_passing: {}
portability.posix.message_passing.minimal:
extra_configs:
- CONFIG_MINIMAL_LIBC=y
portability.posix.message_passing.newlib:
filter: TOOLCHAIN_HAS_NEWLIB == 1
extra_configs:
- CONFIG_NEWLIB_LIBC=y
portability.posix.message_passing.picolibc:
tags: picolibc
filter: CONFIG_PICOLIBC_SUPPORTED
extra_configs:
- CONFIG_PICOLIBC=y

0 comments on commit c5fa3a2

Please sign in to comment.