Fix AMU non-zero counters test
The condition checked in one of the AMU tests (AMU counters always
non-zero) does not always hold. The counter that counts the memory stall
cycles, under certain circumstances, can be zero. Hence, the test is
adjusted accordingly and, consequently, renamed.
Change-Id: I8c7300481c2b45825101ee87f61c68c2ab51758a
Signed-off-by: John Tsichritzis <john.tsichritzis@arm.com>
diff --git a/tftf/tests/extensions/amu/test_amu.c b/tftf/tests/extensions/amu/test_amu.c
index a272aaf..8799aa5 100644
--- a/tftf/tests/extensions/amu/test_amu.c
+++ b/tftf/tests/extensions/amu/test_amu.c
@@ -91,12 +91,31 @@
}
/*
- * Check that group0/group1 counters are non-zero. As EL3
- * has enabled the counters before the first entry to NS world,
- * the counters should have increased by the time we reach this
- * test case.
+ * Helper function that checks whether the value of a group0 counter is valid
+ * or not. The first 3 counters (0,1,2) cannot have values of zero but the last
+ * counter that counts "memory stall cycles" can have a value of zero, under
+ * certain circumstances.
+ *
+ * Return values:
+ * 0 = valid counter value
+ * -1 = invalid counter value
*/
-test_result_t test_amu_nonzero_ctr(void)
+static int amu_group0_cnt_valid(unsigned int idx, uint64_t value)
+{
+ int answer = 0;
+
+ if ((idx <= 2) && (value == 0))
+ answer = -1;
+
+ return answer;
+}
+
+/*
+ * Check that group0 counters are valid. As EL3 has enabled the counters before
+ * the first entry to NS world, the counters should have increased by the time
+ * we reach this test case.
+ */
+test_result_t test_amu_valid_ctr(void)
{
int i;
@@ -108,11 +127,11 @@
return TEST_RESULT_SKIPPED;
for (i = 0; i < AMU_GROUP0_NR_COUNTERS; i++) {
- uint64_t v;
+ uint64_t value;
- v = amu_group0_cnt_read(i);
- if (v == 0) {
- tftf_testcase_printf("Group0 counter cannot be 0\n");
+ value = amu_group0_cnt_read(i);
+ if (amu_group0_cnt_valid(i, value)) {
+ tftf_testcase_printf("Group0 counter %d has invalid value %lld\n", i, value);
return TEST_RESULT_FAIL;
}
}
@@ -148,13 +167,13 @@
* If they are not, the AMU context save/restore in EL3 is buggy.
*/
for (i = 0; i < AMU_GROUP0_NR_COUNTERS; i++) {
- uint64_t v;
+ uint64_t value;
- v = amu_group0_cnt_read(i);
- if (v < group0_ctrs[i]) {
+ value = amu_group0_cnt_read(i);
+ if (value < group0_ctrs[i]) {
tftf_testcase_printf("Invalid counter value: before: %llx, after: %llx\n",
(unsigned long long)group0_ctrs[i],
- (unsigned long long)v);
+ (unsigned long long)value);
return TEST_RESULT_FAIL;
}
}