aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/test/validation/api/shmem/shmem_odp2.c
blob: 1f4c04fa0e880733bcc60f2b93f0edd043a63770 (plain)
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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2016-2018 Linaro Limited
 */

#include <odp_api.h>
#include <odp/helper/odph_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
 * status 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)) {
		ODPH_ERR("odp_init_global() failed\n");
		return 1;
	}
	if (0 != odp_init_local(odp2, ODP_THREAD_CONTROL)) {
		ODPH_ERR("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) {
		ODPH_ERR("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) {
		ODPH_ERR("odp_shm_import() 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))) {
		ODPH_ERR("odp_shm_info() failed\n");
		return 1;
	}

	test_shared_data = odp_shm_addr(shm);
	if (test_shared_data == NULL) {
		ODPH_ERR("odp_shm_addr() failed\n");
		return 1;
	}

	if (test_shared_data->foo != TEST_SHARE_FOO) {
		ODPH_ERR("Invalid data TEST_SHARE_FOO\n");
		return 1;
	}

	if (test_shared_data->bar != TEST_SHARE_BAR) {
		ODPH_ERR("Invalid data TEST_SHARE_BAR\n");
		return 1;
	}

	if (odp_shm_free(shm) != 0) {
		ODPH_ERR("odp_shm_free() failed\n");
		return 1;
	}

	/* odp term: */
	if (0 != odp_term_local()) {
		ODPH_ERR("odp_term_local() failed\n");
		return 1;
	}

	if (0 != odp_term_global(odp2)) {
		ODPH_ERR("odp_term_global() failed\n");
		return 1;
	}

	printf("%s SUCCESS\n", __FILE__);
	return 0;
}