| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <sys/prctl.h> |
| 4 |
|
| 5 |
#include "tests.h" |
| 6 |
|
| 7 |
#define PR_THP_DISABLE_NOT_SET 0 |
| 8 |
#define PR_THP_DISABLE 1 |
| 9 |
|
| 10 |
static const char *arg_mode = NULL; |
| 11 |
|
| 12 |
static int intro(void) { |
| 13 |
int r; |
| 14 |
|
| 15 |
r = prctl(PR_GET_THP_DISABLE, 0, 0, 0, 0); |
| 16 |
if (streq_ptr(arg_mode, "no-disable")) { |
| 17 |
/* Test case: THPs should not be disabled */ |
| 18 |
if (r != PR_THP_DISABLE_NOT_SET) { |
| 19 |
log_error("THPs disabled for the process r = %d: %m", r); |
| 20 |
return EXIT_FAILURE; |
| 21 |
} |
| 22 |
} else if (streq_ptr(arg_mode, "disable")) { |
| 23 |
/* Test case: THPs should be completely disabled */ |
| 24 |
if (r == PR_THP_DISABLE_NOT_SET) |
| 25 |
return log_tests_skipped("Disabling THPs completely for the process not supported"); |
| 26 |
|
| 27 |
if (r != PR_THP_DISABLE) { |
| 28 |
log_error("THPs not completely disabled for the process r = %d: %m", r); |
| 29 |
return EXIT_FAILURE; |
| 30 |
} |
| 31 |
} else if (streq_ptr(arg_mode, "madvise")) { |
| 32 |
/* Test case: THPs should be only enabled on a madvise basis */ |
| 33 |
if (r == PR_THP_DISABLE_NOT_SET) |
| 34 |
return log_tests_skipped("Disabling THPs except for madvise not supported"); |
| 35 |
|
| 36 |
if (r != (PR_THP_DISABLE | PR_THP_DISABLE_EXCEPT_ADVISED)) { |
| 37 |
log_error("THPs (except madvise) not completely disabled for the process r = %d: %m", r); |
| 38 |
return EXIT_FAILURE; |
| 39 |
} |
| 40 |
} else { |
| 41 |
log_error("Invalid mode: %s (expected: no-disable, disable, or madvise)", strna(arg_mode)); |
| 42 |
return EXIT_FAILURE; |
| 43 |
} |
| 44 |
|
| 45 |
return EXIT_SUCCESS; |
| 46 |
} |
| 47 |
|
| 48 |
int main(int argc, char *argv[]) { |
| 49 |
if (argc != 2) { |
| 50 |
log_error("Invalid number of args passed to the test %d", argc); |
| 51 |
return EXIT_FAILURE; |
| 52 |
} |
| 53 |
arg_mode = argv[1]; |
| 54 |
test_setup_logging(LOG_DEBUG); |
| 55 |
return intro(); |
| 56 |
} |