tests: add threads customdata api test case with unified kernel
the commit cover basic customdata apis: k_thread_custom_data_set() k_thread_custom_data_get() Change-Id: Ide27cfd59230303767414c7f827d6ad627989a6f Signed-off-by: jing wang <jing.j.wang@intel.com>
This commit is contained in:
parent
6ffe10f50f
commit
64579bc490
8 changed files with 152 additions and 0 deletions
4
tests/kernel/threads_customdata/cdata_api/Makefile
Normal file
4
tests/kernel/threads_customdata/cdata_api/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
BOARD ?= qemu_x86
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
10
tests/kernel/threads_customdata/cdata_api/README
Normal file
10
tests/kernel/threads_customdata/cdata_api/README
Normal file
|
@ -0,0 +1,10 @@
|
|||
$make qemu
|
||||
Running test suite test_customdata_api
|
||||
tc_start() - test_customdata_get_set_coop
|
||||
===================================================================
|
||||
PASS - test_customdata_get_set_coop.
|
||||
tc_start() - test_customdata_get_set_preempt
|
||||
===================================================================
|
||||
PASS - test_customdata_get_set_preempt.
|
||||
===================================================================
|
||||
PROJECT EXECUTION SUCCESSFUL
|
2
tests/kernel/threads_customdata/cdata_api/prj.conf
Normal file
2
tests/kernel/threads_customdata/cdata_api/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_THREAD_CUSTOM_DATA=y
|
3
tests/kernel/threads_customdata/cdata_api/src/Makefile
Normal file
3
tests/kernel/threads_customdata/cdata_api/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
include $(ZEPHYR_BASE)/tests/Makefile.test
|
||||
|
||||
obj-y = main.o test_customdata_api.o
|
38
tests/kernel/threads_customdata/cdata_api/src/main.c
Normal file
38
tests/kernel/threads_customdata/cdata_api/src/main.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed 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 <ztest.h>
|
||||
#include "test_cdata.h"
|
||||
|
||||
/**
|
||||
* @addtogroup t_threads_customdata
|
||||
* @{
|
||||
* @defgroup t_threads_customdata_api test_threads_customdata_api
|
||||
* @}
|
||||
*/
|
||||
|
||||
/*test case main entry*/
|
||||
void test_main(void *p1, void *p2, void *p3)
|
||||
{
|
||||
ARG_UNUSED(p1);
|
||||
ARG_UNUSED(p2);
|
||||
ARG_UNUSED(p3);
|
||||
|
||||
ztest_test_suite(test_customdata_api,
|
||||
ztest_unit_test(test_customdata_get_set_coop),
|
||||
ztest_unit_test(test_customdata_get_set_preempt));
|
||||
ztest_run_test_suite(test_customdata_api);
|
||||
}
|
23
tests/kernel/threads_customdata/cdata_api/src/test_cdata.h
Normal file
23
tests/kernel/threads_customdata/cdata_api/src/test_cdata.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef __TEST_CUSTOMDATA_H__
|
||||
#define __TEST_CUSTOMDATA_H__
|
||||
|
||||
void test_customdata_get_set_coop(void);
|
||||
void test_customdata_get_set_preempt(void);
|
||||
|
||||
#endif /* __TEST_CUSTOMDATA_H__ */
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed 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 <ztest.h>
|
||||
|
||||
/*macro definition*/
|
||||
#define STACK_SIZE 256
|
||||
|
||||
/*local variables*/
|
||||
static char __stack tstack[STACK_SIZE];
|
||||
|
||||
static void customdata_entry(void *p1, void *p2, void *p3)
|
||||
{
|
||||
uint32_t data = 1;
|
||||
|
||||
assert_is_null(k_thread_custom_data_get(), NULL);
|
||||
while (1) {
|
||||
k_thread_custom_data_set((void *)data);
|
||||
/* relinguish cpu for a while */
|
||||
k_sleep(50);
|
||||
/** TESTPOINT: custom data comparison */
|
||||
assert_equal(data, (uint32_t)k_thread_custom_data_get(), NULL);
|
||||
data++;
|
||||
}
|
||||
}
|
||||
|
||||
/* test cases */
|
||||
/**
|
||||
* @ingroup t_customdata_api
|
||||
* @brief test thread custom data get/set from coop thread
|
||||
*/
|
||||
void test_customdata_get_set_coop(void)
|
||||
{
|
||||
k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE,
|
||||
customdata_entry, NULL, NULL, NULL,
|
||||
K_PRIO_COOP(1), 0, 0);
|
||||
k_sleep(500);
|
||||
|
||||
/* cleanup environment */
|
||||
k_thread_abort(tid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup t_customdata_api
|
||||
* @brief test thread custom data get/set from preempt thread
|
||||
*/
|
||||
void test_customdata_get_set_preempt(void)
|
||||
{
|
||||
/** TESTPOINT: custom data of preempt thread */
|
||||
k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE,
|
||||
customdata_entry, NULL, NULL, NULL,
|
||||
K_PRIO_PREEMPT(0), 0, 0);
|
||||
k_sleep(500);
|
||||
|
||||
/* cleanup environment */
|
||||
k_thread_abort(tid);
|
||||
}
|
2
tests/kernel/threads_customdata/cdata_api/testcase.ini
Normal file
2
tests/kernel/threads_customdata/cdata_api/testcase.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
[test]
|
||||
tags = kernel
|
Loading…
Add table
Add a link
Reference in a new issue