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