|
1 | 1 | #include "agnocast_kunit_subscriber_add.h"
|
2 | 2 |
|
3 | 3 | #include "../agnocast.h"
|
| 4 | +#include "../agnocast_memory_allocator.h" |
4 | 5 |
|
5 | 6 | #include <kunit/test.h>
|
6 | 7 |
|
@@ -390,6 +391,47 @@ void test_case_subscriber_add_without_publisher_process(struct kunit * test)
|
390 | 391 |
|
391 | 392 | void test_case_subscriber_add_too_many_mmap(struct kunit * test)
|
392 | 393 | {
|
393 |
| - // TODO(Ryuta Kambe): Implement this test case |
394 |
| - KUNIT_EXPECT_EQ(test, 0, 0); |
| 394 | + // Arrange: create MAX_PROCESS_NUM_PER_MEMPOOL processes which map to the same memory pool |
| 395 | + int ret; |
| 396 | + union ioctl_subscriber_args subscriber_args; |
| 397 | + union ioctl_publisher_args publisher_args; |
| 398 | + const pid_t publisher_pid = 999; |
| 399 | + pid_t subscriber_pid = 1000; |
| 400 | + const uint32_t qos_depth = 1; |
| 401 | + const bool qos_is_transient_local = false; |
| 402 | + setup_process(test, publisher_pid); |
| 403 | + int mmap_process_num = 1; |
| 404 | + for (int i = 0; i < MAX_PROCESS_NUM_PER_MEMPOOL / MAX_SUBSCRIBER_NUM + 1; i++) { |
| 405 | + char topic_name[50]; |
| 406 | + snprintf(topic_name, sizeof(topic_name), "/kunit_test_topic%d", i); |
| 407 | + ret = publisher_add( |
| 408 | + topic_name, NODE_NAME, publisher_pid, qos_depth, qos_is_transient_local, &publisher_args); |
| 409 | + KUNIT_ASSERT_EQ(test, ret, 0); |
| 410 | + for (int j = 0; j < MAX_SUBSCRIBER_NUM; j++) { |
| 411 | + if (mmap_process_num >= MAX_PROCESS_NUM_PER_MEMPOOL) { |
| 412 | + break; |
| 413 | + } |
| 414 | + setup_process(test, subscriber_pid); |
| 415 | + ret = subscriber_add( |
| 416 | + topic_name, NODE_NAME, subscriber_pid++, qos_depth, qos_is_transient_local, IS_TAKE_SUB, |
| 417 | + &subscriber_args); |
| 418 | + KUNIT_ASSERT_EQ(test, ret, 0); |
| 419 | + mmap_process_num++; |
| 420 | + } |
| 421 | + } |
| 422 | + const char * topic_name = "/kunit_test_topic_1000"; |
| 423 | + ret = publisher_add( |
| 424 | + topic_name, NODE_NAME, publisher_pid, qos_depth, qos_is_transient_local, &publisher_args); |
| 425 | + KUNIT_ASSERT_EQ(test, ret, 0); |
| 426 | + KUNIT_ASSERT_EQ(test, get_proc_info_htable_size(), MAX_PROCESS_NUM_PER_MEMPOOL); |
| 427 | + |
| 428 | + setup_process(test, subscriber_pid); |
| 429 | + |
| 430 | + // Act |
| 431 | + ret = subscriber_add( |
| 432 | + topic_name, NODE_NAME, subscriber_pid, qos_depth, qos_is_transient_local, IS_TAKE_SUB, |
| 433 | + &subscriber_args); |
| 434 | + |
| 435 | + // Assert |
| 436 | + KUNIT_EXPECT_EQ(test, ret, -ENOBUFS); |
395 | 437 | }
|
0 commit comments