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