This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".
The branch, master has been updated
via 92ae191876c39a3f5d4fba63e58dd9e8c444239b (commit)
from 6104182f253161f17fd3ca5a377ed1bac62e366e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 92ae191876c39a3f5d4fba63e58dd9e8c444239b
Author: Maxim Uvarov <maxim.uvarov(a)linaro.org>
Date: Wed Dec 21 16:38:31 2016 +0300
test: tm: queue id can be not updated
get_unique_id() function on error do not update it's second and
third arguments (unique_id and is_ipv4). gcc -O3 finds that
and traps compilation.
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
Tested-and-reviewed-by: Mike Holmes <mike.holmes(a)linaro.org>
diff --git a/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c b/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c
index fcc7187..0271758 100644
--- a/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c
+++ b/test/common_plat/validation/api/traffic_mngr/traffic_mngr.c
@@ -944,8 +944,8 @@ static void dump_rcvd_pkts(uint32_t first_rcv_idx, uint32_t last_rcv_idx)
odp_packet_t rcv_pkt;
uint32_t rcv_idx;
int32_t xmt_idx;
- uint16_t unique_id;
- uint8_t is_ipv4;
+ uint16_t unique_id = 0;
+ uint8_t is_ipv4 = 0;
int rc;
for (rcv_idx = first_rcv_idx; rcv_idx <= last_rcv_idx; rcv_idx++) {
-----------------------------------------------------------------------
Summary of changes:
test/common_plat/validation/api/traffic_mngr/traffic_mngr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
hooks/post-receive
--
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".
The branch, next has been updated
via f0eb70696dd46d7fd35e221dfc86733ae26f38ad (commit)
from f47f91e7e867fb55e5f41df66b0c4ef6fbf3a293 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f0eb70696dd46d7fd35e221dfc86733ae26f38ad
Author: Christophe Milard <christophe.milard(a)linaro.org>
Date: Tue Dec 6 18:25:32 2016 +0100
linux-gen: _ishm: unlinking files asap for cleaner termination
_ishm now unlinks the created files as soon as possible, hence reducing
the chance to see left-overs, if ODP terminates abnormaly.
This does not provide 100% guaranty: if we are unlucky enough,
ODP may be killed between open() and unlink().
Also this method excludes exported files (flag _ODP_ISHM_EXPORT),
whose names shall be seen in the file system.
Signed-off-by: Christophe Milard <christophe.milard(a)linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c
index a0188ad..33ef731 100644
--- a/platform/linux-generic/_ishm.c
+++ b/platform/linux-generic/_ishm.c
@@ -70,6 +70,7 @@
#include <sys/types.h>
#include <inttypes.h>
#include <sys/wait.h>
+#include <libgen.h>
/*
* Maximum number of internal shared memory blocks.
@@ -159,6 +160,7 @@ typedef struct ishm_block {
char exptname[ISHM_FILENAME_MAXLEN]; /* name of the export file */
uint32_t user_flags; /* any flags the user want to remember. */
uint32_t flags; /* block creation flags. */
+ uint32_t external_fd:1; /* block FD was externally provided */
uint64_t user_len; /* length, as requested at reserve time. */
void *start; /* only valid if _ODP_ISHM_SINGLE_VA is set*/
uint64_t len; /* length. multiple of page size. 0 if free*/
@@ -452,15 +454,17 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
ODP_ERR("ftruncate failed: fd=%d, err=%s.\n",
fd, strerror(errno));
close(fd);
+ unlink(filename);
return -1;
}
- strncpy(new_block->filename, filename, ISHM_FILENAME_MAXLEN - 1);
/* if _ODP_ISHM_EXPORT is set, create a description file for
* external ref:
*/
if (flags & _ODP_ISHM_EXPORT) {
+ strncpy(new_block->filename, filename,
+ ISHM_FILENAME_MAXLEN - 1);
snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN,
ISHM_EXPTNAME_FORMAT,
odp_global_data.main_pid,
@@ -483,6 +487,8 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
}
} else {
new_block->exptname[0] = 0;
+ /* remove the file from the filesystem, keeping its fd open */
+ unlink(filename);
}
return fd;
@@ -814,6 +820,9 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd,
return -1;
}
new_block->huge = EXTERNAL;
+ new_block->external_fd = 1;
+ } else {
+ new_block->external_fd = 0;
}
/* Otherwise, Try first huge pages when possible and needed: */
@@ -865,8 +874,9 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd,
/* if neither huge pages or normal pages works, we cannot proceed: */
if ((fd < 0) || (addr == NULL) || (len == 0)) {
- if ((new_block->filename[0]) && (fd >= 0))
+ if ((!new_block->external_fd) && (fd >= 0))
close(fd);
+ delete_file(new_block);
odp_spinlock_unlock(&ishm_tbl->lock);
ODP_ERR("_ishm_reserve failed.\n");
return -1;
-----------------------------------------------------------------------
Summary of changes:
platform/linux-generic/_ishm.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
hooks/post-receive
--
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".
The branch, api-next has been updated
via b843386fb4f62585c637bc81e04c0b44fa907aab (commit)
from f6772a1c2c86c1982d68fc50480748751ac36e98 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b843386fb4f62585c637bc81e04c0b44fa907aab
Author: Christophe Milard <christophe.milard(a)linaro.org>
Date: Tue Dec 6 18:25:32 2016 +0100
linux-gen: _ishm: unlinking files asap for cleaner termination
_ishm now unlinks the created files as soon as possible, hence reducing
the chance to see left-overs, if ODP terminates abnormaly.
This does not provide 100% guaranty: if we are unlucky enough,
ODP may be killed between open() and unlink().
Also this method excludes exported files (flag _ODP_ISHM_EXPORT),
whose names shall be seen in the file system.
Signed-off-by: Christophe Milard <christophe.milard(a)linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c
index 449e357..efdb7bc 100644
--- a/platform/linux-generic/_ishm.c
+++ b/platform/linux-generic/_ishm.c
@@ -71,6 +71,7 @@
#include <sys/types.h>
#include <inttypes.h>
#include <sys/wait.h>
+#include <libgen.h>
/*
* Maximum number of internal shared memory blocks.
@@ -159,6 +160,7 @@ typedef struct ishm_block {
char exptname[ISHM_FILENAME_MAXLEN]; /* name of the export file */
uint32_t user_flags; /* any flags the user want to remember. */
uint32_t flags; /* block creation flags. */
+ uint32_t external_fd:1; /* block FD was externally provided */
uint64_t user_len; /* length, as requested at reserve time. */
void *start; /* only valid if _ODP_ISHM_SINGLE_VA is set*/
uint64_t len; /* length. multiple of page size. 0 if free*/
@@ -452,15 +454,17 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
ODP_ERR("ftruncate failed: fd=%d, err=%s.\n",
fd, strerror(errno));
close(fd);
+ unlink(filename);
return -1;
}
- strncpy(new_block->filename, filename, ISHM_FILENAME_MAXLEN - 1);
/* if _ODP_ISHM_EXPORT is set, create a description file for
* external ref:
*/
if (flags & _ODP_ISHM_EXPORT) {
+ strncpy(new_block->filename, filename,
+ ISHM_FILENAME_MAXLEN - 1);
snprintf(new_block->exptname, ISHM_FILENAME_MAXLEN,
ISHM_EXPTNAME_FORMAT,
odp_global_data.main_pid,
@@ -483,6 +487,8 @@ static int create_file(int block_index, huge_flag_t huge, uint64_t len,
}
} else {
new_block->exptname[0] = 0;
+ /* remove the file from the filesystem, keeping its fd open */
+ unlink(filename);
}
return fd;
@@ -814,6 +820,9 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd,
return -1;
}
new_block->huge = EXTERNAL;
+ new_block->external_fd = 1;
+ } else {
+ new_block->external_fd = 0;
}
/* Otherwise, Try first huge pages when possible and needed: */
@@ -865,8 +874,9 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd,
/* if neither huge pages or normal pages works, we cannot proceed: */
if ((fd < 0) || (addr == NULL) || (len == 0)) {
- if ((new_block->filename[0]) && (fd >= 0))
+ if ((!new_block->external_fd) && (fd >= 0))
close(fd);
+ delete_file(new_block);
odp_spinlock_unlock(&ishm_tbl->lock);
ODP_ERR("_ishm_reserve failed.\n");
return -1;
-----------------------------------------------------------------------
Summary of changes:
platform/linux-generic/_ishm.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
hooks/post-receive
--
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".
The branch, next has been updated
via 472b66cd232bd0594ac235c3852bfbc04c3f19d7 (commit)
from 1becf47561d1230b5bba747d33b11eff829803de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 472b66cd232bd0594ac235c3852bfbc04c3f19d7
Author: Christophe Milard <christophe.milard(a)linaro.org>
Date: Thu Nov 24 17:22:30 2016 +0100
test: linux-gen: api: shmem: test sharing memory between ODP instances
The platform tests odp/test/linux-generic/validation/api/shmem
are updated to both test ODP<->linux process memory sharing, but also test
ODP to ODP (different instances) memory sharing.
shmem_linux is the main test process, and shmem_linux.c contains (at
file top) a chart flow of the test procedure.
Signed-off-by: Christophe Milard <christophe.milard(a)linaro.org>
Reviewed-and-tested-by: Bill Fischofer <bill.fischofer(a)linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
diff --git a/test/linux-generic/validation/api/shmem/.gitignore b/test/linux-generic/validation/api/shmem/.gitignore
index 7627079..74195f5 100644
--- a/test/linux-generic/validation/api/shmem/.gitignore
+++ b/test/linux-generic/validation/api/shmem/.gitignore
@@ -1,2 +1,3 @@
shmem_linux
-shmem_odp
+shmem_odp1
+shmem_odp2
diff --git a/test/linux-generic/validation/api/shmem/Makefile.am b/test/linux-generic/validation/api/shmem/Makefile.am
index 341747f..b0ae627 100644
--- a/test/linux-generic/validation/api/shmem/Makefile.am
+++ b/test/linux-generic/validation/api/shmem/Makefile.am
@@ -2,19 +2,27 @@ include ../Makefile.inc
#the main test program is shmem_linux, which, in turn, starts a shmem_odp:
test_PROGRAMS = shmem_linux$(EXEEXT)
-test_extra_PROGRAMS = shmem_odp$(EXEEXT)
+test_extra_PROGRAMS = shmem_odp1$(EXEEXT) shmem_odp2$(EXEEXT)
test_extradir = $(testdir)
#shmem_linux is stand alone, pure linux (no ODP):
dist_shmem_linux_SOURCES = shmem_linux.c
shmem_linux_LDFLAGS = $(AM_LDFLAGS) -lrt
-#shmem_odp is the odp part:
-dist_shmem_odp_SOURCES = shmem_odp.c
-shmem_odp_CFLAGS = $(AM_CFLAGS) \
+#shmem_odp1 and shmem_odp2 are the 2 ODP processes:
+dist_shmem_odp1_SOURCES = shmem_odp1.c
+shmem_odp1_CFLAGS = $(AM_CFLAGS) \
$(INCCUNIT_COMMON) \
$(INCODP)
-shmem_odp_LDFLAGS = $(AM_LDFLAGS)
-shmem_odp_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
+shmem_odp1_LDFLAGS = $(AM_LDFLAGS)
+shmem_odp1_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
-noinst_HEADERS = shmem_common.h shmem_linux.h shmem_odp.h
+dist_shmem_odp2_SOURCES = shmem_odp2.c
+shmem_odp2_CFLAGS = $(AM_CFLAGS) \
+ $(INCCUNIT_COMMON) \
+ $(INCODP)
+shmem_odp2_LDFLAGS = $(AM_LDFLAGS)
+shmem_odp2_LDADD = $(LIBCUNIT_COMMON) $(LIBODP)
+
+
+noinst_HEADERS = shmem_common.h shmem_linux.h shmem_odp1.h shmem_odp2.h
diff --git a/test/linux-generic/validation/api/shmem/shmem_linux.c b/test/linux-generic/validation/api/shmem/shmem_linux.c
index 9ab0e2b..39473f3 100644
--- a/test/linux-generic/validation/api/shmem/shmem_linux.c
+++ b/test/linux-generic/validation/api/shmem/shmem_linux.c
@@ -5,8 +5,10 @@
*/
/* this test makes sure that odp shared memory created with the ODP_SHM_PROC
- * flag is visible under linux. It therefore checks both that the device
- * name under /dev/shm is correct, and also checks that the memory contents
+ * flag is visible under linux, and checks that memory created with the
+ * ODP_SHM_EXPORT flag is visible by other ODP instances.
+ * It therefore checks both that the link
+ * name under /tmp is correct, and also checks that the memory contents
* is indeed shared.
* we want:
* -the odp test to run using C UNIT
@@ -15,18 +17,47 @@
*
* To achieve this, the flow of operations is as follows:
*
- * linux process (main, non odp) | ODP process
- * (shmem_linux.c) | (shmem_odp.c)
+ * linux process (main, non odp) |
+ * (shmem_linux.c) |
+ * |
+ * |
* |
* main() |
- * forks odp process | allocate shmem
- * wait for named pipe creation | populate shmem
+ * forks odp_app1 process |
+ * wait for named pipe creation |
+ * |
+ * | ODP_APP1 process
+ * | (shmem_odp1.c)
+ * |
+ * | allocate shmem
+ * | populate shmem
* | create named pipe
- * read shared memory | wait for test report in fifo
+ * | wait for test report in fifo...
+ * read shared memory |
* check if memory contents is OK |
- * if OK, write "S" in fifo, else "F" | report success or failure to C-Unit
- * wait for child terminaison & status| terminate with usual F/S status
+ * If not OK, write "F" in fifo and |
+ * exit with failure code. | -------------------
+ * |
+ * forks odp app2 process | ODP APP2 process
+ * wait for child terminaison & status| (shmem_odp2.c)
+ * | lookup ODP_APP1 shared memory,
+ * | check if memory contents is OK
+ * | Exit(0) on success, exit(1) on fail
+ * If child failed, write "F" in fifo |
+ * exit with failure code. | -------------------
+ * |
+ * OK, write "S" in fifo, |
+ * wait for child terminaison & status|
* terminate with same status as child|
+ * | ODP APP1 process
+ * | (shmem_odp1.c)
+ * |
+ * | ...(continued)
+ * | read S(success) or F(fail) from fifo
+ * | report success or failure to C-Unit
+ * | Exit(0) on success, exit(1) on fail
+ * wait for child terminaison & status |
+ * terminate with same status as child |
* |
* \|/
* time
@@ -49,7 +80,8 @@
#include "shmem_linux.h"
#include "shmem_common.h"
-#define ODP_APP_NAME "shmem_odp" /* name of the odp program, in this dir */
+#define ODP_APP1_NAME "shmem_odp1" /* name of the odp1 program, in this dir */
+#define ODP_APP2_NAME "shmem_odp2" /* name of the odp2 program, in this dir */
#define DEVNAME_FMT "/tmp/odp-%" PRIu64 "-shm-%s" /* odp-<pid>-shm-<name> */
#define MAX_FIFO_WAIT 30 /* Max time waiting for the fifo (sec) */
@@ -117,7 +149,7 @@ void test_success(char *fifo_name, int fd, pid_t odp_app)
/* write "Success" to the FIFO */
nb_char = write(fd, &result, sizeof(char));
close(fd);
- /* wait for the odp app to terminate */
+ /* wait for the odp app1 to terminate */
waitpid(odp_app, &status, 0);
/* if the write failed, report an error anyway */
if (nb_char != 1)
@@ -134,10 +166,10 @@ void test_failure(char *fifo_name, int fd, pid_t odp_app)
int nb_char __attribute__((unused)); /*ignored: we fail anyway */
result = TEST_FAILURE;
- /* write "Success" to the FIFO */
+ /* write "Failure" to the FIFO */
nb_char = write(fd, &result, sizeof(char));
close(fd);
- /* wait for the odp app to terminate */
+ /* wait for the odp app1 to terminate */
waitpid(odp_app, &status, 0);
unlink(fifo_name);
exit(1); /* error */
@@ -146,36 +178,43 @@ void test_failure(char *fifo_name, int fd, pid_t odp_app)
int main(int argc __attribute__((unused)), char *argv[])
{
char prg_name[PATH_MAX];
- char odp_name[PATH_MAX];
+ char odp_name1[PATH_MAX];
+ char odp_name2[PATH_MAX];
int nb_sec;
- uint64_t size;
- pid_t odp_app;
- char *odp_params = NULL;
+ int size;
+ pid_t odp_app1;
+ pid_t odp_app2;
+ char *odp_params1 = NULL;
+ char *odp_params2[3];
+ char pid1[10];
char fifo_name[PATH_MAX]; /* fifo for linux->odp feedback */
int fifo_fd = -1;
- char shm_devname[PATH_MAX];/* shared mem device name.*/
+ char shm_filename[PATH_MAX];/* shared mem device name, under /dev/shm */
uint64_t len;
uint32_t flags;
uint32_t align;
int shm_fd;
test_shared_linux_data_t *addr;
+ int app2_status;
- /* odp app is in the same directory as this file: */
+ /* odp_app1 is in the same directory as this file: */
strncpy(prg_name, argv[0], PATH_MAX - 1);
- sprintf(odp_name, "%s/%s", dirname(prg_name), ODP_APP_NAME);
+ sprintf(odp_name1, "%s/%s", dirname(prg_name), ODP_APP1_NAME);
/* start the ODP application: */
- odp_app = fork();
- if (odp_app < 0) /* error */
+ odp_app1 = fork();
+ if (odp_app1 < 0) /* error */
exit(1);
- if (odp_app == 0) /* child */
- execv(odp_name, &odp_params);
+ if (odp_app1 == 0) { /* child */
+ execv(odp_name1, &odp_params1); /* no return unless error */
+ fprintf(stderr, "execv failed: %s\n", strerror(errno));
+ }
/* wait max 30 sec for the fifo to be created by the ODP side.
* Just die if time expire as there is no fifo to communicate
* through... */
- sprintf(fifo_name, FIFO_NAME_FMT, odp_app);
+ sprintf(fifo_name, FIFO_NAME_FMT, odp_app1);
for (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) {
fifo_fd = open(fifo_name, O_WRONLY);
if (fifo_fd >= 0)
@@ -191,17 +230,17 @@ int main(int argc __attribute__((unused)), char *argv[])
* check to see if linux can see the created shared memory: */
/* read the shared memory attributes (includes the shm filename): */
- if (read_shmem_attribues(odp_app, ODP_SHM_NAME,
- shm_devname, &len, &flags, &align) != 0)
- test_failure(fifo_name, fifo_fd, odp_app);
+ if (read_shmem_attribues(odp_app1, ODP_SHM_NAME,
+ shm_filename, &len, &flags, &align) != 0)
+ test_failure(fifo_name, fifo_fd, odp_app1);
/* open the shm filename (which is either on /tmp or on hugetlbfs)
* O_CREAT flag not given => failure if shm_devname does not already
* exist */
- shm_fd = open(shm_devname, O_RDONLY,
+ shm_fd = open(shm_filename, O_RDONLY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (shm_fd == -1)
- test_failure(fifo_name, fifo_fd, odp_app);
+ test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
/* linux ODP guarantees page size alignement. Larger alignment may
* fail as 2 different processes will have fully unrelated
@@ -210,12 +249,41 @@ int main(int argc __attribute__((unused)), char *argv[])
size = sizeof(test_shared_linux_data_t);
addr = mmap(NULL, size, PROT_READ, MAP_SHARED, shm_fd, 0);
- if (addr == MAP_FAILED)
- test_failure(fifo_name, fifo_fd, odp_app);
+ if (addr == MAP_FAILED) {
+ printf("shmem_linux: map failed!\n");
+ test_failure(fifo_name, fifo_fd, odp_app1);
+ }
/* check that we see what the ODP application wrote in the memory */
- if ((addr->foo == TEST_SHARE_FOO) && (addr->bar == TEST_SHARE_BAR))
- test_success(fifo_name, fifo_fd, odp_app);
- else
- test_failure(fifo_name, fifo_fd, odp_app);
+ if ((addr->foo != TEST_SHARE_FOO) || (addr->bar != TEST_SHARE_BAR))
+ test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
+
+ /* odp_app2 is in the same directory as this file: */
+ strncpy(prg_name, argv[0], PATH_MAX - 1);
+ sprintf(odp_name2, "%s/%s", dirname(prg_name), ODP_APP2_NAME);
+
+ /* start the second ODP application with pid of ODP_APP1 as parameter:*/
+ sprintf(pid1, "%d", odp_app1);
+ odp_params2[0] = odp_name2;
+ odp_params2[1] = pid1;
+ odp_params2[2] = NULL;
+ odp_app2 = fork();
+ if (odp_app2 < 0) /* error */
+ exit(1);
+
+ if (odp_app2 == 0) { /* child */
+ execv(odp_name2, odp_params2); /* no return unless error */
+ fprintf(stderr, "execv failed: %s\n", strerror(errno));
+ }
+
+ /* wait for the second ODP application to terminate:
+ * status is OK if that second ODP application could see the
+ * memory shared by the first one. */
+ waitpid(odp_app2, &app2_status, 0);
+
+ if (app2_status)
+ test_failure(fifo_name, fifo_fd, odp_app1); /* no return */
+
+ /* everything looked good: */
+ test_success(fifo_name, fifo_fd, odp_app1);
}
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp.c b/test/linux-generic/validation/api/shmem/shmem_odp1.c
similarity index 81%
rename from test/linux-generic/validation/api/shmem/shmem_odp.c
rename to test/linux-generic/validation/api/shmem/shmem_odp1.c
index a1f750f..3869c2e 100644
--- a/test/linux-generic/validation/api/shmem/shmem_odp.c
+++ b/test/linux-generic/validation/api/shmem/shmem_odp1.c
@@ -13,7 +13,7 @@
#include <fcntl.h>
#include <odp_cunit_common.h>
-#include "shmem_odp.h"
+#include "shmem_odp1.h"
#include "shmem_common.h"
#define TEST_SHARE_FOO (0xf0f0f0f0)
@@ -27,9 +27,10 @@ void shmem_test_odp_shm_proc(void)
test_shared_data_t *test_shared_data;
char test_result;
+ /* reminder: ODP_SHM_PROC => export to linux, ODP_SHM_EXPORT=>to odp */
shm = odp_shm_reserve(ODP_SHM_NAME,
sizeof(test_shared_data_t),
- ALIGN_SIZE, ODP_SHM_PROC);
+ ALIGN_SIZE, ODP_SHM_PROC | ODP_SHM_EXPORT);
CU_ASSERT_FATAL(ODP_SHM_INVALID != shm);
test_shared_data = odp_shm_addr(shm);
CU_ASSERT_FATAL(NULL != test_shared_data);
@@ -39,15 +40,18 @@ void shmem_test_odp_shm_proc(void)
odp_mb_full();
/* open the fifo: this will indicate to linux process that it can
- * start the shmem lookup and check if it sees the data */
+ * start the shmem lookups and check if it sees the data */
sprintf(fifo_name, FIFO_NAME_FMT, getpid());
CU_ASSERT_FATAL(mkfifo(fifo_name, 0666) == 0);
/* read from the fifo: the linux process result: */
+ printf("shmem_odp1: opening fifo: %s\n", fifo_name);
fd = open(fifo_name, O_RDONLY);
CU_ASSERT_FATAL(fd >= 0);
+ printf("shmem_odp1: reading fifo: %s\n", fifo_name);
CU_ASSERT(read(fd, &test_result, sizeof(char)) == 1);
+ printf("shmem_odp1: closing fifo: %s\n", fifo_name);
close(fd);
CU_ASSERT_FATAL(test_result == TEST_SUCCESS);
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp.h b/test/linux-generic/validation/api/shmem/shmem_odp1.h
similarity index 100%
copy from test/linux-generic/validation/api/shmem/shmem_odp.h
copy to test/linux-generic/validation/api/shmem/shmem_odp1.h
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp2.c b/test/linux-generic/validation/api/shmem/shmem_odp2.c
new file mode 100644
index 0000000..e39dc76
--- /dev/null
+++ b/test/linux-generic/validation/api/shmem/shmem_odp2.c
@@ -0,0 +1,95 @@
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <odp.h>
+#include <linux/limits.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include <odp_cunit_common.h>
+#include "shmem_odp2.h"
+#include "shmem_common.h"
+
+#define TEST_SHARE_FOO (0xf0f0f0f0)
+#define TEST_SHARE_BAR (0xf0f0f0f)
+
+/* The C unit test harness is run by ODP1 app which will be told the return
+ * staus of this process. See top of shmem_linux.c for chart flow of events
+ */
+int main(int argc, char *argv[])
+{
+ odp_instance_t odp1;
+ odp_instance_t odp2;
+ odp_shm_t shm;
+ test_shared_data_t *test_shared_data;
+
+ /* odp init: */
+ if (0 != odp_init_global(&odp2, NULL, NULL)) {
+ fprintf(stderr, "error: odp_init_global() failed.\n");
+ return 1;
+ }
+ if (0 != odp_init_local(odp2, ODP_THREAD_CONTROL)) {
+ fprintf(stderr, "error: odp_init_local() failed.\n");
+ return 1;
+ }
+
+ /* test: map ODP1 memory and check its contents:
+ * The pid of the ODP instantiation process sharing its memory
+ * is given as first arg. In linux-generic ODP, this pid is actually
+ * the ODP instance */
+ if (argc != 2) {
+ fprintf(stderr, "One single parameter expected, %d found.\n",
+ argc);
+ return 1;
+ }
+ odp1 = (odp_instance_t)atoi(argv[1]);
+
+ printf("shmem_odp2: trying to grab %s from pid %d\n",
+ ODP_SHM_NAME, (int)odp1);
+ shm = odp_shm_import(ODP_SHM_NAME, odp1, ODP_SHM_NAME);
+ if (shm == ODP_SHM_INVALID) {
+ fprintf(stderr, "error: odp_shm_lookup_external failed.\n");
+ return 1;
+ }
+
+ test_shared_data = odp_shm_addr(shm);
+ if (test_shared_data == NULL) {
+ fprintf(stderr, "error: odp_shm_addr failed.\n");
+ return 1;
+ }
+
+ if (test_shared_data->foo != TEST_SHARE_FOO) {
+ fprintf(stderr, "error: Invalid data TEST_SHARE_FOO.\n");
+ return 1;
+ }
+
+ if (test_shared_data->bar != TEST_SHARE_BAR) {
+ fprintf(stderr, "error: Invalid data TEST_SHARE_BAR.\n");
+ return 1;
+ }
+
+ if (odp_shm_free(shm) != 0) {
+ fprintf(stderr, "error: odp_shm_free() failed.\n");
+ return 1;
+ }
+
+ /* odp term: */
+ if (0 != odp_term_local()) {
+ fprintf(stderr, "error: odp_term_local() failed.\n");
+ return 1;
+ }
+
+ if (0 != odp_term_global(odp2)) {
+ fprintf(stderr, "error: odp_term_global() failed.\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/test/linux-generic/validation/api/shmem/shmem_odp.h b/test/linux-generic/validation/api/shmem/shmem_odp2.h
similarity index 76%
rename from test/linux-generic/validation/api/shmem/shmem_odp.h
rename to test/linux-generic/validation/api/shmem/shmem_odp2.h
index 614bbf8..a8db909 100644
--- a/test/linux-generic/validation/api/shmem/shmem_odp.h
+++ b/test/linux-generic/validation/api/shmem/shmem_odp2.h
@@ -4,4 +4,4 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-void shmem_test_odp_shm_proc(void);
+int main(int argc, char *argv[]);
-----------------------------------------------------------------------
Summary of changes:
test/linux-generic/validation/api/shmem/.gitignore | 3 +-
.../linux-generic/validation/api/shmem/Makefile.am | 22 ++--
.../validation/api/shmem/shmem_linux.c | 140 +++++++++++++++------
.../api/shmem/{shmem_odp.c => shmem_odp1.c} | 10 +-
.../api/shmem/{shmem_odp.h => shmem_odp1.h} | 0
.../validation/api/shmem/shmem_odp2.c | 95 ++++++++++++++
.../api/shmem/{shmem_odp.h => shmem_odp2.h} | 2 +-
7 files changed, 224 insertions(+), 48 deletions(-)
rename test/linux-generic/validation/api/shmem/{shmem_odp.c => shmem_odp1.c} (81%)
copy test/linux-generic/validation/api/shmem/{shmem_odp.h => shmem_odp1.h} (100%)
create mode 100644 test/linux-generic/validation/api/shmem/shmem_odp2.c
rename test/linux-generic/validation/api/shmem/{shmem_odp.h => shmem_odp2.h} (76%)
hooks/post-receive
--
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".
The branch, api-next has been updated
via f6772a1c2c86c1982d68fc50480748751ac36e98 (commit)
via ea51e9f8dba20f06b56c3e293b5b1eebc01e3d71 (commit)
via 58a2fd9358675a54f2ed0f43ef3574a7b4a2c7dd (commit)
from 9fa4b3c5efa041351ba915ca35b3dfe252ecb34c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f6772a1c2c86c1982d68fc50480748751ac36e98
Author: Bill Fischofer <bill.fischofer(a)linaro.org>
Date: Mon Dec 12 09:06:17 2016 -0600
doc: userguide: expand crypto documentation to cover random apis
Clean up the crypto section of the User Guide and expand on the
ODP random data APIs.
Signed-off-by: Bill Fischofer <bill.fischofer(a)linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen(a)nokia.com>
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
diff --git a/doc/users-guide/users-guide-crypto.adoc b/doc/users-guide/users-guide-crypto.adoc
index 04b3e87..c18e369 100644
--- a/doc/users-guide/users-guide-crypto.adoc
+++ b/doc/users-guide/users-guide-crypto.adoc
@@ -1,7 +1,8 @@
== Cryptographic services
ODP provides APIs to perform cryptographic operations required by various
-communication protocols (e.g. IPSec). ODP cryptographic APIs are session based.
+communication protocols (_e.g.,_ IPsec). ODP cryptographic APIs are session
+based.
ODP provides APIs for following cryptographic services:
@@ -19,24 +20,26 @@ ODP supports synchronous and asynchronous crypto sessions. For asynchronous
sessions, the output of crypto operation is posted in a queue defined as
the completion queue in its session parameters.
-ODP crypto APIs support chained operation sessions in which hashing and ciphering
-both can be achieved using a single session and operation call. The order of
-cipher and hashing can be controlled by the `auth_cipher_text` session parameter.
+ODP crypto APIs support chained operation sessions in which hashing and
+ciphering both can be achieved using a single session and operation call. The
+order of cipher and hashing can be controlled by the `auth_cipher_text`
+session parameter.
Other Session parameters include algorithms, keys, initialization vector
-(optional), encode or decode, output queue for async mode and output packet pool
-for allocation of an output packet if required.
+(optional), encode or decode, output queue for async mode and output packet
+pool for allocation of an output packet if required.
=== Crypto operations
After session creation, a cryptographic operation can be applied to a packet
using the `odp_crypto_operation()` API. Applications may indicate a preference
-for synchronous or asynchronous processing in the session's `pref_mode` parameter.
-However crypto operations may complete synchronously even if an asynchronous
-preference is indicated, and applications must examine the `posted` output
-parameter from `odp_crypto_operation()` to determine whether the operation has
-completed or if an `ODP_EVENT_CRYPTO_COMPL` notification is expected. In the case
-of an async operation, the `posted` output parameter will be set to true.
+for synchronous or asynchronous processing in the session's `pref_mode`
+parameter. However crypto operations may complete synchronously even if an
+asynchronous preference is indicated, and applications must examine the
+`posted` output parameter from `odp_crypto_operation()` to determine whether
+the operation has completed or if an `ODP_EVENT_CRYPTO_COMPL` notification is
+expected. In the case of an async operation, the `posted` output parameter
+will be set to true.
The operation arguments specify for each packet the areas that are to be
@@ -49,9 +52,9 @@ In case of out-of-place mode output packet is different from input packet as
specified by the application, while in new buffer mode implementation allocates
a new output buffer from the session’s output pool.
-The application can also specify a context associated with a given operation that
-will be retained during async operation and can be retrieved via the completion
-event.
+The application can also specify a context associated with a given operation
+that will be retained during async operation and can be retrieved via the
+completion event.
Results of an asynchronous session will be posted as completion events to the
session’s completion queue, which can be accessed directly or via the ODP
@@ -60,12 +63,60 @@ result. The application has the responsibility to free the completion event.
=== Random number Generation
-ODP provides an API `odp_random_data()` to generate random data bytes. It has
-an argument to specify whether to use system entropy source for random number
-generation or not.
+ODP provides two APIs to generate various kinds of random data bytes. Random
+data is characterized by _kind_, which specifies the "quality" of the
+randomness required. ODP support three kinds of random data:
+
+ODP_RANDOM_BASIC:: No specific requirement other than the data appear to be
+uniformly distributed. Suitable for load-balancing or other non-cryptographic
+use.
+
+ODP_RANDOM_CRYPTO:: Data suitable for cryptographic use. This is a more
+stringent requirement that the data pass tests for statistical randomness.
+
+ODP_RANDOM_TRUE:: Data generated from a hardware entropy source rather than
+any software generated pseudo-random data. May not be available on all
+platforms.
+
+These form a hierarchy with BASIC being the lowest kind of random and TRUE
+behing the highest. The main API for accessing random data is:
+
+[source,c]
+-----
+int32_t odp_random_data(uint8_t buf, uint32_t len, odp_random_kind_t kind);
+-----
+
+The expectation is that lesser-quality random is easier and faster to generate
+while higher-quality random may take more time. Implementations are always free
+to substitute a higher kind of random than the one requested if they are able
+to do so more efficiently, however calls must return a failure indicator
+(rc < 0) if a higher kind of data is requested than the implementation can
+provide. This is most likely the case for ODP_RANDOM_TRUE since not all
+platforms have access to a true hardware random number generator.
+
+The `odp_random_max_kind()` API returns the highest kind of random data
+available on this implementation.
+
+For testing purposes it is often desirable to generate repeatable sequences
+of "random" data. To address this need ODP provides the additional API:
+
+[source,c]
+-----
+int32_t odp_random_test_data(uint8_t buf, uint32_t len, uint64_t *seed);
+-----
+
+This operates the same as `odp_random_data()` except that it always returns
+data of kind `ODP_RANDOM_BASIC` and an additional thread-local `seed`
+parameter is provide that specifies a seed value to use in generating the
+data. This value is updated on each call, so repeated calls with the same
+variable will generate a sequence of random data starting from the initial
+specified seed. If another sequence of calls is made starting with the same
+initial seed value, then `odp_random_test_data()` will return the same
+sequence of data bytes.
=== Capability inquiries
-ODP provides an API interface `odp_crypto_capability()` to inquire implementation’s
-crypto capabilities. This interface returns a bitmask for supported algorithms
-and hardware backed algorithms.
+ODP provides the API `odp_crypto_capability()` to inquire the implementation’s
+crypto capabilities. This interface returns a the maximum number of crypto
+sessions supported as well as bitmasks for supported algorithms and hardware
+backed algorithms.
\ No newline at end of file
commit ea51e9f8dba20f06b56c3e293b5b1eebc01e3d71
Author: Bill Fischofer <bill.fischofer(a)linaro.org>
Date: Mon Dec 12 09:06:16 2016 -0600
doc: userguide: move crypto documentation to its own sub-document
Signed-off-by: Bill Fischofer <bill.fischofer(a)linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen(a)nokia.com>
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
diff --git a/doc/users-guide/Makefile.am b/doc/users-guide/Makefile.am
index a01c717..01b4df3 100644
--- a/doc/users-guide/Makefile.am
+++ b/doc/users-guide/Makefile.am
@@ -2,6 +2,7 @@ include ../Makefile.inc
SRC = $(top_srcdir)/doc/users-guide/users-guide.adoc \
$(top_srcdir)/doc/users-guide/users-guide-cls.adoc \
+ $(top_srcdir)/doc/users-guide/users-guide-crypto.adoc \
$(top_srcdir)/doc/users-guide/users-guide-packet.adoc \
$(top_srcdir)/doc/users-guide/users-guide-pktio.adoc \
$(top_srcdir)/doc/users-guide/users-guide-timer.adoc \
diff --git a/doc/users-guide/users-guide-crypto.adoc b/doc/users-guide/users-guide-crypto.adoc
new file mode 100644
index 0000000..04b3e87
--- /dev/null
+++ b/doc/users-guide/users-guide-crypto.adoc
@@ -0,0 +1,71 @@
+== Cryptographic services
+
+ODP provides APIs to perform cryptographic operations required by various
+communication protocols (e.g. IPSec). ODP cryptographic APIs are session based.
+
+ODP provides APIs for following cryptographic services:
+
+* Ciphering
+* Authentication/data integrity via Keyed-Hashing (HMAC)
+* Random number generation
+* Crypto capability inquiries
+
+=== Crypto Sessions
+
+To apply a cryptographic operation to a packet a session must be created. All
+packets processed by a session share the parameters that define the session.
+
+ODP supports synchronous and asynchronous crypto sessions. For asynchronous
+sessions, the output of crypto operation is posted in a queue defined as
+the completion queue in its session parameters.
+
+ODP crypto APIs support chained operation sessions in which hashing and ciphering
+both can be achieved using a single session and operation call. The order of
+cipher and hashing can be controlled by the `auth_cipher_text` session parameter.
+
+Other Session parameters include algorithms, keys, initialization vector
+(optional), encode or decode, output queue for async mode and output packet pool
+for allocation of an output packet if required.
+
+=== Crypto operations
+
+After session creation, a cryptographic operation can be applied to a packet
+using the `odp_crypto_operation()` API. Applications may indicate a preference
+for synchronous or asynchronous processing in the session's `pref_mode` parameter.
+However crypto operations may complete synchronously even if an asynchronous
+preference is indicated, and applications must examine the `posted` output
+parameter from `odp_crypto_operation()` to determine whether the operation has
+completed or if an `ODP_EVENT_CRYPTO_COMPL` notification is expected. In the case
+of an async operation, the `posted` output parameter will be set to true.
+
+
+The operation arguments specify for each packet the areas that are to be
+encrypted or decrypted and authenticated. Also, there is an option of overriding
+the initialization vector specified in session parameters.
+
+An operation can be executed in in-place, out-of-place or new buffer mode.
+In in-place mode output packet is same as the input packet.
+In case of out-of-place mode output packet is different from input packet as
+specified by the application, while in new buffer mode implementation allocates
+a new output buffer from the session’s output pool.
+
+The application can also specify a context associated with a given operation that
+will be retained during async operation and can be retrieved via the completion
+event.
+
+Results of an asynchronous session will be posted as completion events to the
+session’s completion queue, which can be accessed directly or via the ODP
+scheduler. The completion event contains the status of the operation and the
+result. The application has the responsibility to free the completion event.
+
+=== Random number Generation
+
+ODP provides an API `odp_random_data()` to generate random data bytes. It has
+an argument to specify whether to use system entropy source for random number
+generation or not.
+
+=== Capability inquiries
+
+ODP provides an API interface `odp_crypto_capability()` to inquire implementation’s
+crypto capabilities. This interface returns a bitmask for supported algorithms
+and hardware backed algorithms.
diff --git a/doc/users-guide/users-guide.adoc b/doc/users-guide/users-guide.adoc
index 9a427fa..41c57d1 100755
--- a/doc/users-guide/users-guide.adoc
+++ b/doc/users-guide/users-guide.adoc
@@ -1018,77 +1018,7 @@ include::users-guide-pktio.adoc[]
include::users-guide-timer.adoc[]
-== Cryptographic services
-
-ODP provides APIs to perform cryptographic operations required by various
-communication protocols (e.g. IPSec). ODP cryptographic APIs are session based.
-
-ODP provides APIs for following cryptographic services:
-
-* Ciphering
-* Authentication/data integrity via Keyed-Hashing (HMAC)
-* Random number generation
-* Crypto capability inquiries
-
-=== Crypto Sessions
-
-To apply a cryptographic operation to a packet a session must be created. All
-packets processed by a session share the parameters that define the session.
-
-ODP supports synchronous and asynchronous crypto sessions. For asynchronous
-sessions, the output of crypto operation is posted in a queue defined as
-the completion queue in its session parameters.
-
-ODP crypto APIs support chained operation sessions in which hashing and ciphering
-both can be achieved using a single session and operation call. The order of
-cipher and hashing can be controlled by the `auth_cipher_text` session parameter.
-
-Other Session parameters include algorithms, keys, initialization vector
-(optional), encode or decode, output queue for async mode and output packet pool
-for allocation of an output packet if required.
-
-=== Crypto operations
-
-After session creation, a cryptographic operation can be applied to a packet
-using the `odp_crypto_operation()` API. Applications may indicate a preference
-for synchronous or asynchronous processing in the session's `pref_mode` parameter.
-However crypto operations may complete synchronously even if an asynchronous
-preference is indicated, and applications must examine the `posted` output
-parameter from `odp_crypto_operation()` to determine whether the operation has
-completed or if an `ODP_EVENT_CRYPTO_COMPL` notification is expected. In the case
-of an async operation, the `posted` output parameter will be set to true.
-
-
-The operation arguments specify for each packet the areas that are to be
-encrypted or decrypted and authenticated. Also, there is an option of overriding
-the initialization vector specified in session parameters.
-
-An operation can be executed in in-place, out-of-place or new buffer mode.
-In in-place mode output packet is same as the input packet.
-In case of out-of-place mode output packet is different from input packet as
-specified by the application, while in new buffer mode implementation allocates
-a new output buffer from the session’s output pool.
-
-The application can also specify a context associated with a given operation that
-will be retained during async operation and can be retrieved via the completion
-event.
-
-Results of an asynchronous session will be posted as completion events to the
-session’s completion queue, which can be accessed directly or via the ODP
-scheduler. The completion event contains the status of the operation and the
-result. The application has the responsibility to free the completion event.
-
-=== Random number Generation
-
-ODP provides an API `odp_random_data()` to generate random data bytes. It has
-an argument to specify whether to use system entropy source for random number
-generation or not.
-
-=== Capability inquiries
-
-ODP provides an API interface `odp_crypto_capability()` to inquire implementation’s
-crypto capabilities. This interface returns a bitmask for supported algorithms
-and hardware backed algorithms.
+include::users-guide-crypto.adoc[]
include::users-guide-tm.adoc[]
commit 58a2fd9358675a54f2ed0f43ef3574a7b4a2c7dd
Author: Bill Fischofer <bill.fischofer(a)linaro.org>
Date: Mon Dec 12 09:06:15 2016 -0600
api: random: add explicit controls over random data
Rework the odp_random_data() API to replace the use_entropy with an
explicit odp_random_kind parameter that controls the type of random
desired. Two new APIs are also introduced:
- odp_random_max_kind() returns the maximum kind of random data available
- odp_random_test_data() permits applications to generate repeatable
random sequences for testing purposes
Signed-off-by: Bill Fischofer <bill.fischofer(a)linaro.org>
Reviewed-by: Petri Savolainen <petri.savolainen(a)nokia.com>
Signed-off-by: Maxim Uvarov <maxim.uvarov(a)linaro.org>
diff --git a/include/odp/api/spec/random.h b/include/odp/api/spec/random.h
index 00fa15b..4765475 100644
--- a/include/odp/api/spec/random.h
+++ b/include/odp/api/spec/random.h
@@ -24,18 +24,82 @@ extern "C" {
*/
/**
+ * Random kind selector
+ *
+ * The kind of random denotes the statistical quality of the random data
+ * returned. Basic random simply appears uniformly distributed, Cryptographic
+ * random is statistically random and suitable for use by cryptographic
+ * functions. True random is generated from a hardware entropy source rather
+ * than an algorithm and is thus completely unpredictable. These form a
+ * hierarchy where higher quality data is presumably more costly to generate
+ * than lower quality data.
+ */
+typedef enum {
+ /** Basic random, presumably pseudo-random generated by SW. This
+ * is the lowest kind of random */
+ ODP_RANDOM_BASIC,
+ /** Cryptographic quality random */
+ ODP_RANDOM_CRYPTO,
+ /** True random, generated from a HW entropy source. This is the
+ * highest kind of random */
+ ODP_RANDOM_TRUE,
+} odp_random_kind_t;
+
+/**
+ * Query random max kind
+ *
+ * Implementations support the returned max kind and all kinds weaker than it.
+ *
+ * @return kind The maximum odp_random_kind_t supported by this implementation
+ */
+odp_random_kind_t odp_random_max_kind(void);
+
+/**
* Generate random byte data
*
+ * The intent in supporting different kinds of random data is to allow
+ * tradeoffs between performance and the quality of random data needed. The
+ * assumption is that basic random is cheap while true random is relatively
+ * expensive in terms of time to generate, with cryptographic random being
+ * something in between. Implementations that support highly efficient true
+ * random are free to use this for all requested kinds. So it is always
+ * permissible to "upgrade" a random data request, but never to "downgrade"
+ * such requests.
+ *
* @param[out] buf Output buffer
- * @param size Size of output buffer
- * @param use_entropy Use entropy
+ * @param len Length of output buffer in bytes
+ * @param kind Specifies the type of random data required. Request
+ * is expected to fail if the implementation is unable to
+ * provide the requested type.
+ *
+ * @return Number of bytes written
+ * @retval <0 on failure
+ */
+int32_t odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind);
+
+/**
+ * Generate repeatable random data for testing purposes
+ *
+ * For testing purposes it is often useful to generate "random" sequences that
+ * are repeatable. This is accomplished by supplying a seed value that is used
+ * for pseudo-random data generation. The caller-provided seed value is
+ * updated for each call to continue the sequence. Restarting a series of
+ * calls with the same initial seed value will generate the same sequence of
+ * random test data.
+ *
+ * This function returns data of ODP_RANDOM_BASIC quality and should be used
+ * only for testing purposes. Use odp_random_data() for production.
*
- * @todo Define the implication of the use_entropy parameter
+ * @param[out] buf Output buffer
+ * @param len Length of output buffer in bytes
+ * @param[in,out] seed Seed value to use. This must be a thread-local
+ * variable. Results are undefined if multiple threads
+ * call this routine with the same seed variable.
*
* @return Number of bytes written
* @retval <0 on failure
*/
-int32_t odp_random_data(uint8_t *buf, int32_t size, odp_bool_t use_entropy);
+int32_t odp_random_test_data(uint8_t *buf, uint32_t len, uint64_t *seed);
/**
* @}
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index 6b7d60e..5808d16 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <odp_posix_extensions.h>
#include <odp/api/crypto.h>
#include <odp_internal.h>
#include <odp/api/atomic.h>
@@ -19,6 +20,7 @@
#include <odp_packet_internal.h>
#include <string.h>
+#include <stdlib.h>
#include <openssl/des.h>
#include <openssl/rand.h>
@@ -999,12 +1001,48 @@ int odp_crypto_term_global(void)
return rc;
}
-int32_t
-odp_random_data(uint8_t *buf, int32_t len, odp_bool_t use_entropy ODP_UNUSED)
+odp_random_kind_t odp_random_max_kind(void)
{
- int32_t rc;
- rc = RAND_bytes(buf, len);
- return (1 == rc) ? len /*success*/: -1 /*failure*/;
+ return ODP_RANDOM_CRYPTO;
+}
+
+int32_t odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind)
+{
+ int rc;
+
+ switch (kind) {
+ case ODP_RANDOM_BASIC:
+ RAND_pseudo_bytes(buf, len);
+ return len;
+
+ case ODP_RANDOM_CRYPTO:
+ rc = RAND_bytes(buf, len);
+ return (1 == rc) ? (int)len /*success*/: -1 /*failure*/;
+
+ case ODP_RANDOM_TRUE:
+ default:
+ return -1;
+ }
+}
+
+int32_t odp_random_test_data(uint8_t *buf, uint32_t len, uint64_t *seed)
+{
+ union {
+ uint32_t rand_word;
+ uint8_t rand_byte[4];
+ } u;
+ uint32_t i = 0, j;
+ uint32_t seed32 = (*seed) & 0xffffffff;
+
+ while (i < len) {
+ u.rand_word = rand_r(&seed32);
+
+ for (j = 0; j < 4 && i < len; j++, i++)
+ *buf++ = u.rand_byte[j];
+ }
+
+ *seed = seed32;
+ return len;
}
odp_crypto_compl_t odp_crypto_compl_from_event(odp_event_t ev)
diff --git a/test/common_plat/validation/api/random/random.c b/test/common_plat/validation/api/random/random.c
index 7572366..a0e2ef7 100644
--- a/test/common_plat/validation/api/random/random.c
+++ b/test/common_plat/validation/api/random/random.c
@@ -13,12 +13,58 @@ void random_test_get_size(void)
int32_t ret;
uint8_t buf[32];
- ret = odp_random_data(buf, sizeof(buf), false);
+ 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,
};
diff --git a/test/common_plat/validation/api/random/random.h b/test/common_plat/validation/api/random/random.h
index 26202cc..c4bca78 100644
--- a/test/common_plat/validation/api/random/random.h
+++ b/test/common_plat/validation/api/random/random.h
@@ -11,6 +11,8 @@
/* 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[];
-----------------------------------------------------------------------
Summary of changes:
doc/users-guide/Makefile.am | 1 +
doc/users-guide/users-guide-crypto.adoc | 122 ++++++++++++++++++++++++
doc/users-guide/users-guide.adoc | 72 +-------------
include/odp/api/spec/random.h | 72 +++++++++++++-
platform/linux-generic/odp_crypto.c | 48 +++++++++-
test/common_plat/validation/api/random/random.c | 48 +++++++++-
test/common_plat/validation/api/random/random.h | 2 +
7 files changed, 284 insertions(+), 81 deletions(-)
create mode 100644 doc/users-guide/users-guide-crypto.adoc
hooks/post-receive
--