diff --git a/tests/ztest/test/base/Makefile b/tests/ztest/test/base/Makefile new file mode 100644 index 00000000000..2dad078c4eb --- /dev/null +++ b/tests/ztest/test/base/Makefile @@ -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 diff --git a/tests/ztest/test/base/prj.conf b/tests/ztest/test/base/prj.conf new file mode 100644 index 00000000000..79028c27963 --- /dev/null +++ b/tests/ztest/test/base/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_ASSERT_VERBOSE=1 diff --git a/tests/ztest/test/base/prj_verbose_0.conf b/tests/ztest/test/base/prj_verbose_0.conf new file mode 100644 index 00000000000..c47f69824da --- /dev/null +++ b/tests/ztest/test/base/prj_verbose_0.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_ASSERT_VERBOSE=0 diff --git a/tests/ztest/test/base/prj_verbose_1.conf b/tests/ztest/test/base/prj_verbose_1.conf new file mode 100644 index 00000000000..79028c27963 --- /dev/null +++ b/tests/ztest/test/base/prj_verbose_1.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_ASSERT_VERBOSE=1 diff --git a/tests/ztest/test/base/prj_verbose_2.conf b/tests/ztest/test/base/prj_verbose_2.conf new file mode 100644 index 00000000000..0bda78a5b4f --- /dev/null +++ b/tests/ztest/test/base/prj_verbose_2.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_ASSERT_VERBOSE=2 diff --git a/tests/ztest/test/base/src/Makefile b/tests/ztest/test/base/src/Makefile new file mode 100644 index 00000000000..e7d8b5a1703 --- /dev/null +++ b/tests/ztest/test/base/src/Makefile @@ -0,0 +1,3 @@ +obj-y = main.o + +include $(ZEPHYR_BASE)/tests/Makefile.test diff --git a/tests/ztest/test/base/src/main.c b/tests/ztest/test/base/src/main.c new file mode 100644 index 00000000000..6f3ad478634 --- /dev/null +++ b/tests/ztest/test/base/src/main.c @@ -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 + +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); +} diff --git a/tests/ztest/test/base/testcase.ini b/tests/ztest/test/base/testcase.ini new file mode 100644 index 00000000000..ac78beb3889 --- /dev/null +++ b/tests/ztest/test/base/testcase.ini @@ -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 diff --git a/tests/ztest/test/mock/Makefile b/tests/ztest/test/mock/Makefile new file mode 100644 index 00000000000..2dad078c4eb --- /dev/null +++ b/tests/ztest/test/mock/Makefile @@ -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 diff --git a/tests/ztest/test/mock/prj.conf b/tests/ztest/test/mock/prj.conf new file mode 100644 index 00000000000..5534fce2c04 --- /dev/null +++ b/tests/ztest/test/mock/prj.conf @@ -0,0 +1,4 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_ASSERT_VERBOSE=1 +CONFIG_ZTEST_MOCKING=y +CONFIG_ZTEST_PARAMETER_COUNT=5 diff --git a/tests/ztest/test/mock/src/Makefile b/tests/ztest/test/mock/src/Makefile new file mode 100644 index 00000000000..e7d8b5a1703 --- /dev/null +++ b/tests/ztest/test/mock/src/Makefile @@ -0,0 +1,3 @@ +obj-y = main.o + +include $(ZEPHYR_BASE)/tests/Makefile.test diff --git a/tests/ztest/test/mock/src/main.c b/tests/ztest/test/mock/src/main.c new file mode 100644 index 00000000000..e150ad60d47 --- /dev/null +++ b/tests/ztest/test/mock/src/main.c @@ -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 + +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); +} diff --git a/tests/ztest/test/mock/testcase.ini b/tests/ztest/test/mock/testcase.ini new file mode 100644 index 00000000000..c13a8c7ad91 --- /dev/null +++ b/tests/ztest/test/mock/testcase.ini @@ -0,0 +1,7 @@ +[test] +tags = test_framework +arch_whitelist = x86 arc + +[test_unit] +type = unit +tags = test_framework