summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-06-04 09:19:04 +0200
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>2019-12-09 13:13:24 +0100
commitf4344bb4055cab8dc3bbe82a7f3d97fc6fabcb7e (patch)
tree6c7d4b2c38d329a6fbcb72e1863df3b1bfcdd158
parent613a02b7d67864af1860e9137e2ee101d603463e (diff)
downloadsystemd-f4344bb4055cab8dc3bbe82a7f3d97fc6fabcb7e.tar.gz
test-cpu-set-util: fix comparison for allocation size
On i386, __cpu_mask is 4 bytes, so we'd check if c.allocated >= 0, and gcc would warn about a bogus comparison. Let's round up. Fixes #12726. (cherry picked from commit a299ce058b41b21c87f36e77e2c563b0ddd1be0d) Related: #1734787
-rw-r--r--src/test/test-cpu-set-util.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c
index 9522582891..3456add989 100644
--- a/src/test/test-cpu-set-util.c
+++ b/src/test/test-cpu-set-util.c
@@ -17,7 +17,7 @@ static void test_parse_cpu_set(void) {
/* Single value */
assert_se(parse_cpu_set_full("0", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
assert_se(c.set);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_ISSET_S(0, c.allocated, c.set));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 1);
@@ -33,7 +33,7 @@ static void test_parse_cpu_set(void) {
/* Simple range (from CPUAffinity example) */
assert_se(parse_cpu_set_full("1 2 4", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
assert_se(c.set);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_ISSET_S(1, c.allocated, c.set));
assert_se(CPU_ISSET_S(2, c.allocated, c.set));
assert_se(CPU_ISSET_S(4, c.allocated, c.set));
@@ -50,7 +50,7 @@ static void test_parse_cpu_set(void) {
/* A more interesting range */
assert_se(parse_cpu_set_full("0 1 2 3 8 9 10 11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
for (cpu = 0; cpu < 4; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -68,7 +68,7 @@ static void test_parse_cpu_set(void) {
/* Quoted strings */
assert_se(parse_cpu_set_full("8 '9' 10 \"11\"", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 4);
for (cpu = 8; cpu < 12; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -83,7 +83,7 @@ static void test_parse_cpu_set(void) {
/* Use commas as separators */
assert_se(parse_cpu_set_full("0,1,2,3 8,9,10,11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
for (cpu = 0; cpu < 4; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -96,7 +96,7 @@ static void test_parse_cpu_set(void) {
/* Commas with spaces (and trailing comma, space) */
assert_se(parse_cpu_set_full("0, 1, 2, 3, 4, 5, 6, 7, 63, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 9);
for (cpu = 0; cpu < 8; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -113,7 +113,7 @@ static void test_parse_cpu_set(void) {
/* Ranges */
assert_se(parse_cpu_set_full("0-3,8-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
for (cpu = 0; cpu < 4; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -126,7 +126,7 @@ static void test_parse_cpu_set(void) {
/* Ranges with trailing comma, space */
assert_se(parse_cpu_set_full("0-3 8-11, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
for (cpu = 0; cpu < 4; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -143,13 +143,13 @@ static void test_parse_cpu_set(void) {
/* Negative range (returns empty cpu_set) */
assert_se(parse_cpu_set_full("3-0", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 0);
cpu_set_reset(&c);
/* Overlapping ranges */
assert_se(parse_cpu_set_full("0-7 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 12);
for (cpu = 0; cpu < 12; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
@@ -164,7 +164,7 @@ static void test_parse_cpu_set(void) {
/* Mix ranges and individual CPUs */
assert_se(parse_cpu_set_full("0,2 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
- assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(c.allocated >= DIV_ROUND_UP(sizeof(__cpu_mask), 8));
assert_se(CPU_COUNT_S(c.allocated, c.set) == 10);
assert_se(CPU_ISSET_S(0, c.allocated, c.set));
assert_se(CPU_ISSET_S(2, c.allocated, c.set));