1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/* Copyright (c) 2016-2018, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <odp_api.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;
odp_shm_info_t info;
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",
SHM_NAME, (int)odp1);
shm = odp_shm_import(SHM_NAME, odp1, SHM_NAME);
if (shm == ODP_SHM_INVALID) {
fprintf(stderr, "error: odp_shm_lookup_external failed.\n");
return 1;
}
/* check that the read size matches the allocated size (in other ODP):*/
if ((odp_shm_info(shm, &info)) ||
(info.size != sizeof(*test_shared_data))) {
fprintf(stderr, "error: odp_shm_info 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;
}
printf("%s SUCSESS\n", __FILE__);
return 0;
}
|