summaryrefslogtreecommitdiff
path: root/zephyr/test/math/src
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/math/src')
-rw-r--r--zephyr/test/math/src/fixed_point_int_sqrtf.c4
-rw-r--r--zephyr/test/math/src/mask.c4
-rw-r--r--zephyr/test/math/src/math_util.c33
-rw-r--r--zephyr/test/math/src/suite.c4
-rw-r--r--zephyr/test/math/src/vector.c4
5 files changed, 39 insertions, 10 deletions
diff --git a/zephyr/test/math/src/fixed_point_int_sqrtf.c b/zephyr/test/math/src/fixed_point_int_sqrtf.c
index d8360ec189..163c36c26b 100644
--- a/zephyr/test/math/src/fixed_point_int_sqrtf.c
+++ b/zephyr/test/math/src/fixed_point_int_sqrtf.c
@@ -1,9 +1,9 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include <ztest.h>
+#include <zephyr/ztest.h>
#include "math.h"
#include "math_util.h"
diff --git a/zephyr/test/math/src/mask.c b/zephyr/test/math/src/mask.c
index 9ced211a88..5e690c9653 100644
--- a/zephyr/test/math/src/mask.c
+++ b/zephyr/test/math/src/mask.c
@@ -1,10 +1,10 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <inttypes.h>
-#include <ztest.h>
+#include <zephyr/ztest.h>
#include "math.h"
#include "math_util.h"
diff --git a/zephyr/test/math/src/math_util.c b/zephyr/test/math/src/math_util.c
index 901c3a6cc6..d3bd2c6fb6 100644
--- a/zephyr/test/math/src/math_util.c
+++ b/zephyr/test/math/src/math_util.c
@@ -1,12 +1,14 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include <ztest.h>
+#include <zephyr/ztest.h>
+#include "common.h"
#include "math.h"
#include "math_util.h"
+#include "builtin/stdio.h"
ZTEST_USER(math, arc_cos__x_below_range)
{
@@ -39,3 +41,30 @@ ZTEST_USER(math, fp_sqrtf)
zassert_within(fp_sqrtf(FLOAT_TO_FP(15)), FLOAT_TO_FP(3.872983),
FLOAT_TO_FP(0.001), NULL);
}
+
+ZTEST_USER(math, print_ints)
+{
+ char buffer[10];
+
+ /* Fixed point. */
+ zassert_true(crec_snprintf(buffer, sizeof(buffer), "%.5d", 123) > 0,
+ NULL);
+ zassert_equal(0, strcmp(buffer, "0.00123"), "got '%s'", buffer);
+ zassert_true(crec_snprintf(buffer, sizeof(buffer), "%2.1d", 123) > 0,
+ NULL);
+ zassert_equal(0, strcmp(buffer, "12.3"), "got '%s'", buffer);
+
+ /* Precision or width larger than buffer should fail. */
+ zassert_equal(-EC_ERROR_OVERFLOW, crec_snprintf(buffer, 4, "%5d", 123),
+ NULL);
+ zassert_equal(0, strcmp(buffer, " 1"), "got '%s'", buffer);
+ zassert_equal(-EC_ERROR_OVERFLOW, crec_snprintf(buffer, 4, "%10d", 123),
+ NULL);
+ zassert_equal(0, strcmp(buffer, " "), "got '%s'", buffer);
+ zassert_equal(-EC_ERROR_OVERFLOW,
+ crec_snprintf(buffer, 4, "%-10d", 123), NULL);
+ zassert_equal(0, strcmp(buffer, "123"), "got '%s'", buffer);
+ zassert_equal(-EC_ERROR_OVERFLOW,
+ crec_snprintf(buffer, 4, "%.10d", 123), NULL);
+ zassert_equal(0, strcmp(buffer, "0.0"), "got '%s'", buffer);
+}
diff --git a/zephyr/test/math/src/suite.c b/zephyr/test/math/src/suite.c
index 75b8e84bde..95da93b113 100644
--- a/zephyr/test/math/src/suite.c
+++ b/zephyr/test/math/src/suite.c
@@ -1,8 +1,8 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include <ztest.h>
+#include <zephyr/ztest.h>
ZTEST_SUITE(math, NULL, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/math/src/vector.c b/zephyr/test/math/src/vector.c
index 2e8ca52c5d..e79a350a92 100644
--- a/zephyr/test/math/src/vector.c
+++ b/zephyr/test/math/src/vector.c
@@ -1,9 +1,9 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include <ztest.h>
+#include <zephyr/ztest.h>
#include "math.h"
#include "math_util.h"