1 /* Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; only
6 * version 2.1 of the License.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <sys/types.h>
26 #include <lttng/align.h>
27 #include "libringbuffer/shm.h"
31 #define SHM_PATH "/ust-shm-test"
36 size_t shmsize
= LTTNG_UST_PAGE_SIZE
* 10;
37 struct shm_object_table
*table
;
38 struct shm_object
*shmobj
;
39 struct shm_ref shm_ref
;
43 /* Open a zero byte shm fd */
44 shmfd
= shm_open(SHM_PATH
, O_RDWR
| O_CREAT
, S_IRUSR
| S_IWUSR
);
45 ok(shmfd
> 0, "Open a POSIX shm fd");
47 /* Create a dummy shm object table to test the allocation function */
48 table
= shm_object_table_create(1);
49 ok(table
, "Create a shm object table");
52 /* This function sets the initial size of the shm with ftruncate and zeros it */
53 shmobj
= shm_object_table_alloc(table
, shmsize
, SHM_OBJECT_SHM
, shmfd
, -1);
54 ok(shmobj
, "Allocate the shm object table");
57 shm_ref
= zalloc_shm(shmobj
, LTTNG_UST_PAGE_SIZE
* 5);
58 ok(shm_ref
.index
!= -1, "Allocate an object in the shm with sufficient space");
60 shm_ref
= zalloc_shm(shmobj
, LTTNG_UST_PAGE_SIZE
* 6);
61 ok(shm_ref
.index
== -1, "Allocate an object in the shm with insufficient space");
64 shm_object_table_destroy(table
, 1);
This page took 0.030755 seconds and 4 git commands to generate.