Added additional setup code to get all pubsub tests passing.
* limitations under the License.
*/
+#include <csp/arch/csp_thread.h>
#include <unity/unity.h>
#include <unity/k_test.h>
#include "ipc/pubsub.h"
@@ -33,6 +34,33 @@ static void csp_test_setup(void)
csp_route_start_task(500, 1);
}
+CSP_DEFINE_TASK(subscriber_task)
+{
+ pubsub_conn conn;
+ char buffer;
+ if (subscriber_connect(&conn, TEST_ADDRESS, TEST_PORT))
+ {
+ send_csp(conn, (void*)&buffer, sizeof(buffer));
+ }
+ csp_thread_exit();
+}
+
+CSP_DEFINE_TASK(publisher_task)
+{
+ pubsub_conn conn;
+ csp_socket_t * socket = NULL;
+ char buffer;
+
+ if (server_setup(&socket, TEST_PORT, 1))
+ {
+ if (server_accept(&socket, &conn))
+ {
+ send_csp(conn, (void*)&buffer, sizeof(buffer));
+ }
+ }
+ csp_thread_exit();
+}
+
static void test_server_setup_null_socket(void)
{
TEST_ASSERT_EQUAL_INT(server_setup(NULL, TEST_PORT, 1), false);
@@ -62,7 +90,13 @@ static void test_server_accept(void)
{
pubsub_conn conn;
csp_socket_t * socket = NULL;
+ csp_test_setup();
server_setup(&socket, TEST_PORT, 1);
+
+ csp_thread_handle_t subscriber_handle;
+ csp_thread_create(subscriber_task, "SUBSCRIBE", 1000, NULL, 0, &subscriber_handle);
+
+
TEST_ASSERT_EQUAL_INT(server_accept(&socket, &conn), true);
}
@@ -103,7 +137,14 @@ static void test_send(void)
pubsub_conn conn;
int data = 10;
// setup conn here
- TEST_ASSERT_EQUAL_INT(send_csp(conn, &data, sizeof(int)), true);
+
+ csp_test_setup();
+ csp_socket_t * socket = NULL;
+ server_setup(&socket, TEST_PORT, 1);
+
+ subscriber_connect(&conn, TEST_ADDRESS, TEST_PORT);
+
+ TEST_ASSERT_EQUAL_INT(send_csp(conn, (void*)&data, sizeof(data)), true);
}
static void test_publisher_read_null_conn(void)
@@ -126,6 +167,15 @@ static void test_publisher_read(void)
pubsub_conn conn;
char buffer;
+ csp_test_setup();
+ csp_socket_t * socket = NULL;
+ server_setup(&socket, TEST_PORT, 1);
+
+ csp_thread_handle_t subscriber_handle;
+ csp_thread_create(subscriber_task, "SUBSCRIBE", 1000, NULL, 0, &subscriber_handle);
+
+ server_accept(&socket, &conn);
+
TEST_ASSERT_EQUAL_INT(publisher_read(conn, &buffer, 1, TEST_PORT), true);
}
@@ -149,6 +199,14 @@ static void test_subscriber_read(void)
pubsub_conn conn;
char buffer;
+ csp_test_setup();
+
+ csp_thread_handle_t publisher_handle;
+ csp_thread_create(publisher_task, "PUBLISH", 1000, NULL, 0, &publisher_handle);
+
+ subscriber_connect(&conn, TEST_ADDRESS, TEST_PORT);
+ send_csp(conn, (void*)&buffer, sizeof(buffer));
+
TEST_ASSERT_EQUAL_INT(subscriber_read(conn, &buffer, 1, TEST_PORT), true);
}
