4fbe94
From f4344bb4055cab8dc3bbe82a7f3d97fc6fabcb7e Mon Sep 17 00:00:00 2001
4fbe94
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
4fbe94
Date: Tue, 4 Jun 2019 09:19:04 +0200
4fbe94
Subject: [PATCH] test-cpu-set-util: fix comparison for allocation size
4fbe94
4fbe94
On i386, __cpu_mask is 4 bytes, so we'd check if c.allocated >= 0, and
4fbe94
gcc would warn about a bogus comparison. Let's round up.
4fbe94
4fbe94
Fixes #12726.
4fbe94
4fbe94
(cherry picked from commit a299ce058b41b21c87f36e77e2c563b0ddd1be0d)
4fbe94
4fbe94
Related: #1734787
4fbe94
---
4fbe94
 src/test/test-cpu-set-util.c | 22 +++++++++++-----------
4fbe94
 1 file changed, 11 insertions(+), 11 deletions(-)
4fbe94
4fbe94
diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c
4fbe94
index 9522582891..3456add989 100644
4fbe94
--- a/src/test/test-cpu-set-util.c
4fbe94
+++ b/src/test/test-cpu-set-util.c
4fbe94
@@ -17,7 +17,7 @@ static void test_parse_cpu_set(void) {
4fbe94
         /* Single value */
4fbe94
         assert_se(parse_cpu_set_full("0", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
         assert_se(c.set);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_ISSET_S(0, c.allocated, c.set));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 1);
4fbe94
 
4fbe94
@@ -33,7 +33,7 @@ static void test_parse_cpu_set(void) {
4fbe94
         /* Simple range (from CPUAffinity example) */
4fbe94
         assert_se(parse_cpu_set_full("1 2 4", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
         assert_se(c.set);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_ISSET_S(1, c.allocated, c.set));
4fbe94
         assert_se(CPU_ISSET_S(2, c.allocated, c.set));
4fbe94
         assert_se(CPU_ISSET_S(4, c.allocated, c.set));
4fbe94
@@ -50,7 +50,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* A more interesting range */
4fbe94
         assert_se(parse_cpu_set_full("0 1 2 3 8 9 10 11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
4fbe94
         for (cpu = 0; cpu < 4; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -68,7 +68,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Quoted strings */
4fbe94
         assert_se(parse_cpu_set_full("8 '9' 10 \"11\"", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 4);
4fbe94
         for (cpu = 8; cpu < 12; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -83,7 +83,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Use commas as separators */
4fbe94
         assert_se(parse_cpu_set_full("0,1,2,3 8,9,10,11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
4fbe94
         for (cpu = 0; cpu < 4; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -96,7 +96,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Commas with spaces (and trailing comma, space) */
4fbe94
         assert_se(parse_cpu_set_full("0, 1, 2, 3, 4, 5, 6, 7, 63, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 9);
4fbe94
         for (cpu = 0; cpu < 8; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -113,7 +113,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Ranges */
4fbe94
         assert_se(parse_cpu_set_full("0-3,8-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
4fbe94
         for (cpu = 0; cpu < 4; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -126,7 +126,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Ranges with trailing comma, space */
4fbe94
         assert_se(parse_cpu_set_full("0-3  8-11, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
4fbe94
         for (cpu = 0; cpu < 4; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -143,13 +143,13 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Negative range (returns empty cpu_set) */
4fbe94
         assert_se(parse_cpu_set_full("3-0", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 0);
4fbe94
         cpu_set_reset(&c);
4fbe94
 
4fbe94
         /* Overlapping ranges */
4fbe94
         assert_se(parse_cpu_set_full("0-7 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 12);
4fbe94
         for (cpu = 0; cpu < 12; cpu++)
4fbe94
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
4fbe94
@@ -164,7 +164,7 @@ static void test_parse_cpu_set(void) {
4fbe94
 
4fbe94
         /* Mix ranges and individual CPUs */
4fbe94
         assert_se(parse_cpu_set_full("0,2 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
4fbe94
-        assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
4fbe94
+        assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
4fbe94
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 10);
4fbe94
         assert_se(CPU_ISSET_S(0, c.allocated, c.set));
4fbe94
         assert_se(CPU_ISSET_S(2, c.allocated, c.set));