projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tests: Implement trigger capture test cases
[lttng-tools.git]
/
tests
/
unit
/
test_payload.c
diff --git
a/tests/unit/test_payload.c
b/tests/unit/test_payload.c
index 11c57f21de911e842f53a95c0342558fe2a81f15..e232cde66cfaba6f07f5d0cab56e55181e6228ad 100644
(file)
--- a/
tests/unit/test_payload.c
+++ b/
tests/unit/test_payload.c
@@
-5,6
+5,9
@@
*
*/
*
*/
+#include <unistd.h>
+
+#include <common/compat/fcntl.h>
#include <common/payload.h>
#include <common/payload-view.h>
#include <tap/tap.h>
#include <common/payload.h>
#include <common/payload-view.h>
#include <tap/tap.h>
@@
-20,16
+23,28
@@
static void test_fd_push_pop_order(void)
{
int ret, i;
struct lttng_payload payload;
{
int ret, i;
struct lttng_payload payload;
+ int fds[3];
lttng_payload_init(&payload);
diag("Validating fd push/pop order");
for (i = 0; i < 3; i++) {
lttng_payload_init(&payload);
diag("Validating fd push/pop order");
for (i = 0; i < 3; i++) {
- ret = lttng_payload_push_fd(&payload, i);
+ int fd = fcntl(STDOUT_FILENO, F_DUPFD, 0);
+ struct fd_handle *handle;
+
+ assert(fd >= 0);
+ fds[i] = fd;
+
+ handle = fd_handle_create(fd);
+ assert(handle);
+
+ ret = lttng_payload_push_fd_handle(&payload, handle);
+ fd_handle_put(handle);
if (ret) {
break;
}
}
if (ret) {
break;
}
}
+
ok(ret == 0, "Added three file descriptors to an lttng_payload");
{
ok(ret == 0, "Added three file descriptors to an lttng_payload");
{
@@
-39,8
+54,11
@@
static void test_fd_push_pop_order(void)
&payload, 0, -1);
for (i = 0; i < 3; i++) {
&payload, 0, -1);
for (i = 0; i < 3; i++) {
- ret = lttng_payload_view_pop_fd(&view);
- fail_pop |= ret != i;
+ struct fd_handle *handle =
+ lttng_payload_view_pop_fd_handle(&view);
+
+ fail_pop |= fd_handle_get_fd(handle) != fds[i];
+ fd_handle_put(handle);
}
ok(!fail_pop, "File descriptors are popped from a payload view in the order of insertion");
}
ok(!fail_pop, "File descriptors are popped from a payload view in the order of insertion");
@@
-59,26
+77,38
@@
static void test_fd_push_pop_imbalance(void)
diag("Validating fd pop imbalance");
for (i = 0; i < 10; i++) {
diag("Validating fd pop imbalance");
for (i = 0; i < 10; i++) {
- ret = lttng_payload_push_fd(&payload, i);
+ struct fd_handle *handle;
+ int fd = fcntl(STDOUT_FILENO, F_DUPFD, 0);
+
+ assert(fd >= 0);
+
+ handle = fd_handle_create(fd);
+ assert(handle);
+
+ ret = lttng_payload_push_fd_handle(&payload, handle);
+ fd_handle_put(handle);
if (ret) {
break;
}
}
{
if (ret) {
break;
}
}
{
+ struct fd_handle *handle;
struct lttng_payload_view view =
lttng_payload_view_from_payload(
&payload, 0, -1);
for (i = 0; i < 10; i++) {
struct lttng_payload_view view =
lttng_payload_view_from_payload(
&payload, 0, -1);
for (i = 0; i < 10; i++) {
- ret = lttng_payload_view_pop_fd(&view);
- if (ret == -1) {
+ handle = lttng_payload_view_pop_fd_handle(&view);
+ fd_handle_put(handle);
+ if (!handle) {
goto fail;
}
}
goto fail;
}
}
- ret = lttng_payload_view_pop_fd(&view);
- ok(ret == -1, test_description);
+ handle = lttng_payload_view_pop_fd_handle(&view);
+ ok(!handle, test_description);
+ fd_handle_put(handle);
}
lttng_payload_reset(&payload);
}
lttng_payload_reset(&payload);
@@
-91,53
+121,73
@@
fail:
static void test_fd_pop_fd_root_views(void)
{
int ret, i;
static void test_fd_pop_fd_root_views(void)
{
int ret, i;
- const int fd = 42;
+ int fd = fcntl(STDOUT_FILENO, F_DUPFD, 0);
+ struct fd_handle *handle;
struct lttng_payload payload;
const char * const test_description = "Same file descriptor returned when popping from different top-level views";
struct lttng_payload payload;
const char * const test_description = "Same file descriptor returned when popping from different top-level views";
+ assert(fd >= 0);
+ handle = fd_handle_create(fd);
+ assert(handle);
+
lttng_payload_init(&payload);
diag("Validating root view fd pop behaviour");
lttng_payload_init(&payload);
diag("Validating root view fd pop behaviour");
- ret = lttng_payload_push_fd
(&payload, fd
);
+ ret = lttng_payload_push_fd
_handle(&payload, handle
);
if (ret) {
goto fail;
}
for (i = 0; i < 5; i++) {
if (ret) {
goto fail;
}
for (i = 0; i < 5; i++) {
+ int view_fd;
+ struct fd_handle *view_handle;
struct lttng_payload_view view =
lttng_payload_view_from_payload(
&payload, 0, -1);
struct lttng_payload_view view =
lttng_payload_view_from_payload(
&payload, 0, -1);
- ret = lttng_payload_view_pop_fd(&view);
- if (ret != fd) {
+ view_handle = lttng_payload_view_pop_fd_handle(&view);
+ if (!view_handle) {
+ goto fail;
+ }
+
+ view_fd = fd_handle_get_fd(view_handle);
+ fd_handle_put(view_handle);
+ if (view_fd != fd || view_handle != handle) {
goto fail;
}
}
lttng_payload_reset(&payload);
pass(test_description);
goto fail;
}
}
lttng_payload_reset(&payload);
pass(test_description);
+ fd_handle_put(handle);
return;
fail:
lttng_payload_reset(&payload);
fail(test_description);
return;
fail:
lttng_payload_reset(&payload);
fail(test_description);
+ fd_handle_put(handle);
}
static void test_fd_pop_fd_descendant_views(void)
{
int ret;
const int fd1 = 42, fd2 = 1837;
}
static void test_fd_pop_fd_descendant_views(void)
{
int ret;
const int fd1 = 42, fd2 = 1837;
+ struct fd_handle *handle1 = fd_handle_create(fd1);
+ struct fd_handle *handle2 = fd_handle_create(fd2);
+ struct fd_handle *view_handle1 = NULL, *view_handle2 = NULL;
struct lttng_payload payload;
const char * const test_description = "Different file descriptors returned when popping from descendant views";
lttng_payload_init(&payload);
struct lttng_payload payload;
const char * const test_description = "Different file descriptors returned when popping from descendant views";
lttng_payload_init(&payload);
+ assert(handle1);
+ assert(handle2);
diag("Validating descendant view fd pop behaviour");
diag("Validating descendant view fd pop behaviour");
- ret = lttng_payload_push_fd
(&payload, fd
1);
+ ret = lttng_payload_push_fd
_handle(&payload, handle
1);
if (ret) {
goto fail;
}
if (ret) {
goto fail;
}
- ret = lttng_payload_push_fd
(&payload, fd
2);
+ ret = lttng_payload_push_fd
_handle(&payload, handle
2);
if (ret) {
goto fail;
}
if (ret) {
goto fail;
}
@@
-150,23
+200,31
@@
static void test_fd_pop_fd_descendant_views(void)
lttng_payload_view_from_view(
&view1, 0, -1);
lttng_payload_view_from_view(
&view1, 0, -1);
-
ret = lttng_payload_view_pop_fd
(&view1);
- if (
ret
!= fd1) {
+
view_handle1 = lttng_payload_view_pop_fd_handle
(&view1);
+ if (
!view_handle1 || fd_handle_get_fd(view_handle1)
!= fd1) {
goto fail;
}
goto fail;
}
-
ret = lttng_payload_view_pop_fd
(&view2);
- if (
ret
!= fd2) {
+
view_handle2 = lttng_payload_view_pop_fd_handle
(&view2);
+ if (
!view_handle2 || fd_handle_get_fd(view_handle2)
!= fd2) {
goto fail;
}
}
lttng_payload_reset(&payload);
pass(test_description);
goto fail;
}
}
lttng_payload_reset(&payload);
pass(test_description);
+ fd_handle_put(handle1);
+ fd_handle_put(handle2);
+ fd_handle_put(view_handle1);
+ fd_handle_put(view_handle2);
return;
fail:
lttng_payload_reset(&payload);
fail(test_description);
return;
fail:
lttng_payload_reset(&payload);
fail(test_description);
+ fd_handle_put(handle1);
+ fd_handle_put(handle2);
+ fd_handle_put(view_handle1);
+ fd_handle_put(view_handle2);
}
int main(void)
}
int main(void)
This page took
0.026514 seconds
and
4
git commands to generate.