From 64dc2bcd949498450c5c53847b0b410112714d39 Mon Sep 17 00:00:00 2001 From: Lokesh B V Date: Wed, 26 Jul 2017 15:06:13 +0530 Subject: [PATCH] Add test cases for libc/fixedmath module Adds test cases for libc/fixedmath API's namely, b16atan2, b16cos, b16divb16, b16mulb16, b16sin, b16sqr, ub16divub16, ub16mulub16 and ub16sqr Signed-off-by: Lokesh B V --- apps/examples/testcase/le_tc/kernel/Make.defs | 3 + .../testcase/le_tc/kernel/kernel_tc_main.c | 4 + apps/examples/testcase/le_tc/kernel/tc_internal.h | 1 + .../testcase/le_tc/kernel/tc_libc_fixedmath.c | 175 +++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 apps/examples/testcase/le_tc/kernel/tc_libc_fixedmath.c diff --git a/apps/examples/testcase/le_tc/kernel/Make.defs b/apps/examples/testcase/le_tc/kernel/Make.defs index 4d7c606..ee163ac 100644 --- a/apps/examples/testcase/le_tc/kernel/Make.defs +++ b/apps/examples/testcase/le_tc/kernel/Make.defs @@ -65,6 +65,9 @@ endif ifeq ($(CONFIG_TC_KERNEL_GROUP),y) CSRCS += tc_group.c endif +ifeq ($(CONFIG_TC_KERNEL_LIBC_FIXEDMATH),y) + CSRCS += tc_libc_fixedmath.c +endif ifeq ($(CONFIG_TC_KERNEL_LIBC_LIBGEN),y) CSRCS += tc_libc_libgen.c endif diff --git a/apps/examples/testcase/le_tc/kernel/kernel_tc_main.c b/apps/examples/testcase/le_tc/kernel/kernel_tc_main.c index 7e4685d..a6e43a7 100644 --- a/apps/examples/testcase/le_tc/kernel/kernel_tc_main.c +++ b/apps/examples/testcase/le_tc/kernel/kernel_tc_main.c @@ -75,6 +75,10 @@ int kernel_tc_main(int argc, char *argv[]) group_main(); #endif +#ifdef CONFIG_TC_KERNEL_LIBC_FIXEDMATH + libc_fixedmath_main(); +#endif + #ifdef CONFIG_TC_KERNEL_LIBC_LIBGEN libc_libgen_main(); #endif diff --git a/apps/examples/testcase/le_tc/kernel/tc_internal.h b/apps/examples/testcase/le_tc/kernel/tc_internal.h index a8c6e61..d094a3c 100644 --- a/apps/examples/testcase/le_tc/kernel/tc_internal.h +++ b/apps/examples/testcase/le_tc/kernel/tc_internal.h @@ -66,6 +66,7 @@ int clock_main(void); int environ_main(void); int errno_main(void); int group_main(void); +int libc_fixedmath_main(void); int libc_libgen_main(void); int libc_math_main(void); int libc_misc_main(void); diff --git a/apps/examples/testcase/le_tc/kernel/tc_libc_fixedmath.c b/apps/examples/testcase/le_tc/kernel/tc_libc_fixedmath.c new file mode 100644 index 0000000..292cd7c --- /dev/null +++ b/apps/examples/testcase/le_tc/kernel/tc_libc_fixedmath.c @@ -0,0 +1,175 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * 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. + * + ****************************************************************************/ + +/// @file libc_fixedmath.c +/// @brief Test Case Example for Libc FixedMath API + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include "tc_internal.h" +#include "fixedmath.h" + +static void tc_fixedmath_b16mulb16(void) +{ + b16_t num; + + num = b16mulb16(b16TEN , b16TEN); + TC_ASSERT_EQ("b16mulb16", num, b16HUNDRED); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_ub16mulub16(void) +{ + ub16_t num; + + num = ub16mulub16(b16TEN , b16TEN); + TC_ASSERT_EQ("ub16mulub16", num, b16HUNDRED); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_b16sqr(void) +{ + b16_t num; + + num = b16sqr(b16TEN); + TC_ASSERT_EQ("b16sqr", num, b16HUNDRED); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_ub16sqr(void) +{ + ub16_t num; + + num = ub16sqr(b16TEN); + TC_ASSERT_EQ("ub16sqr", num, b16HUNDRED); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_b16divb16(void) +{ + b16_t num; + + num = b16divb16(b16HUNDRED , b16TEN); + TC_ASSERT_EQ("b16divb16", num, b16TEN); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_ub16divub16(void) +{ + ub16_t num; + + num = ub16divub16(b16HUNDRED , b16TEN); + TC_ASSERT_EQ("ub16divub16", num, b16TEN); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_b16sin(void) +{ + int degree; + int radian; + int output; + b16_t b16radian; + b16_t b16output; + + degree = -233; + radian = (degree * M_PI) / 180; + output = (int)sinf(radian); + + b16radian = itob16(radian); + b16output = b16sin(b16radian); + TC_ASSERT_EQ("b16sin", output, b16toi(b16output)); + + degree = 0; + radian = (degree * M_PI) / 180; + output = (int)sinf(radian); + + b16radian = itob16(radian); + b16output = b16sin(b16radian); + TC_ASSERT_EQ("b16sin", output, b16toi(b16output)); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_b16cos(void) +{ + int degree = 0; + int radian; + int output; + b16_t b16radian; + b16_t b16output; + + radian = (degree * M_PI) / 180; + output = (int)cosf(radian); + b16radian = itob16(radian); + b16output = b16cos(b16radian); + + TC_ASSERT_EQ("b16cos", output, OK); + TC_ASSERT_EQ("b16cos", output, b16toi(b16output)); + + TC_SUCCESS_RESULT(); +} + +static void tc_fixedmath_b16atan2(void) +{ + int x = -7; + int y = 7; + int radian; + int output; + b16_t b16_x; + b16_t b16_y; + b16_t b16output; + + radian = 180 / M_PI ; + output = (int)atan2(y, x) * radian; + + b16_x = itob16(x); + b16_y = itob16(y); + b16output = b16atan2(b16_y, b16_x); + TC_ASSERT_EQ("b16atan2", output, (b16toi(b16output) * radian)); + + TC_SUCCESS_RESULT(); +} + +/**************************************************************************** + * Name: libc_fixedmath + ****************************************************************************/ +int libc_fixedmath_main(void) +{ + tc_fixedmath_b16atan2(); + tc_fixedmath_b16cos(); + tc_fixedmath_b16divb16(); + tc_fixedmath_b16mulb16(); + tc_fixedmath_b16sin(); + tc_fixedmath_b16sqr(); + tc_fixedmath_ub16divub16(); + tc_fixedmath_ub16mulub16(); + tc_fixedmath_ub16sqr(); + + return 0; +} + -- 2.7.4