Test: Remove test result from struct test_t
It is unnecessary to assign a dedicated test result structure in
each test description. Test framework can define a common
test_result_t and pass it to each test case.
This patch removed the test_result_t in struct test_t to decrease
16 bytes * numbers of test cases.
Signed-off-by: Jianliang Shen <jianliang.shen@arm.com>
Change-Id: Ia46f88ec1641860b1d3416089cc79a63579a9cb0
diff --git a/test/framework/test_framework.c b/test/framework/test_framework.c
index 73bdbeb..0310474 100644
--- a/test/framework/test_framework.c
+++ b/test/framework/test_framework.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -12,9 +12,8 @@
#include <stdlib.h>
#include <string.h>
-static void test_failed(const struct test_t *p_test)
+static void test_failed(const struct test_result_t *ret, const char *name)
{
- const struct test_result_t *ret = &p_test->ret;
printf_set_color(RED);
if (ret->info_msg != 0) {
TEST_LOG(" %s", ret->info_msg);
@@ -27,7 +26,7 @@
}
}
- TEST_LOG(" TEST: %s - FAILED!\r\n", p_test->name);
+ TEST_LOG(" TEST: %s - FAILED!\r\n", name);
}
static void print_error(const char *err_msg)
@@ -89,6 +88,7 @@
uint32_t failed_tests = 0;
uint32_t i;
struct test_t *p_test;
+ struct test_result_t ret = {0};
if (test_suite == 0 || test_suite->freg == 0) {
print_error("TEST_SUITE_ERR_INVALID_DATA!");
@@ -120,12 +120,12 @@
p_test->name, p_test->desc);
/* Sets the default value before the test */
- p_test->ret.val = TEST_PASSED;
+ ret.val = TEST_PASSED;
/* Executes the test */
- p_test->test(&p_test->ret);
- if (p_test->ret.val == TEST_FAILED) {
- test_failed(p_test);
+ p_test->test(&ret);
+ if (ret.val == TEST_FAILED) {
+ test_failed(&ret, p_test->name);
failed_tests++;
} else {
printf_set_color(GREEN);