testing_helpers.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
  2. /* Copyright (C) 2020 Facebook, Inc. */
  3. #ifndef __TESTING_HELPERS_H
  4. #define __TESTING_HELPERS_H
  5. #include <stdbool.h>
  6. #include <bpf/bpf.h>
  7. #include <bpf/libbpf.h>
  8. #include <time.h>
  9. #define __TO_STR(x) #x
  10. #define TO_STR(x) __TO_STR(x)
  11. int parse_num_list(const char *s, bool **set, int *set_len);
  12. __u32 link_info_prog_id(const struct bpf_link *link, struct bpf_link_info *info);
  13. int bpf_prog_test_load(const char *file, enum bpf_prog_type type,
  14. struct bpf_object **pobj, int *prog_fd);
  15. int bpf_test_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
  16. size_t insns_cnt, const char *license,
  17. __u32 kern_version, char *log_buf,
  18. size_t log_buf_sz);
  19. /*
  20. * below function is exported for testing in prog_test test
  21. */
  22. struct test_filter_set;
  23. int parse_test_list(const char *s,
  24. struct test_filter_set *test_set,
  25. bool is_glob_pattern);
  26. int parse_test_list_file(const char *path,
  27. struct test_filter_set *test_set,
  28. bool is_glob_pattern);
  29. __u64 read_perf_max_sample_freq(void);
  30. int load_bpf_testmod(bool verbose);
  31. int unload_bpf_testmod(bool verbose);
  32. int kern_sync_rcu(void);
  33. int finit_module(int fd, const char *param_values, int flags);
  34. int delete_module(const char *name, int flags);
  35. int load_module(const char *path, bool verbose);
  36. int unload_module(const char *name, bool verbose);
  37. static inline __u64 get_time_ns(void)
  38. {
  39. struct timespec t;
  40. clock_gettime(CLOCK_MONOTONIC, &t);
  41. return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
  42. }
  43. struct bpf_insn;
  44. /* Request BPF program instructions after all rewrites are applied,
  45. * e.g. verifier.c:convert_ctx_access() is done.
  46. */
  47. int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt);
  48. int testing_prog_flags(void);
  49. bool is_jit_enabled(void);
  50. #endif /* __TESTING_HELPERS_H */