<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
 

#include "testutil/testutil.h"
#include "os/os.h"
#include "os_test_priv.h"
#include "os/os_eventq.h"

#define MY_STACK_SIZE        (5120)

/*Task 1 sending task*/
/* Define task stack and task object */
#define SEND_TASK_PRIO        (1)
struct os_task eventq_task_s;
os_stack_t eventq_task_stack_s[MY_STACK_SIZE];

/*Task 2 receiving task*/
#define RECEIVE_TASK_PRIO     (2)
struct os_task eventq_task_r;
os_stack_t eventq_task_stack_r[MY_STACK_SIZE];

struct os_eventq my_eventq;

#define SIZE_MULTI_EVENT        (4)
struct os_eventq multi_eventq[SIZE_MULTI_EVENT];

/* This is to set the events we will use below */
struct os_event g_event;
struct os_event m_event[SIZE_MULTI_EVENT];

/* Setting the event to send and receive multiple data */
uint8_t my_event_type = 1;

/* This is the task function  to send data */
void
eventq_task_send(void *arg)
{
    int i;

    g_event.ev_queued = 0;
    g_event.ev_type = my_event_type;
    g_event.ev_arg = NULL;

    os_eventq_put(&my_eventq, &g_event);

    os_time_delay(OS_TICKS_PER_SEC / 2);

    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        m_event[i].ev_type = i + 2;
        m_event[i].ev_arg = NULL;

        /* Put and send */
        os_eventq_put(&multi_eventq[i], &m_event[i]);
        os_time_delay(OS_TICKS_PER_SEC / 2);
    }

    /* This task sleeps until the receive task completes the test. */
    os_time_delay(1000000);
}

/* This is the task function is the receiving function */
void
eventq_task_receive(void *arg)
{
    struct os_event *event;
    int i;

    event = os_eventq_get(&my_eventq);
    TEST_ASSERT(event->ev_type == my_event_type);

    /* Receiving multi event from the send task */
    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
        event = os_eventq_get(&multi_eventq[i]);
        TEST_ASSERT(event->ev_type == i + 2);
    }

    /* Finishes the test when OS has been started */
    os_test_restart();
}

TEST_CASE(event_test_sr)
{
    int i;

    /* Initializing the OS */
    os_init();
    /* Initialize the task */
    os_task_init(&eventq_task_s, "eventq_task_s", eventq_task_send, NULL,
        SEND_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_s, MY_STACK_SIZE);

    /* Receive events and check whether the eevnts are correctly received */
    os_task_init(&eventq_task_r, "eventq_task_r", eventq_task_receive, NULL,
        RECEIVE_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_r,
        MY_STACK_SIZE);

    os_eventq_init(&my_eventq);

    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        os_eventq_init(&multi_eventq[i]);
    }

    /* Does not return until OS_restart is called */
    os_start();

}

TEST_SUITE(os_eventq_test_suite)
{
    event_test_sr();
}<commit_msg>This closes #70.<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
 

#include "testutil/testutil.h"
#include "os/os.h"
#include "os_test_priv.h"
#include "os/os_eventq.h"

#define MY_STACK_SIZE        (5120)
#define POLL_STACK_SIZE        (4096)
/* Task 1 sending task */
/* Define task stack and task object */
#define SEND_TASK_PRIO        (1)
struct os_task eventq_task_s;
os_stack_t eventq_task_stack_s[MY_STACK_SIZE];

/* Task 2 receiving task */
#define RECEIVE_TASK_PRIO     (2)
struct os_task eventq_task_r;
os_stack_t eventq_task_stack_r[MY_STACK_SIZE];

struct os_eventq my_eventq;

#define SIZE_MULTI_EVENT        (4)
struct os_eventq multi_eventq[SIZE_MULTI_EVENT];

/* This is to set the events we will use below */
struct os_event g_event;
struct os_event m_event[SIZE_MULTI_EVENT];

/* Setting the event to send and receive multiple data */
uint8_t my_event_type = 1;

/* Setting up data for the poll */
/* Define the task stack for the eventq_task_poll_send */
#define SEND_TASK_POLL_PRIO        (3)
struct os_task eventq_task_poll_s;
os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE];

/* Define the task stack for the eventq_task_poll_receive */
#define RECEIVE_TASK_POLL_PRIO     (4)
struct os_task eventq_task_poll_r;
os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ];

struct os_eventq *poll_eventq[POLL_STACK_SIZE];
struct os_eventq p_event[POLL_STACK_SIZE];
struct os_event poll_event[POLL_STACK_SIZE];

/* Setting the data for the poll timeout */
/* Define the task stack for the eventq_task_poll_timeout_send */
#define SEND_TASK_POLL_TIMEOUT_PRIO        (5)
struct os_task eventq_task_poll_timeout_s;
os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE];

/* Define the task stack for the eventq_task_poll_receive */
#define RECEIVE_TASK_POLL_TIMEOUT_PRIO     (6)
struct os_task eventq_task_poll_timeout_r;
os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE];

struct os_eventq *poll_eventq_timeout[POLL_STACK_SIZE];
struct os_eventq p_event_timeout[POLL_STACK_SIZE];
struct os_event poll_event_timeout[POLL_STACK_SIZE];

/* Setting the data for the poll single */
/* Define the task stack for the eventq_task_poll_single_send */
#define SEND_TASK_POLL_SINGLE_PRIO        (7)
struct os_task eventq_task_poll_single_s;
os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];

/* Define the task stack for the eventq_task_poll_single_receive */
#define RECEIVE_TASK_POLL_SINGLE_PRIO     (8)
struct os_task eventq_task_poll_single_r;
os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];

struct os_eventq *poll_eventq_single[POLL_STACK_SIZE];
struct os_eventq p_event_single[POLL_STACK_SIZE];
struct os_event poll_event_single[POLL_STACK_SIZE];

/* This is the task function  to send data */
void
eventq_task_send(void *arg)
{
    int i;

    g_event.ev_queued = 0;
    g_event.ev_type = my_event_type;
    g_event.ev_arg = NULL;

    os_eventq_put(&my_eventq, &g_event);

    os_time_delay(OS_TICKS_PER_SEC / 2);

    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        m_event[i].ev_type = i + 2;
        m_event[i].ev_arg = NULL;

        /* Put and send */
        os_eventq_put(&multi_eventq[i], &m_event[i]);
        os_time_delay(OS_TICKS_PER_SEC / 2);
    }

    /* This task sleeps until the receive task completes the test. */
    os_time_delay(1000000);
}

/* This is the task function is the receiving function */
void
eventq_task_receive(void *arg)
{
    struct os_event *event;
    int i;

    event = os_eventq_get(&my_eventq);
    TEST_ASSERT(event->ev_type == my_event_type);

    /* Receiving multi event from the send task */
    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
        event = os_eventq_get(&multi_eventq[i]);
        TEST_ASSERT(event->ev_type == i + 2);
    }

    /* Finishes the test when OS has been started */
    os_test_restart();
}

void
eventq_task_poll_send(void *arg)
{
    int i;

    /* Assigning the *poll_eventq[] */
    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        poll_eventq[i] = &p_event[i];
    }

    /* Initializing the *poll_eventq */
    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        os_eventq_init(poll_eventq[i]);
    }

    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        poll_event[i].ev_type = i + 10;
        poll_event[i].ev_arg = NULL;

        /* Put and send */
        os_eventq_put(poll_eventq[i], &poll_event[i]);
        os_time_delay(OS_TICKS_PER_SEC / 2);
    }

    /* This task sleeps until the receive task completes the test. */
    os_time_delay(1000000);
}

void
eventq_task_poll_receive(void *arg)
{
    struct os_event *event;
    int i;

    /* Recieving using the os_eventq_poll*/
    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
        event = os_eventq_poll(poll_eventq, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
        TEST_ASSERT(event->ev_type == i +10);
    }

    /* Finishes the test when OS has been started */
    os_test_restart();

}

/* Sending with a time failure */
void
eventq_task_poll_timeout_send(void *arg)
{
    int i;

    /* Assigning the *poll_eventq_timeout[] */
    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        poll_eventq_timeout[i] = &p_event_timeout[i];
    }

    /* Initializing the *poll_eventq_timeout */
    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        os_eventq_init(poll_eventq_timeout[i]);
    }

    for (i = 0; i < SIZE_MULTI_EVENT; i++){
         os_time_delay(1000);

        poll_event_timeout[i].ev_type = i + 10;
        poll_event_timeout[i].ev_arg = NULL;

        /* Put and send */
        os_eventq_put(poll_eventq_timeout[i], &poll_event_timeout[i]);
        os_time_delay(OS_TICKS_PER_SEC / 2);
    }

    /* This task sleeps until the receive task completes the test. */
    os_time_delay(1000000);
    
}

/* Receiving multiple event queues with a time failure */
void
eventq_task_poll_timeout_receive(void *arg)
{
     struct os_event *event;
    int i;

    /* Recieving using the os_eventq_poll_timeout*/
    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
        event = os_eventq_poll(poll_eventq_timeout, SIZE_MULTI_EVENT, 200);
        TEST_ASSERT(event == NULL);
    }

    /* Finishes the test when OS has been started */
    os_test_restart();

}

/* Sending a single event to poll */
void
eventq_task_poll_single_send(void *arg)
{
    int i;
    int position = 2;

    /* Assigning the *poll_eventq_single */
    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        poll_eventq_single[i] = &p_event_single[i];
    }

    /* Initializing the *poll_eventq_single */
    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        os_eventq_init(poll_eventq_single[i]);
    }

    poll_event_single[position].ev_type = 20;
    poll_event_single[position].ev_arg = NULL;

        /* Put and send */
        os_eventq_put(poll_eventq_single[position],
            &poll_event_single[position]);
        os_time_delay(OS_TICKS_PER_SEC / 2);

    /* This task sleeps until the receive task completes the test. */
    os_time_delay(1000000);

}

/* Recieving the single event */
void
eventq_task_poll_single_receive(void *arg)
{
    struct os_event *event;

    /* Recieving using the os_eventq_poll*/
    event = os_eventq_poll(poll_eventq_single, SIZE_MULTI_EVENT,  OS_WAIT_FOREVER);
    TEST_ASSERT(event->ev_type == 20);

    /* Finishes the test when OS has been started */
    os_test_restart();

}

TEST_CASE(event_test_sr)
{
    int i;

    /* Initializing the OS */
    os_init();
    /* Initialize the task */
    os_task_init(&eventq_task_s, "eventq_task_s", eventq_task_send, NULL,
        SEND_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_s, MY_STACK_SIZE);

    /* Receive events and check whether the eevnts are correctly received */
    os_task_init(&eventq_task_r, "eventq_task_r", eventq_task_receive, NULL,
        RECEIVE_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_r,
        MY_STACK_SIZE);

    os_eventq_init(&my_eventq);

    for (i = 0; i < SIZE_MULTI_EVENT; i++){
        os_eventq_init(&multi_eventq[i]);
    }

    /* Does not return until OS_restart is called */
    os_start();

}

/* To test for the basic function of os_eventq_poll() */
TEST_CASE(event_test_poll_sr)
{
    /* Initializing the OS */
    os_init();
    /* Initialize the task */
    os_task_init(&eventq_task_poll_s, "eventq_task_poll_s", eventq_task_poll_send,
        NULL, SEND_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_s, 
        POLL_STACK_SIZE);

    /* Receive events and check whether the eevnts are correctly received */
    os_task_init(&eventq_task_poll_r, "eventq_task_r", eventq_task_poll_receive,
        NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r,
        POLL_STACK_SIZE);

    /* Does not return until OS_restart is called */
    os_start();

}

/* Test case for poll timeout */
TEST_CASE(event_test_poll_timeout_sr)
{
    /* Initializing the OS */
    os_init();
    /* Initialize the task */
    os_task_init(&eventq_task_poll_timeout_s, "eventq_task_poll_timeout_s", 
        eventq_task_poll_timeout_send, NULL, SEND_TASK_POLL_TIMEOUT_PRIO,
        OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_s, POLL_STACK_SIZE);

    /* Receive events and check whether the eevnts are correctly received */
    os_task_init(&eventq_task_poll_timeout_r, "eventq_task_timeout_r",
        eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO,
        OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE);

    /* Does not return until OS_restart is called */
    os_start();

}

/* The case for poll single */
/* Test case for poll timeout */
TEST_CASE(event_test_poll_single_sr)
{
    /* Initializing the OS */
    os_init();
    /* Initialize the task */
    os_task_init(&eventq_task_poll_single_s, "eventq_task_poll_single_s", 
        eventq_task_poll_single_send, NULL, SEND_TASK_POLL_SINGLE_PRIO,
        OS_WAIT_FOREVER, eventq_task_stack_poll_single_s, POLL_STACK_SIZE);

    /* Receive events and check whether the eevnts are correctly received */
    os_task_init(&eventq_task_poll_single_r, "eventq_task_single_r",
        eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO,
        OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE);

    /* Does not return until OS_restart is called */
    os_start();

}

TEST_SUITE(os_eventq_test_suite)
{
    event_test_sr();
    event_test_poll_sr();
    event_test_poll_timeout_sr();
    event_test_poll_single_sr();

}
{'fraction_non_alphanumeric': 0.09428161508505842, 'fraction_numerical': 0.008471681355469017, 'mean_word_length': 3.6796675191815855, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988991', 'n_tokens_mistral': 5391, 'n_tokens_neox': 5197, 'n_words': 1261}