void mutex_buf_queue_coopr_test(void) { kstat_t ret; krhino_mutex_dyn_create(&test_mutex, "mutextest"); krhino_buf_queue_create(&test_buf_queue, "bugqueue", (void *)buf_queue_test_buf, 8, 1); ret = krhino_task_dyn_create(&task_mutex, MODULE_NAME, 0, TASK_COMB_PRI, 0, TASK_TEST_STACK_SIZE, task_mutex_opr_entry, 1); if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } ret = krhino_task_dyn_create(&task_buf_queue, MODULE_NAME, 0, TASK_COMB_PRI + 1, 0, TASK_TEST_STACK_SIZE, task_buf_queue_entry, 1); if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } ret = krhino_task_dyn_create(&task_buf_queue_trigger, MODULE_NAME, 0, TASK_COMB_PRI + 2, 0, TASK_TEST_STACK_SIZE, task_buf_queue_trigger_entry, 1); if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } }
void task_del_test() { test_case_check_err = 0; if (krhino_task_dyn_create(&task_del_test_0, "task_del_test0", NULL, 7, 0, TASK_TEST_STACK_SIZE, task_del_entry_0, 1) != RHINO_SUCCESS) { test_case_check_err++; printf("task_del_test 0 creat fail \n"); } if (krhino_task_dyn_create(&task_del_test_1, "task_del_test1", NULL, 5, 0, TASK_TEST_STACK_SIZE, task_del_entry_1, 1) != RHINO_SUCCESS) { test_case_check_err++; printf("task_del_test1 creat fail \n"); } if (krhino_task_dyn_create(&task_del_test_2, "task_del_test2", NULL, 59, 0, TASK_TEST_STACK_SIZE, task_del_entry_2, 1) != RHINO_SUCCESS) { test_case_check_err++; printf("task_del_test2 creat fail \n"); } if (test_case_check_err != 0) { test_case_fail ++; PRINT_RESULT("task_del", FAIL); } else { test_case_success++; PRINT_RESULT("task_del", PASS); } next_test_case_notify(); }
static void task_mutex_opr_entry(void *arg) { kstat_t ret; krhino_mutex_lock(test_mutex, RHINO_WAIT_FOREVER); while (notify_flag != 0x5a) { krhino_task_sleep(5); } ret = krhino_mutex_unlock(test_mutex); if (ret == RHINO_SUCCESS) { test_case_success++; PRINT_RESULT(MODULE_NAME, PASS); } else { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } next_test_case_notify(); ret = krhino_mutex_dyn_del(test_mutex); if (ret != RHINO_SUCCESS) { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } krhino_task_dyn_del(krhino_cur_task_get()); }
int main() { PRINT_RESULT(1, Test1()); PRINT_RESULT(2, Test2()); int i = 0; for(i = 0; i < ARR_SIZE - 4; i += 5) { printf("%d %d %d %d %d\n", array[i], array[i + 1], array[i + 2], array[i + 3], array[i + 4]); } return 1; }
static void task_timer0_entry(void *arg) { kstat_t ret = 0; while (1) { /* check krhino_timer_dyn_create param */ timer_dyn_create_param_test(); /* check krhino_timer_dyn_del param */ timer_dyn_del_param_test(); ret = krhino_sem_create(&sem_0_test, "sem_0_test", 0); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test", (timer_cb_t)timer_0_func, TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 0); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_dyn_del(timer_0_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_dyn_create(&timer_0_test, "timer_0_test", (timer_cb_t)timer_0_func, TIMER0_ROUND, TIMER0_ROUND, (void *)TIMER0_MAGIC, 1); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER); TIMER_VAL_CHK(ret == RHINO_SUCCESS); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_stop(timer_0_test); ret = krhino_timer_dyn_del(timer_0_test); if (ret == RHINO_SUCCESS) { test_case_success++; PRINT_RESULT("timer dyn create&del", PASS); } else { test_case_fail++; PRINT_RESULT("timer dyn create&del", FAIL); } krhino_sem_del(&sem_0_test); next_test_case_notify(); krhino_task_dyn_del(task_0_test); } }
void task_yield_2_entry(void *arg) { while (1) { test_case_success++; PRINT_RESULT("task_yield", PASS); next_test_case_notify(); krhino_task_dyn_del(krhino_cur_task_get()); } }
static void task_queue0_entry(void *arg) { kstat_t ret; while (1) { ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0", g_test_bufqueue_buf0, TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); /* check krhino_buf_queue_flush param */ buf_queue_flush_param_test(); ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0, TEST_BUFQUEUE_MSG_MAX); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0, TEST_BUFQUEUE_MSG_MAX); BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL); ret = krhino_buf_queue_flush(&g_test_bufqueue0); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0, TEST_BUFQUEUE_MSG_MAX); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_buf_queue_del(&g_test_bufqueue0); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); if (test_case_check_err == 0) { test_case_success++; PRINT_RESULT("buf queue flush", PASS); } else { test_case_check_err = 0; test_case_fail++; PRINT_RESULT("buf queue flush", FAIL); } next_test_case_notify(); krhino_task_dyn_del(task_0_test); } }
static void task_timer0_entry(void *arg) { kstat_t ret = 0; while (1) { /* check krhino_timer_change param */ timer_change_param_test(); ret = krhino_sem_create(&sem_0_test, "sem_0_test", 0); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_create(&timer_0_test, "timer_0_test", timer_0_func, TIMER0_ROUND * 10, TIMER0_ROUND * 10, (void *)TIMER0_MAGIC, 0); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_create(&timer_1_test, "timer_1_test", timer_1_func, TIMER0_ROUND * 20, TIMER0_ROUND * 20, (void *)TIMER0_MAGIC, 0); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_change(&timer_1_test, TIMER0_ROUND, TIMER0_ROUND); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_start(&timer_1_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_start(&timer_0_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_sem_take(&sem_0_test, RHINO_WAIT_FOREVER); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_stop(&timer_0_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_del(&timer_0_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_stop(&timer_1_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_timer_del(&timer_1_test); TIMER_VAL_CHK(ret == RHINO_SUCCESS); test_case_success++; PRINT_RESULT("timer change", PASS); krhino_sem_del(&sem_0_test); next_test_case_notify(); krhino_task_dyn_del(task_0_test); } }
static void task_queue0_entry(void *arg) { kstat_t ret; while (1) { ret = krhino_queue_create(&g_test_queue0, "test_queue0", (void **)&g_test_queue_msg0, TEST_QUEUE_MSG0_SIZE); QUEUE_VAL_CHK(ret == RHINO_SUCCESS); /* check krhino_queue_flush param */ queue_flush_param_test(); ret = krhino_queue_is_full(&g_test_queue0); QUEUE_VAL_CHK(ret == RHINO_QUEUE_NOT_FULL); ret = krhino_queue_back_send(&g_test_queue0, queue_send_msg); QUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_queue_is_full(&g_test_queue0); QUEUE_VAL_CHK(ret == RHINO_QUEUE_FULL); ret = krhino_queue_flush(&g_test_queue0); QUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_queue_is_full(&g_test_queue0); if (ret == RHINO_QUEUE_NOT_FULL) { test_case_success++; PRINT_RESULT("queue flush", PASS); } else { test_case_fail++; PRINT_RESULT("queue flush", PASS); } krhino_queue_del(&g_test_queue0); next_test_case_notify(); krhino_task_dyn_del(task_0_test); } }
void tasksem_count_test(void) { kstat_t ret; task_tasksem_entry_register(MODULE_NAME, (test_func_t *)tasksem_func_runner, sizeof(tasksem_func_runner) / sizeof(test_case_t)); ret = krhino_task_dyn_create(&task_tasksem, MODULE_NAME, 0, TASK_SEM_PRI, 0, TASK_TEST_STACK_SIZE, task_tasksem_entry, 1); if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } }
void ringbuf_break_test(void) { kstat_t ret; task_ringbuf_entry_register(MODULE_NAME, (test_func_t *)ringbuf_func_runner, sizeof(ringbuf_func_runner) / sizeof(test_func_t)); ret = krhino_task_dyn_create(&task_ringbuf, MODULE_NAME, 0, TASK_RINGBUF_PRI, 0, TASK_TEST_STACK_SIZE, task_ringbuf_entry, 1); if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) { test_case_fail++; PRINT_RESULT(MODULE_NAME, FAIL); } }
void task_workqueue_entry(void *arg) { test_func_t *runner; uint8_t caseidx; char name[64]; uint8_t casenum; runner = (test_func_t *)module_runner; casenum = module_casenum; caseidx = 0; while (1) { if (*runner == NULL) { break; } if (casenum > 2) { caseidx++; sprintf(name, "%s_%d", module_name, caseidx); } else { sprintf(name, "%s", module_name); } if ((*runner)() == 0) { test_case_success++; PRINT_RESULT(name, PASS); } else { test_case_fail++; PRINT_RESULT(name, FAIL); } runner++; } next_test_case_notify(); krhino_task_dyn_del(krhino_cur_task_get()); }
/* In this routine we block until the connected variable is 1 */ static int try_to_connect(struct mqtt_client_ctx *client_ctx) { int i = 0; while (i++ < APP_CONNECT_TRIES && !client_ctx->mqtt_ctx.connected) { int rc; rc = mqtt_tx_connect(&client_ctx->mqtt_ctx, &client_ctx->connect_msg); k_sleep(APP_SLEEP_MSECS); PRINT_RESULT("mqtt_tx_connect", rc); if (rc != 0) { continue; } } if (client_ctx->mqtt_ctx.connected) { return 0; } return -EINVAL; }
static void task_queue0_entry(void *arg) { kstat_t ret; size_t size; int count = 0; size_t msg; /* err param test */ ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0", (void *)g_test_bufqueue_buf0, TEST_BUFQUEUE_BUF0_SIZE, 0); BUFQUEUE_VAL_CHK(ret == RHINO_INV_PARAM); ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0", (void *)g_test_bufqueue_buf0, TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_fix_buf_queue_create(&g_test_bufqueue1, "test_bufqueue1", (void *)g_test_bufqueue_buf1, sizeof(size_t), 2); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); msg = 0x11; ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t)); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t)); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t)); BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL); (void)krhino_buf_queue_recv(&g_test_bufqueue1, RHINO_NO_WAIT, &msg, &size); (void)krhino_buf_queue_recv(&g_test_bufqueue1, RHINO_NO_WAIT, &msg, &size); ret = krhino_buf_queue_recv(&g_test_bufqueue1, 1, &msg, &size); BUFQUEUE_VAL_CHK(ret == RHINO_BLK_TIMEOUT); /* check krhino_buf_queue_recv */ buf_queue_recv_param_test(); buf_queue_send_param_test(); /* check RHINO_NO_WAIT */ ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_NO_WAIT, &g_test_recv_msg0, &size); BUFQUEUE_VAL_CHK(ret == RHINO_NO_PEND_WAIT); /* check sched disalbe */ ret = krhino_sched_disable(); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER, &g_test_recv_msg0, &size); BUFQUEUE_VAL_CHK(ret == RHINO_SCHED_DISABLE); ret = krhino_sched_enable(); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); ret = krhino_task_dyn_create(&task_1_test, "task_bufqueue1_test", 0, TEST_BUFQUEUE_SND_TASK_LOW_RPI, 0, TASK_TEST_STACK_SIZE, task_queue1_entry, 1); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); do { ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER, g_test_recv_msg0, &size); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); memset(g_test_send_msg0, send_char[count], TEST_BUFQUEUE_MSG_MAX); ret = memcmp(g_test_send_msg0, g_test_recv_msg0, size); count ++; } while (count < TEST_BUFQUEUE_MSG_NUM); ret = krhino_task_dyn_create(&task_2_test, "task_bufqueue2_test", 0, TEST_BUFQUEUE_SND_TASK_HIGH_RPI, 0, TASK_TEST_STACK_SIZE, task_queue2_entry, 1); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND / 10); count = 0; do { ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER, g_test_recv_msg0, &size); BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS); memset(g_test_send_msg1, send_char[count], TEST_BUFQUEUE_MSG_MAX); ret = memcmp(g_test_send_msg1, g_test_recv_msg0, size); count ++; } while (count < TEST_BUFQUEUE_MSG_NUM); if (test_case_check_err == 0) { test_case_success++; PRINT_RESULT("buf queue recv", PASS); } else { test_case_check_err = 0; test_case_fail++; PRINT_RESULT("buf queue recv", FAIL); } next_test_case_notify(); krhino_task_dyn_del(task_0_test); }
static void publisher(void) { int i, rc; /* Set everything to 0 and later just assign the required fields. */ memset(&client_ctx, 0x00, sizeof(client_ctx)); /* connect, disconnect and malformed may be set to NULL */ client_ctx.mqtt_ctx.connect = connect_cb; client_ctx.mqtt_ctx.disconnect = disconnect_cb; client_ctx.mqtt_ctx.malformed = malformed_cb; client_ctx.mqtt_ctx.net_init_timeout = APP_NET_INIT_TIMEOUT; client_ctx.mqtt_ctx.net_timeout = APP_TX_RX_TIMEOUT; client_ctx.mqtt_ctx.peer_addr_str = SERVER_ADDR; client_ctx.mqtt_ctx.peer_port = SERVER_PORT; #if defined(CONFIG_MQTT_LIB_TLS) /** TLS setup */ client_ctx.mqtt_ctx.request_buf = tls_request_buf; client_ctx.mqtt_ctx.request_buf_len = TLS_REQUEST_BUF_SIZE; client_ctx.mqtt_ctx.personalization_data = TLS_PRIVATE_DATA; client_ctx.mqtt_ctx.personalization_data_len = strlen(TLS_PRIVATE_DATA); client_ctx.mqtt_ctx.cert_host = TLS_SNI_HOSTNAME; client_ctx.mqtt_ctx.tls_mem_pool = &tls_mem_pool; client_ctx.mqtt_ctx.tls_stack = tls_stack; client_ctx.mqtt_ctx.tls_stack_size = K_THREAD_STACK_SIZEOF(tls_stack); client_ctx.mqtt_ctx.cert_cb = setup_cert; client_ctx.mqtt_ctx.entropy_src_cb = NULL; #endif /* Publisher apps TX the MQTT PUBLISH msg */ client_ctx.mqtt_ctx.publish_tx = publish_cb; /* The connect message will be sent to the MQTT server (broker). * If clean_session here is 0, the mqtt_ctx clean_session variable * will be set to 0 also. Please don't do that, set always to 1. * Clean session = 0 is not yet supported. */ client_ctx.connect_msg.client_id = MQTT_CLIENTID; client_ctx.connect_msg.client_id_len = strlen(MQTT_CLIENTID); client_ctx.connect_msg.clean_session = 1; client_ctx.connect_data = "CONNECTED"; client_ctx.disconnect_data = "DISCONNECTED"; client_ctx.publish_data = "PUBLISH"; rc = network_setup(); PRINT_RESULT("network_setup", rc); if (rc < 0) { return; } rc = mqtt_init(&client_ctx.mqtt_ctx, MQTT_APP_PUBLISHER); PRINT_RESULT("mqtt_init", rc); if (rc != 0) { return; } for (i = 0; i < CONN_TRIES; i++) { rc = mqtt_connect(&client_ctx.mqtt_ctx); PRINT_RESULT("mqtt_connect", rc); if (!rc) { goto connected; } } goto exit_app; connected: rc = try_to_connect(&client_ctx); PRINT_RESULT("try_to_connect", rc); if (rc != 0) { goto exit_app; } i = 0; while (i++ < APP_MAX_ITERATIONS) { rc = mqtt_tx_pingreq(&client_ctx.mqtt_ctx); k_sleep(APP_SLEEP_MSECS); PRINT_RESULT("mqtt_tx_pingreq", rc); prepare_mqtt_publish_msg(&client_ctx.pub_msg, MQTT_QoS0); rc = mqtt_tx_publish(&client_ctx.mqtt_ctx, &client_ctx.pub_msg); k_sleep(APP_SLEEP_MSECS); PRINT_RESULT("mqtt_tx_publish", rc); prepare_mqtt_publish_msg(&client_ctx.pub_msg, MQTT_QoS1); rc = mqtt_tx_publish(&client_ctx.mqtt_ctx, &client_ctx.pub_msg); k_sleep(APP_SLEEP_MSECS); PRINT_RESULT("mqtt_tx_publish", rc); prepare_mqtt_publish_msg(&client_ctx.pub_msg, MQTT_QoS2); rc = mqtt_tx_publish(&client_ctx.mqtt_ctx, &client_ctx.pub_msg); k_sleep(APP_SLEEP_MSECS); PRINT_RESULT("mqtt_tx_publish", rc); } rc = mqtt_tx_disconnect(&client_ctx.mqtt_ctx); PRINT_RESULT("mqtt_tx_disconnect", rc); exit_app: mqtt_close(&client_ctx.mqtt_ctx); printk("\nBye!\n"); }