[Qemu-devel] [PATCH 4/6] test-qht: test removal of non-existent entries

Emilio G. Cota posted 6 patches 7 years, 2 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 4/6] test-qht: test removal of non-existent entries
Posted by Emilio G. Cota 7 years, 2 months ago
This improves qht.c code coverage from 89.44% to 90.00%.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 tests/test-qht.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/tests/test-qht.c b/tests/test-qht.c
index 283fb3db39..05b1d6807a 100644
--- a/tests/test-qht.c
+++ b/tests/test-qht.c
@@ -41,7 +41,7 @@ static void insert(int a, int b)
     }
 }
 
-static void rm(int init, int end)
+static void do_rm(int init, int end, bool exist)
 {
     int i;
 
@@ -49,10 +49,24 @@ static void rm(int init, int end)
         uint32_t hash;
 
         hash = arr[i];
-        g_assert_true(qht_remove(&ht, &arr[i], hash));
+        if (exist) {
+            g_assert_true(qht_remove(&ht, &arr[i], hash));
+        } else {
+            g_assert_false(qht_remove(&ht, &arr[i], hash));
+        }
     }
 }
 
+static void rm(int init, int end)
+{
+    do_rm(init, end, true);
+}
+
+static void rm_nonexist(int init, int end)
+{
+    do_rm(init, end, false);
+}
+
 static void check(int a, int b, bool expected)
 {
     struct qht_stats stats;
@@ -157,8 +171,15 @@ static void qht_do_test(unsigned int mode, size_t init_entries)
     check_n(0);
 
     qht_init(&ht, is_equal, 0, mode);
+    rm_nonexist(0, 4);
+    insert(0, 4);
+    rm_nonexist(5, 6);
+    insert(4, 6);
+    rm_nonexist(7, 8);
+    iter_rm_mod(1);
 
     check_n(0);
+    rm_nonexist(0, 10);
     insert(0, N);
     check(0, N, true);
     check_n(N);
@@ -183,6 +204,7 @@ static void qht_do_test(unsigned int mode, size_t init_entries)
 
     qht_reset(&ht);
     insert(0, N);
+    rm_nonexist(N, N + 32);
     iter_rm_mod(10);
     iter_rm_mod_check(10);
     check_n(N * 9 / 10);
-- 
2.17.1


Re: [Qemu-devel] [PATCH 4/6] test-qht: test removal of non-existent entries
Posted by Alex Bennée 7 years, 1 month ago
Emilio G. Cota <cota@braap.org> writes:

> This improves qht.c code coverage from 89.44% to 90.00%.
>
> Signed-off-by: Emilio G. Cota <cota@braap.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  tests/test-qht.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/tests/test-qht.c b/tests/test-qht.c
> index 283fb3db39..05b1d6807a 100644
> --- a/tests/test-qht.c
> +++ b/tests/test-qht.c
> @@ -41,7 +41,7 @@ static void insert(int a, int b)
>      }
>  }
>
> -static void rm(int init, int end)
> +static void do_rm(int init, int end, bool exist)
>  {
>      int i;
>
> @@ -49,10 +49,24 @@ static void rm(int init, int end)
>          uint32_t hash;
>
>          hash = arr[i];
> -        g_assert_true(qht_remove(&ht, &arr[i], hash));
> +        if (exist) {
> +            g_assert_true(qht_remove(&ht, &arr[i], hash));
> +        } else {
> +            g_assert_false(qht_remove(&ht, &arr[i], hash));
> +        }
>      }
>  }
>
> +static void rm(int init, int end)
> +{
> +    do_rm(init, end, true);
> +}
> +
> +static void rm_nonexist(int init, int end)
> +{
> +    do_rm(init, end, false);
> +}
> +
>  static void check(int a, int b, bool expected)
>  {
>      struct qht_stats stats;
> @@ -157,8 +171,15 @@ static void qht_do_test(unsigned int mode, size_t init_entries)
>      check_n(0);
>
>      qht_init(&ht, is_equal, 0, mode);
> +    rm_nonexist(0, 4);
> +    insert(0, 4);
> +    rm_nonexist(5, 6);
> +    insert(4, 6);
> +    rm_nonexist(7, 8);
> +    iter_rm_mod(1);
>
>      check_n(0);
> +    rm_nonexist(0, 10);
>      insert(0, N);
>      check(0, N, true);
>      check_n(N);
> @@ -183,6 +204,7 @@ static void qht_do_test(unsigned int mode, size_t init_entries)
>
>      qht_reset(&ht);
>      insert(0, N);
> +    rm_nonexist(N, N + 32);
>      iter_rm_mod(10);
>      iter_rm_mod_check(10);
>      check_n(N * 9 / 10);


--
Alex Bennée