aboutsummaryrefslogtreecommitdiff
path: root/test/validation/api/random
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2017-10-05 04:33:44 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-10-16 21:50:18 +0300
commit326192cd87888abbea6c0dbdd3dc972db41f3325 (patch)
tree624cb9ab5431cf9a48fb140e0538b0a664aaae8c /test/validation/api/random
parent55e6afa29bdc2ae314bada7ac5648049909e1775 (diff)
test: drop now-unused common_plat directory
All tests in test/ are now common to all platforms, so no point in specifying that via (the only) common_plat subdirectory inside test dir. Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'test/validation/api/random')
-rw-r--r--test/validation/api/random/.gitignore1
-rw-r--r--test/validation/api/random/Makefile.am5
-rw-r--r--test/validation/api/random/random.c92
-rw-r--r--test/validation/api/random/random.h26
-rw-r--r--test/validation/api/random/random_main.c14
5 files changed, 138 insertions, 0 deletions
diff --git a/test/validation/api/random/.gitignore b/test/validation/api/random/.gitignore
new file mode 100644
index 000000000..2c88ec0b8
--- /dev/null
+++ b/test/validation/api/random/.gitignore
@@ -0,0 +1 @@
+random_main
diff --git a/test/validation/api/random/Makefile.am b/test/validation/api/random/Makefile.am
new file mode 100644
index 000000000..e026f045a
--- /dev/null
+++ b/test/validation/api/random/Makefile.am
@@ -0,0 +1,5 @@
+include ../Makefile.inc
+
+test_PROGRAMS = random_main$(EXEEXT)
+random_main_SOURCES = random_main.c random.c random.h
+random_main_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
diff --git a/test/validation/api/random/random.c b/test/validation/api/random/random.c
new file mode 100644
index 000000000..071c265f0
--- /dev/null
+++ b/test/validation/api/random/random.c
@@ -0,0 +1,92 @@
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "config.h"
+
+#include <odp_api.h>
+#include <odp_cunit_common.h>
+#include "random.h"
+
+void random_test_get_size(void)
+{
+ int32_t ret;
+ uint8_t buf[32];
+
+ ret = odp_random_data(buf, sizeof(buf), ODP_RANDOM_BASIC);
+ CU_ASSERT(ret == sizeof(buf));
+}
+
+void random_test_kind(void)
+{
+ int32_t rc;
+ uint8_t buf[4096];
+ uint32_t buf_size = sizeof(buf);
+ odp_random_kind_t max_kind = odp_random_max_kind();
+
+ rc = odp_random_data(buf, buf_size, max_kind);
+ CU_ASSERT(rc > 0);
+
+ switch (max_kind) {
+ case ODP_RANDOM_BASIC:
+ rc = odp_random_data(buf, 4, ODP_RANDOM_CRYPTO);
+ CU_ASSERT(rc < 0);
+ /* Fall through */
+
+ case ODP_RANDOM_CRYPTO:
+ rc = odp_random_data(buf, 4, ODP_RANDOM_TRUE);
+ CU_ASSERT(rc < 0);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void random_test_repeat(void)
+{
+ uint8_t buf1[1024];
+ uint8_t buf2[1024];
+ int32_t rc;
+ uint64_t seed1 = 12345897;
+ uint64_t seed2 = seed1;
+
+ rc = odp_random_test_data(buf1, sizeof(buf1), &seed1);
+ CU_ASSERT(rc == sizeof(buf1));
+
+ rc = odp_random_test_data(buf2, sizeof(buf2), &seed2);
+ CU_ASSERT(rc == sizeof(buf2));
+
+ CU_ASSERT(seed1 == seed2);
+ CU_ASSERT(memcmp(buf1, buf2, sizeof(buf1)) == 0);
+}
+
+odp_testinfo_t random_suite[] = {
+ ODP_TEST_INFO(random_test_get_size),
+ ODP_TEST_INFO(random_test_kind),
+ ODP_TEST_INFO(random_test_repeat),
+ ODP_TEST_INFO_NULL,
+};
+
+odp_suiteinfo_t random_suites[] = {
+ {"Random", NULL, NULL, random_suite},
+ ODP_SUITE_INFO_NULL,
+};
+
+int random_main(int argc, char *argv[])
+{
+ int ret;
+
+ /* parse common options: */
+ if (odp_cunit_parse_options(argc, argv))
+ return -1;
+
+ ret = odp_cunit_register(random_suites);
+
+ if (ret == 0)
+ ret = odp_cunit_run();
+
+ return ret;
+}
diff --git a/test/validation/api/random/random.h b/test/validation/api/random/random.h
new file mode 100644
index 000000000..c4bca7827
--- /dev/null
+++ b/test/validation/api/random/random.h
@@ -0,0 +1,26 @@
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _ODP_TEST_RANDOM_H_
+#define _ODP_TEST_RANDOM_H_
+
+#include <odp_cunit_common.h>
+
+/* test functions: */
+void random_test_get_size(void);
+void random_test_kind(void);
+void random_test_repeat(void);
+
+/* test arrays: */
+extern odp_testinfo_t random_suite[];
+
+/* test registry: */
+extern odp_suiteinfo_t random_suites[];
+
+/* main test program: */
+int random_main(int argc, char *argv[]);
+
+#endif
diff --git a/test/validation/api/random/random_main.c b/test/validation/api/random/random_main.c
new file mode 100644
index 000000000..ca9f5262d
--- /dev/null
+++ b/test/validation/api/random/random_main.c
@@ -0,0 +1,14 @@
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "config.h"
+
+#include "random.h"
+
+int main(int argc, char *argv[])
+{
+ return random_main(argc, argv);
+}