fix(unittests): fix checkpatch errors and warnings on .cpp files
This patch fixes all the errors and warnings reported by the
updated checkpatch.pl script with support for cpputest files.
xlat_tests_g1.cpp and xlat_tests_g2.cpp are excluded from
this patch as they will be fixed in a different patch.
Signed-off-by: Javier Almansa Sobrino <javier.almansasobrino@arm.com>
Change-Id: Ibfd9884f1ede2e70b9ff6db24c4e8f2558325c4d
diff --git a/lib/realm/tests/buffer.cpp b/lib/realm/tests/buffer.cpp
index f309028..7f97e6e 100644
--- a/lib/realm/tests/buffer.cpp
+++ b/lib/realm/tests/buffer.cpp
@@ -32,8 +32,10 @@
/*
* Function to get a random granule address within the valid address range.
*/
-static inline uintptr_t get_rand_granule_addr(void) {
+static inline uintptr_t get_rand_granule_addr(void)
+{
uintptr_t addr;
+
int random_granule = test_helpers_get_rand_in_range(0,
test_helpers_get_nr_granules() - 1);
@@ -53,10 +55,11 @@
arr[i] = get_rand_granule_addr();
if (i > 0U) {
bool match;
+
do {
/* Check for duplicates so far */
match = false;
- for (unsigned j = 0U; j < i; j++) {
+ for (unsigned int j = 0U; j < i; j++) {
if (arr[j] == arr[i]) {
arr[i] =
get_rand_granule_addr();
@@ -64,7 +67,7 @@
break;
}
}
- } while(match == true);
+ } while (match == true);
}
}
@@ -374,7 +377,7 @@
cb.buffer_unmap = test_buffer_unmap_aarch64_vmsa;
(void)test_helpers_register_cb(cb, CB_BUFFER_UNMAP);
- test_granule = realm_test_util_granule_struct_base() + \
+ test_granule = realm_test_util_granule_struct_base() +
HOST_NR_GRANULES;
slot = (enum buffer_slot)test_helpers_get_rand_in_range(
SLOT_NS + 1U, NR_CPU_SLOTS);
@@ -419,7 +422,7 @@
host_util_set_cpuid(cpuid);
test_helpers_expect_assert_fail(true);
- (void)granule_map((struct granule*)test_granule, slot);
+ (void)granule_map((struct granule *)test_granule, slot);
test_helpers_fail_if_no_assert_failed();
}
@@ -480,7 +483,7 @@
ns_buffer_write(SLOT_NS, test_granule,
GRANULE_BLOCK_SIZE * j,
GRANULE_BLOCK_SIZE,
- (void*)(granule_addrs[1] +
+ (void *)(granule_addrs[1] +
(GRANULE_BLOCK_SIZE * j)));
MEMCMP_EQUAL((void *)granule_addrs[1],
@@ -595,7 +598,7 @@
host_util_set_cpuid(cpu[i]);
ns_buffer_write(SLOT_NS, addr_to_granule(granule_addrs[i]), 0U,
- sizeof(long), (void*)&pattern[i]);
+ sizeof(long), (void *)&pattern[i]);
}
/*
@@ -917,7 +920,7 @@
ns_buffer_read(SLOT_NS, test_granule,
GRANULE_BLOCK_SIZE * j,
GRANULE_BLOCK_SIZE,
- (void*)(granule_addrs[1] +
+ (void *)(granule_addrs[1] +
(GRANULE_BLOCK_SIZE * j)));
MEMCMP_EQUAL((void *)granule_addrs[1],
@@ -1032,7 +1035,7 @@
host_util_set_cpuid(cpu[i]);
ns_buffer_read(SLOT_NS, addr_to_granule(granule_addrs[i]), 0U,
- sizeof(long), (void*)&dest[i]);
+ sizeof(long), (void *)&dest[i]);
}
/*
diff --git a/lib/realm/tests/granule.cpp b/lib/realm/tests/granule.cpp
index dea38fb..9abbbc4 100644
--- a/lib/realm/tests/granule.cpp
+++ b/lib/realm/tests/granule.cpp
@@ -41,7 +41,8 @@
* Function to get a random address within the granules range.
* The address will be aligned to granule size.
*/
-static inline unsigned long get_rand_granule_addr(void) {
+static inline unsigned long get_rand_granule_addr(void)
+{
unsigned long addr;
int random_granule = get_rand_granule_idx();
@@ -71,8 +72,9 @@
*addr += host_util_get_granule_base();
} else {
unsigned int granules_below;
- granules_below = (unsigned int)(host_util_get_granule_base() /
- GRANULE_SIZE);
+
+ granules_below =
+ (unsigned int)(host_util_get_granule_base() / GRANULE_SIZE);
if (granules_below == 0) {
return false;
@@ -94,7 +96,7 @@
*
* The input granule pointer must be valid.
*/
-static inline unsigned int set_rand_non_zero_lock_value(struct granule * granule)
+static inline unsigned int set_rand_non_zero_lock_value(struct granule *granule)
{
unsigned int lock =
(unsigned int)test_helpers_get_rand_in_range(1, INT_MAX);
@@ -141,10 +143,9 @@
{
struct granule *granule;
struct granule *expected_granule;
- unsigned int granule_indexes[3] =
- {0U,
- get_rand_granule_idx(),
- get_last_granule_idx()};
+ unsigned int granule_indexes[3] = {0U,
+ get_rand_granule_idx(),
+ get_last_granule_idx()};
unsigned long addr;
/******************************************************************
@@ -236,10 +237,9 @@
TEST(granule, granule_addr_TC1)
{
struct granule *granule;
- unsigned int granule_indexes[3] =
- {0U,
- get_rand_granule_idx(),
- get_last_granule_idx()};
+ unsigned int granule_indexes[3] = {0U,
+ get_rand_granule_idx(),
+ get_last_granule_idx()};
unsigned long expected_address;
unsigned long addr;
@@ -407,10 +407,9 @@
TEST(granule, find_granule_TC1)
{
struct granule *expected_granule;
- unsigned int granule_indexes[3] =
- {0U,
- get_rand_granule_idx(),
- get_last_granule_idx()};
+ unsigned int granule_indexes[3] = {0U,
+ get_rand_granule_idx(),
+ get_last_granule_idx()};
unsigned long address;
struct granule *granule;
@@ -424,7 +423,7 @@
******************************************************************/
for (unsigned int i = 0U; i < 3U; i++) {
- expected_granule = realm_test_util_granule_struct_base() + \
+ expected_granule = realm_test_util_granule_struct_base() +
granule_indexes[i];
address = (granule_indexes[i] * GRANULE_SIZE) +
host_util_get_granule_base();
@@ -473,8 +472,7 @@
POINTERS_EQUAL(NULL, granule);
/* Try the lower boundary as well */
- if (get_out_of_range_granule(&address, false) == true)
- {
+ if (get_out_of_range_granule(&address, false) == true) {
granule = find_granule(address);
POINTERS_EQUAL(NULL, granule);
}
@@ -697,13 +695,13 @@
g1 = NULL;
g2 = NULL;
- for(unsigned int state1 = GRANULE_STATE_NS;
- state1 <= GRANULE_STATE_LAST; state1++) {
+ for (unsigned int state1 = GRANULE_STATE_NS;
+ state1 <= GRANULE_STATE_LAST; state1++) {
- for(unsigned int state2 = GRANULE_STATE_NS;
- state2 <= GRANULE_STATE_LAST; state2++) {
- if(state1 == GRANULE_STATE_NS &&
- state2 == GRANULE_STATE_NS) {
+ for (unsigned int state2 = GRANULE_STATE_NS;
+ state2 <= GRANULE_STATE_LAST; state2++) {
+ if (state1 == GRANULE_STATE_NS &&
+ state2 == GRANULE_STATE_NS) {
/*
* Skip. Test case already checked as we expect
* the default state to be STATE_NS.
@@ -822,9 +820,8 @@
* granules in between.
***************************************************************/
for (unsigned int i = 0U; i < 3U; i++) {
- for(unsigned int state = GRANULE_STATE_NS + 1U;
- state <= GRANULE_STATE_LAST; state++)
- {
+ for (unsigned int state = GRANULE_STATE_NS + 1U;
+ state <= GRANULE_STATE_LAST; state++) {
granule = find_lock_granule(addrs[i],
(enum granule_state)state);
POINTERS_EQUAL(NULL, granule);
@@ -845,9 +842,8 @@
***************************************************************/
addr = get_rand_granule_addr();
addr += test_helpers_get_rand_in_range(1, GRANULE_SIZE - 1);
- for(unsigned int state = GRANULE_STATE_NS;
- state <= GRANULE_STATE_LAST; state++)
- {
+ for (unsigned int state = GRANULE_STATE_NS;
+ state <= GRANULE_STATE_LAST; state++) {
granule = find_lock_granule(addr,
(enum granule_state)state);
POINTERS_EQUAL(NULL, granule);
@@ -867,9 +863,8 @@
***************************************************************/
(void)get_out_of_range_granule(&addr, true);
- for(unsigned int state = GRANULE_STATE_NS;
- state <= GRANULE_STATE_LAST; state++)
- {
+ for (unsigned int state = GRANULE_STATE_NS;
+ state <= GRANULE_STATE_LAST; state++) {
granule = find_lock_granule(addr,
(enum granule_state)state);
POINTERS_EQUAL(NULL, granule);
@@ -926,9 +921,9 @@
* to ensure the correctness of the granule. Therefore, skip any tests
* with invalid granules.
*
- * In addition to that, granule_lock() also expects:
- * * That the expected state belongs to enum granule_state,
- * so it doesn't perform any checks on that either.
+ * In addition to that, granule_lock() also expects that the expected
+ * state belongs to enum granule_state so it doesn't perform any checks
+ * on that either.
*/
}
@@ -1640,12 +1635,11 @@
/*
* Start the test with a granule in the same state as at the
* end of the previous test
- */
+ */
granule_set_state(granule, GRANULE_STATE_RD);
- for(unsigned int state = GRANULE_STATE_NS;
- state <= GRANULE_STATE_LAST; state++)
- {
+ for (unsigned int state = GRANULE_STATE_NS;
+ state <= GRANULE_STATE_LAST; state++) {
if (state == GRANULE_STATE_RD) {
/* Skip as the state is the correct one */
continue;
@@ -1760,7 +1754,7 @@
* Repeat the operation on all possible CPUs.
*
* NOTE: granule_memzero() will fail with SLOT_NS, so skip that
- * testcase.
+ * testcase.
***************************************************************/
for (unsigned int i = 0U; i < 3U; i++) {