| 1 |
|
| 2 |
|
| 3 | |
| 4 | * Copyright (c) 2025, Google LLC.
|
| 5 | * Pasha Tatashin <[email protected]>
|
| 6 | *
|
| 7 | * Utility functions for LUO kselftests.
|
| 8 |
|
| 9 |
|
| 10 | #ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
|
| 11 | #define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
|
| 12 |
|
| 13 | #include <errno.h>
|
| 14 | #include <string.h>
|
| 15 | #include <linux/liveupdate.h>
|
| 16 | #include "../../../kselftest.h"
|
| 17 |
|
| 18 | #define LUO_DEVICE "/dev/liveupdate"
|
| 19 |
|
| 20 | #define fail_exit(fmt, ...) \
|
| 21 | ksft_exit_fail_msg("[%s:%d] " fmt " (errno: %s)\n", \
|
| 22 | __func__, __LINE__, ##__VA_ARGS__, strerror(errno))
|
| 23 |
|
| 24 | int luo_open_device(void);
|
| 25 | int luo_create_session(int luo_fd, const char *name);
|
| 26 | int luo_retrieve_session(int luo_fd, const char *name);
|
| 27 | int luo_session_finish(int session_fd);
|
| 28 | int luo_get_session_name(int session_fd, char *name, size_t name_len);
|
| 29 |
|
| 30 | int luo_ensure_nofile_limit(long min_limit);
|
| 31 | int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
|
| 32 | int luo_session_retrieve_fd(int session_fd, __u64 token);
|
| 33 |
|
| 34 | int create_and_preserve_memfd(int session_fd, int token, const char *data);
|
| 35 | int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
|
| 36 |
|
| 37 | void create_state_file(int luo_fd, const char *session_name, int token,
|
| 38 | int next_stage);
|
| 39 | void restore_and_read_stage(int state_session_fd, int token, int *stage);
|
| 40 |
|
| 41 | void daemonize_and_wait(void);
|
| 42 |
|
| 43 | typedef void (*luo_test_stage1_fn)(int luo_fd);
|
| 44 | typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd);
|
| 45 |
|
| 46 | int luo_test(int argc, char *argv[], const char *state_session_name,
|
| 47 | luo_test_stage1_fn stage1, luo_test_stage2_fn stage2);
|
| 48 |
|
| 49 | #endif
|