refact(trng): cleanup TRNG service tests

This patch adds the following changes:
1. Updates tftf-docs on the TRNG test support
2. Improvise few other files and macro names

Signed-off-by: Jayanth Dodderi Chidanand <jayanthdodderi.chidanand@arm.com>
Change-Id: I69bbcb24e8485d2cd1384970e7424541d11838af
diff --git a/docs/about/features.rst b/docs/about/features.rst
index dbaec12..dbdb324 100644
--- a/docs/about/features.rst
+++ b/docs/about/features.rst
@@ -19,6 +19,7 @@
 -  `Firmware update`_ (or recovery mode)
 -  `EL3 payload boot flow`_
 -  Secure partition support
+-  `True Random Number Generator Firmware Interface (TRNG_FW)`_
 
 These tests are not a compliance test suite for the Arm interface standards used
 in TF-A (such as PSCI).
@@ -55,3 +56,4 @@
 .. _TSP: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/bl32/tsp
 .. _Firmware update: https://trustedfirmware-a.readthedocs.io/en/latest/components/firmware-update.html
 .. _EL3 payload boot flow: https://trustedfirmware-a.readthedocs.io/en/latest/design/alt-boot-flows.html#el3-payloads-alternative-boot-flow
+.. _TRNG_FW: https://developer.arm.com/documentation/den0098/latest
diff --git a/include/runtime_services/trng.h b/include/runtime_services/trng.h
index a5d8e4d..41600b4 100644
--- a/include/runtime_services/trng.h
+++ b/include/runtime_services/trng.h
@@ -42,12 +42,12 @@
 #define SMC_TRNG_RND				0x84000053
 #define TRNG_MAX_BITS				U(96)
 #define TRNG_ENTROPY_MASK			U(0xFFFFFFFF)
-#endif
+#endif  /* __aarch64__ */
 
 /*
  * Number of TRNG calls defined in the TRNG specification.
  */
-#define TRNG_NUM_CALLS				4
+#define TRNG_NUM_CALLS				(4U)
 
 #ifndef __ASSEMBLY__
 typedef struct {
@@ -67,17 +67,16 @@
 /*******************************************************************************
  * TRNG version
  ******************************************************************************/
-#define TRNG_MAJOR_VER_SHIFT	(16)
-#define TRNG_VERSION(major, minor)	((major << TRNG_MAJOR_VER_SHIFT) \
-					| minor)
+#define TRNG_MAJOR_VER_SHIFT	        (16)
+#define TRNG_VERSION(major, minor)	((major << TRNG_MAJOR_VER_SHIFT)| minor)
 
 /*******************************************************************************
  * TRNG error codes
  ******************************************************************************/
-#define TRNG_E_SUCCESS		(0)
-#define TRNG_E_NOT_SUPPORTED	(-1)
-#define TRNG_E_INVALID_PARAMS	(-2)
-#define TRNG_E_NO_ENTOPY	(-3)
-#define TRNG_E_NOT_IMPLEMENTED	(-4)
+#define TRNG_E_SUCCESS			(0)
+#define TRNG_E_NOT_SUPPORTED		(-1)
+#define TRNG_E_INVALID_PARAMS		(-2)
+#define TRNG_E_NO_ENTROPY		(-3)
+#define TRNG_E_NOT_IMPLEMENTED		(-4)
 
 #endif /* __TRNG_H__ */
diff --git a/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c b/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
index 64b8db7..72a4ec5 100644
--- a/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
+++ b/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -29,7 +29,6 @@
 		return TEST_RESULT_SKIPPED;
 	}
 
-
 	if (version < TRNG_VERSION(1, 0)) {
 		return TEST_RESULT_FAIL;
 	}
@@ -51,8 +50,7 @@
 		return TEST_RESULT_SKIPPED;
 	}
 
-	if (!(tftf_trng_feature_implemented(SMC_TRNG_VERSION) &&
-	      tftf_trng_feature_implemented(SMC_TRNG_FEATURES) &&
+	if (!(tftf_trng_feature_implemented(SMC_TRNG_FEATURES) &&
 	      tftf_trng_feature_implemented(SMC_TRNG_UUID) &&
 	      tftf_trng_feature_implemented(SMC_TRNG_RND))) {
 		return TEST_RESULT_FAIL;
@@ -75,6 +73,11 @@
 		return TEST_RESULT_SKIPPED;
 	}
 
+	/* Ensure function is implemented before requesting Entropy */
+	if (!(tftf_trng_feature_implemented(SMC_TRNG_RND))) {
+		return TEST_RESULT_FAIL;
+	}
+
 	/* Test invalid entropy sizes */
 	rnd_out = tftf_trng_rnd(U(0));
 	if (rnd_out.ret0 != TRNG_E_INVALID_PARAMS) {
@@ -97,7 +100,7 @@
 	/* For N = 1, all returned entropy bits should be 0
 	 * except the least significant bit */
 	rnd_out = tftf_trng_rnd(U(1));
-	if (rnd_out.ret0 == TRNG_E_NO_ENTOPY) {
+	if (rnd_out.ret0 == TRNG_E_NO_ENTROPY) {
 		WARN("There is not a single bit of entropy\n");
 		return TEST_RESULT_SKIPPED;
 	}
@@ -116,7 +119,7 @@
 
 	/* For N = MAX_BITS-1, the most significant bit should be 0 */
 	rnd_out = tftf_trng_rnd(TRNG_MAX_BITS - U(1));
-	if (rnd_out.ret0 == TRNG_E_NO_ENTOPY) {
+	if (rnd_out.ret0 == TRNG_E_NO_ENTROPY) {
 		WARN("There is not a single bit of entropy\n");
 		return TEST_RESULT_SKIPPED;
 	}
diff --git a/tftf/tests/tests-trng.mk b/tftf/tests/tests-trng.mk
index d284296..abeb5b5 100644
--- a/tftf/tests/tests-trng.mk
+++ b/tftf/tests/tests-trng.mk
@@ -1,7 +1,10 @@
 #
-# Copyright (c) 2021, Arm Limited. All rights reserved.
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-TESTS_SOURCES	+= tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
+TESTS_SOURCES	+=							\
+	$(addprefix tftf/tests/runtime_services/standard_service/,	\
+		/trng/api_tests/test_trng.c				\
+	)