diff mbox series

[v1] lib: add .min_swap_avail in tst_test struct

Message ID 20230904074443.24701-1-andrea.cervesato@suse.de
State Accepted
Headers show
Series [v1] lib: add .min_swap_avail in tst_test struct | expand

Commit Message

Andrea Cervesato Sept. 4, 2023, 7:44 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

This new field is mainly to set the minimum size of SwapFree for
LTP testcase. If system available free swap memory is less than
.min_swap_avail, test will be exit with TCONF.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_memutils.h | 5 +++++
 include/tst_test.h     | 3 +++
 lib/tst_memutils.c     | 9 +++++++++
 lib/tst_test.c         | 3 +++
 4 files changed, 20 insertions(+)

Comments

Cyril Hrubis Sept. 4, 2023, 8:48 a.m. UTC | #1
Hi!
This looks good, but should be immediatelly followed by a patch that
fixes the process_madvise test.
Andrea Cervesato Sept. 4, 2023, 9:45 a.m. UTC | #2
Hi!

I can send it after this patch.

On 9/4/23 10:48, Cyril Hrubis wrote:
> Hi!
> This looks good, but should be immediatelly followed by a patch that
> fixes the process_madvise test.
>
Andrea
Li Wang Sept. 5, 2023, 3:09 a.m. UTC | #3
Hi Andrea,

On Mon, Sep 4, 2023 at 3:45 PM Andrea Cervesato <andrea.cervesato@suse.de>
wrote:

> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> This new field is mainly to set the minimum size of SwapFree for
> LTP testcase. If system available free swap memory is less than
> .min_swap_avail, test will be exit with TCONF.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  include/tst_memutils.h | 5 +++++
>  include/tst_test.h     | 3 +++
>  lib/tst_memutils.c     | 9 +++++++++
>  lib/tst_test.c         | 3 +++
>  4 files changed, 20 insertions(+)
>
> diff --git a/include/tst_memutils.h b/include/tst_memutils.h
> index 45dec55bc..19b593430 100644
> --- a/include/tst_memutils.h
> +++ b/include/tst_memutils.h
> @@ -25,6 +25,11 @@ void tst_pollute_memory(size_t maxsize, int fillchar);
>   */
>  long long tst_available_mem(void);
>
> +/*
> + * Read the value of SwapFree from /proc/meminfo.
> + */
> +long long tst_available_swap(void);
> +
>  /*
>   * Enable OOM protection to prevent process($PID) being killed by OOM
> Killer.
>   *   echo -1000 >/proc/$PID/oom_score_adj
> diff --git a/include/tst_test.h b/include/tst_test.h
> index 0ac492a80..75c2109b9 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -210,6 +210,9 @@ struct tst_test {
>         /* Minimum size(MB) of MemAvailable required by the test */
>         unsigned long min_mem_avail;
>
> +       /* Minimum size(MB) of SwapFree required by the test */
> +       unsigned long min_swap_avail;
>

It would be great to have a brief introduction in the document,
like what we did for min_mem_avail.

Anyway, we can add it in a separate patch. Thanks!
diff mbox series

Patch

diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 45dec55bc..19b593430 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -25,6 +25,11 @@  void tst_pollute_memory(size_t maxsize, int fillchar);
  */
 long long tst_available_mem(void);
 
+/*
+ * Read the value of SwapFree from /proc/meminfo.
+ */
+long long tst_available_swap(void);
+
 /*
  * Enable OOM protection to prevent process($PID) being killed by OOM Killer.
  *   echo -1000 >/proc/$PID/oom_score_adj
diff --git a/include/tst_test.h b/include/tst_test.h
index 0ac492a80..75c2109b9 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -210,6 +210,9 @@  struct tst_test {
 	/* Minimum size(MB) of MemAvailable required by the test */
 	unsigned long min_mem_avail;
 
+	/* Minimum size(MB) of SwapFree required by the test */
+	unsigned long min_swap_avail;
+
 	/*
 	 * Two policies for reserving hugepage:
 	 *
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index 6fc9f6a93..c5382ff10 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -95,6 +95,15 @@  long long tst_available_mem(void)
 	return mem_available;
 }
 
+long long tst_available_swap(void)
+{
+	unsigned long long swap_available = 0;
+
+	FILE_LINES_SCANF("/proc/meminfo", "SwapFree: %llu", &swap_available);
+
+	return swap_available;
+}
+
 static int has_caps(void)
 {
 	struct tst_cap_user_header hdr = {
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 0efabe467..3cc4aee0a 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1198,6 +1198,9 @@  static void do_setup(int argc, char *argv[])
 	if (tst_test->min_mem_avail > (unsigned long)(tst_available_mem() / 1024))
 		tst_brk(TCONF, "Test needs at least %luMB MemAvailable", tst_test->min_mem_avail);
 
+	if (tst_test->min_swap_avail > (unsigned long)(tst_available_swap() / 1024))
+		tst_brk(TCONF, "Test needs at least %luMB SwapFree", tst_test->min_swap_avail);
+
 	if (tst_test->hugepages.number)
 		tst_reserve_hugepages(&tst_test->hugepages);