2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
13 #include <lttng/ust-error.h>
18 * Sync with liblttng-ust-comm/lttng-ust-comm.c
20 static const char *ok_str
= "Success";
21 static const char *unknown_str
= "Unknown error";
22 static const char *noent_str
= "No entry";
23 static const char *peercred_str
= "Peer credentials PID is invalid. Socket appears to belong to a distinct, non-nested pid namespace.";
28 void test_ust_error(void)
30 const char *error_str
= NULL
;
32 error_str
= lttng_ust_strerror(LTTNG_UST_OK
);
33 ok(strcmp(ok_str
, error_str
) == 0, "lttng_ust_strerror - Positive LTTNG_UST_OK returns '%s' (%s)", ok_str
, error_str
);
35 error_str
= lttng_ust_strerror(-LTTNG_UST_OK
);
36 ok(strcmp(ok_str
, error_str
) == 0, "lttng_ust_strerror - Negative LTTNG_UST_OK returns '%s' (%s)", ok_str
, error_str
);
38 error_str
= lttng_ust_strerror(INT_MAX
);
39 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Positive large int returns '%s' (%s)", unknown_str
, error_str
);
41 error_str
= lttng_ust_strerror(INT_MIN
);
42 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Negative large int returns '%s' (%s)", unknown_str
, error_str
);
44 error_str
= lttng_ust_strerror(LTTNG_UST_ERR_NR
);
45 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Positive LTTNG_UST_ERR_NR returns '%s' (%s)", unknown_str
, error_str
);
47 error_str
= lttng_ust_strerror(-LTTNG_UST_ERR_NR
);
48 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Negative LTTNG_UST_ERR_NR returns '%s' (%s)", unknown_str
, error_str
);
50 error_str
= lttng_ust_strerror(LTTNG_UST_ERR_NR
+ 1);
51 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Positive LTTNG_UST_ERR_NR + 1 returns '%s' (%s)", unknown_str
, error_str
);
53 error_str
= lttng_ust_strerror(-LTTNG_UST_ERR_NR
- 1);
54 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Negative LTTNG_UST_ERR_NR - 1 returns '%s' (%s)", unknown_str
, error_str
);
56 error_str
= lttng_ust_strerror(LTTNG_UST_ERR_NOENT
);
57 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Positive LTTNG_UST_ERR_NOENT returns '%s' (%s)", unknown_str
, error_str
);
59 error_str
= lttng_ust_strerror(-LTTNG_UST_ERR_NOENT
);
60 ok(strcmp(noent_str
, error_str
) == 0, "lttng_ust_strerror - Negative LTTNG_UST_ERR_NOENT returns '%s' (%s)", noent_str
, error_str
);
63 error_str
= lttng_ust_strerror(LTTNG_UST_ERR_PEERCRED_PID
);
64 ok(strcmp(unknown_str
, error_str
) == 0, "lttng_ust_strerror - Positive LTTNG_UST_ERR_PEERCRED_PID returns '%s' (%s)", unknown_str
, error_str
);
66 error_str
= lttng_ust_strerror(-LTTNG_UST_ERR_PEERCRED_PID
);
67 ok(strcmp(peercred_str
, error_str
) == 0, "lttng_ust_strerror - Negative LTTNG_UST_ERR_PEERCRED_PID returns '%s' (%s)", peercred_str
, error_str
);
72 plan_tests(NUM_TESTS
);