ztest: Add simple integration and unit tests

These tests mainly test the stack whether it compiles and runs fine
under normal conditions. They do not test most failure conditions.

Origin: Original

Change-Id: Iaac73511a0664abd84685112b4e526eab3eb5748
Signed-off-by: Jaakko Hannikainen <jaakko.hannikainen@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Jaakko Hannikainen 2016-08-22 15:02:31 +03:00 committed by Anas Nashif
parent 891c369807
commit 349a6c5c28
13 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,11 @@
BOARD ?= qemu_x86
ifneq ($(BOARD), unit_testing)
KERNEL_TYPE ?= nano
CONF_FILE ?= prj.conf
include $(ZEPHYR_BASE)/Makefile.inc
else
OBJECTS = src/main.o
include $(ZEPHYR_BASE)/tests/unit/Makefile.unittest
endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,41 @@
/*
* 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>
static void empty_test(void)
{
}
static void assert_tests(void)
{
assert_true(1, NULL);
assert_false(0, NULL);
assert_is_null(NULL, NULL);
assert_not_null("foo", NULL);
assert_equal(1, 1, NULL);
assert_equal_ptr(NULL, NULL, NULL);
}
void test_main(void)
{
ztest_test_suite(framework_tests,
ztest_unit_test(empty_test),
ztest_unit_test(assert_tests)
);
ztest_run_test_suite(framework_tests);
}

View file

@ -0,0 +1,12 @@
[test_verbose_0]
tags = test_framework
[test_verbose_1]
tags = test_framework
[test_verbose_2]
tags = test_framework
[test]
type = unit
tags = test_framework

View file

@ -0,0 +1,11 @@
BOARD ?= qemu_x86
ifneq ($(BOARD), unit_testing)
KERNEL_TYPE ?= nano
CONF_FILE ?= prj.conf
include $(ZEPHYR_BASE)/Makefile.inc
else
OBJECTS = src/main.o
include $(ZEPHYR_BASE)/tests/unit/Makefile.unittest
endif

View file

@ -0,0 +1,4 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_ASSERT_VERBOSE=1
CONFIG_ZTEST_MOCKING=y
CONFIG_ZTEST_PARAMETER_COUNT=5

View file

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

View file

@ -0,0 +1,59 @@
/*
* 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>
static void expect_one_parameter(int a)
{
ztest_check_expected_value(a);
}
static void expect_two_parameters(int a, int b)
{
ztest_check_expected_value(a);
ztest_check_expected_value(b);
}
static void parameter_tests(void)
{
ztest_expect_value(expect_one_parameter, a, 1);
expect_one_parameter(1);
ztest_expect_value(expect_two_parameters, a, 2);
ztest_expect_value(expect_two_parameters, b, 3);
expect_two_parameters(2, 3);
}
static int returns_int(void)
{
return ztest_get_return_value();
}
static void return_value_tests(void)
{
ztest_returns_value(returns_int, 5);
assert_equal(returns_int(), 5, NULL);
}
void test_main(void)
{
ztest_test_suite(mock_framework_tests,
ztest_unit_test(parameter_tests),
ztest_unit_test(return_value_tests)
);
ztest_run_test_suite(mock_framework_tests);
}

View file

@ -0,0 +1,7 @@
[test]
tags = test_framework
arch_whitelist = x86 arc
[test_unit]
type = unit
tags = test_framework