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:
jing wang 2016-12-27 10:32:15 +08:00 committed by Anas Nashif
commit 64579bc490
8 changed files with 152 additions and 0 deletions

View file

@ -0,0 +1,4 @@
BOARD ?= qemu_x86
CONF_FILE = prj.conf
include ${ZEPHYR_BASE}/Makefile.inc

View 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

View file

@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_THREAD_CUSTOM_DATA=y

View file

@ -0,0 +1,3 @@
include $(ZEPHYR_BASE)/tests/Makefile.test
obj-y = main.o test_customdata_api.o

View 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);
}

View 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__ */

View file

@ -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);
}

View file

@ -0,0 +1,2 @@
[test]
tags = kernel