WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / cgroup / cgroup_util.h
blob5a1305dd1f0b35d224b0f5cc19d5782d964800cd
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <stdbool.h>
3 #include <stdlib.h>
5 #define PAGE_SIZE 4096
7 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
9 #define MB(x) (x << 20)
12 * Checks if two given values differ by less than err% of their sum.
14 static inline int values_close(long a, long b, int err)
16 return abs(a - b) <= (a + b) / 100 * err;
19 extern int cg_find_unified_root(char *root, size_t len);
20 extern char *cg_name(const char *root, const char *name);
21 extern char *cg_name_indexed(const char *root, const char *name, int index);
22 extern char *cg_control(const char *cgroup, const char *control);
23 extern int cg_create(const char *cgroup);
24 extern int cg_destroy(const char *cgroup);
25 extern int cg_read(const char *cgroup, const char *control,
26 char *buf, size_t len);
27 extern int cg_read_strcmp(const char *cgroup, const char *control,
28 const char *expected);
29 extern int cg_read_strstr(const char *cgroup, const char *control,
30 const char *needle);
31 extern long cg_read_long(const char *cgroup, const char *control);
32 long cg_read_key_long(const char *cgroup, const char *control, const char *key);
33 extern long cg_read_lc(const char *cgroup, const char *control);
34 extern int cg_write(const char *cgroup, const char *control, char *buf);
35 extern int cg_run(const char *cgroup,
36 int (*fn)(const char *cgroup, void *arg),
37 void *arg);
38 extern int cg_enter(const char *cgroup, int pid);
39 extern int cg_enter_current(const char *cgroup);
40 extern int cg_enter_current_thread(const char *cgroup);
41 extern int cg_run_nowait(const char *cgroup,
42 int (*fn)(const char *cgroup, void *arg),
43 void *arg);
44 extern int get_temp_fd(void);
45 extern int alloc_pagecache(int fd, size_t size);
46 extern int alloc_anon(const char *cgroup, void *arg);
47 extern int is_swap_enabled(void);
48 extern int set_oom_adj_score(int pid, int score);
49 extern int cg_wait_for_proc_count(const char *cgroup, int count);
50 extern int cg_killall(const char *cgroup);
51 extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size);
52 extern int proc_read_strstr(int pid, bool thread, const char *item, const char *needle);
53 extern pid_t clone_into_cgroup(int cgroup_fd);
54 extern int clone_reap(pid_t pid, int options);
55 extern int clone_into_cgroup_run_wait(const char *cgroup);
56 extern int dirfd_open_opath(const char *dir);