smc(fuzzer): random seed generation and build parameters

This patch adds build parameters to TFTF to allow more control of the
SMC fuzzing test suite as well as randomly generating seeds for the
pseudo-random number generator used for SMC fuzzing tests.

Build Options

SMC_FUZZ_CALLS_PER_INSTANCE=n: Sets the number of SMC calls per test
instance, where n is the number of calls. If not provided, this value
defaults to 100.

SMC_FUZZ_INSTANCE_COUNT=n: Sets the number of instances to run, where n
is the number of instances. If not provided, this value defaults to 1.

SMC_FUZZ_SEEDS=i,j,k,...: If randomly generated seeds are not desired,
such as a case where a certain seed results in a fail, seeds can be
provided in the build command.  The seeds can either be integers or hex
values, must be formatted as shown with a comma between each seed and
no spaces, and the number of seeds provided must match
SMC_FUZZ_INSTANCE_COUNT. If not provided, seeds are randomly generated
by the build system.

Signed-off-by: John Powell <john.powell@arm.com>
Change-Id: I2cc6f4d7a02ec4b590db335ac098c9d41df42f0c
diff --git a/tftf/tests/tests-smcfuzzing.mk b/tftf/tests/tests-smcfuzzing.mk
index 82b6a7c..1837ee9 100644
--- a/tftf/tests/tests-smcfuzzing.mk
+++ b/tftf/tests/tests-smcfuzzing.mk
@@ -4,6 +4,37 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+# Generate random fuzzing seeds
+# If no instance count is provided, default to 1 instance
+# If no seeds are provided, generate them randomly
+# The number of seeds provided must match the instance count
+SMC_FUZZ_INSTANCE_COUNT ?= 1
+SMC_FUZZ_SEEDS ?= $(shell python -c "from random import randint; seeds = [randint(0, 4294967295) for i in range($(SMC_FUZZ_INSTANCE_COUNT))];print(\",\".join(str(x) for x in seeds));")
+SMC_FUZZ_CALLS_PER_INSTANCE ?= 100
+
+# Validate SMC fuzzer parameters
+
+# Instance count must not be zero
+ifeq ($(SMC_FUZZ_INSTANCE_COUNT),0)
+$(error SMC_FUZZ_INSTANCE_COUNT must not be zero!)
+endif
+
+# Calls per instance must not be zero
+ifeq ($(SMC_FUZZ_CALLS_PER_INSTANCE),0)
+$(error SMC_FUZZ_CALLS_PER_INSTANCE must not be zero!)
+endif
+
+# Make sure seed count and instance count match
+TEST_SEED_COUNT = $(shell python -c "print(len(\"$(SMC_FUZZ_SEEDS)\".split(\",\")))")
+ifneq ($(TEST_SEED_COUNT), $(SMC_FUZZ_INSTANCE_COUNT))
+$(error Number of seeds does not match SMC_FUZZ_INSTANCE_COUNT!)
+endif
+
+# Add definitions to TFTF_DEFINES so they can be used in the code
+$(eval $(call add_define,TFTF_DEFINES,SMC_FUZZ_SEEDS))
+$(eval $(call add_define,TFTF_DEFINES,SMC_FUZZ_INSTANCE_COUNT))
+$(eval $(call add_define,TFTF_DEFINES,SMC_FUZZ_CALLS_PER_INSTANCE))
+
 TESTS_SOURCES	+=							\
 	$(addprefix smc_fuzz/src/,					\
 		randsmcmod.c						\