luo_test_utils.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2025, Google LLC.
  4. * Pasha Tatashin <pasha.tatashin@soleen.com>
  5. *
  6. * Utility functions for LUO kselftests.
  7. */
  8. #ifndef LUO_TEST_UTILS_H
  9. #define LUO_TEST_UTILS_H
  10. #include <errno.h>
  11. #include <string.h>
  12. #include <linux/liveupdate.h>
  13. #include "../kselftest.h"
  14. #define LUO_DEVICE "/dev/liveupdate"
  15. #define fail_exit(fmt, ...) \
  16. ksft_exit_fail_msg("[%s:%d] " fmt " (errno: %s)\n", \
  17. __func__, __LINE__, ##__VA_ARGS__, strerror(errno))
  18. int luo_open_device(void);
  19. int luo_create_session(int luo_fd, const char *name);
  20. int luo_retrieve_session(int luo_fd, const char *name);
  21. int luo_session_finish(int session_fd);
  22. int create_and_preserve_memfd(int session_fd, int token, const char *data);
  23. int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
  24. void create_state_file(int luo_fd, const char *session_name, int token,
  25. int next_stage);
  26. void restore_and_read_stage(int state_session_fd, int token, int *stage);
  27. void daemonize_and_wait(void);
  28. typedef void (*luo_test_stage1_fn)(int luo_fd);
  29. typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd);
  30. int luo_test(int argc, char *argv[], const char *state_session_name,
  31. luo_test_stage1_fn stage1, luo_test_stage2_fn stage2);
  32. #endif /* LUO_TEST_UTILS_H */