aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2010-05-31 15:13:50 +1000
committerEric B Munson <ebmunson@us.ibm.com>2010-06-01 07:37:43 +0100
commit2cb166e5504e7deac14577aaf7397a807ffe6058 (patch)
treedbee8926fa0edb87cc6289e6ec959459ca21faf2
parentfe48000e66d6686e132b65fd11f1187c99204133 (diff)
downloadlibhugetlbfs-2cb166e5504e7deac14577aaf7397a807ffe6058.tar.gz
Fix bug in gethugepagesizes testcase
The gethugepagesizes testcase tests the calls to retreieve the available page sizes against faked up sysfs contents. This includes testing that the gethugepagesizes() call doesn't return more entries than the maximum it's given (which might clobber memory). However, it does this incorrectly: specifically, validate_sizes() checks that the n returned entries exactly match the first n expected entries, even when the maxmum number of entries to return is smaller than the total number of pagesizes available. gethugepagesizes() is not guaranteed to return the pagesizes in any particular order (based as it is on getting a directory listing), so this test will generate bogus failures. In fact, for the case where the given maximum is smaller than the total number of pagesizes, the test should accept as a pass any subset of the expected pagesizes in the returned results. This patch makes the correction. Signed-off-by: David Gibson <dwg@au1.ibm.com> Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
-rw-r--r--tests/gethugepagesizes.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/tests/gethugepagesizes.c b/tests/gethugepagesizes.c
index 8a6d2d6..860b9a5 100644
--- a/tests/gethugepagesizes.c
+++ b/tests/gethugepagesizes.c
@@ -255,22 +255,29 @@ void cleanup(void)
cleanup_fake_data();
}
-void validate_sizes(int line, long actual_sizes[], int actual, int max_actual,
- long expected_sizes[], int expected)
+void validate_sizes(int line, long actual_sizes[], int actual,
+ int max, int maxmax,
+ long expected_sizes[], int expected)
{
int i, j;
- if (expected != actual)
+
+ verbose_printf("Line %d: Expecting sizes:", line);
+ for (i = 0; i < expected; i++)
+ verbose_printf(" %ld", expected_sizes[i]);
+ verbose_printf("\n");
+ verbose_printf("Line %d: Actual sizes are:", line);
+ for (i = 0; i < actual; i++)
+ verbose_printf(" %ld", actual_sizes[i]);
+ verbose_printf("\n");
+
+ if (((expected <= max) && (expected != actual))
+ || ((expected > max) && (actual < max)))
FAIL("Line %i: Wrong number of sizes returned -- expected %i "
- "got %i", line, expected, actual);
+ "got %i", line, expected, actual);
+ else if (actual > max)
+ FAIL("Line %i: %i sizes returned > maximum %i",
+ line, actual, max);
- for (i = 0; i < expected; i++) {
- for (j = 0; j < actual; j++)
- if (expected_sizes[i] == actual_sizes[j])
- break;
- if (j >= actual)
- FAIL("Line %i: Expected size %li not found in actual "
- "results", line, expected_sizes[i]);
- }
for (i = 0; i < actual; i++) {
for (j = 0; j < expected; j++)
if (actual_sizes[i] == expected_sizes[j])
@@ -280,7 +287,13 @@ void validate_sizes(int line, long actual_sizes[], int actual, int max_actual,
"results", line, expected_sizes[i]);
}
- for (i = expected; i < max_actual; i++)
+ for (i = 0; i < actual; i++)
+ for (j = i+1; j < actual; j++)
+ if (actual_sizes[i] == actual_sizes[j])
+ FAIL("Line %i: Duplicate size %li at %i/%i",
+ line, actual_sizes[i], i, j);
+
+ for (i = actual; i < maxmax; i++)
if (actual_sizes[i] != 42)
FAIL("Line %i: Wrote past official limit at %i",
line, i);
@@ -291,11 +304,10 @@ void validate_sizes(int line, long actual_sizes[], int actual, int max_actual,
({ \
long __a[MAX] = { [0 ... MAX-1] = 42 }; \
int __na; \
- int __l = (count < max) ? count : max; \
\
__na = func(__a, max); \
\
- validate_sizes(__LINE__, __a, __na, MAX, expected, __l); \
+ validate_sizes(__LINE__, __a, __na, max, MAX, expected, count); \
\
__na; \
})