1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 /* 4 * Copyright (c) 2025, Google LLC. 5 * Pasha Tatashin <pasha.tatashin@soleen.com> 6 * 7 * Utility functions for LUO kselftests. 8 */ 9 10 #ifndef LUO_TEST_UTILS_H 11 #define LUO_TEST_UTILS_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 29 int create_and_preserve_memfd(int session_fd, int token, const char *data); 30 int restore_and_verify_memfd(int session_fd, int token, const char *expected_data); 31 32 void create_state_file(int luo_fd, const char *session_name, int token, 33 int next_stage); 34 void restore_and_read_stage(int state_session_fd, int token, int *stage); 35 36 void daemonize_and_wait(void); 37 38 typedef void (*luo_test_stage1_fn)(int luo_fd); 39 typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd); 40 41 int luo_test(int argc, char *argv[], const char *state_session_name, 42 luo_test_stage1_fn stage1, luo_test_stage2_fn stage2); 43 44 #endif /* LUO_TEST_UTILS_H */ 45