aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGary Morrison <gary.morrison@arm.com>2020-05-01 20:03:30 +0100
committerAnton Komlev <Anton.Komlev@arm.com>2021-05-21 13:18:07 +0200
commit4c823bdbef28f327e7b4882d363ec284a4c20012 (patch)
treed678c6592be6e76b085cf431702baea6e4d3bc95 /tools
parentaa6e8ce59beb4a21d0b8cd8891a4e57774ed9d08 (diff)
downloadtrusted-firmware-m-4c823bdbef28f327e7b4882d363ec284a4c20012.tar.gz
TF-Fuzz: Restructure TF-Fuzz for correct code generation
This patch provides changes to separate a Simulation Phase (calculating expected results) from the Parse Phase (parsing the input test-template file), to correctly manage variables named in the test template, and to move documentation from per-directory README files to .rst files (README files now point to rendered .rst files). Change-Id: I223420ad8d431ad508663744bba46511812e663a Signed-off-by: Gary Morrison <gary.morrison@arm.com> Signed-off-by: Karl Zhang <karl.zhang@arm.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/tf_fuzz/Makefile94
-rw-r--r--tools/tf_fuzz/README125
-rw-r--r--tools/tf_fuzz/assets/README13
-rw-r--r--tools/tf_fuzz/assets/psa_asset.cpp9
-rw-r--r--tools/tf_fuzz/assets/psa_asset.hpp14
-rw-r--r--tools/tf_fuzz/assets/sst_asset.cpp2
-rw-r--r--tools/tf_fuzz/boilerplate/README15
-rw-r--r--tools/tf_fuzz/calls/README14
-rw-r--r--tools/tf_fuzz/calls/crypto_call.cpp313
-rw-r--r--tools/tf_fuzz/calls/crypto_call.hpp14
-rw-r--r--tools/tf_fuzz/calls/psa_call.cpp91
-rw-r--r--tools/tf_fuzz/calls/psa_call.hpp22
-rw-r--r--tools/tf_fuzz/calls/security_call.cpp22
-rw-r--r--tools/tf_fuzz/calls/security_call.hpp2
-rw-r--r--tools/tf_fuzz/calls/sst_call.cpp351
-rw-r--r--tools/tf_fuzz/calls/sst_call.hpp6
-rw-r--r--tools/tf_fuzz/class_forwards.hpp11
-rw-r--r--tools/tf_fuzz/demo/README16
-rw-r--r--tools/tf_fuzz/lib/README10
-rw-r--r--tools/tf_fuzz/lib/tfm_boilerplate.txt3
-rw-r--r--tools/tf_fuzz/parser/README11
-rw-r--r--tools/tf_fuzz/parser/tf_fuzz_grammar.l2
-rw-r--r--tools/tf_fuzz/parser/tf_fuzz_grammar.y492
-rw-r--r--tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py120
-rw-r--r--tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c10
-rw-r--r--tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py120
-rw-r--r--tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c12
-rw-r--r--tools/tf_fuzz/regression/000003_set_sst_name_data/check.py120
-rw-r--r--tools/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr6
-rw-r--r--tools/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c16
-rw-r--r--tools/tf_fuzz/regression/000003_set_sst_name_data/template2
-rw-r--r--tools/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py120
-rw-r--r--tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c12
-rw-r--r--tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py120
-rw-r--r--tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c12
-rw-r--r--tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py120
-rw-r--r--tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c60
-rw-r--r--tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py120
-rw-r--r--tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c60
-rw-r--r--tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py120
-rw-r--r--tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c21
-rw-r--r--tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py120
-rw-r--r--tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr6
-rw-r--r--tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c32
-rw-r--r--tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template2
-rw-r--r--tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py120
-rw-r--r--tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c9
-rw-r--r--tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py120
-rw-r--r--tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c9
-rw-r--r--tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py120
-rw-r--r--tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c9
-rw-r--r--tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py120
-rw-r--r--tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c14
-rw-r--r--tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py120
-rw-r--r--tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c15
-rw-r--r--tools/tf_fuzz/regression/000015_set_sst_name_only/check.py119
-rw-r--r--tools/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr25
-rw-r--r--tools/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c86
-rw-r--r--tools/tf_fuzz/regression/000015_set_sst_name_only/template3
-rw-r--r--tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/check.py119
-rw-r--r--tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr50
-rw-r--r--tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c111
-rw-r--r--tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/template6
-rw-r--r--tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/check.py119
-rw-r--r--tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr56
-rw-r--r--tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c123
-rw-r--r--tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/template7
-rw-r--r--tools/tf_fuzz/regression/000018_000016_and_000017/check.py119
-rw-r--r--tools/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr94
-rw-r--r--tools/tf_fuzz/regression/000018_000016_and_000017/exp_test.c173
-rw-r--r--tools/tf_fuzz/regression/000018_000016_and_000017/template11
-rw-r--r--tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/check.py119
-rw-r--r--tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr60
-rw-r--r--tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c142
-rw-r--r--tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/template7
-rw-r--r--tools/tf_fuzz/regression/README132
-rw-r--r--tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c30
-rw-r--r--tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr4
-rw-r--r--tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c30
-rw-r--r--tools/tf_fuzz/regression/regress14
-rw-r--r--tools/tf_fuzz/regression/regress_lib/line_by_line.py172
-rw-r--r--tools/tf_fuzz/template/README12
-rw-r--r--tools/tf_fuzz/template/crypto_template_line.cpp176
-rw-r--r--tools/tf_fuzz/template/crypto_template_line.hpp5
-rw-r--r--tools/tf_fuzz/template/secure_template_line.cpp25
-rw-r--r--tools/tf_fuzz/template/secure_template_line.hpp7
-rw-r--r--tools/tf_fuzz/template/sst_template_line.cpp196
-rw-r--r--tools/tf_fuzz/template/sst_template_line.hpp6
-rw-r--r--tools/tf_fuzz/template/template_line.cpp56
-rw-r--r--tools/tf_fuzz/template/template_line.hpp32
-rw-r--r--tools/tf_fuzz/tests/README12
-rw-r--r--tools/tf_fuzz/tf_fuzz.cpp79
-rw-r--r--tools/tf_fuzz/tf_fuzz.hpp46
-rw-r--r--tools/tf_fuzz/utility/README12
-rw-r--r--tools/tf_fuzz/utility/data_blocks.cpp61
-rw-r--r--tools/tf_fuzz/utility/data_blocks.hpp35
-rw-r--r--tools/tf_fuzz/utility/find_or_create_asset.hpp39
-rw-r--r--tools/tf_fuzz/utility/gibberish.cpp2
-rw-r--r--tools/tf_fuzz/utility/randomization.cpp20
-rw-r--r--tools/tf_fuzz/utility/variables.cpp72
-rw-r--r--tools/tf_fuzz/utility/variables.hpp59
-rw-r--r--tools/tf_fuzz/visualStudio/README14
115 files changed, 4992 insertions, 1596 deletions
diff --git a/tools/tf_fuzz/Makefile b/tools/tf_fuzz/Makefile
index 6d8be2b86..87b8f4daa 100644
--- a/tools/tf_fuzz/Makefile
+++ b/tools/tf_fuzz/Makefile
@@ -11,8 +11,8 @@ edit:
template/sst_template_line.hpp template/crypto_template_line.hpp \
template/secure_template_line.hpp calls/psa_call.hpp calls/sst_call.hpp \
calls/crypto_call.hpp calls/security_call.hpp assets/psa_asset.hpp \
- assets/sst_asset.hpp assets/crypto_asset.hpp utility/data_blocks.hpp \
- utility/gibberish.hpp utility/randomization.hpp \
+ assets/sst_asset.hpp assets/crypto_asset.hpp utility/data_blocks.hpp \
+ utility/variables.hpp utility/gibberish.hpp utility/randomization.hpp \
utility/find_or_create_asset.hpp utility/string_ops.hpp \
utility/compute.hpp boilerplate/boilerplate.hpp \
utility/find_or_create_asset.hpp class_forwards.hpp tf_fuzz.hpp \
@@ -38,7 +38,7 @@ edit3:
template/secure_template_line.hpp calls/psa_call.hpp calls/sst_call.hpp \
calls/crypto_call.hpp calls/security_call.hpp assets/psa_asset.hpp \
assets/sst_asset.hpp assets/crypto_asset.hpp utility/data_blocks.hpp \
- utility/gibberish.hpp utility/randomization.hpp \
+ utility/variables.hpp utility/gibberish.hpp utility/randomization.hpp \
utility/find_or_create_asset.hpp utility/string_ops.hpp \
utility/compute.hpp boilerplate/boilerplate.hpp \
utility/find_or_create_asset.hpp class_forwards.hpp tf_fuzz.hpp &
@@ -48,9 +48,9 @@ edit3:
template/secure_template_line.cpp calls/psa_call.cpp calls/sst_call.cpp \
calls/crypto_call.cpp calls/security_call.cpp assets/psa_asset.cpp \
assets/sst_asset.cpp assets/crypto_asset.cpp utility/data_blocks.cpp \
- utility/gibberish.cpp utility/randomization.cpp utility/string_ops.cpp \
- utility/compute.cpp \
- boilerplate/boilerplate.cpp tf_fuzz.cpp &
+ utility/variables.cpp utility/gibberish.cpp utility/randomization.cpp \
+ utility/string_ops.cpp utility/compute.cpp boilerplate/boilerplate.cpp \
+ tf_fuzz.cpp &
$(EDITOR) tests/example_template tests/sstSets tests/sstReads \
lib/tfm_boilerplate.txt boilerplate/boilerplate.hpp \
Makefile README assets/README \
@@ -62,7 +62,8 @@ includes = -I . -I ./parser -I ./template -I ./assets -I ./calls -I ./boilerplat
parser/tf_fuzz_grammar.tab.hpp: parser/tf_fuzz_grammar.y class_forwards.hpp \
boilerplate/boilerplate.hpp utility/gibberish.hpp utility/string_ops.hpp \
-tf_fuzz.hpp utility/data_blocks.hpp utility/find_or_create_asset.hpp assets/psa_asset.hpp \
+tf_fuzz.hpp utility/data_blocks.hpp utility/variables.hpp \
+utility/find_or_create_asset.hpp assets/psa_asset.hpp \
assets/sst_asset.hpp assets/crypto_asset.hpp calls/psa_call.hpp \
template/template_line.hpp Makefile
rm -f parser/tf_fuzz_grammar.tab.hpp parser/tf_fuzz_grammar.tab.cpp \
@@ -72,7 +73,8 @@ template/template_line.hpp Makefile
parser/tf_fuzz_grammar.tab.cpp: parser/tf_fuzz_grammar.y class_forwards.hpp \
boilerplate/boilerplate.hpp utility/gibberish.hpp utility/string_ops.hpp \
-tf_fuzz.hpp utility/data_blocks.hpp utility/find_or_create_asset.hpp assets/psa_asset.hpp \
+tf_fuzz.hpp utility/data_blocks.hpp utility/variables.hpp \
+utility/find_or_create_asset.hpp assets/psa_asset.hpp \
assets/sst_asset.hpp assets/crypto_asset.hpp calls/psa_call.hpp \
template/template_line.hpp Makefile
rm -f parser/tf_fuzz_grammar.tab.hpp parser/tf_fuzz_grammar.tab.cpp \
@@ -92,78 +94,87 @@ parser/tf_fuzz_grammar.tab.cpp parser/tf_fuzz_grammar.tab.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c -I /usr/include $(includes) -o \
parser/tf_fuzz_grammar.tab.o parser/tf_fuzz_grammar.tab.cpp
-utility/data_block.o: utility/data_blocks.hpp utility/data_blocks.cpp Makefile
- g++ -Wall -std=c++11 -O0 -g -c $(includes) -o utility/data_block.o \
+utility/data_blocks.o: utility/data_blocks.hpp utility/data_blocks.cpp Makefile
+ g++ -Wall -std=c++11 -O0 -g -c $(includes) -o utility/data_blocks.o \
utility/data_blocks.cpp
+utility/variables.o: utility/find_or_create_asset.hpp \
+utility/variables.hpp utility/variables.cpp Makefile
+ g++ -Wall -std=c++11 -O0 -g -c $(includes) -o utility/variables.o \
+ utility/variables.cpp
+
template/template_line.o: utility/randomization.hpp template/template_line.cpp \
class_forwards.hpp boilerplate/boilerplate.hpp tf_fuzz.hpp calls/psa_call.hpp \
-assets/psa_asset.hpp utility/data_blocks.hpp template/template_line.hpp assets/sst_asset.hpp \
-assets/crypto_asset.hpp Makefile
+assets/psa_asset.hpp utility/data_blocks.hpp template/template_line.hpp \
+assets/sst_asset.hpp assets/crypto_asset.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o template/template_line.o \
template/template_line.cpp
template/sst_template_line.o: template/sst_template_line.cpp class_forwards.hpp \
boilerplate/boilerplate.hpp tf_fuzz.hpp calls/psa_call.hpp assets/psa_asset.hpp \
-utility/data_blocks.hpp template/template_line.hpp template/sst_template_line.hpp assets/sst_asset.hpp \
-assets/crypto_asset.hpp Makefile
+utility/data_blocks.hpp template/template_line.hpp template/sst_template_line.hpp \
+assets/sst_asset.hpp assets/crypto_asset.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o template/sst_template_line.o \
template/sst_template_line.cpp
template/crypto_template_line.o: template/crypto_template_line.cpp \
class_forwards.hpp boilerplate/boilerplate.hpp tf_fuzz.hpp calls/psa_call.hpp \
-assets/psa_asset.hpp utility/data_blocks.hpp template/template_line.hpp assets/sst_asset.hpp \
-assets/crypto_asset.hpp template/crypto_template_line.hpp Makefile
+assets/psa_asset.hpp utility/data_blocks.hpp template/template_line.hpp \
+assets/sst_asset.hpp assets/crypto_asset.hpp template/crypto_template_line.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o template/crypto_template_line.o \
template/crypto_template_line.cpp
template/secure_template_line.o: utility/randomization.hpp class_forwards.hpp \
boilerplate/boilerplate.hpp tf_fuzz.hpp calls/psa_call.hpp \
-assets/psa_asset.hpp utility/data_blocks.hpp template/secure_template_line.hpp assets/sst_asset.hpp \
-assets/crypto_asset.hpp Makefile
+assets/psa_asset.hpp utility/data_blocks.hpp template/secure_template_line.hpp \
+assets/sst_asset.hpp assets/crypto_asset.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o template/secure_template_line.o \
template/secure_template_line.cpp
assets/psa_asset.o: assets/psa_asset.cpp class_forwards.hpp \
-boilerplate/boilerplate.hpp tf_fuzz.hpp utility/data_blocks.hpp calls/psa_call.hpp assets/psa_asset.hpp \
-template/template_line.hpp Makefile
+boilerplate/boilerplate.hpp tf_fuzz.hpp utility/data_blocks.hpp calls/psa_call.hpp \
+assets/psa_asset.hpp template/template_line.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o assets/psa_asset.o \
assets/psa_asset.cpp
assets/sst_asset.o: assets/sst_asset.cpp class_forwards.hpp \
-boilerplate/boilerplate.hpp utility/data_blocks.hpp tf_fuzz.hpp calls/psa_call.hpp assets/psa_asset.hpp \
-template/template_line.hpp assets/sst_asset.hpp Makefile
+boilerplate/boilerplate.hpp utility/data_blocks.hpp tf_fuzz.hpp calls/psa_call.hpp \
+assets/psa_asset.hpp template/template_line.hpp assets/sst_asset.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o assets/sst_asset.o \
assets/sst_asset.cpp
assets/crypto_asset.o: utility/randomization.hpp assets/crypto_asset.cpp \
-class_forwards.hpp boilerplate/boilerplate.hpp tf_fuzz.hpp utility/data_blocks.hpp calls/psa_call.hpp \
-assets/psa_asset.hpp assets/crypto_asset.hpp Makefile
+class_forwards.hpp boilerplate/boilerplate.hpp tf_fuzz.hpp utility/data_blocks.hpp \
+calls/psa_call.hpp assets/psa_asset.hpp assets/crypto_asset.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o assets/crypto_asset.o \
assets/crypto_asset.cpp
calls/psa_call.o: calls/psa_call.cpp class_forwards.hpp \
-boilerplate/boilerplate.hpp utility/data_blocks.hpp tf_fuzz.hpp calls/psa_call.hpp Makefile
+boilerplate/boilerplate.hpp utility/data_blocks.hpp utility/variables.hpp tf_fuzz.hpp \
+calls/psa_call.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o calls/psa_call.o calls/psa_call.cpp
calls/sst_call.o: calls/sst_call.cpp class_forwards.hpp \
boilerplate/boilerplate.hpp tf_fuzz.hpp calls/psa_call.hpp assets/psa_asset.hpp \
-template/template_line.hpp utility/data_blocks.hpp calls/sst_call.hpp assets/sst_asset.hpp \
-assets/crypto_asset.hpp utility/string_ops.hpp Makefile
+template/template_line.hpp utility/data_blocks.hpp utility/variables.hpp \
+calls/sst_call.hpp assets/sst_asset.hpp assets/crypto_asset.hpp utility/string_ops.hpp \
+Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o calls/sst_call.o \
calls/sst_call.cpp
calls/crypto_call.o: utility/randomization.hpp calls/crypto_call.cpp \
class_forwards.hpp boilerplate/boilerplate.hpp utility/string_ops.hpp \
-tf_fuzz.hpp calls/psa_call.hpp utility/data_blocks.hpp assets/psa_asset.hpp template/template_line.hpp \
+tf_fuzz.hpp calls/psa_call.hpp utility/data_blocks.hpp utility/variables.hpp \
+assets/psa_asset.hpp template/template_line.hpp \
calls/crypto_call.hpp assets/sst_asset.hpp assets/crypto_asset.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o calls/crypto_call.o \
calls/crypto_call.cpp
calls/security_call.o: utility/randomization.hpp calls/security_call.hpp \
calls/security_call.cpp class_forwards.hpp boilerplate/boilerplate.hpp \
-utility/string_ops.hpp utility/data_blocks.hpp tf_fuzz.hpp calls/psa_call.hpp assets/psa_asset.hpp \
-template/template_line.hpp calls/security_call.hpp assets/sst_asset.hpp \
+utility/string_ops.hpp utility/data_blocks.hpp utility/variables.hpp tf_fuzz.hpp \
+calls/psa_call.hpp assets/psa_asset.hpp template/template_line.hpp \
+calls/security_call.hpp assets/sst_asset.hpp \
Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o calls/security_call.o \
calls/security_call.cpp
@@ -193,25 +204,25 @@ utility/compute.o: utility/compute.cpp utility/compute.hpp Makefile
utility/compute.cpp
tf_fuzz.o: tf_fuzz.cpp class_forwards.hpp boilerplate/boilerplate.hpp tf_fuzz.hpp \
-calls/psa_call.hpp assets/psa_asset.hpp utility/data_blocks.hpp template/template_line.hpp \
-parser/tf_fuzz_grammar.tab.hpp Makefile
+calls/psa_call.hpp assets/psa_asset.hpp utility/data_blocks.hpp utility/variables.hpp \
+template/template_line.hpp parser/tf_fuzz_grammar.tab.hpp Makefile
g++ -Wall -std=c++11 -O0 -g -c $(includes) -o tf_fuzz.o tf_fuzz.cpp
tfz: parser/tf_fuzz_grammar.lex.o parser/tf_fuzz_grammar.tab.o \
template/secure_template_line.o template/template_line.o \
-template/sst_template_line.o template/crypto_template_line.o utility/data_block.o \
-assets/psa_asset.o assets/sst_asset.o assets/crypto_asset.o utility/gibberish.o \
-utility/string_ops.o calls/psa_call.o calls/sst_call.o calls/crypto_call.o \
-utility/randomization.o utility/compute.o boilerplate/boilerplate.o \
+template/sst_template_line.o template/crypto_template_line.o utility/data_blocks.o \
+utility/variables.o assets/psa_asset.o assets/sst_asset.o assets/crypto_asset.o \
+utility/gibberish.o utility/string_ops.o calls/psa_call.o calls/sst_call.o \
+calls/crypto_call.o utility/randomization.o utility/compute.o boilerplate/boilerplate.o \
calls/security_call.o tf_fuzz.o \
Makefile
g++ -Wall -std=c++11 -O0 -g -o tfz parser/tf_fuzz_grammar.lex.o \
parser/tf_fuzz_grammar.tab.o template/secure_template_line.o \
- template/template_line.o template/sst_template_line.o utility/data_block.o \
- template/crypto_template_line.o assets/psa_asset.o assets/sst_asset.o \
- assets/crypto_asset.o utility/gibberish.o utility/string_ops.o \
- utility/randomization.o utility/compute.o calls/psa_call.o \
- calls/sst_call.o calls/crypto_call.o calls/security_call.o \
+ template/template_line.o template/sst_template_line.o utility/data_blocks.o \
+ utility/variables.o template/crypto_template_line.o assets/psa_asset.o \
+ assets/sst_asset.o assets/crypto_asset.o utility/gibberish.o \
+ utility/string_ops.o utility/randomization.o utility/compute.o \
+ calls/psa_call.o calls/sst_call.o calls/crypto_call.o calls/security_call.o \
boilerplate/boilerplate.o tf_fuzz.o
clean:
@@ -221,5 +232,4 @@ clean:
parser/tf_fuzz_grammar.output
rm -f `find regression -name "stdout_stderr"`
rm -f `find regression -name "test.c"`
- rm -f `find regression -name "diff_*"`
rm -f demo/tossThis*
diff --git a/tools/tf_fuzz/README b/tools/tf_fuzz/README
deleted file mode 100644
index 47e266380..000000000
--- a/tools/tf_fuzz/README
+++ /dev/null
@@ -1,125 +0,0 @@
-.../tf_fuzz directory contents:
-
-assets calls demo parser tests regression
-backupStuff class_forwards.hpp lib README tf_fuzz.cpp utility
-boilerplate commands Makefile template tf_fuzz.hpp visualStudio
-
-TF-Fuzz root directory.
-
---------------------------------------------------------------------------------
-
-TF-Fuzz is a TF-M fuzzing tool, at the PSA-call level. At the time of writing
-this at least, presentations available at:
- https://www.trustedfirmware.org/docs/TF-M_Fuzzing_Tool_TFOrg.pdf
- https://zoom.us/rec/share/1dxZcZit111IadadyFqFU7IoP5X5aaa8gXUdr_UInxmMbyLzEqEmXQdx79-IWQ9p
-(These presentation materials may not be viewable by all parties.)
-
---------------------------------------------------------------------------------
-
-To build TF-Fuzz, simply type "make" in this directory. Executable, called
-"tfz," is placed in this directory.
-
-To run tfz, two environment variables must first be assigned. In bash syntax:
-export TF_FUZZ_LIB_DIR=<path to this TF-M installation>/tools/tf_fuzz/lib
-export TF_FUZZ_BPLATE=tfm_boilerplate.txt
-
-Examples of usage can be found in the demo directory.
-
---------------------------------------------------------------------------------
-
-To help understand the code, below is a C++-class hierarchy used in this code
-base. They are explained further in the READMEs in their respective direc-
-tories, so the file names where the classes are defined is listed below (this,
-very roughly in order of functional interactions, of chronological usage during
-execution, and of most-to-least importance):
-
- template_line ./template/template_line.hpp
- sst_template_line ./template/template_line.hpp
- read_sst_template_line ./template/sst_template_line.hpp
- remove_sst_template_line ./template/sst_template_line.hpp
- set_sst_template_line ./template/sst_template_line.hpp
- policy_template_line ./template/template_line.hpp
- read_policy_template_line ./template/crypto_template_line.hpp
- set_policy_template_line ./template/crypto_template_line.hpp
- key_template_line ./template/template_line.hpp
- read_key_template_line ./template/crypto_template_line.hpp
- remove_key_template_line ./template/crypto_template_line.hpp
- set_key_template_line ./template/crypto_template_line.hpp
- security_template_line ./template/template_line.hpp
- security_hash_template_line ./template/secure_template_line.hpp
-
- psa_call ./calls/psa_call.hpp
- crypto_call ./calls/psa_call.hpp
- policy_call ./calls/crypto_call.hpp
- policy_get_call ./calls/crypto_call.hpp
- policy_set_call ./calls/crypto_call.hpp
- key_call ./calls/crypto_call.hpp
- get_key_info_call ./calls/crypto_call.hpp
- set_key_call ./calls/crypto_call.hpp
- destroy_key_call ./calls/crypto_call.hpp
- sst_call ./calls/psa_call.hpp
- sst_remove_call ./calls/sst_call.hpp
- sst_get_call ./calls/sst_call.hpp
- sst_set_call ./calls/sst_call.hpp
- security_call ./calls/psa_call.hpp
- hash_call ./calls/security_call.hpp
-
- boilerplate ./boilerplate/boilerplate.hpp
-
- psa_asset ./assets/psa_asset.hpp
- crypto_asset ./assets/crypto_asset.hpp
- policy_asset ./assets/crypto_asset.hpp
- key_asset ./assets/crypto_asset.hpp
- sst_asset ./assets/sst_asset.hpp
-
- tf_fuzz_info ./tf_fuzz.hpp
-
- crc32 ./utility/compute.hpp
-
- gibberish ./utility/gibberish.hpp
-
- expect_info ./utility/data_blocks.hpp
- set_data_info ./utility/data_blocks.hpp
- asset_name_id_info ./utility/data_blocks.hpp
-
---------------------------------------------------------------------------------
-
-There are currently two especially annoying warts on the design of TF-Fuzz:
-* Need better management of variables in the generated code. Currently,
- for example, upon "read"ing a value from a PSA asset more than once, it
- creates a same-named (i.e., duplicate) variable for each such time, which
- is obviously not right.
-* Upon adding the ability to do "do any N of these PSA calls at random,"
- in hindsight, a fundamental flaw was uncovered in the top-level flow of
- how TF-Fuzz generates the code. High-level summary:
- * It should have completely distinct Parse, Simulate, then Code-generation
- stages.
- * Currently, the Parse and Simulate stages aren't really completely
- distinct, so there's a bunch of complicated Boolean flags traffic-
- copping between what in hindsight should be completely-separate Parse
- vs. Code-generation functionality.
- The function, interpret_template_line(), currently in
- .../tf_fuzz/parser/tf_fuzz_grammar.y (which may be moved to the its own file
- with randomize_template_lines()), has the lion's share of such Booleans,
- such as fill_in_template, create_call_bool, and create_asset_bool.
- The way it *should* work is:
- * The parser in .../tf_fuzz_grammar.y should generate an STL vector (or
- list) of psa_call-subclass "tracker" objects. It should not generate
- PSA-asset tracker objects (subclasses of psa_asset).
- * There should then be an organized Simulate stage, that sequences through
- the psa_call-subclass list, creating and accumulating/maintaining current
- state in psa_asset-subclass objects, using that current state to
- determine expected results of each PSA call, which get annotated back
- into the psa_call-tracker objects.
- * Finally, there already is, and should continue to be, a Code-generation
- phase that writes out the code, based upon text substitutions of
- "boilerplate" code snippets.
- * Currently, (hindsight obvious) the Parse and Simulate phases got somewhat
- muddled together. This shouldn't be super-hard to fix.
- That final Code-generation phase, conceptually at least, could be replaced
- instead with simply executing those commands directly, for targets that
- sufficient space to run TF-Fuzz in real-time.
-
---------------
-
-*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
diff --git a/tools/tf_fuzz/assets/README b/tools/tf_fuzz/assets/README
index d5f0a0a59..870416e75 100644
--- a/tools/tf_fuzz/assets/README
+++ b/tools/tf_fuzz/assets/README
@@ -1,18 +1,9 @@
-.../tf_fuzz/assets directory contents:
-
-crypto_asset.cpp psa_asset.cpp sst_asset.cpp
-crypto_asset.hpp psa_asset.hpp sst_asset.hpp
-
---------------------------------------------------------------------------------
-
This directory contains C++ header and program files for classes of objects that
track PSA assets, notably during the Simulate phase.
-These hold current state of those assets as the run is simulated, after the
-exact sequence of PSA commands to be executed is generated by the Parse stage.
+For more information, please browse to:
-Currently, the Simulate stage, which should be completely distinct from the
-initial Parse stage, in hindsight, is a bit muddled up with the Parse stage.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/asset_dir.html
--------------
diff --git a/tools/tf_fuzz/assets/psa_asset.cpp b/tools/tf_fuzz/assets/psa_asset.cpp
index d5bed0884..2c230e7dd 100644
--- a/tools/tf_fuzz/assets/psa_asset.cpp
+++ b/tools/tf_fuzz/assets/psa_asset.cpp
@@ -25,7 +25,7 @@
void psa_asset::set_name (string set_val)
{
- asset_id.name_specified = true;
+ asset_info.name_specified = true;
asset_name.assign (set_val);
}
@@ -34,9 +34,14 @@ string psa_asset::get_name (void)
return asset_name;
}
+bool psa_asset::simulate (void) {
+ return false;
+ // by default, assume that nothing changed; derived classes may override.
+}
+
psa_asset::psa_asset (void) // (default constructor)
{
- asset_ser_no = unique_id_counter++; // just something to pin a breakpoint onto
+ asset_info.asset_ser_no = unique_id_counter++;
}
diff --git a/tools/tf_fuzz/assets/psa_asset.hpp b/tools/tf_fuzz/assets/psa_asset.hpp
index 94c7ddfd2..ba42f2204 100644
--- a/tools/tf_fuzz/assets/psa_asset.hpp
+++ b/tools/tf_fuzz/assets/psa_asset.hpp
@@ -28,20 +28,28 @@ public:
on-going, real-time asset data value than about *setting* its data
value. On a template_line or a psa_call, it's about setting its
value at one particular time. */
- asset_name_id_info asset_id; // everything about the asset(s) for this line
+ expect_info exp_data;
+ /* For now at least, this is here only for its n_exp_vars member, to
+ keep track of how many expected-data variables in the test. */
+ asset_name_id_info asset_info; // everything about the asset(s) for this line
vector<int> template_ref;
// list of template line #s that reference this asset
vector<psa_call> call_ref; // list of PSA calls that reference this asset
string handle_str; // the text name of the key's "handle"
string flags_string; // creation flags
- long asset_ser_no;
- // unique serial# for this psa_asset; see note in tf_fuzz.hpp
bool asset_name_specified;
/* true if the template specified the asset_name, as opposed to us
having inferred it. */
// Methods:
void set_name (string set_val);
string get_name (void);
+ virtual bool simulate (void);
+ /* simulate() tells this asset to react to its current state information.
+ Initially, this won't really do much, but will allow assets to react
+ to each other, if that is relevant. It returns true if anything
+ in the state of the asset changed, in which case all assets' simulate()
+ methods will be invoked again to react again. That will repeat until
+ all assets read a quiescent state. */
psa_asset(); // (constructor)
~psa_asset();
diff --git a/tools/tf_fuzz/assets/sst_asset.cpp b/tools/tf_fuzz/assets/sst_asset.cpp
index 8b482eb87..ac4de6f05 100644
--- a/tools/tf_fuzz/assets/sst_asset.cpp
+++ b/tools/tf_fuzz/assets/sst_asset.cpp
@@ -30,7 +30,7 @@ bool sst_asset::set_uid (uint64_t uid)
/* TODO: What are the limits upon UIDs? I don't necessarily not want to be
able to set an illegal value, but if it is illegal, I might want to
set some flag appropriately to generate expected results. */
- asset_id.set_id_n (uid);
+ asset_info.set_id_n (uid);
return true;
}
diff --git a/tools/tf_fuzz/boilerplate/README b/tools/tf_fuzz/boilerplate/README
index 6bca1583e..60c78faa5 100644
--- a/tools/tf_fuzz/boilerplate/README
+++ b/tools/tf_fuzz/boilerplate/README
@@ -1,16 +1,9 @@
-.../tf_fuzz/boilerplate directory contents:
-
-boilerplate.cpp boilerplate.hpp
-
---------------------------------------------------------------------------------
-
These are the C++ code to work with the customizable, "boilerplate" code
-snippets in the .../lib directory. Actually, mostly what this code does is
-read these code snippets into an STL vector of, essentially, named strings.
+snippets in the .../lib directory.
+
+For more information, please browse to:
-This is currently implemented as a vector of strings, with a parallel vector
-of const int array-index names. A much better way, in hindsight, to manage
-the boilerplate code is in an STL "map" container.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/boilerplate_dir.html
--------------
diff --git a/tools/tf_fuzz/calls/README b/tools/tf_fuzz/calls/README
index e9f9c3945..c57499e43 100644
--- a/tools/tf_fuzz/calls/README
+++ b/tools/tf_fuzz/calls/README
@@ -1,15 +1,9 @@
-.../tf_fuzz/calls directory contents:
-
-crypto_call.cpp psa_call.cpp security_call.cpp sst_call.cpp
-crypto_call.hpp psa_call.hpp security_call.hpp sst_call.hpp
+These classes define objects that describe everything needed to generate a PSA
+call.
---------------------------------------------------------------------------------
+For more information, please browse to:
-These classes define objects that describe everything needed to generate a PSA
-call. In the future, it's probably possible to, instead of writing these calls
-out to a .c file, for target systems that can support sufficiently large memory
-footprints, to directly execute these PSA calls from the psa_call-subclass
-"tracker" objects.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/calls_dir.html
--------------
diff --git a/tools/tf_fuzz/calls/crypto_call.cpp b/tools/tf_fuzz/calls/crypto_call.cpp
index ffc5ed398..dc73d8e07 100644
--- a/tools/tf_fuzz/calls/crypto_call.cpp
+++ b/tools/tf_fuzz/calls/crypto_call.cpp
@@ -38,6 +38,7 @@ policy_call::policy_call (tf_fuzz_info *test_state, // (constructor)
// Randomize key-policy usage and algorithm:
policy_usage = rand_key_usage();
policy_algorithm = rand_key_algorithm();
+ asset_info.the_asset = nullptr;
}
policy_call::~policy_call (void)
{
@@ -45,6 +46,65 @@ policy_call::~policy_call (void)
return; // just to have something to pin a breakpoint onto
}
+vector<psa_asset*>::iterator policy_call::resolve_asset (bool create_asset_bool,
+ psa_asset_usage where) {
+ vector<psa_asset*>::iterator found_asset;
+ vector<psa_asset*> *asset_vector;
+ int asset_pick;
+
+ if (random_asset != psa_asset_usage::all) {
+ // != psa_asset_usage::all means to choose some known asset at random:
+ if (random_asset == psa_asset_usage::active) {
+ asset_vector = &(test_state->active_policy_asset);
+ asset_info.how_asset_found = asset_search::found_active;
+ } else if (random_asset == psa_asset_usage::deleted) {
+ asset_vector = &(test_state->deleted_policy_asset);
+ asset_info.how_asset_found = asset_search::found_deleted;
+ } else {
+ // "invalid" assets are not currently used.
+ cerr << "\nError: Tool-internal: Please report error 1102 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(1102);
+ }
+ if (asset_vector->size() > 0) {
+ /* Pick an active or deleted asset at random: */
+ asset_pick = rand() % asset_vector->size();
+ found_asset = asset_vector->begin() + asset_pick;
+ /* Copy asset information into template tracker: */
+ asset_info.id_n = (*found_asset)->asset_info.id_n;
+ asset_info.asset_ser_no
+ = (*found_asset)->asset_info.asset_ser_no;
+ } else {
+ if (random_asset == psa_asset_usage::active) {
+ cerr << "\nError: A policy call asks for a "
+ << "randomly chosen active asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1010);
+ } else if (random_asset == psa_asset_usage::deleted) {
+ cerr << "\nError: A policy call asks for a "
+ << "randomly chosen deleted asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1011);
+ } // "invalid" assets are not currently used.
+ }
+ } else {
+ // Find the asset by name:
+ asset_info.how_asset_found = test_state->find_or_create_policy_asset (
+ psa_asset_search::name, where,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ create_asset_bool, found_asset );
+ if ( asset_info.how_asset_found == asset_search::unsuccessful
+ || asset_info.how_asset_found == asset_search::something_wrong ) {
+ cerr << "\nError: Tool-internal: Please report error 108 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(108);
+ }
+ }
+ return found_asset;
+}
+
/**********************************************************************************
End of methods of class policy_call.
**********************************************************************************/
@@ -75,6 +135,7 @@ key_call::key_call (tf_fuzz_info *test_state, // (constructor)
// Choose a random expected key size in bits:
expected_n_bits = to_string(rand()%10000);
delete gib;
+ asset_info.the_asset = nullptr;
}
key_call::~key_call (void)
{
@@ -82,6 +143,65 @@ key_call::~key_call (void)
return; // just to have something to pin a breakpoint onto
}
+vector<psa_asset*>::iterator key_call::resolve_asset (bool create_asset_bool,
+ psa_asset_usage where) {
+ vector<psa_asset*>::iterator found_asset;
+ vector<psa_asset*> *asset_vector;
+ int asset_pick;
+
+ if (random_asset != psa_asset_usage::all) {
+ // != psa_asset_usage::all means to choose some known asset at random:
+ if (random_asset == psa_asset_usage::active) {
+ asset_vector = &(test_state->active_key_asset);
+ asset_info.how_asset_found = asset_search::found_active;
+ } else if (random_asset == psa_asset_usage::deleted) {
+ asset_vector = &(test_state->deleted_key_asset);
+ asset_info.how_asset_found = asset_search::found_deleted;
+ } else {
+ // "invalid" assets are not currently used.
+ cerr << "\nError: Tool-internal: Please report error 1103 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(1103);
+ }
+ if (asset_vector->size() > 0) {
+ /* Pick an active or deleted asset at random: */
+ asset_pick = rand() % asset_vector->size();
+ found_asset = asset_vector->begin() + asset_pick;
+ /* Copy asset information into template tracker: */
+ asset_info.id_n = (*found_asset)->asset_info.id_n;
+ asset_info.asset_ser_no
+ = (*found_asset)->asset_info.asset_ser_no;
+ } else {
+ if (random_asset == psa_asset_usage::active) {
+ cerr << "\nError: A key call asks for a "
+ << "randomly chosen active asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1012);
+ } else if (random_asset == psa_asset_usage::deleted) {
+ cerr << "\nError: A key call asks for a "
+ << "randomly chosen deleted asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1013);
+ } // "invalid" assets are not currently used.
+ }
+ } else {
+ // Find the asset by name:
+ asset_info.how_asset_found = test_state->find_or_create_key_asset (
+ psa_asset_search::name, where,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ create_asset_bool, found_asset );
+ if ( asset_info.how_asset_found == asset_search::unsuccessful
+ || asset_info.how_asset_found == asset_search::something_wrong ) {
+ cerr << "\nError: Tool-internal: Please report error 108 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(108);
+ }
+ }
+ return found_asset;
+}
+
/**********************************************************************************
End of methods of class key_call.
**********************************************************************************/
@@ -108,6 +228,46 @@ policy_set_call::~policy_set_call (void)
return; // just to have something to pin a breakpoint onto
}
+bool policy_set_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ asset_search how_found = test_state->find_or_create_sst_asset (
+ psa_asset_search::name, psa_asset_usage::all,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ dont_create_asset, found_asset );
+ // The vector is base-class, but this itself *really is* an sst_asset object:
+ if (how_found == asset_search::unsuccessful) {
+ cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
+ << endl;
+ exit(108);
+ }
+ // Copy *the other way* on asset reads!
+ if (how_found != asset_search::not_found) {
+ asset_info.the_asset = reinterpret_cast<policy_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* policy_asset.
+ int i = asset_info.the_asset->set_data.n_set_vars; // save this
+ asset_info.the_asset->set_data = set_data;
+ asset_info.the_asset->set_data.n_set_vars = set_data.n_set_vars = ++i;
+ asset_info.the_asset->flags_string = flags_string;
+ if (asset_info.how_asset_found == asset_search::created_new) {
+ asset_info.the_asset->asset_info.name_specified = asset_info.name_specified;
+ asset_info.the_asset->asset_info.set_name (asset_info.get_name());
+ asset_info.the_asset->asset_info.asset_ser_no = asset_info.asset_ser_no;
+ asset_info.the_asset->asset_info.id_n = asset_info.id_n;
+ }
+ }
+ return true;
+}
+
+bool policy_set_call::copy_asset_to_call (void)
+{
+ // Get updated asset info from the asset:
+ asset_info.asset_ser_no = asset_info.the_asset->asset_info.asset_ser_no;
+ asset_info.id_n = asset_info.the_asset->asset_info.id_n;
+ return true;
+}
+
void policy_set_call::fill_in_prep_code (void)
{
// No prep code required.
@@ -119,18 +279,17 @@ void policy_set_call::fill_in_command (void)
vector<psa_asset*>::iterator found_asset;
// Is this search really needed?
- // Find the call by serial number (must search; may have moved).
- how_asset_found = test_state->find_or_create_policy_asset (
+ asset_info.how_asset_found = test_state->find_or_create_policy_asset (
psa_asset_search::serial, psa_asset_usage::all,
- "", 0, asset_ser_no,
+ "", 0, asset_info.asset_ser_no,
yes_create_asset, found_asset );
- if (how_asset_found == asset_search::unsuccessful) {
+ if (asset_info.how_asset_found == asset_search::unsuccessful) {
cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
<< endl;
exit(103);
}
- string var_name = asset_id.get_name() + "_data";
- string id_string = to_string((long) asset_id.id_n);
+ string var_name = asset_info.get_name() + "_data";
+ string id_string = to_string((long) asset_info.id_n);
// Fill in the PSA command itself:
find_replace_1st ("$policy", id_string, call_code);
find_replace_1st ("$usage", policy_usage, call_code);
@@ -164,6 +323,40 @@ policy_get_call::~policy_get_call (void)
return; // just to have something to pin a breakpoint onto
}
+bool policy_get_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ asset_search how_found = test_state->find_or_create_sst_asset (
+ psa_asset_search::name, psa_asset_usage::all,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ dont_create_asset, found_asset );
+ // The vector is base-class, but this itself *really is* an sst_asset object:
+ if (how_found == asset_search::unsuccessful) {
+ cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
+ << endl;
+ exit(108);
+ }
+ // Copy *the other way* on asset reads!
+ if (how_found != asset_search::not_found) {
+ asset_info.the_asset = reinterpret_cast<policy_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* policy_asset.
+ }
+ return true;
+}
+
+bool policy_get_call::copy_asset_to_call (void)
+{
+ if (asset_info.the_asset != nullptr) {
+ set_data.string_specified = asset_info.the_asset->set_data.string_specified;
+ set_data.file_specified = asset_info.the_asset->set_data.file_specified;
+ flags_string = asset_info.the_asset->flags_string;
+ asset_info.id_n = asset_info.the_asset->asset_info.id_n;
+ asset_info.name_specified = asset_info.the_asset->asset_info.name_specified;
+ }
+ return true;
+}
+
void policy_get_call::fill_in_prep_code (void)
{
return; // just to have something to pin a breakpoint onto
@@ -175,7 +368,8 @@ void policy_get_call::fill_in_command (void)
// Figure out what expected results:
// TODO: Make data checks contingent upon the PSA call itself passing!
calc_result_code();
- // TODO: DOESN'T SOMETHING HAVE TO CHECK THE ALGORITHM AND USAGE (perhaps that's a different call)?
+ /* TODO: DOESN'T SOMETHING HAVE TO CHECK THE ALGORITHM AND USAGE (perhaps
+ that's a different call)? */
}
/**********************************************************************************
@@ -202,6 +396,47 @@ set_key_call::~set_key_call (void)
{
}
+bool set_key_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ // Find the asset by serial number (must search; may have moved).
+ asset_search how_found = test_state->find_or_create_key_asset (
+ psa_asset_search::name, psa_asset_usage::all,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ yes_create_asset, found_asset );
+ // The vector is base-class, but this itself *really is* a key_asset object:
+ if (how_found == asset_search::unsuccessful) {
+ cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
+ << endl;
+ exit(109);
+ }
+ // Copy over everything relevant:
+ if (how_found != asset_search::not_found) {
+ asset_info.the_asset = reinterpret_cast<key_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* key_asset.
+ int i = asset_info.the_asset->set_data.n_set_vars; // save this
+ asset_info.the_asset->set_data = set_data;
+ asset_info.the_asset->set_data.n_set_vars = set_data.n_set_vars = ++i;
+ asset_info.the_asset->flags_string = flags_string;
+ if (asset_info.how_asset_found == asset_search::created_new) {
+ asset_info.the_asset->asset_info.name_specified = asset_info.name_specified;
+ asset_info.the_asset->asset_info.set_name (asset_info.get_name());
+ asset_info.the_asset->asset_info.asset_ser_no = asset_info.asset_ser_no;
+ asset_info.the_asset->asset_info.id_n = asset_info.id_n;
+ }
+ }
+ return true;
+}
+
+bool set_key_call::copy_asset_to_call (void)
+{
+ // Get updated asset info from the asset:
+ asset_info.asset_ser_no = asset_info.the_asset->asset_info.asset_ser_no;
+ asset_info.id_n = asset_info.the_asset->asset_info.id_n;
+ return true;
+}
+
void set_key_call::fill_in_prep_code (void)
{
// Create declaration of lifetime's holder variable:
@@ -242,6 +477,38 @@ get_key_info_call::~get_key_info_call (void)
{
}
+bool get_key_info_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+ asset_search how_found = test_state->find_or_create_sst_asset (
+ psa_asset_search::name, psa_asset_usage::all,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ dont_create_asset, found_asset );
+ // The vector is base-class, but this itself *really is* an sst_asset object:
+ if (how_found == asset_search::unsuccessful) {
+ cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
+ << endl;
+ exit(108);
+ }
+ // Copy *the other way* on asset reads!
+ if (how_found != asset_search::not_found) {
+ asset_info.the_asset = reinterpret_cast<key_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* key_asset.
+ // Found the asset; copy_asset_to_call() will do exactly that.
+ }
+ return true;
+}
+
+bool get_key_info_call::copy_asset_to_call (void)
+{
+ if (asset_info.the_asset != nullptr) {
+ set_data.string_specified = asset_info.the_asset->set_data.string_specified;
+ set_data.file_specified = asset_info.the_asset->set_data.file_specified;
+ asset_info = asset_info.the_asset->asset_info;
+ }
+ return true;
+}
+
void get_key_info_call::fill_in_prep_code (void)
{
// Create declaration of size_t variable to accept #bits info into:
@@ -259,8 +526,8 @@ void get_key_info_call::fill_in_command (void)
// Figure out what expected return code:
calc_result_code();
// But also need to write code to check #bits returned:
- if (!expect.pf_nothing) {
-// TODO: Make data checks contingent upon the PSA call itself passing!
+ if (!exp_data.pf_nothing) {
+ // TODO: Make data checks contingent upon the PSA call itself passing!
call_code.append (test_state->bplate->bplate_string[get_key_check_n_bits]);
find_replace_1st ("$n_bits", handle_str + "_n_bits", check_code);
find_replace_1st ("$m_bits", expected_n_bits, check_code);
@@ -292,6 +559,34 @@ destroy_key_call::~destroy_key_call (void)
return; // just to have something to pin a breakpoint onto
}
+bool destroy_key_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ found_asset = resolve_asset (dont_create_asset, psa_asset_usage::all);
+ if (asset_info.how_asset_found != asset_search::not_found) {
+ asset_info.the_asset = reinterpret_cast<key_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* key_asset.
+ if (asset_info.how_asset_found == asset_search::found_active) {
+ // Delete asset; move it from active vector to deleted vector:
+ test_state->deleted_key_asset.push_back (asset_info.the_asset);
+ test_state->active_key_asset.erase (found_asset);
+ } /* if not active, we'll deem the call expected to fail. */
+ }
+ return true;
+}
+
+bool destroy_key_call::copy_asset_to_call (void)
+{
+ if (asset_info.the_asset != nullptr) { // will be found for make calls, but not necessarily others
+ set_data.string_specified = asset_info.the_asset->set_data.string_specified;
+ set_data.file_specified = asset_info.the_asset->set_data.file_specified;
+ // Get updated asset info from the asset:
+ asset_info = asset_info.the_asset->asset_info;
+ }
+ return true;
+}
+
void destroy_key_call::fill_in_prep_code (void)
{
// No prep code required.
diff --git a/tools/tf_fuzz/calls/crypto_call.hpp b/tools/tf_fuzz/calls/crypto_call.hpp
index a35e179ed..35fd1d13e 100644
--- a/tools/tf_fuzz/calls/crypto_call.hpp
+++ b/tools/tf_fuzz/calls/crypto_call.hpp
@@ -28,6 +28,8 @@ public:
string policy_usage;
string policy_algorithm;
// Methods:
+ vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
+ psa_asset_usage where);
policy_call (tf_fuzz_info *test_state, long &asset_ser_no,
asset_search how_asset_found); // (constructor)
~policy_call (void);
@@ -54,6 +56,8 @@ public:
string expected_n_bits;
// for get_key_info call (possibly others) exected key size in bits
// Methods:
+ vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
+ psa_asset_usage where);
key_call (tf_fuzz_info *test_state, long &asset_ser_no,
asset_search how_asset_found); // (constructor)
~key_call (void);
@@ -74,6 +78,8 @@ class policy_set_call : public policy_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
policy_set_call (tf_fuzz_info *test_state, long &asset_ser_no,
@@ -95,6 +101,8 @@ class policy_get_call : public policy_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
policy_get_call (tf_fuzz_info *test_state, long &asset_ser_no,
@@ -117,6 +125,8 @@ class set_key_call : public key_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
set_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
@@ -138,6 +148,8 @@ class get_key_info_call : public key_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
get_key_info_call (tf_fuzz_info *test_state, long &asset_ser_no,
@@ -159,6 +171,8 @@ class destroy_key_call : public key_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
destroy_key_call (tf_fuzz_info *test_state, long &asset_ser_no,
diff --git a/tools/tf_fuzz/calls/psa_call.cpp b/tools/tf_fuzz/calls/psa_call.cpp
index 51060e102..108a276fa 100644
--- a/tools/tf_fuzz/calls/psa_call.cpp
+++ b/tools/tf_fuzz/calls/psa_call.cpp
@@ -31,7 +31,7 @@ psa_call::psa_call (tf_fuzz_info *test_state, long &call_ser_no, // (construct
asset_search how_asset_found)
{
this->test_state = test_state;
- this->how_asset_found = how_asset_found;
+ this->asset_info.how_asset_found = how_asset_found;
set_data.string_specified = false;
set_data.set (""); // actual data
assign_data_var.assign (""); // name of variable assigned (dumped) to
@@ -61,7 +61,7 @@ void psa_call::write_out_command (ofstream &test_file)
void psa_call::write_out_check_code (ofstream &test_file)
{
- if (!expect.pf_nothing) {
+ if (!exp_data.pf_nothing) {
test_file << check_code;
} else {
test_file << " /* (No checks for this PSA call.) */" << endl;
@@ -84,18 +84,18 @@ void psa_call::write_out_check_code (ofstream &test_file)
so lots of room for further refinement here. */
void sst_call::calc_result_code (void)
{
- if (!expect.pf_nothing) {
- if (expect.pf_pass) {
+ if (!exp_data.pf_nothing) {
+ if (exp_data.pf_pass) {
find_replace_all ("$expect",
test_state->bplate->bplate_string[sst_pass_string],
check_code);
} else {
- if (expect.pf_specified) {
- find_replace_all ("$expect", expect.pf_result_string,
+ if (exp_data.pf_specified) {
+ find_replace_all ("$expect", exp_data.pf_result_string,
check_code);
} else {
// Figure out what the message should read:
- switch (how_asset_found) {
+ switch (asset_info.how_asset_found) {
case asset_search::found_active:
case asset_search::created_new:
find_replace_all ("$expect",
@@ -124,10 +124,70 @@ void sst_call::calc_result_code (void)
}
}
+vector<psa_asset*>::iterator sst_call::resolve_asset (bool create_asset_bool,
+ psa_asset_usage where) {
+ vector<psa_asset*>::iterator found_asset;
+ vector<psa_asset*> *asset_vector;
+ int asset_pick;
+
+ if (random_asset != psa_asset_usage::all) {
+ // != psa_asset_usage::all means to choose some known asset at random:
+ if (random_asset == psa_asset_usage::active) {
+ asset_vector = &(test_state->active_sst_asset);
+ asset_info.how_asset_found = asset_search::found_active;
+ } else if (random_asset == psa_asset_usage::deleted) {
+ asset_vector = &(test_state->deleted_sst_asset);
+ asset_info.how_asset_found = asset_search::found_deleted;
+ } else {
+ // "invalid" assets are not currently used.
+ cerr << "\nError: Tool-internal: Please report error 1101 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(1101);
+ }
+ if (asset_vector->size() > 0) {
+ /* Pick an active or deleted asset at random: */
+ asset_pick = rand() % asset_vector->size();
+ found_asset = asset_vector->begin() + asset_pick;
+ /* Copy asset information into template tracker: */
+ asset_info.id_n = (*found_asset)->asset_info.id_n;
+ asset_info.asset_ser_no
+ = (*found_asset)->asset_info.asset_ser_no;
+ } else {
+ if (random_asset == psa_asset_usage::active) {
+ cerr << "\nError: An sst call asks for a "
+ << "randomly chosen active asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1008);
+ } else if (random_asset == psa_asset_usage::deleted) {
+ cerr << "\nError: An sst call asks for a "
+ << "randomly chosen deleted asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1009);
+ } // "invalid" assets are not currently used.
+ }
+ } else {
+ // Find the asset by name:
+ asset_info.how_asset_found = test_state->find_or_create_sst_asset (
+ psa_asset_search::name, where,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ create_asset_bool, found_asset );
+ if ( asset_info.how_asset_found == asset_search::unsuccessful
+ || asset_info.how_asset_found == asset_search::something_wrong ) {
+ cerr << "\nError: Tool-internal: Please report error 108 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(108);
+ }
+ }
+ return found_asset;
+}
+
sst_call::sst_call (tf_fuzz_info *test_state, long &call_ser_no, // (constructor)
asset_search how_asset_found)
: psa_call(test_state, call_ser_no, how_asset_found)
{
+ asset_info.the_asset = nullptr;
return; // just to have something to pin a breakpoint onto
}
sst_call::~sst_call (void)
@@ -151,16 +211,16 @@ sst_call::~sst_call (void)
method, (starting around line 20ish). */
void crypto_call::calc_result_code (void)
{
- if (!expect.pf_nothing) {
- if (expect.pf_pass) {
+ if (!exp_data.pf_nothing) {
+ if (exp_data.pf_pass) {
find_replace_1st ("$expect", "PSA_SUCCESS", check_code);
} else {
- if (expect.pf_specified) {
- find_replace_1st ("$expect", expect.pf_result_string,
+ if (exp_data.pf_specified) {
+ find_replace_1st ("$expect", exp_data.pf_result_string,
check_code);
} else {
// Figure out what the message should read:
- switch (how_asset_found) {
+ switch (asset_info.how_asset_found) {
case asset_search::found_active:
case asset_search::created_new:
find_replace_all ("$expect", "PSA_SUCCESS",
@@ -218,6 +278,13 @@ security_call::~security_call (void)
return; // just to have something to pin a breakpoint onto
}
+// resolve_asset() doesn't do anything for security_calls, since there's no asset involved.
+vector<psa_asset*>::iterator security_call::resolve_asset (bool create_asset_bool,
+ psa_asset_usage where)
+{
+ return test_state->active_sst_asset.end(); // (anything)
+}
+
/* calc_result_code() fills in the check_code string member with the correct result
code (e.g., "PSA_SUCCESS" or whatever).
diff --git a/tools/tf_fuzz/calls/psa_call.hpp b/tools/tf_fuzz/calls/psa_call.hpp
index 324381014..64384f045 100644
--- a/tools/tf_fuzz/calls/psa_call.hpp
+++ b/tools/tf_fuzz/calls/psa_call.hpp
@@ -24,22 +24,27 @@ class psa_call
public:
/* Data members -- not all PSA calls have/need these, but they need to be acces-
sible polymorphically via a psa_call iterator: */
- expect_info expect; // everything about expected results
+ expect_info exp_data; // everything about expected results
set_data_info set_data; // everything about setting PSA-asset-data values
+ asset_name_id_info asset_info; // everything about the asset(s) for this line
+ psa_asset_usage random_asset;
+ /* if asked to use some random asset from active or deleted, this says
+ which. psa_asset_usage::all if not using this feature. */
+ bool assign_data_var_specified; // asset data to/from named variable
string assign_data_var; // name of variable to dump (assign) data into
- asset_name_id_info asset_id; // everything about the asset(s) for this line
- bool assign_data_var_specified;
// Expected-result info:
bool print_data; // true to print asset data to test log
bool hash_data; // true to hash data for later comparison
string id_string; // not all PSA calls involve an ID, but a diverse set do
- long asset_ser_no; // unique ID for psa asset needed to find data string
long call_ser_no; // unique serial# for this psa_call (see note in tf_fuzz.hpp)
- asset_search how_asset_found;
tf_fuzz_info *test_state; // the big blob with pointers to everything going on
string flags_string;
// creation flags, nominally for SST but have to be in a vector of base-class
// Methods:
+ virtual vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
+ psa_asset_usage where) = 0;
+ virtual bool copy_call_to_asset (void) = 0;
+ virtual bool copy_asset_to_call (void) = 0;
virtual void fill_in_prep_code (void) = 0;
virtual void fill_in_command (void) = 0;
void write_out_prep_code (ofstream &test_file);
@@ -69,6 +74,8 @@ class sst_call : public psa_call
public:
// Data members: // (low value in hiding these behind setters and getters)
// Methods:
+ vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
+ psa_asset_usage where);
sst_call (tf_fuzz_info *test_state, long &asset_ser_no,
asset_search how_asset_found); // (constructor)
~sst_call (void);
@@ -87,9 +94,6 @@ class crypto_call : public psa_call
{
public:
// Data members: // (low value in hiding these behind setters and getters)
- key_asset the_key_asset; // are these used (yet)?
- policy_asset the_policy_asset;
- // the policy (if any) involved in this call
// Methods:
crypto_call (tf_fuzz_info *test_state, long &asset_ser_no,
asset_search how_asset_found); // (constructor)
@@ -114,6 +118,8 @@ class security_call : public psa_call
public:
// Data members: // (low value in hiding these behind setters and getters)
// Methods:
+ vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
+ psa_asset_usage where);
security_call (tf_fuzz_info *test_state, long &asset_ser_no,
asset_search how_asset_found); // (constructor)
~security_call (void);
diff --git a/tools/tf_fuzz/calls/security_call.cpp b/tools/tf_fuzz/calls/security_call.cpp
index 3aeb959b7..9093092e1 100644
--- a/tools/tf_fuzz/calls/security_call.cpp
+++ b/tools/tf_fuzz/calls/security_call.cpp
@@ -35,7 +35,7 @@ hash_call::hash_call (tf_fuzz_info *test_state, // (constructor)
asset_search how_asset_found)
: security_call(test_state, call_ser_no, how_asset_found)
{
- // TODO: Randomize key-policy usage and algorithm:
+ return; // just to have something to pin a breakpoint onto
}
hash_call::~hash_call (void)
{
@@ -43,6 +43,18 @@ hash_call::~hash_call (void)
return; // just to have something to pin a breakpoint onto
}
+bool hash_call::copy_call_to_asset (void)
+{
+ // The assets are not directly involved in this call.
+ return true;
+}
+
+bool hash_call::copy_asset_to_call (void)
+{
+ // The assets are not directly involved in this call.
+ return true;
+}
+
/* Note: These functions are overridden in all subclasses, but they still need to be
defined, or the linker gives the error "undefined reference to `vtable... */
void hash_call::fill_in_prep_code (void)
@@ -52,14 +64,14 @@ void hash_call::fill_in_prep_code (void)
void hash_call::fill_in_command (void)
{
- if (asset_id.asset_name_vector.size() > 1) { // nothing to compare with less than 2
+ if (asset_info.asset_name_vector.size() > 1) { // nothing to compare with less than 2
// Fill in preceding comment:
// Fill in the hash-comparison code itself:
- for (auto outer = asset_id.asset_name_vector.begin();
- outer < asset_id.asset_name_vector.end();
+ for (auto outer = asset_info.asset_name_vector.begin();
+ outer < asset_info.asset_name_vector.end();
++outer) {
for (auto inner = outer+1;
- inner < asset_id.asset_name_vector.end();
+ inner < asset_info.asset_name_vector.end();
++inner) {
call_code.append (" if (" + *outer + "_hash == " + *inner + "_hash) {\n");
call_code.append ( " TEST_FAIL(\"Probable data leak between assets "
diff --git a/tools/tf_fuzz/calls/security_call.hpp b/tools/tf_fuzz/calls/security_call.hpp
index 0bc0600c0..e55a27830 100644
--- a/tools/tf_fuzz/calls/security_call.hpp
+++ b/tools/tf_fuzz/calls/security_call.hpp
@@ -23,6 +23,8 @@ class hash_call : public security_call
public:
// Data members: // (low value in hiding these behind setters and getters)
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
/* Hash checks are different from the rest in that there's a single "call" --
diff --git a/tools/tf_fuzz/calls/sst_call.cpp b/tools/tf_fuzz/calls/sst_call.cpp
index 93f7a6e38..d2c4e5d99 100644
--- a/tools/tf_fuzz/calls/sst_call.cpp
+++ b/tools/tf_fuzz/calls/sst_call.cpp
@@ -21,6 +21,7 @@
#include "sst_call.hpp"
#include "sst_asset.hpp"
#include "crypto_asset.hpp"
+#include "variables.hpp"
@@ -43,33 +44,107 @@ sst_set_call::~sst_set_call (void)
return; // just to have something to pin a breakpoint onto
}
+bool sst_set_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ found_asset = resolve_asset (yes_create_asset, psa_asset_usage::all);
+ // Copy over everything relevant:
+ if (asset_info.how_asset_found != asset_search::not_found) {
+ // will be found for make calls, but not necessarily others
+ asset_info.the_asset = reinterpret_cast<sst_asset*>(*found_asset);
+ /* Note: The vector is base-class, but the assets in this list
+ themselves *really are* sst_asset-type objects. */
+ int i = asset_info.the_asset->set_data.n_set_vars; // save this
+ asset_info.the_asset->set_data = set_data;
+ asset_info.the_asset->set_data.n_set_vars = set_data.n_set_vars = ++i;
+ asset_info.the_asset->flags_string = flags_string;
+ if (asset_info.how_asset_found == asset_search::created_new) {
+ asset_info.the_asset->asset_info.name_specified = asset_info.name_specified;
+ asset_info.the_asset->asset_info.set_name (asset_info.get_name());
+ asset_info.the_asset->asset_info.asset_ser_no = asset_info.asset_ser_no;
+ asset_info.the_asset->asset_info.id_n = asset_info.id_n;
+ }
+ }
+ return true;
+}
+
+bool sst_set_call::copy_asset_to_call (void)
+{
+ // Get updated asset info from the asset:
+ asset_info.asset_ser_no = asset_info.the_asset->asset_info.asset_ser_no;
+ asset_info.id_n = asset_info.the_asset->asset_info.id_n;
+ exp_data.n_exp_vars = asset_info.the_asset->exp_data.n_exp_vars;
+ exp_data.data = asset_info.the_asset->exp_data.data;
+ return true;
+}
+
void sst_set_call::fill_in_prep_code (void)
{
- // Single string of two lines declaring string data and its length:
- string var_name = asset_id.get_name() + "_data"; // the data holder var
- prep_code = test_state->bplate->bplate_string[declare_string];
- find_replace_1st ("$var", var_name, prep_code);
- find_replace_1st ("$init", set_data.get(), prep_code);
- var_name = asset_id.get_name() + "_data_size"; // the data length value
- prep_code.append (test_state->bplate->bplate_string[declare_int]);
- find_replace_1st ("$var", var_name, prep_code);
- find_replace_1st ("$init", to_string(set_data.get().length()), prep_code);
+ string var_name, length_var_name, var_name_suffix, length_var_name_suffix,
+ temp_string;
+ vector<variable_info>::iterator assign_variable;
+
+ if (assign_data_var_specified) {
+ var_name.assign (assign_data_var + "_data");
+ length_var_name.assign (assign_data_var + "_length");
+ /* If actual-data variable doesn't already exist, create variable tracker,
+ and write declaration for it: */
+ assign_variable = test_state->find_var (assign_data_var);
+ if (assign_variable == test_state->variable.end()) {
+ test_state->make_var (assign_data_var);
+ assign_variable = test_state->find_var (assign_data_var);
+ prep_code.append (test_state->bplate->bplate_string[declare_big_string]);
+ find_replace_1st ("$var", var_name, prep_code);
+ temp_string = (char *) assign_variable->value;
+ find_replace_1st ("$init", temp_string, prep_code);
+ // Actual-data length:
+ temp_string.assign (test_state->bplate->bplate_string[declare_int]);
+ find_replace_1st ("static int", "static size_t", temp_string);
+ prep_code.append (temp_string);
+ find_replace_1st ("$var", length_var_name, prep_code);
+ find_replace_1st ("$init", to_string(temp_string.length()), prep_code);
+ // Offset (always 0 for now):
+ find_replace_1st ("$offset", "0", prep_code);
+ }
+ } else {
+ // Single string of two lines declaring string data and its length:
+ var_name_suffix = "_set_data";
+ length_var_name_suffix = "_set_length";
+ if (set_data.n_set_vars > 0) {
+ var_name_suffix += "_" + to_string(set_data.n_set_vars);
+ length_var_name_suffix += "_" + to_string(set_data.n_set_vars);
+ }
+ var_name.assign (asset_info.get_name() + var_name_suffix);
+ length_var_name.assign (asset_info.get_name() + length_var_name_suffix);
+ prep_code = test_state->bplate->bplate_string[declare_string];
+ find_replace_1st ("$var", var_name, prep_code);
+ find_replace_1st ("$init", set_data.get(), prep_code);
+ temp_string.assign (test_state->bplate->bplate_string[declare_int]);
+ find_replace_1st ("static int", "static uint32_t", temp_string);
+ prep_code.append (temp_string);
+ find_replace_1st ("$var", length_var_name, prep_code);
+ find_replace_1st ("$init", to_string(set_data.get().length()), prep_code);
+ }
}
void sst_set_call::fill_in_command (void)
{
+ string var_name, length_var_name, var_name_suffix, length_var_name_suffix,
+ temp_string;
+
// Fill in preceding comment:
- if (how_asset_found == asset_search::created_new) {
+ if (asset_info.how_asset_found == asset_search::created_new) {
find_replace_1st ("$op", "Creating", call_code);
} else {
find_replace_1st ("$op", "Resetting", call_code);
}
- if (asset_id.name_specified) {
- find_replace_1st ("$description", "\"" + asset_id.get_name() + ",\"",
+ if (asset_info.name_specified) {
+ find_replace_1st ("$description", "\"" + asset_info.get_name() + ",\"",
call_code);
} else {
find_replace_1st ("$description",
- "UID = " + to_string((long) asset_id.id_n), call_code);
+ "UID = " + to_string((long) asset_info.id_n), call_code);
}
if (set_data.string_specified) {
find_replace_1st ("$data_source",
@@ -82,13 +157,26 @@ void sst_set_call::fill_in_command (void)
find_replace_1st (" $data_source", "", call_code);
}
// Fill in the PSA command itself:
- string var_name = asset_id.get_name() + "_data_size";
- string id_string = to_string((long) asset_id.id_n);
- find_replace_1st ("$uid", id_string, call_code);
- find_replace_1st ("$length", var_name, call_code);
- var_name = asset_id.get_name() + "_data";
+ if (assign_data_var_specified) {
+ var_name.assign (assign_data_var + "_data");
+ length_var_name.assign (assign_data_var + "_length");
+ } else {
+ var_name_suffix = "_set_data";
+ if (set_data.n_set_vars > 0) {
+ var_name_suffix += "_" + to_string(set_data.n_set_vars);
+ }
+ var_name.assign (asset_info.get_name() + var_name_suffix);
+ length_var_name_suffix = "_set_length";
+ if (set_data.n_set_vars > 0) {
+ length_var_name_suffix += "_" + to_string(set_data.n_set_vars);
+ }
+ length_var_name.assign (asset_info.get_name() + length_var_name_suffix);
+ }
find_replace_1st ("$data", var_name, call_code);
find_replace_1st ("$flags", flags_string, call_code);
+ string id_string = to_string((long) asset_info.id_n);
+ find_replace_1st ("$uid", id_string, call_code);
+ find_replace_1st ("$length", length_var_name, call_code);
// Figure out what expected results:
calc_result_code();
}
@@ -118,84 +206,143 @@ sst_get_call::~sst_get_call (void)
return; // just to have something to pin a breakpoint onto
}
-void sst_get_call::fill_in_prep_code (void)
+bool sst_get_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ found_asset = resolve_asset (dont_create_asset, psa_asset_usage::active);
+ if (asset_info.how_asset_found != asset_search::not_found) {
+ // will be found for set calls, but not necessarily others
+ asset_info.the_asset = reinterpret_cast<sst_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* sst_asset.
+ /* Locating the asset is all we need to do here; copy_asset_to_call() will
+ do the rest. */
+ }
+ return true;
+ // TODO: Shouldn't data be copied over?
+}
+
+bool sst_get_call::copy_asset_to_call (void)
{
- string var_name, temp_string;
-
- /* Create and use gibberish object to create for-sure-bad data for the
- psa_ps_get() call to overwrite. */
- gibberish *gib = new gibberish;
- char gib_buff[1024]; // TODO: Sizing of buffers needs to be managed better
- string wrong_data;
- /* bogus data to prefill actual data with in order to distinguish
- whether actual data was provided. */
-
- gib->sentence (gib_buff, gib_buff + 100 + (rand() % 800));
- // TODO: Sizes of random data needs to be strategized better
- wrong_data = gib_buff;
- // Expected data:
- if (expect.data_specified) {
- /* Template specified expected verbatim, literal data. Put that into a
- variable: */
- var_name.assign (asset_id.get_name() + "_exp_data");
- } else if (expect.data_var_specified) {
- // Template specified a variable name for expected data; use that:
- var_name.assign (expect.data_var);
+ if (asset_info.the_asset != nullptr) {
+ // will be found for set calls, but not necessarily others
+ set_data.string_specified = asset_info.the_asset->set_data.string_specified;
+ set_data.file_specified = asset_info.the_asset->set_data.file_specified;
+ set_data.set (asset_info.the_asset->set_data.get());
+ flags_string = asset_info.the_asset->flags_string;
+ asset_info.id_n = asset_info.the_asset->asset_info.id_n;
+ asset_info.asset_ser_no = asset_info.the_asset->asset_info.asset_ser_no;
+ asset_info.name_specified = asset_info.the_asset->asset_info.name_specified;
+ asset_info.the_asset->exp_data.n_exp_vars++;
+ exp_data.n_exp_vars = asset_info.the_asset->exp_data.n_exp_vars;
}
- // Expected data:
+ return true;
+}
+
+void sst_get_call::fill_in_prep_code (void)
+{
+ string var_base, var_name, length_var_name, temp_string, var_name_suffix,
+ expected;
+ vector<variable_info>::iterator act_variable, exp_variable;
+
if (!(print_data || hash_data)) {
- prep_code.assign(test_state->bplate->bplate_string[declare_string]);
- find_replace_1st("$var", var_name, prep_code);
- find_replace_1st("$init", expect.data, prep_code);
+ // Checking asset data verbatim against expected, so:
+ if (exp_data.data_var_specified) {
+ // Template specified a variable name to "check" against; use that:
+ var_base.assign (exp_data.data_var);
+ exp_variable = test_state->find_var (var_base);
+ if (exp_variable == test_state->variable.end()) {
+ test_state->make_var (var_base);
+ exp_variable = test_state->find_var (var_base);
+ var_name = var_base + "_data";
+ length_var_name = var_base + "_length";
+ prep_code.append (test_state->bplate->bplate_string[declare_string]);
+ find_replace_1st ("$var", var_name, prep_code);
+ temp_string = (char *) exp_variable->value;
+ find_replace_1st ("$init", temp_string, prep_code);
+ // Expected-data length:
+ temp_string.assign (test_state->bplate->bplate_string[declare_int]);
+ find_replace_1st ("static int", "static size_t", temp_string);
+ prep_code.append (temp_string);
+ find_replace_1st ("$var", length_var_name, prep_code);
+ find_replace_1st ("$init", to_string(temp_string.length()), prep_code);
+ }
+ } else {
+ if (exp_data.data_specified) {
+ // Checking against literal expected data:
+ expected.assign (exp_data.data);
+ } else {
+ // Check against what we believe the asset to contain:
+ expected.assign (set_data.get());
+ }
+ var_name_suffix = "_exp_data";
+ if (exp_data.n_exp_vars > 0) {
+ var_name_suffix =
+ var_name_suffix + "_" + to_string(exp_data.n_exp_vars);
+ }
+ var_name.assign (asset_info.get_name() + var_name_suffix);
+ prep_code.assign(test_state->bplate->bplate_string[declare_string]);
+ find_replace_1st("$var", var_name, prep_code);
+ find_replace_1st("$init", expected, prep_code);
+ }
}
// Actual data:
if (assign_data_var_specified) {
- var_name.assign (assign_data_var);
+ var_base.assign (assign_data_var);
} else {
- var_name.assign (asset_id.get_name() + "_act_data");
+ var_base.assign (asset_info.get_name() + "_act");
+ }
+ var_name.assign (var_base + "_data");
+ length_var_name.assign (var_base + "_length");
+ /* If actual-data variable doesn't already exist, create variable tracker,
+ and write declaration for it: */
+ act_variable = test_state->find_var (var_base);
+ if (act_variable == test_state->variable.end()) {
+ test_state->make_var (var_base);
+ act_variable = test_state->find_var (var_base);
+ prep_code.append (test_state->bplate->bplate_string[declare_big_string]);
+ find_replace_1st ("$var", var_name, prep_code);
+ temp_string = (char *) act_variable->value;
+ find_replace_1st ("$init", temp_string, prep_code);
+ // Actual-data length:
+ temp_string.assign (test_state->bplate->bplate_string[declare_int]);
+ find_replace_1st ("static int", "static size_t", temp_string);
+ prep_code.append (temp_string);
+ find_replace_1st ("$var", length_var_name, prep_code);
+ find_replace_1st ("$init", to_string(temp_string.length()), prep_code);
+ // Offset (always 0 for now):
+ find_replace_1st ("$offset", "0", prep_code);
}
- prep_code.append (test_state->bplate->bplate_string[declare_big_string]);
- find_replace_1st ("$var", var_name, prep_code);
- find_replace_1st ("$init", wrong_data, prep_code); // fill with gibberish
- // (Don't need to specify data length for expected data.)
- // Actual-data length:
- var_name = asset_id.get_name() + "_act_length";
- temp_string.assign (test_state->bplate->bplate_string[declare_int]);
- find_replace_1st ("static int", "static size_t", temp_string);
- prep_code.append (temp_string);
- find_replace_1st ("$var", var_name, prep_code);
- find_replace_1st ("$init", "0", prep_code);
- // Offset (always 0 for now):
- find_replace_1st ("$offset", "0", prep_code);
// If hashing the (actual) data, then create a variable for that:
- if (hash_data) {
+ if (hash_data && !act_variable->hash_declared) {
+ var_name = var_base + "_hash";
prep_code.append (test_state->bplate->bplate_string[declare_generic]);
- var_name.assign (asset_id.get_name() + "_hash"); // where to put the hash of the data
+ // where to put the hash of the data
find_replace_1st ("$type", "uint32_t", prep_code);
find_replace_1st ("$var", var_name, prep_code);
find_replace_1st ("$init", "0", prep_code); // for now...
+ act_variable->hash_declared = true;
}
- // Clean-up:
- delete gib;
}
void sst_get_call::fill_in_command (void)
{
- string exp_var_name, act_var_name, act_data_length, hash_var_name, id_string;
+ string exp_var_name, act_var_name, act_data_length, hash_var_name,
+ id_string, var_name_suffix;
-/* TODO: Flesh-out/fix this (a good try, but not quite right):
+/* TODO: Flesh-out/fix this (it was a good try/start, but not quite right):
// Fill in preceding comment:
- if (how_asset_found == asset_search::created_new) {
+ if (asset_info.how_asset_found == asset_search::created_new) {
find_replace_1st ("$op", "Creating", call_code);
} else {
find_replace_1st ("$op", "Resetting", call_code);
}
- if (asset_id.name_specified) {
- find_replace_1st ("$description", "\"" + asset_id.get_name() + ",\"",
+ if (asset_info.name_specified) {
+ find_replace_1st ("$description", "\"" + asset_info.get_name() + ",\"",
call_code);
} else {
find_replace_1st ("$description",
- "UID = " + to_string((long) asset_id.id_n), call_code);
+ "UID = " + to_string((long) asset_info.id_n), call_code);
}
if (set_data.string_specified) {
find_replace_1st ("$data_source",
@@ -208,33 +355,37 @@ void sst_get_call::fill_in_command (void)
find_replace_1st (" $data_source", "", call_code);
}
*/ // Fill in the call itself:
- if (assign_data_var_specified || print_data || hash_data) {
+ if (print_data || hash_data) {
// Dump to variable; no data-check code needed:
check_code.assign (test_state->bplate->bplate_string[get_sst_check]);
} else {
- // Check either against literal or variable, so need data-check code:
+ // Check either against literal or variable, so need data-check code too:
check_code.assign (test_state->bplate->bplate_string[get_sst_check_all]);
}
/* Note: Can fill in the check code identically between the dump-to-variable
and check-data cases, because the boilerplate for the former is just an
abbreviated version of the latter. The find_replace_1st() calls for
the check-data stuff will just simply not have any effect. */
- if (expect.data_specified) {
- exp_var_name.assign (asset_id.get_name() + "_exp_data");
+ if (exp_data.data_var_specified) {
+ // Check against data in variable:
+ exp_var_name.assign (exp_data.data_var);
} else {
- // whether expect.data_var_specified is true or not:
- exp_var_name.assign (expect.data_var);
+ var_name_suffix = "_exp_data";
+ if (exp_data.n_exp_vars > 0) {
+ var_name_suffix =
+ var_name_suffix + "_" + to_string(exp_data.n_exp_vars);
+ }
+ exp_var_name.assign (asset_info.get_name() + var_name_suffix);
}
if (assign_data_var_specified) {
- act_var_name.assign (assign_data_var);
+ act_var_name.assign (assign_data_var + "_data");
+ act_data_length.assign (assign_data_var + "_length");
} else {
- act_var_name.assign (asset_id.get_name() + "_act_data");
+ act_var_name.assign (asset_info.get_name() + "_act_data");
+ act_data_length.assign (asset_info.get_name() + "_act_length");
}
- /* TODO: In the case of reading into a variable, does it make more sense to
- assign into two variables: Data and length? */
- act_data_length = asset_id.get_name() + "_act_length";
- id_string = to_string((long) asset_id.id_n);
+ id_string = to_string((long) asset_info.id_n);
// Fill in the PSA command itself:
find_replace_1st ("$uid", id_string, call_code);
find_replace_all ("$length", to_string(set_data.get().length()), call_code);
@@ -243,17 +394,18 @@ void sst_get_call::fill_in_command (void)
find_replace_all ("$act_data", act_var_name, call_code);
find_replace_all ("$act_length", act_data_length, call_code);
// Perform most of the same substitutions in the check_code:
-// TODO: Make data checks contingent upon the PSA call itself passing!
+// TODO: Make data checks contingent upon the PSA call itself passing?
find_replace_1st ("$offset", "0", check_code);
find_replace_1st ("$exp_data", exp_var_name, check_code);
find_replace_all ("$act_data", act_var_name, check_code);
- find_replace_all ("$length", to_string(expect.data.length()), check_code);
+ find_replace_all ("$length", act_data_length, check_code);
if (print_data) {
check_code.append (test_state->bplate->bplate_string[test_log]);
find_replace_1st ("$message", act_var_name, check_code);
}
if (hash_data) {
- hash_var_name.assign (asset_id.get_name() + "_hash"); // where to put the hash of the data
+ hash_var_name.assign (asset_info.get_name() + "_hash");
+ // this is where to put the hash of the data
check_code.append (test_state->bplate->bplate_string[get_sst_hash]);
find_replace_all ("$act_data_var", act_var_name, check_code);
find_replace_all ("$hash_var", hash_var_name, check_code);
@@ -287,6 +439,35 @@ sst_remove_call::~sst_remove_call (void)
return; // just to have something to pin a breakpoint onto
}
+bool sst_remove_call::copy_call_to_asset (void)
+{
+ vector<psa_asset*>::iterator found_asset;
+
+ found_asset = resolve_asset (dont_create_asset, psa_asset_usage::all);
+ if (asset_info.how_asset_found != asset_search::not_found) {
+ asset_info.the_asset = reinterpret_cast<sst_asset*>(*found_asset);
+ // Note: Vector is of base-class type, but the assets *are* sst_asset.
+ if (asset_info.how_asset_found == asset_search::found_active) {
+ // Delete asset; move it from active vector to deleted vector:
+ test_state->deleted_sst_asset.push_back (asset_info.the_asset);
+ test_state->active_sst_asset.erase (found_asset);
+ } /* if not active, we'll deem the call expected to fail. */
+ }
+ return true;
+}
+
+bool sst_remove_call::copy_asset_to_call (void)
+{
+ if (asset_info.the_asset != nullptr) {
+ set_data.string_specified = asset_info.the_asset->set_data.string_specified;
+ set_data.file_specified = asset_info.the_asset->set_data.file_specified;
+ flags_string = asset_info.the_asset->flags_string;
+ asset_info.id_n = asset_info.the_asset->asset_info.id_n;
+ asset_info.name_specified = asset_info.the_asset->asset_info.name_specified;
+ }
+ return true;
+}
+
void sst_remove_call::fill_in_prep_code (void)
{
// No prep-code.
@@ -296,7 +477,7 @@ void sst_remove_call::fill_in_prep_code (void)
void sst_remove_call::fill_in_command (void)
{
// Fill in the call:
- string id_string = to_string((long) asset_id.id_n);
+ string id_string = to_string((long) asset_info.id_n);
find_replace_1st ("$uid", id_string, call_code);
// Fill in expected results:
calc_result_code(); // this only fills $expect check_code
diff --git a/tools/tf_fuzz/calls/sst_call.hpp b/tools/tf_fuzz/calls/sst_call.hpp
index 4557c5c1a..537b21fc9 100644
--- a/tools/tf_fuzz/calls/sst_call.hpp
+++ b/tools/tf_fuzz/calls/sst_call.hpp
@@ -27,6 +27,8 @@ class sst_set_call : public sst_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
sst_set_call (tf_fuzz_info *test_state, long &asset_ser_no,
@@ -51,6 +53,8 @@ public:
uint32_t data_length;
string data_var_name;
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
sst_get_call (tf_fuzz_info *test_state, long &asset_ser_no,
@@ -71,6 +75,8 @@ class sst_remove_call : public sst_call
public:
// Data members:
// Methods:
+ bool copy_call_to_asset (void);
+ bool copy_asset_to_call (void);
void fill_in_prep_code (void);
void fill_in_command (void);
sst_remove_call (tf_fuzz_info *test_state, long &asset_ser_no,
diff --git a/tools/tf_fuzz/class_forwards.hpp b/tools/tf_fuzz/class_forwards.hpp
index 949181107..53d81d761 100644
--- a/tools/tf_fuzz/class_forwards.hpp
+++ b/tools/tf_fuzz/class_forwards.hpp
@@ -13,8 +13,19 @@
using namespace std;
+// find_or_create_asset.hpp:
+enum class asset_search;
+enum class psa_asset_usage;
+enum class psa_asset_search;
+enum class psa_asset_type;
+
// data_blocks.hpp:
class expect_info;
+class set_data_info;
+class asset_name_id_info;
+
+// variables.hpp:
+class variable_info;
// template_line.hpp:
class template_line;
diff --git a/tools/tf_fuzz/demo/README b/tools/tf_fuzz/demo/README
index bad7d92a2..4dc4bbe9e 100644
--- a/tools/tf_fuzz/demo/README
+++ b/tools/tf_fuzz/demo/README
@@ -1,17 +1,9 @@
-.../tf_fuzz/demo directory contents:
+This directory contains some example usages of TF-Fuzz, in a form that makes it
+easy to run each case and quickly see the results.
-1 10 11 12 13 14 15 16 17 18 19 2 3 4 5 6 7 8 9 r
+For more information, please browse to:
---------------------------------------------------------------------------------
-
-The numbered files are test-template files -- input to TF-Fuzz -- for demon-
-strating what it can do.
-
-The "r" shell script is designed to make it quick and easy to run the demo
-tests one by one: just type "r 5" for example.
-
-The initial, "purpose" line in each numbered file briefly describes what that
-file demonstrates.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/demo_dir.html
--------------
diff --git a/tools/tf_fuzz/lib/README b/tools/tf_fuzz/lib/README
index 932e92acf..7c46edcb4 100644
--- a/tools/tf_fuzz/lib/README
+++ b/tools/tf_fuzz/lib/README
@@ -1,12 +1,10 @@
-.../tf_fuzz/lib directory contents:
-
-tfm_boilerplate.txt
-
---------------------------------------------------------------------------------
-
This directory contains the customizable "boilerplate" code snippets used to
write out C source code.
+For more information, please browse to:
+
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/lib_dir.html
+
--------------
*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
diff --git a/tools/tf_fuzz/lib/tfm_boilerplate.txt b/tools/tf_fuzz/lib/tfm_boilerplate.txt
index 3539510f2..4bba10387 100644
--- a/tools/tf_fuzz/lib/tfm_boilerplate.txt
+++ b/tools/tf_fuzz/lib/tfm_boilerplate.txt
@@ -166,7 +166,8 @@ void test_thread (struct test_result_t *ret) {
return;
}
/* Check that the data is correct */
- if (tfm_memcmp($act_data, $exp_data, $length) != 0) {
+ if (tfm_memcmp($act_data, $exp_data,
+ $length) != 0) {
TEST_FAIL("Read data should be equal to result data");
return;
}
diff --git a/tools/tf_fuzz/parser/README b/tools/tf_fuzz/parser/README
index f5251a46f..830148837 100644
--- a/tools/tf_fuzz/parser/README
+++ b/tools/tf_fuzz/parser/README
@@ -1,12 +1,9 @@
-.../tf_fuzz/parser directory contents:
-
-tf_fuzz_grammar.l tf_fuzz_grammar.y
+This directory contains the Lex and YACC grammars for parsing the TF-Fuzz command
+"language" (if it can be called a language as such).
---------------------------------------------------------------------------------
+For more information, please browse to:
-This directory contains the Lex and YACC grammars for parsing the TF-Fuzz command
-"language," if it can be called that. The tf_fuzz_grammar.tab.cpp/.hpp files
-generated also form the executive for the entire parsing process.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/parser_dir.html
--------------
diff --git a/tools/tf_fuzz/parser/tf_fuzz_grammar.l b/tools/tf_fuzz/parser/tf_fuzz_grammar.l
index d3f1cf646..30e72a76c 100644
--- a/tools/tf_fuzz/parser/tf_fuzz_grammar.l
+++ b/tools/tf_fuzz/parser/tf_fuzz_grammar.l
@@ -86,7 +86,7 @@ data return DATA;
active return ACTIVE;
deleted return DELETED;
check return CHECK;
-assign return ASSIGN;
+var return VAR;
print return PRINT;
hash return HASH;
neq return NEQ;
diff --git a/tools/tf_fuzz/parser/tf_fuzz_grammar.y b/tools/tf_fuzz/parser/tf_fuzz_grammar.y
index 600cf5365..9939e72bf 100644
--- a/tools/tf_fuzz/parser/tf_fuzz_grammar.y
+++ b/tools/tf_fuzz/parser/tf_fuzz_grammar.y
@@ -45,7 +45,8 @@
int yylex (void);
void yyerror (tf_fuzz_info *, const char *);
- /* not sure why it sends the yyparse() argument to yyerror(), but OK... */
+ /* Sends the yyparse() argument to yyerror(), probably, to print incorrect
+ text it parsed. */
/* A few consts just to make code more comprehensible: */
const bool yes_fill_in_template = true;
@@ -56,7 +57,8 @@ const bool dont_create_call = false;
tf_fuzz_info *rsrc;
/* These are object pointers used to parse the template and create the test. Ac-
- tually, probably only templateLin will be used. */
+ tually, probably only templateLin is used for now, but this is a good outline of
+ of the template_line class hierarchy. */
template_line *templateLin = nullptr;
sst_template_line *sstTemplateLin = nullptr;
set_sst_template_line *setSstTemplateLin = nullptr;
@@ -72,8 +74,8 @@ template_line *templateLin = nullptr;
security_template_line *secTemplateLin = nullptr;
security_hash_template_line *secHasTemplateLin = nullptr;
/* Call and asset objects are presumably not immediately needed, because the objects of
- these types are within the resource object, *rsrc, but even if just to show class
- hierarchy: */
+ these types are within the resource object, *rsrc, but even if only just to show
+ that class hierarchy: */
psa_call *psaCal = nullptr;
sst_call *sstCal = nullptr;
sst_set_call *sstSetCal = nullptr;
@@ -99,7 +101,6 @@ char gib_buff[4096]; // spew gibberish into here
int rand_data_length = 0;
/* General-utility variables: */
-string purp_str; /* test purpose */
psa_asset_usage random_asset = psa_asset_usage::all; /* pick what type of asset at random */
bool random_name; /* template didn't specify name, so it's generated randomly */
string literal_data; /* literal data for an asset value */
@@ -107,7 +108,7 @@ string literal_data; /* literal data for an asset value */
/* Holders for state in read commands: */
expect_info expect; /* everything about expected results and data */
set_data_info set_data; /* everything about setting the value of PSA-asset data */
-asset_name_id_info asset_id; /* everything about identifying assets */
+asset_name_id_info asset_info; /* everything about identifying assets */
bool assign_data_var_specified;
string assign_data_var;
bool print_data; /* true to just print asset data to the test log */
@@ -117,7 +118,7 @@ bool hash_data; /* true to just print asset data to the test log */
string literal; /* temporary holder for all string literals */
string identifier; /* temporary holder for strings representing identifiers */
string var_name; /* a variable name */
-string asset_name; /* as parsed, not yet put into asset_id */
+string asset_name; /* as parsed, not yet put into asset_info */
string aid; /* string-typed holder for an asset ID in a list thereof */
int nid; /* same idea as aid, but for asset ID# lists */
size_t strFind1, strFind2; /* for searching through strings */
@@ -155,6 +156,34 @@ int exact_nmbr_lines = 1;
using namespace std;
+
+void set_purp_str (
+ char *raw_purpose, /* the purpose C string from parser */
+ tf_fuzz_info *rsrc /* test resources containing the actual test-purpose string */
+) {
+ size_t l; /* temporary of size_t type */
+ string purp_str = raw_purpose;
+ strFind1 = purp_str.find (" ");
+ purp_str = purp_str.substr (strFind1, purp_str.length());
+ purp_str.erase (0, 1); // (extra space)
+ strFind1 = purp_str.rfind (";");
+ purp_str = purp_str.substr (0, strFind1);
+ l = 0;
+ do { /* escape all " chars (if not already escaped) */
+ l = purp_str.find ("\"", l);
+ if ( l < purp_str.length()) { /* did find a quote character */
+ if ( l == 0 /* it's the first character in the string*/
+ || purp_str[l-1] != '\\' /* or it's not already escaped */
+ ) {
+ purp_str.insert (l, "\\"); /* then escape the " char */
+ l++; /* point l to the " again */
+ }
+ l++; /* point l past the " */
+ }
+ } while (l < purp_str.length());
+ rsrc->test_purpose = purp_str;
+}
+
/* randomize_template_lines() chooses a template-line order in cases where they are to
be randomized -- shuffled or random picked. */
void randomize_template_lines (
@@ -163,7 +192,8 @@ void randomize_template_lines (
int &high_nmbr_lines, /* ... block at random, these are fewest and most lines. */
int &exact_nmbr_lines,
vector<template_line*> &template_block_vector,
- vector<int> &block_order
+ vector<int> &block_order,
+ tf_fuzz_info *rsrc /* test resources containing the actual test-purpose string */
) {
set<int> template_used; /* used for shuffle */
low_nmbr_lines = (low_nmbr_lines < 0)? 0 : low_nmbr_lines;
@@ -193,7 +223,7 @@ void randomize_template_lines (
} else {
exact_nmbr_lines = low_nmbr_lines
+ (rand() % ( high_nmbr_lines
- - low_nmbr_lines + 1 ) );
+ - low_nmbr_lines + 1 ) );
}
for (int j = 0; j < exact_nmbr_lines; ++j) {
/* Repeatedly choose a random template line from the block: */
@@ -201,6 +231,12 @@ void randomize_template_lines (
block_order.push_back (i);
}
}
+ IVM(cout << "Order of lines in block: " << flush;
+ for (auto i : block_order) {
+ cout << i << " ";
+ }
+ cout << endl;
+ )
}
/* interpret_template_line() fills in random data, locates PSA assets, (etc.) and
@@ -213,219 +249,83 @@ void interpret_template_line (
set_data_info set_data, psa_asset_usage random_asset,
bool assign_data_var_specified, expect_info expect, bool print_data, bool hash_data,
string asset_name, string assign_data_var,
- asset_name_id_info &asset_id, /* everything about the asset(s) involved */
+ asset_name_id_info &asset_info, /* everything about the asset(s) involved */
bool create_call_bool, /* true to create the PSA call at this time */
bool create_asset_bool, /* true to create the PSA asset at this time */
bool fill_in_template, /* true to back-fill info into template */
int instance
- /* if further differentiation to the names or IDs is needed, make this >0 */
+ /* if further differentiation to the names or IDs is needed, make instance >0 */
) {
- const bool yes_fill_in_template = true; // just to clarify a call
- vector<psa_asset*> *active_asset, *deleted_asset;
+ const bool yes_fill_in_template = true; /* just to improve readability */
vector<psa_asset*>::iterator t_psa_asset;
if (fill_in_template) {
/* Set basic parameters from the template line: */
- templateLin->asset_id.id_n_not_name = asset_id.id_n_not_name;
- templateLin->set_data.random_data = set_data.random_data;
- templateLin->asset_id.set_name (asset_name);
+ templateLin->asset_info.id_n_not_name = asset_info.id_n_not_name;
+ templateLin->asset_info.set_name (asset_name);
/* Fill in state parsed from the template below: */
templateLin->assign_data_var_specified = assign_data_var_specified;
templateLin->assign_data_var.assign (assign_data_var);
- templateLin->expect.data_var_specified
- = expect.data_var_specified;
- templateLin->expect.data_var.assign (expect.data_var);
- templateLin->expect.data_specified = expect.data_specified;
- templateLin->expect.data = expect.data;
+ templateLin->expect = expect;
templateLin->print_data = print_data;
templateLin->hash_data = hash_data;
templateLin->random_asset = random_asset;
+ templateLin->set_data.random_data = set_data.random_data;
templateLin->set_data.string_specified = set_data.literal_data_not_file;
/* TODO: is this right for multiple assets? */
if (set_data.literal_data_not_file && !set_data.random_data) {
templateLin->set_data.set (literal_data);
}
/* Save names or IDs to the template-line tracker: */
- for (auto id_no : asset_id.asset_id_n_vector) {
- templateLin->asset_id.asset_id_n_vector.push_back (id_no);
+ for (auto id_no : asset_info.asset_id_n_vector) {
+ templateLin->asset_info.asset_id_n_vector.push_back (id_no);
}
- asset_id.asset_id_n_vector.clear();
- for (auto as_name : asset_id.asset_name_vector) {
- templateLin->asset_id.asset_name_vector.push_back (as_name);
+ asset_info.asset_id_n_vector.clear();
+ for (auto as_name : asset_info.asset_name_vector) {
+ templateLin->asset_info.asset_name_vector.push_back (as_name);
}
- asset_id.asset_name_vector.clear();
- }
-
- switch (templateLin->asset_type) {
- case psa_asset_type::sst:
- active_asset = &(rsrc->active_sst_asset);
- deleted_asset = &(rsrc->deleted_sst_asset);
- /* Currently "invalid" assets aren't used */
- break;
- case psa_asset_type::key:
- active_asset = &(rsrc->active_key_asset);
- deleted_asset = &(rsrc->deleted_key_asset);
- break;
- case psa_asset_type::policy:
- active_asset = &(rsrc->active_policy_asset);
- deleted_asset = &(rsrc->deleted_policy_asset);
- break;
- default:
- cerr << "\nError: Internal: Please report error "
- << "#1502 to TF-Fuzz developers." << endl;
- exit (1500);
+ asset_info.asset_name_vector.clear();
}
if (templateLin->random_asset != psa_asset_usage::all) {
- /* != psa_asset_usage::all means to choose some known asset at random: */
- if (templateLin->random_asset == psa_asset_usage::active) {
- if (active_asset->size() > 0) {
- i = rand() % active_asset->size();
- t_psa_asset = active_asset->begin() + i;
- templateLin->how_asset_found = asset_search::found_active;
- templateLin->asset_id.id_n = (*t_psa_asset)->asset_id.id_n;
- templateLin->asset_ser_no = (*t_psa_asset)->asset_ser_no;
- if (templateLin->is_remove) {
- templateLin->set_data.string_specified
- = (*t_psa_asset)->set_data.string_specified;
- templateLin->asset_id.name_specified
- = (*t_psa_asset)->asset_id.name_specified;
- templateLin->asset_id.set_calc_name ((*t_psa_asset)->asset_id.get_name());
- templateLin->set_data.set_calculated ((*t_psa_asset)->set_data.get());
- }
- templateLin->setup_call (set_data, templateLin->set_data.random_data,
- yes_fill_in_template, create_call_bool,
- templateLin, rsrc );
- if (templateLin->is_remove) {
- /* Move asset from active vector to deleted vector: */
- if (templateLin->how_asset_found == asset_search::found_active) {
- deleted_asset->push_back(*t_psa_asset);
- active_asset->erase(t_psa_asset);
- } /* if not active, deem the call expected to fail. */
- }
- } else {
- cerr << "\nWarning: Request for random active asset, "
- << "when no active assets of that type exist."
- << " Request disregarded." << endl;
- }
- } else if (templateLin->random_asset == psa_asset_usage::deleted) {
- if (deleted_asset->size() > 0) {
- i = rand() % deleted_asset->size();
- t_psa_asset = deleted_asset->begin() + i;
- templateLin->how_asset_found = asset_search::found_deleted;
- templateLin->asset_id.id_n = (*t_psa_asset)->asset_id.id_n;
- templateLin->asset_ser_no = (*t_psa_asset)->asset_ser_no;
- if (templateLin->is_remove) {
- templateLin->set_data.string_specified
- = (*t_psa_asset)->set_data.string_specified;
- templateLin->asset_id.name_specified
- = (*t_psa_asset)->asset_id.name_specified;
- templateLin->asset_id.set_calc_name (
- (*t_psa_asset)->asset_id.get_name() );
- templateLin->set_data.set_calculated ((*t_psa_asset)->set_data.get());
- }
- templateLin->setup_call (set_data, templateLin->set_data.random_data,
- yes_fill_in_template, create_call_bool,
- templateLin, rsrc );
- if (templateLin->is_remove && create_call_bool) {
- /* Move asset from active vector to deleted vector: */
- if (templateLin->how_asset_found == asset_search::found_active) {
- deleted_asset->push_back(*t_psa_asset);
- active_asset->erase(t_psa_asset);
- } /* if not active, deem the call expected to fail. */
- }
- } else {
- cerr << "\nWarning: Request for random deleted asset, "
- << "when no deleted assets of that type exist."
- << " Request disregarded." << endl;
- }
- } /* "invalid" assets are not used, so if not psa_asset_usage::active or
- psa_asset_usage::deleted, then just ignore the template request */
- } else {
- if (asset_id.id_n_not_name) { /* Not random asset, asset by ID */
- for (auto id_no : templateLin->asset_id.asset_id_n_vector) {
- templateLin->asset_id.set_id_n(id_no);
- asset_name = templateLin->asset_id.make_id_n_based_name (
- id_no + (uint64_t) instance * 10000, asset_name );
- templateLin->asset_id.set_calc_name (asset_name);
- templateLin->how_asset_found = rsrc->find_or_create_psa_asset (
- templateLin->asset_type, psa_asset_search::id,
- psa_asset_usage::all, "",
- (id_no + (uint64_t) instance * 10000),
- templateLin->asset_ser_no, create_asset_bool,
- t_psa_asset );
- if (!templateLin->is_remove) {
- /* Set asset's ID to what's being searched for (whether it's
- already that because it's been found, or was just created): */
- (*t_psa_asset)->asset_id.id_n = templateLin->asset_id.id_n;
- templateLin->expect.data_var = var_name;
- if (!set_data.literal_data_not_file) {
- templateLin->set_data.set_file (set_data.file_path);
- }
- if (templateLin->how_asset_found != asset_search::not_found) {
- templateLin->asset_id.id_n = (*t_psa_asset)->asset_id.id_n;
- templateLin->asset_ser_no = (*t_psa_asset)->asset_ser_no;
- }
- templateLin->setup_call (set_data, templateLin->set_data.random_data,
- fill_in_template, create_call_bool,
- templateLin, rsrc );
- }
- }
- } else { /* Not random asset, asset by name */
- for (auto as_name : templateLin->asset_id.asset_name_vector) {
- /* Also copy into template line object's local vector: */
- string t_string, t_string2;
- t_string.assign(as_name);
- if (instance > 0) {
- t_string += "_" + to_string (instance);
- }
- templateLin->asset_id.set_name (t_string);
- templateLin->how_asset_found = rsrc->find_or_create_psa_asset (
- templateLin->asset_type, psa_asset_search::name,
- psa_asset_usage::all, t_string,
- (uint64_t) 0, templateLin->asset_ser_no,
- create_asset_bool, t_psa_asset );
- if (!templateLin->is_remove) {
- /* Give each occurrence a different UID: */
- templateLin->asset_id.set_id_n (100 + (rand() % 10000));
- /* TODO: unlikely, but this could alias! */
- if (templateLin->how_asset_found != asset_search::not_found) {
- templateLin->asset_id.id_n = (*t_psa_asset)->asset_id.id_n;
- templateLin->asset_ser_no = (*t_psa_asset)->asset_ser_no;
- }
- templateLin->setup_call (set_data, templateLin->set_data.random_data,
- yes_fill_in_template, create_call_bool,
- templateLin, rsrc );
- }
+ /* Just create the call tracker; it will address this in simulation stage: */
+ templateLin->setup_call (set_data, templateLin->set_data.random_data,
+ yes_fill_in_template, create_call_bool,
+ templateLin, rsrc );
+ } else if (asset_info.id_n_not_name) {
+ /* Not random asset; asset(s) by ID rather than name. Go through all
+ specified asset IDs: */
+ uint64_t id_no;
+ for (auto id_n : templateLin->asset_info.asset_id_n_vector) {
+ id_no = id_n + (uint64_t) instance * 10000UL;
+ templateLin->asset_info.set_id_n(id_no); /* just a holder */
+ asset_name = templateLin->asset_info.make_id_n_based_name (id_no);
+ templateLin->asset_info.set_calc_name (asset_name);
+ templateLin->expect.data_var = var_name;
+ if (!set_data.literal_data_not_file) {
+ templateLin->set_data.set_file (set_data.file_path);
}
+ templateLin->setup_call (set_data, templateLin->set_data.random_data,
+ fill_in_template, create_call_bool,
+ templateLin, rsrc );
}
- if (templateLin->is_remove) {
- if (templateLin->how_asset_found != asset_search::not_found) {
- templateLin->asset_ser_no = (*t_psa_asset)->asset_ser_no;
- }
- if (templateLin->how_asset_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: Please report error #109 "
- << "to the TF-Fuzz developers." << endl;
- exit(109);
+ } else {
+ /* Not random asset, asset(s) specified by name. Go through all specified
+ asset names: */
+ for (auto as_name : templateLin->asset_info.asset_name_vector) {
+ /* Also copy into template line object's local vector: */
+ string t_string;
+ t_string.assign(as_name);
+ if (instance > 0) {
+ t_string += "_" + to_string (instance);
}
+ templateLin->asset_info.set_name (t_string);
+ /* Give each occurrence a different random ID: */
+ templateLin->asset_info.set_id_n (100 + (rand() % 10000));
+ /* TODO: unlikely, but this *could* alias! */
templateLin->setup_call (set_data, templateLin->set_data.random_data,
- dont_fill_in_template, create_call_bool,
- templateLin, rsrc);
- templateLin->copy_template_to_asset();
- /* TODO: See comment in setup_call() */
- if (create_call_bool && !templateLin->copy_template_to_call()) {
- cerr << "\nError: Tool-internal: Please report error "
- << "#602 to the TF-Fuzz developers." << endl;
- exit(602);
- }
-
- /* TODO: This ideally would be done in an organized "simulate" stage. */
- /* Move asset from active vector to deleted vector: */
- if ( create_call_bool /* don't do this if just parsing */
- && templateLin->how_asset_found == asset_search::found_active) {
- rsrc->deleted_sst_asset.push_back(*t_psa_asset);
- rsrc->active_sst_asset.erase(t_psa_asset);
- } /* if not active, deem the call expected to fail. */
+ yes_fill_in_template, create_call_bool,
+ templateLin, rsrc );
}
}
}
@@ -438,7 +338,7 @@ void interpret_template_line (
%token <tokenN> PURPOSE RAW_TEXT
%token <tokenN> SET READ REMOVE SECURE DONE /* root commands */
%token <tokenN> SST KEY POLICY NAME UID STAR ACTIVE DELETED EQUAL DATA DFNAME
-%token <tokenN> CHECK ASSIGN HASH NEQ PRINT EXPECT PASS NOTHING ERROR /* expected results */
+%token <tokenN> CHECK VAR HASH NEQ PRINT EXPECT PASS NOTHING ERROR /* expected results */
%token <str> IDENTIFIER_TOK LITERAL_TOK FILE_PATH_TOK /* variables and content */
%token <valueN> NUMBER_TOK /* variables and content */
%token <tokenN> SEMICOLON SHUFFLE TO OF OPEN_BRACE CLOSE_BRACE /* block structure */
@@ -459,18 +359,12 @@ lines: /* nothing */
line:
PURPOSE {
IVM(cout << "Purpose line: " << flush;)
- purp_str = yytext;
- strFind1 = purp_str.find (" ");
- purp_str = purp_str.substr (strFind1, purp_str.length());
- purp_str.erase (0, 1); // (extra space)
- strFind1 = purp_str.rfind (";");
- purp_str = purp_str.substr (0, strFind1);
- rsrc->test_purpose = purp_str;
+ set_purp_str (yytext, rsrc);
IVM(cout << rsrc->test_purpose << endl;)
/* Just a precaution to make sure that these vectors start out empty.
- Should be, and purpose is typically specified first: */
- asset_id.asset_id_n_vector.clear();
- asset_id.asset_name_vector.clear();
+ Should already be, but purpose is typically specified first: */
+ asset_info.asset_id_n_vector.clear();
+ asset_info.asset_name_vector.clear();
}
| block {
/* TODO: This code may not won't work with "secure hash neq ..." */
@@ -479,14 +373,8 @@ line:
the selected lines in order here. */
randomize_template_lines (shuffle_not_pick,
low_nmbr_lines, high_nmbr_lines, exact_nmbr_lines,
- template_block_vector, block_order
+ template_block_vector, block_order, rsrc
);
- IVM(cout << "Order of lines in block: " << flush;
- for (auto i : block_order) {
- cout << i << " ";
- }
- cout << endl;
- )
/* Vector block_order contains the sequence of template lines to be
realized, in order. Pop the indicated template line off the
vector and generate code from it: */
@@ -497,19 +385,19 @@ line:
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
yes_create_call, /* did not create call nor asset earlier */
yes_create_asset,
dont_fill_in_template, /* but did fill it all in before */
- k
+ 0
);
k++;
for (; add_expect < rsrc->calls.size(); ++add_expect) {
templateLin->expect.copy_expect_to_call (rsrc->calls[add_expect]);
}
}
- templateLin->asset_id.asset_id_n_vector.clear();
- templateLin->asset_id.asset_name_vector.clear();
+ templateLin->asset_info.asset_id_n_vector.clear();
+ templateLin->asset_info.asset_name_vector.clear();
/* Done. Empty out the "statisticalization" vector: */
block_order.clear();
/* Empty out the vector of template lines; no longer needed. */
@@ -537,7 +425,7 @@ line:
for (; add_expect < rsrc->calls.size(); ++add_expect) {
templateLin->expect.copy_expect_to_call (rsrc->calls[add_expect]);
}
- delete templateLin; /* done with this template line */
+ delete templateLin;
} else {
template_block_vector.push_back (templateLin);
}
@@ -583,39 +471,39 @@ expect:
/* Root commands: */
set_command:
- SET sst_set_args {
+ SET SST sst_set_args {
IVM(cout << "Set SST command: \"" << flush;)
templateLin = new set_sst_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
nesting_level == 0 /* similarly, create asset unless inside {} */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
}
- | SET key_set_args {
+ | SET KEY key_set_args {
IVM(cout << "Set key command: \"" << flush;)
templateLin = new set_key_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
nesting_level == 0 /* similarly, create asset unless inside {} */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
}
- | SET policy_set_args {
+ | SET POLICY policy_set_args {
IVM(cout << "Set policy command: \"" << flush;)
templateLin = new set_policy_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
nesting_level == 0 /* similarly, create asset unless inside {} */,
yes_fill_in_template, 0
@@ -625,72 +513,72 @@ set_command:
}
;
-remove_command:
- REMOVE sst_remove_args {
- IVM(cout << "Remove SST command: \"" << flush;)
- templateLin = new remove_sst_template_line (rsrc);
+read_command:
+ READ SST sst_read_args {
+ IVM(cout << "Read SST command: \"" << flush;)
+ templateLin = new read_sst_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
- dont_create_asset /* don't create an asset being deleted */,
+ dont_create_asset /* if no such asset exists, fail the call */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
}
- | REMOVE key_remove_args {
- IVM(cout << "Remove key command: \"" << flush;)
- templateLin = new remove_key_template_line (rsrc);
- templateLin->asset_id.set_name (asset_name); // set in key_asset_name, below
+ | READ KEY key_read_args {
+ IVM(cout << "Read key command: \"" << flush;)
+ templateLin = new read_key_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
- dont_create_asset /* don't create an asset being deleted */,
+ dont_create_asset /* if no such asset exists, fail the call */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
}
- ;
-
-read_command:
- READ SST sst_read_args {
- IVM(cout << "Read SST command: \"" << flush;)
- templateLin = new read_sst_template_line (rsrc);
+ | READ POLICY policy_read_args {
+ IVM(cout << "Read policy command: \"" << flush;)
+ templateLin = new read_policy_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
dont_create_asset /* if no such asset exists, fail the call */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
}
- | READ KEY key_read_args {
- IVM(cout << "Read key command: \"" << flush;)
- templateLin = new read_key_template_line (rsrc);
+ ;
+
+remove_command:
+ REMOVE SST sst_remove_args {
+ IVM(cout << "Remove SST command: \"" << flush;)
+ templateLin = new remove_sst_template_line (rsrc);
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
- dont_create_asset /* if no such asset exists, fail the call */,
+ dont_create_asset /* don't create an asset being deleted */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
}
- | READ POLICY policy_read_args {
- IVM(cout << "Read policy command: \"" << flush;)
- templateLin = new read_policy_template_line (rsrc);
+ | REMOVE KEY key_remove_args {
+ IVM(cout << "Remove key command: \"" << flush;)
+ templateLin = new remove_key_template_line (rsrc);
+ templateLin->asset_info.set_name (asset_name); // set in key_asset_name, below
interpret_template_line (
templateLin, rsrc, set_data, random_asset,
assign_data_var_specified, expect, print_data, hash_data,
- asset_name, assign_data_var, asset_id,
+ asset_name, assign_data_var, asset_info,
nesting_level == 0 /* create call unless inside {} */,
- dont_create_asset /* if no such asset exists, fail the call */,
+ dont_create_asset /* don't create an asset being deleted */,
yes_fill_in_template, 0
);
IVM(cout << yytext << "\"" << endl;)
@@ -701,31 +589,26 @@ secure_command: SECURE HASH NEQ ASSET_IDENTIFIER_LIST {
/* TODO: This needs to allow not only SST assets, but mix and match with others
(keys especially) as well. */
templateLin = new security_hash_template_line (rsrc);
- templateLin->asset_id.set_name (asset_name); // set in sst_asset_name, below
- /* Fill in state parsed out below: */
+ templateLin->asset_info.set_name (asset_name);
templateLin->assign_data_var_specified = assign_data_var_specified;
templateLin->assign_data_var.assign (assign_data_var);
-/* TODO: Replace the below with templateLin->expect = expect? */
- templateLin->expect.data_var_specified = expect.data_var_specified;
- templateLin->expect.data_var.assign (expect.data_var);
- templateLin->expect.data_specified = expect.data_specified;
- templateLin->expect.data = literal;
+ templateLin->expect = expect;
templateLin->print_data = print_data;
templateLin->hash_data = hash_data;
templateLin->random_asset = random_asset;
/* Hash checks are different from the rest in that there's a single
"call" -- not a PSA call though -- for all of the assets cited in the
- template line. In other cases, create a single call for each
+ template line. In *other* cases, create a single call for *each*
asset cited by the template line, but not in this case. */
- for (auto as_name : asset_id.asset_name_vector) {
+ for (auto as_name : asset_info.asset_name_vector) {
/* Also copy into template line object's local vector: */
- templateLin->asset_id.asset_name_vector.push_back (as_name);
+ templateLin->asset_info.asset_name_vector.push_back (as_name);
}
/* Don't need to locate the assets, so no searches required. */
templateLin->expect.data_var = var_name;
templateLin->setup_call (set_data, set_data.random_data, yes_fill_in_template,
nesting_level == 0, templateLin, rsrc );
- asset_id.asset_name_vector.clear();
+ asset_info.asset_name_vector.clear();
IVM(cout << yytext << "\"" << endl;)
@@ -745,40 +628,45 @@ done_command: DONE {
/* Root-command parameters: */
sst_set_args:
- SST sst_asset_name DATA LITERAL {
+ sst_asset_name DATA LITERAL {
IVM(cout << "SST-create from literal data: \"" << flush;)
set_data.random_data = false;
set_data.literal_data_not_file = true;
- literal.erase(0,1); // zap the ""s
+ literal.erase(0,1); // zap the ""s
literal.erase(literal.length()-1,1);
literal_data.assign (literal);
IVM(cout << yytext << "\"" << endl;)
}
- | SST sst_asset_name DATA STAR { /* TF-Fuzz supplies random data */
+ | sst_asset_name DATA STAR { /* TF-Fuzz supplies random data */
IVM(cout << "SST-create from random data" << endl;)
- set_data.random_data = true;
- set_data.literal_data_not_file = true;
- rand_data_length = 40 + (rand() % 256); /* Note: Multiple assets do get different data */
- gib.sentence (gib_buff, gib_buff + rand_data_length - 1);
- set_data.set (gib_buff);
- literal.assign (gib_buff); /* just in case something uses literal */
+ set_data.randomize();
+ literal.assign (set_data.get()); /* just in case something uses literal */
+ }
+ | sst_asset_name {
+ IVM(cout << "SST-create from random data (no 'data *')" << endl;)
+ set_data.randomize();
+ literal.assign (set_data.get()); /* just in case something uses literal */
+ }
+ | sst_asset_name VAR IDENTIFIER { /* set from variable */
+ IVM(cout << "SST-set set from variable: \"" << flush;)
+ assign_data_var.assign (identifier);
+ assign_data_var_specified = true;
+ expect.data_specified = false;
+ expect.data_var_specified = false;
+ IVM(cout << yytext << "\"" << endl;)
}
- | SST sst_asset_name DFNAME sst_asset_set_file_path {
+ | sst_asset_name DFNAME sst_asset_set_file_path {
set_data.literal_data_not_file = set_data.random_data = false;
IVM(cout << "SST-create from file: " << yytext << "\"" << endl;)
/* TODO: Need to decide whether the concept of using files to set SST
- asset values has meaning, and then write code to write code to
+ asset values has meaning, and if so, write code to write code to
set data appropriately from the file. */
}
;
sst_read_args:
- sst_asset_name ASSIGN IDENTIFIER { /* dump to variable */
+ sst_asset_name VAR IDENTIFIER { /* dump to variable */
IVM(cout << "SST-read dump to variable: \"" << flush;)
- /* TODO: set_data content probably doesn't need to be set here;
- constructor probably sets it fine. */
- set_data.random_data = false;
- set_data.literal_data_not_file = true;
assign_data_var.assign (identifier);
assign_data_var_specified = true;
expect.data_specified = false;
@@ -788,10 +676,6 @@ sst_read_args:
| sst_asset_name CHECK sst_read_args_var_name { /* check against variable */
IVM(cout << "SST-read check against variable: \""
<< yytext << "\"" << endl;)
- /* TODO: set_data content probably doesn't need to be set here;
- constructor probably sets it fine. */
- set_data.random_data = false;
- set_data.literal_data_not_file = true; /* most importantly not file */
set_data.set (literal);
assign_data_var_specified = false;
expect.data_specified = false;
@@ -800,16 +684,12 @@ sst_read_args:
}
| sst_asset_name CHECK LITERAL { /* check against literal */
IVM(cout << "SST-read check against literal: " << flush;)
- /* TODO: set_data content probably doesn't need to be set here;
- constructor probably sets it fine. */
- set_data.random_data = false;
- set_data.literal_data_not_file = true;
expect.data.assign (literal);
expect.data.erase(0,1); // zap the ""s
expect.data.erase(expect.data.length()-1,1);
- assign_data_var_specified = false;
- expect.data_specified = true;
- expect.data_var_specified = false;
+ assign_data_var_specified = false; /* don't read variable */
+ expect.data_specified = true; /* check against literal data */
+ expect.data_var_specified = false; /* don't check against variable */
IVM(cout << yytext << endl;)
}
| sst_asset_name PRINT { /* print out content in test log */
@@ -845,7 +725,7 @@ sst_read_args:
;
sst_remove_args:
- SST sst_asset_name {
+ sst_asset_name {
IVM(cout << "SST-remove arguments: \""
<< yytext << "\"" << endl;)
}
@@ -857,7 +737,7 @@ sst_asset_name:
random_name = false;
asset_name.assign (identifier); /* TODO: Not sure this ultimately has any effect... */
random_asset = psa_asset_usage::all; /* don't use random asset */
- asset_id.id_n_not_name = false;
+ asset_info.id_n_not_name = false;
IVM(cout << yytext << "\"" << endl;)
}
| NAME STAR {
@@ -866,38 +746,38 @@ sst_asset_name:
rand_data_length = 2 + (rand() % 10);
gib.word (false, gib_buff, gib_buff + rand_data_length - 1);
aid.assign (gib_buff);
- asset_id.asset_name_vector.push_back (aid);
+ asset_info.asset_name_vector.push_back (aid);
random_asset = psa_asset_usage::all; /* don't use random asset */
- asset_id.id_n_not_name = false;
+ asset_info.id_n_not_name = false;
IVM(cout << yytext << "\"" << endl;)
}
| UID ASSET_NUMBER_LIST {
IVM(cout << "SST-asset UID list: \"" << flush;)
random_name = false;
random_asset = psa_asset_usage::all; /* don't use random asset */
- asset_id.id_n_not_name = true;
- asset_id.id_n_specified = true;
+ asset_info.id_n_not_name = true;
+ asset_info.id_n_specified = true;
IVM(cout << yytext << "\"" << endl;)
}
| UID STAR {
IVM(cout << "SST-asset random UID: \"" << flush;)
- asset_id.id_n_not_name = true;
+ asset_info.id_n_not_name = true;
random_name = false;
nid = 100 + (rand() % 10000);
- asset_id.asset_id_n_vector.push_back (nid);
+ asset_info.asset_id_n_vector.push_back (nid);
random_asset = psa_asset_usage::all; /* don't use random asset */
IVM(cout << yytext << "\"" << endl;)
}
| STAR ACTIVE {
IVM(cout << "SST-asset random active: \"" << flush;)
random_asset = psa_asset_usage::active;
- asset_id.id_n_not_name = false;
+ asset_info.id_n_not_name = false;
IVM(cout << yytext << "\"" << endl;)
}
| STAR DELETED {
IVM(cout << "SST-asset random deleted: \"" << flush;)
random_asset = psa_asset_usage::deleted;
- asset_id.id_n_not_name = false;
+ asset_info.id_n_not_name = false;
IVM(cout << yytext << "\"" << endl;)
}
;
@@ -926,21 +806,21 @@ sst_asset_dump_file_path:
;
key_set_args:
- KEY key_id POLICY policy_asset_name {
+ key_id POLICY policy_asset_name {
IVM(cout << "Key-create arguments: \""
<< yytext << "\"" << endl;)
}
;
key_remove_args:
- KEY key_id {
+ key_id {
IVM(cout << "Key-remove arguments: \""
<< yytext << "\"" << endl;)
}
;
key_read_args:
- KEY key_id key_read_var_name {
+ key_id key_read_var_name {
IVM(cout << "Key dump to variable: \""
<< yytext << "\"" << endl;)
}
@@ -961,14 +841,14 @@ key_id:
;
policy_set_args:
- POLICY policy_asset_name {
+ policy_asset_name {
IVM(cout << "Policy-create arguments: \""
<< yytext << "\"" << endl;)
}
;
policy_read_args:
- POLICY policy_asset_name policy_read_var_name {
+ policy_asset_name policy_read_var_name {
IVM(cout << "Policy dump to variable: \""
<< yytext << "\"" << endl;)
}
@@ -1056,14 +936,14 @@ ASSET_NUMBERS: /* nothing, or */
ASSET_NUMBER: NUMBER_TOK {
IVM(cout << "ASSET_NUMBER: \"" << flush;)
nid = atol(yytext);
- asset_id.asset_id_n_vector.push_back (nid);
+ asset_info.asset_id_n_vector.push_back (nid);
IVM(cout << yytext << "\"" << endl;)
}
;
/* ASSET_IDENTIFIER* are used specifically for lists of assets in a template line.
That, as opposed to list of identifers in general. The difference is the need
- to queue ASSET_IDENTIFIERS up into asset_id.asset_name_vector, and have to do so
+ to queue ASSET_IDENTIFIERS up into asset_info.asset_name_vector, and have to do so
here before they "vanish." */
ASSET_IDENTIFIER_LIST: ASSET_IDENTIFIER ASSET_IDENTIFIERS; /* (at least one) */
@@ -1074,7 +954,7 @@ ASSET_IDENTIFIERS:
ASSET_IDENTIFIER: IDENTIFIER_TOK {
IVM(cout << "ASSET_IDENTIFIER: \"" << flush;)
aid = identifier = yytext;
- asset_id.asset_name_vector.push_back (aid);
+ asset_info.asset_name_vector.push_back (aid);
IVM(cout << yytext << "\"" << endl;)
}
;
diff --git a/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py b/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py
+++ b/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr b/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr
index 05de8dbd0..522fccaa4 100644
--- a/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr
@@ -14,6 +14,8 @@ Expect pass clause: "pass"
Command with expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c b/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c
index 1573156ee..e970fea6d 100644
--- a/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c
+++ b/tools/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c
@@ -44,15 +44,15 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t SST_ID_104_data[] = "Very simple test";
- static int SST_ID_104_data_size = 16;
+ static uint8_t SST_ID_104_set_data[] = "Very simple test";
+ static uint32_t SST_ID_104_set_length = 16;
/* PSA calls to test: */
- /* Creating SST asset UID = 104 with data "Very simpl...". */
- sst_status = psa_ps_set(104, SST_ID_104_data_size, SST_ID_104_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 104 with data "Very simpl...". \*/
+ sst_status = psa_ps_set(104, SST_ID_104_set_length, SST_ID_104_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
diff --git a/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py b/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py
+++ b/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr b/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr
index da7e75789..2bcc4a27a 100644
--- a/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr
@@ -14,6 +14,8 @@ Expect nothing clause: "nothing"
Command with expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c b/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c
index c382d9b04..358c29678 100644
--- a/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c
+++ b/tools/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c
@@ -44,20 +44,20 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t forecast_data[] = "sunny with a 30% chance of weather!";
- static int forecast_data_size = 35;
+ static uint8_t forecast_set_data[] = "sunny with a 30% chance of weather!";
+ static uint32_t forecast_set_length = 35;
/* PSA calls to test: */
- /* Creating SST asset "forecast," with data "sunny with...". */
- sst_status = psa_ps_set(@@@001@@@, forecast_data_size, forecast_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "forecast," with data "sunny with...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, forecast_set_length, forecast_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
/* (No checks for this PSA call.) */
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000003_set_sst_name_data/check.py b/tools/tf_fuzz/regression/000003_set_sst_name_data/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000003_set_sst_name_data/check.py
+++ b/tools/tf_fuzz/regression/000003_set_sst_name_data/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr b/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr
index 1dbe62d9f..cab157104 100644
--- a/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr
@@ -3,7 +3,7 @@ Trusted Firmware Fuzzer (TF-Fuzz) starting...
Info: random seed was not specified.
Using seed value of \d+ \(0x[a-f\d]+\).
-Purpose line: to show that TF-Fuzz can infer results
+Purpose line: to show that TF-Fuzz can \"infer\" \"results\"
ASSET_IDENTIFIER: "jonathan"
SST-asset identifier list: "data"
LITERAL: "I am the man"
@@ -13,6 +13,8 @@ Set command: ""I am the man""
Command with no expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c b/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c
index ea88a133d..c002b8a0a 100644
--- a/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c
+++ b/tools/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c
@@ -7,7 +7,7 @@
/*
* Test purpose:
- * to show that TF-Fuzz can infer results
+ * to show that TF-Fuzz can \"infer\" \"results\"
*
*/
@@ -40,19 +40,19 @@ void test_thread (struct test_result_t *ret) {
return;
}
- TEST_LOG("Test to show that TF-Fuzz can infer results");
+ TEST_LOG("Test to show that TF-Fuzz can \"infer\" \"results\"");
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t jonathan_data[] = "I am the man";
- static int jonathan_data_size = 12;
+ static uint8_t jonathan_set_data[] = "I am the man";
+ static uint32_t jonathan_set_length = 12;
/* PSA calls to test: */
- /* Creating SST asset "jonathan," with data "I am the m...". */
- sst_status = psa_ps_set(@@@001@@@, jonathan_data_size, jonathan_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "jonathan," with data "I am the m...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, jonathan_set_length, jonathan_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
@@ -60,7 +60,7 @@ void test_thread (struct test_result_t *ret) {
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000003_set_sst_name_data/template b/tools/tf_fuzz/regression/000003_set_sst_name_data/template
index 53b8897c9..820e3ab56 100644
--- a/tools/tf_fuzz/regression/000003_set_sst_name_data/template
+++ b/tools/tf_fuzz/regression/000003_set_sst_name_data/template
@@ -1,2 +1,2 @@
-purpose to show that TF-Fuzz can infer results;
+purpose to show that TF-Fuzz can "infer" \"results\";
set sst name jonathan data "I am the man";
diff --git a/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py b/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py
+++ b/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr b/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr
index c719302f9..4fc059cf8 100644
--- a/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr
@@ -12,6 +12,8 @@ Set command: "*"
Command with no expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c b/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c
index f4743eac3..10dcfb207 100644
--- a/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c
+++ b/tools/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c
@@ -44,15 +44,15 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t gibberish_data[] = "@@002@10@@********";
- static int gibberish_data_size = \d+;
+ static uint8_t gibberish_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t gibberish_set_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "gibberish," with data "@@002@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, gibberish_data_size, gibberish_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "gibberish," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, gibberish_set_length, gibberish_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
@@ -60,7 +60,7 @@ void test_thread (struct test_result_t *ret) {
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py b/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py
+++ b/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr b/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr
index 466f25015..78f48d731 100644
--- a/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr
@@ -11,6 +11,8 @@ Set command: "*"
Command with no expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c b/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c
index 238af073d..af4995951 100644
--- a/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c
+++ b/tools/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c
@@ -44,15 +44,15 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t @@@003@@@_data[] = "@@002@10@@********";
- static int @@@003@@@_data_size = \d+;
+ static uint8_t @@@003@@@_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t @@@003@@@_set_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "@@@003@@@," with data "@@002@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, @@@003@@@_data_size, @@@003@@@_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "@@@003@@@," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, @@@003@@@_set_length, @@@003@@@_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
@@ -60,7 +60,7 @@ void test_thread (struct test_result_t *ret) {
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py b/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py
+++ b/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr b/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr
index 1f090d1c7..fa8ccaaea 100644
--- a/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr
@@ -16,6 +16,8 @@ Set command: "*"
Command with no expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c b/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c
index 3950c586c..f432d1764 100644
--- a/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c
+++ b/tools/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c
@@ -44,55 +44,55 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t john_data[] = "@@012@10@@********";
- static int john_data_size = \d+;
- static uint8_t paul_data[] = "@@013@10@@********";
- static int paul_data_size = \d+;
- static uint8_t george_data[] = "@@014@10@@********";
- static int george_data_size = \d+;
- static uint8_t and_data[] = "@@015@10@@********";
- static int and_data_size = \d+;
- static uint8_t ringo_data[] = "@@016@10@@********";
- static int ringo_data_size = \d+;
+ static uint8_t john_set_data\[\] = "@@012@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t john_set_length = \d+;
+ static uint8_t paul_set_data\[\] = "@@013@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t paul_set_length = \d+;
+ static uint8_t george_set_data\[\] = "@@014@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t george_set_length = \d+;
+ static uint8_t and_set_data\[\] = "@@015@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t and_set_length = \d+;
+ static uint8_t ringo_set_data\[\] = "@@016@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t ringo_set_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "john," with data "@@012@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, john_data_size, john_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "john," with data "@@012@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, john_set_length, john_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset "paul," with data "@@013@10@@...". */
- sst_status = psa_ps_set(@@@002@@@, paul_data_size, paul_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "paul," with data "@@013@10@@...". \*/
+ sst_status = psa_ps_set\(@@@002@@@, paul_set_length, paul_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset "george," with data "@@014@10@@...". */
- sst_status = psa_ps_set(@@@003@@@, george_data_size, george_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "george," with data "@@014@10@@...". \*/
+ sst_status = psa_ps_set\(@@@003@@@, george_set_length, george_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset "and," with data "@@015@10@@...". */
- sst_status = psa_ps_set(@@@004@@@, and_data_size, and_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "and," with data "@@015@10@@...". \*/
+ sst_status = psa_ps_set\(@@@004@@@, and_set_length, and_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset "ringo," with data "@@016@10@@...". */
- sst_status = psa_ps_set(@@@005@@@, ringo_data_size, ringo_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "ringo," with data "@@016@10@@...". \*/
+ sst_status = psa_ps_set\(@@@005@@@, ringo_set_length, ringo_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
@@ -100,27 +100,27 @@ void test_thread (struct test_result_t *ret) {
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
}
- psa_ps_remove(@@@002@@@);
+ psa_ps_remove\(@@@002@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
}
- psa_ps_remove(@@@003@@@);
+ psa_ps_remove\(@@@003@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
}
- psa_ps_remove(@@@004@@@);
+ psa_ps_remove\(@@@004@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
}
- psa_ps_remove(@@@005@@@);
+ psa_ps_remove\(@@@005@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py b/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py
+++ b/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr b/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr
index 226833a35..06effdd06 100644
--- a/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr
@@ -17,6 +17,8 @@ Set command: "*"
Command with no expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c b/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c
index 98a2c1716..326f56651 100644
--- a/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c
+++ b/tools/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c
@@ -44,65 +44,65 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t SST_ID_17_data[] = "@@012@10@@********";
- static int SST_ID_17_data_size = \d+;
- static uint8_t SST_ID_19_data[] = "@@013@10@@********";
- static int SST_ID_19_data_size = \d+;
- static uint8_t SST_ID_24_data[] = "@@014@10@@********";
- static int SST_ID_24_data_size = \d+;
- static uint8_t SST_ID_31_data[] = "@@015@10@@********";
- static int SST_ID_31_data_size = \d+;
- static uint8_t SST_ID_34_data[] = "@@016@10@@********";
- static int SST_ID_34_data_size = \d+;
- static uint8_t SST_ID_41_data[] = "@@017@10@@********";
- static int SST_ID_41_data_size = \d+;
+ static uint8_t SST_ID_17_set_data\[\] = "@@012@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t SST_ID_17_set_length = \d+;
+ static uint8_t SST_ID_19_set_data\[\] = "@@013@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t SST_ID_19_set_length = \d+;
+ static uint8_t SST_ID_24_set_data\[\] = "@@014@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t SST_ID_24_set_length = \d+;
+ static uint8_t SST_ID_31_set_data\[\] = "@@015@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t SST_ID_31_set_length = \d+;
+ static uint8_t SST_ID_34_set_data\[\] = "@@016@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t SST_ID_34_set_length = \d+;
+ static uint8_t SST_ID_41_set_data\[\] = "@@017@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t SST_ID_41_set_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset UID = 17 with data "@@012@10@@...". */
- sst_status = psa_ps_set(17, SST_ID_17_data_size, SST_ID_17_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 17 with data "@@012@10@@...". \*/
+ sst_status = psa_ps_set(17, SST_ID_17_set_length, SST_ID_17_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset UID = 19 with data "@@013@10@@...". */
- sst_status = psa_ps_set(19, SST_ID_19_data_size, SST_ID_19_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 19 with data "@@013@10@@...". \*/
+ sst_status = psa_ps_set(19, SST_ID_19_set_length, SST_ID_19_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset UID = 24 with data "@@014@10@@...". */
- sst_status = psa_ps_set(24, SST_ID_24_data_size, SST_ID_24_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 24 with data "@@014@10@@...". \*/
+ sst_status = psa_ps_set(24, SST_ID_24_set_length, SST_ID_24_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset UID = 31 with data "@@015@10@@...". */
- sst_status = psa_ps_set(31, SST_ID_31_data_size, SST_ID_31_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 31 with data "@@015@10@@...". \*/
+ sst_status = psa_ps_set(31, SST_ID_31_set_length, SST_ID_31_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset UID = 34 with data "@@016@10@@...". */
- sst_status = psa_ps_set(34, SST_ID_34_data_size, SST_ID_34_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 34 with data "@@016@10@@...". \*/
+ sst_status = psa_ps_set(34, SST_ID_34_set_length, SST_ID_34_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- /* Creating SST asset UID = 41 with data "@@017@10@@...". */
- sst_status = psa_ps_set(41, SST_ID_41_data_size, SST_ID_41_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset UID = 41 with data "@@017@10@@...". \*/
+ sst_status = psa_ps_set(41, SST_ID_41_set_length, SST_ID_41_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
diff --git a/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py b/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py
+++ b/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr b/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr
index eeed4bc5c..9dbecb870 100644
--- a/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr
@@ -20,6 +20,8 @@ Command with no expect: ";"
Lines: Line number 4.
Lines: Line number 4.
Lines: Line number 4.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c b/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c
index 0d304f88e..a70c9a940 100644
--- a/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c
+++ b/tools/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c
@@ -44,38 +44,39 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t snortwaggle_data[] = "@@002@10@@********";
- static int snortwaggle_data_size = \d+;
+ static uint8_t snortwaggle_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t snortwaggle_set_length = \d+;
static uint8_t snortwaggle_exp_data[] = "almost certainly not *this*";
- static uint8_t snortwaggle_act_data[2048] = "********";
- static size_t snortwaggle_act_length = 0;
+ static uint8_t snortwaggle_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t snortwaggle_act_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "snortwaggle," with data "@@002@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, snortwaggle_data_size, snortwaggle_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "snortwaggle," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, snortwaggle_set_length, snortwaggle_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- sst_status = psa_ps_get(@@@001@@@, 0, 0, snortwaggle_act_data
+ sst_status = psa_ps_get\(@@@001@@@, 0, @@@003@@@, snortwaggle_act_data
&snortwaggle_act_length);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
return;
}
/* Check that the data is correct */
- if (tfm_memcmp(snortwaggle_act_data, snortwaggle_exp_data, 27) != 0) {
+ if \(tfm_memcmp\(snortwaggle_act_data, snortwaggle_exp_data,
+ snortwaggle_act_length\) != 0\) {
TEST_FAIL("Read data should be equal to result data");
return;
}
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py
+++ b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr
index 5f3d60be5..833f74595 100644
--- a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr
@@ -3,7 +3,7 @@ Trusted Firmware Fuzzer (TF-Fuzz) starting...
Info: random seed was not specified.
Using seed value of \d+ \(0x[a-f\d]+\).
-Purpose line: to dump to a variable or to the log
+Purpose line: to check against a variable or dump into the log
ASSET_IDENTIFIER: "greebledorf"
SST-asset identifier list: "data"
SST-create from random data
@@ -28,6 +28,8 @@ Lines: Line number 5.
Lines: Line number 5.
Lines: Line number 5.
Lines: Line number 5.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c
index 4c5b171e6..2c417ad81 100644
--- a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c
+++ b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c
@@ -7,7 +7,7 @@
/*
* Test purpose:
- * to dump to a variable or to the log
+ * to check against a variable or dump into the log
*
*/
@@ -40,42 +40,42 @@ void test_thread (struct test_result_t *ret) {
return;
}
- TEST_LOG("Test to dump to a variable or to the log");
+ TEST_LOG("Test to check against a variable or dump into the log");
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t greebledorf_data[] = "@@002@10@@********";
- static int greebledorf_data_size = \d+;
- static uint8_t a_variable[] = "";
- static uint8_t greebledorf_act_data[2048] = "********";
- static int greebledorf_act_length = 0;
- static uint8_t greebledorf_act_data[2048] = "********";
- static int greebledorf_act_length = 0;
+ static uint8_t greebledorf_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t greebledorf_set_length = \d+;
+ static uint8_t a_variable_data\[\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t a_variable_length = \d+;
+ static uint8_t greebledorf_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t greebledorf_act_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "greebledorf," with data "@@002@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, greebledorf_data_size, greebledorf_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "greebledorf," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, greebledorf_set_length, greebledorf_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- sst_status = psa_ps_get(@@@001@@@, 0, 0, greebledorf_act_data,
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, greebledorf_act_data,
&greebledorf_act_length);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
return;
}
/* Check that the data is correct */
- if (tfm_memcmp(greebledorf_act_data, a_variable, 0) != 0) {
+ if (tfm_memcmp(greebledorf_act_data, a_variable,
+ greebledorf_act_length) != 0) {
TEST_FAIL("Read data should be equal to result data");
return;
}
- sst_status = psa_ps_get(@@@001@@@, 0, 0, greebledorf_act_data,
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, greebledorf_act_data,
&greebledorf_act_length);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
@@ -85,7 +85,7 @@ void test_thread (struct test_result_t *ret) {
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template
index 72cc2692c..dffea573e 100644
--- a/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template
+++ b/tools/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template
@@ -1,4 +1,4 @@
-purpose to dump to a variable or to the log;
+purpose to check against a variable or dump into the log;
set sst name greebledorf data *;
read sst name greebledorf check a_variable;
read sst name greebledorf print;
diff --git a/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py b/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py
+++ b/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr b/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr
index ba723fe55..453e84482 100644
--- a/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr
@@ -13,6 +13,8 @@ Read command: ""this won't work""
Command with no expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c b/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c
index 7916d4199..aec0ad6c1 100644
--- a/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c
+++ b/tools/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c
@@ -45,20 +45,21 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
static uint8_t napoleon_exp_data[] = "this won't work";
- static uint8_t napoleon_act_data[2048] = "********";
- static int napoleon_act_length = 0;
+ static uint8_t napoleon_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
/* PSA calls to test: */
- sst_status = psa_ps_get(********, 0, 0, napoleon_act_data
+ sst_status = psa_ps_get\(\d+, 0, \d+, napoleon_act_data
&napoleon_act_length);
if (sst_status != PSA_ERROR_DOES_NOT_EXIST) {
TEST_FAIL("psa_ps_get() expected PSA_ERROR_DOES_NOT_EXIST.");
return;
}
/* Check that the data is correct */
- if (tfm_memcmp(napoleon_act_data, napoleon_exp_data, ********) != 0) {
+ if \(tfm_memcmp\(napoleon_act_data, napoleon_exp_data,
+ napoleon_act_length\) != 0\) {
TEST_FAIL("Read data should be equal to result data");
return;
}
diff --git a/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py b/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py
+++ b/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr b/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr
index 018ae91c6..614c1b96c 100644
--- a/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr
@@ -14,6 +14,8 @@ Expect pass clause: "pass"
Command with expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c b/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c
index 277f7c3d6..c741ee2f1 100644
--- a/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c
+++ b/tools/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c
@@ -45,20 +45,21 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
static uint8_t napoleon_exp_data[] = "this won't work";
- static uint8_t napoleon_act_data[2048] = "********";
- static int napoleon_act_length = 0;
+ static uint8_t napoleon_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
/* PSA calls to test: */
- sst_status = psa_ps_get(********, 0, 0, napoleon_act_data,
+ sst_status = psa_ps_get\(\d+, 0, @@@001@@@, napoleon_act_data,
&napoleon_act_length);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
return;
}
/* Check that the data is correct */
- if (tfm_memcmp(napoleon_act_data, napoleon_exp_data, ********) != 0) {
+ if \(tfm_memcmp\(napoleon_act_data, napoleon_exp_data,
+ napoleon_act_length\) != 0\) \{
TEST_FAIL("Read data should be equal to result data");
return;
}
diff --git a/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py b/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py
+++ b/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr b/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr
index 6e9d9339c..77ef58ca9 100644
--- a/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr
@@ -15,6 +15,8 @@ Expect error clause: "PSA_ERROR_GENERIC_ERROR"
Command with expect: ";"
Lines: Line number 3.
Lines: Line number 3.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c b/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c
index 6e6635339..f4b59ea85 100644
--- a/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c
+++ b/tools/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c
@@ -45,20 +45,21 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
static uint8_t napoleon_exp_data[] = "this won't work";
- static uint8_t napoleon_act_data[2048] = "********";
- static int napoleon_act_length = 0;
+ static uint8_t napoleon_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
/* PSA calls to test: */
- sst_status = psa_ps_get(********, 0, 0, napoleon_act_data,
+ sst_status = psa_ps_get\(\d+, 0, @@@001@@@, napoleon_act_data,
&napoleon_act_length);
if (sst_status != PSA_ERROR_GENERIC_ERROR) {
TEST_FAIL("psa_ps_get() expected PSA_ERROR_GENERIC_ERROR.");
return;
}
/* Check that the data is correct */
- if (tfm_memcmp(napoleon_act_data, napoleon_exp_data, ********) != 0) {
+ if \(tfm_memcmp\(napoleon_act_data, napoleon_exp_data,
+ napoleon_act_length\) != 0\) \{
TEST_FAIL("Read data should be equal to result data");
return;
}
diff --git a/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py b/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py
+++ b/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr b/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr
index 4ef68d275..e5981058e 100644
--- a/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr
@@ -26,6 +26,8 @@ Lines: Line number 5.
Lines: Line number 5.
Lines: Line number 5.
Lines: Line number 5.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c b/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c
index 99b68e350..1efbbdeb1 100644
--- a/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c
+++ b/tools/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c
@@ -44,27 +44,27 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t george_data[] = "@@002@10@@********";
- static int george_data_size = \d+;
+ static uint8_t george_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t george_set_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "george," with data "@@002@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, george_data_size, george_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "george," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, george_set_length, george_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- sst_status = psa_ps_remove(@@@001@@@);
+ sst_status = psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_remove() expected PSA_SUCCESS.");
return;
}
- sst_status = psa_ps_remove(@@@001@@@);
+ sst_status = psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_ERROR_DOES_NOT_EXIST) {
TEST_FAIL("psa_ps_remove() expected PSA_ERROR_DOES_NOT_EXIST.");
return;
diff --git a/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py b/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py
index a215e77ca..88c17261e 100644
--- a/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py
+++ b/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py
@@ -1,17 +1,119 @@
-#!/usr/bin/env python
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-import sys, os
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
def main():
- if len(sys.argv) != 4:
- print >> sys.stderr, "%s requires 3 command-line arguments. Exiting." % sys.argv[0]
- sys.exit(1)
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
- #print "Command line args: %s" % (', '.join(sys.argv[1:4]))
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
sys.exit(0)
-if __name__ == "__main__":
- main()
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr b/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr
index 25edad00a..b452aa15d 100644
--- a/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr
@@ -19,6 +19,8 @@ Command with no expect: ";"
Lines: Line number 4.
Lines: Line number 4.
Lines: Line number 4.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c b/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c
index c66e70dbd..da0cfa3ea 100644
--- a/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c
+++ b/tools/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c
@@ -44,28 +44,29 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t george_data[] = "@@002@10@@********";
- static int george_data_size = \d+;
+ static uint8_t george_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t george_set_length = \d+;
/* PSA calls to test: */
- /* Creating SST asset "george," with data "@@002@10@@...". */
- sst_status = psa_ps_set(@@@001@@@, george_data_size, george_data,
- PSA_STORAGE_FLAG_********);
+ /\* Creating SST asset "george," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, george_set_length, george_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
return;
}
- sst_status = psa_ps_remove(********);
+ sst_status = psa_ps_remove\(\d+\);
if (sst_status != PSA_ERROR_DOES_NOT_EXIST) {
TEST_FAIL("psa_ps_remove() expected PSA_ERROR_DOES_NOT_EXIST.");
return;
}
+
/* Removing assets left over from testing: */
- psa_ps_remove(@@@001@@@);
+ psa_ps_remove\(@@@001@@@\);
if (sst_status != PSA_SUCCESS) {
TEST_FAIL("Failed to tear down an SST asset upon test completion.");
return;
diff --git a/tools/tf_fuzz/regression/000015_set_sst_name_only/check.py b/tools/tf_fuzz/regression/000015_set_sst_name_only/check.py
new file mode 100644
index 000000000..88c17261e
--- /dev/null
+++ b/tools/tf_fuzz/regression/000015_set_sst_name_only/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
+
+def main():
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
+
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr b/tools/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr
new file mode 100644
index 000000000..2b03126cc
--- /dev/null
+++ b/tools/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr
@@ -0,0 +1,25 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to show that if you don't have say anything about data to randomize it
+ASSET_IDENTIFIER: "random"
+SST-asset identifier list: ";"
+SST-create from random data (no 'data *')
+Set SST command: ";"
+Set command: ";"
+Command with no expect: ";"
+SST-asset random identifier: "*"
+SST-create from random data (no 'data *')
+Set SST command: ";"
+Set command: ";"
+Command with no expect: ";"
+Lines: Line number 4.
+Lines: Line number 4.
+Lines: Line number 4.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c b/tools/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c
new file mode 100644
index 000000000..2fd4ede37
--- /dev/null
+++ b/tools/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * Test purpose:
+ * to show that if you don't have say anything about data to randomize it
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "../sst/non_secure/ns_test_helpers.h"
+#include "psa/protected_storage.h"
+#include "test/framework/test_framework_helpers.h"
+#include "crypto_tests_common.h"
+#include "tfm_memory_utils.h"
+
+/* This is not yet right for how to run a test; need to register tests, etc. */
+
+void test_thread (struct test_result_t *ret) {
+ psa_status_t crypto_status; // result from Crypto calls
+ psa_status_t sst_status;
+
+ /* To prevent unused variable warning, as the variable might not be used
+ * in this testcase
+ */
+ (void)sst_status;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show that if you don't have say anything about data to randomize it");
+
+
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t random_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t random_set_length = \d+;
+ static uint8_t @@@003@@@_set_data\[\] = "@@004@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t @@@003@@@_set_length = \d+;
+
+
+ /* PSA calls to test: */
+
+ /\* Creating SST asset "random," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, random_set_length, random_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /\* Creating SST asset "@@@003@@@," with data "@@004@10@@...". \*/
+ sst_status = psa_ps_set\(@@@004@@@, @@@003@@@_set_length, @@@003@@@_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove\(@@@001@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove\(@@@004@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tools/tf_fuzz/regression/000015_set_sst_name_only/template b/tools/tf_fuzz/regression/000015_set_sst_name_only/template
new file mode 100644
index 000000000..63220dbd5
--- /dev/null
+++ b/tools/tf_fuzz/regression/000015_set_sst_name_only/template
@@ -0,0 +1,3 @@
+purpose to show that if you don't have say anything about data to randomize it;
+set sst name random;
+set sst name *;
diff --git a/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/check.py b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/check.py
new file mode 100644
index 000000000..88c17261e
--- /dev/null
+++ b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
+
+def main():
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
+
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr
new file mode 100644
index 000000000..f4fd57210
--- /dev/null
+++ b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr
@@ -0,0 +1,50 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to assign a sequence of values to a single asset
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+LITERAL: "First value"
+SST-create from literal data: ""First value""
+Set SST command: ""First value""
+Set command: ""First value""
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+LITERAL: "Second value"
+SST-create from literal data: ""Second value""
+Set SST command: ""Second value""
+Set command: ""Second value""
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+SST-create from random data
+Set SST command: "*"
+Set command: "*"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+LITERAL: "Fourth value"
+SST-create from literal data: ""Fourth value""
+Set SST command: ""Fourth value""
+Set command: ""Fourth value""
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+SST-create from random data
+Set SST command: "*"
+Set command: "*"
+Command with no expect: ";"
+Lines: Line number 7.
+Lines: Line number 7.
+Lines: Line number 7.
+Lines: Line number 7.
+Lines: Line number 7.
+Lines: Line number 7.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c
new file mode 100644
index 000000000..ca7575264
--- /dev/null
+++ b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * Test purpose:
+ * to assign a sequence of values to a single asset
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "../sst/non_secure/ns_test_helpers.h"
+#include "psa/protected_storage.h"
+#include "test/framework/test_framework_helpers.h"
+#include "crypto_tests_common.h"
+#include "tfm_memory_utils.h"
+
+/* This is not yet right for how to run a test; need to register tests, etc. */
+
+void test_thread (struct test_result_t *ret) {
+ psa_status_t crypto_status; // result from Crypto calls
+ psa_status_t sst_status;
+
+ /* To prevent unused variable warning, as the variable might not be used
+ * in this testcase
+ */
+ (void)sst_status;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to assign a sequence of values to a single asset");
+
+
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t indecisive_set_data[] = "First value";
+ static uint32_t indecisive_set_length = 11;
+ static uint8_t indecisive_set_data_1[] = "Second value";
+ static uint32_t indecisive_set_length_1 = 12;
+ static uint8_t indecisive_set_data_2\[\] = "@@001@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t indecisive_set_length_2 = \d+;
+ static uint8_t indecisive_set_data_3[] = "Fourth value";
+ static uint32_t indecisive_set_length_3 = 12;
+ static uint8_t indecisive_set_data_4\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t indecisive_set_length_4 = \d+;
+
+
+ /* PSA calls to test: */
+
+ /* Creating SST asset "indecisive," with data "First valu...". */
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length, indecisive_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /* Resetting SST asset "indecisive," with data "Second val...". */
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_1, indecisive_set_data_1,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /\* Resetting SST asset "indecisive," with data "@@001@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_2, indecisive_set_data_2,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /* Resetting SST asset "indecisive," with data "Fourth val...". */
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_3, indecisive_set_data_3,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /\* Resetting SST asset "indecisive," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_4, indecisive_set_data_4,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove\(@@@001@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/template b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/template
new file mode 100644
index 000000000..fc1dfba44
--- /dev/null
+++ b/tools/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/template
@@ -0,0 +1,6 @@
+purpose to assign a sequence of values to a single asset;
+set sst name indecisive data "First value";
+set sst name indecisive data "Second value";
+set sst name indecisive data *;
+set sst name indecisive data "Fourth value";
+set sst name indecisive data *;
diff --git a/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/check.py b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/check.py
new file mode 100644
index 000000000..88c17261e
--- /dev/null
+++ b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
+
+def main():
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
+
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr
new file mode 100644
index 000000000..04222925f
--- /dev/null
+++ b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr
@@ -0,0 +1,56 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to read the value of a single asset multiple times
+ASSET_IDENTIFIER: "just_checking"
+SST-asset identifier list: "data"
+SST-create from random data
+Set SST command: "*"
+Set command: "*"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+SST-asset identifier list: "check"
+LITERAL: "Not this"
+SST-read check against literal: "Not this"
+Read SST command: ""Not this""
+Read command: ""Not this""
+IDENTIFIER: "fail"
+Expect error clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+SST-asset identifier list: "check"
+LITERAL: "Not this either"
+SST-read check against literal: "Not this either"
+Read SST command: ""Not this either""
+Read command: ""Not this either""
+IDENTIFIER: "fail"
+Expect error clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+SST-asset identifier list: "check"
+LITERAL: "No dice on this either"
+SST-read check against literal: "No dice on this either"
+Read SST command: ""No dice on this either""
+Read command: ""No dice on this either""
+IDENTIFIER: "fail"
+Expect error clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+SST-asset identifier list: "print"
+SST-read log to test log: "print"
+Read SST command: "print"
+Read command: "print"
+Command with no expect: ";"
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c
new file mode 100644
index 000000000..6e62b3bcf
--- /dev/null
+++ b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * Test purpose:
+ * to read the value of a single asset multiple times
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "../sst/non_secure/ns_test_helpers.h"
+#include "psa/protected_storage.h"
+#include "test/framework/test_framework_helpers.h"
+#include "crypto_tests_common.h"
+#include "tfm_memory_utils.h"
+
+/* This is not yet right for how to run a test; need to register tests, etc. */
+
+void test_thread (struct test_result_t *ret) {
+ psa_status_t crypto_status; // result from Crypto calls
+ psa_status_t sst_status;
+
+ /* To prevent unused variable warning, as the variable might not be used
+ * in this testcase
+ */
+ (void)sst_status;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to read the value of a single asset multiple times");
+
+
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t just_checking_set_data\[\] = "@@001@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t just_checking_set_length = \d+;
+ static uint8_t just_checking_exp_data[] = "Not this";
+ static uint8_t just_checking_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t just_checking_act_length = \d+;
+ static uint8_t just_checking_exp_data_1[] = "Not this either";
+ static uint8_t just_checking_exp_data_2[] = "No dice on this either";
+
+
+ /* PSA calls to test: */
+
+ /\* Creating SST asset "just_checking," with data "@@001@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, just_checking_set_length, just_checking_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, just_checking_act_data,
+ &just_checking_act_length);
+ if (sst_status != fail) {
+ TEST_FAIL("psa_ps_get() expected fail.");
+ return;
+ }
+ /* Check that the data is correct */
+ if \(tfm_memcmp\(just_checking_act_data, just_checking_exp_data,
+ just_checking_act_length\) != 0\) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, just_checking_act_data,
+ &just_checking_act_length);
+ if (sst_status != fail) {
+ TEST_FAIL("psa_ps_get() expected fail.");
+ return;
+ }
+ /* Check that the data is correct */
+ if \(tfm_memcmp\(just_checking_act_data, just_checking_exp_data_1,
+ just_checking_act_length\) != 0\) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, just_checking_act_data,
+ &just_checking_act_length);
+ if (sst_status != fail) {
+ TEST_FAIL("psa_ps_get() expected fail.");
+ return;
+ }
+ /* Check that the data is correct */
+ if \(tfm_memcmp\(just_checking_act_data, just_checking_exp_data_2,
+ just_checking_act_length\) != 0\) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, just_checking_act_data,
+ &just_checking_act_length);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
+ return;
+ }
+ TEST_LOG(just_checking_act_data);
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove\(@@@001@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/template b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/template
new file mode 100644
index 000000000..9f101226e
--- /dev/null
+++ b/tools/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/template
@@ -0,0 +1,7 @@
+purpose to read the value of a single asset multiple times;
+set sst name just_checking data *;
+// TF-Fuzz needs enhancements to correctly predict the "expect" values below:
+read sst name just_checking check "Not this" expect fail;
+read sst name just_checking check "Not this either" expect fail;
+read sst name just_checking check "No dice on this either" expect fail;
+read sst name just_checking print;
diff --git a/tools/tf_fuzz/regression/000018_000016_and_000017/check.py b/tools/tf_fuzz/regression/000018_000016_and_000017/check.py
new file mode 100644
index 000000000..88c17261e
--- /dev/null
+++ b/tools/tf_fuzz/regression/000018_000016_and_000017/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
+
+def main():
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
+
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr b/tools/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr
new file mode 100644
index 000000000..9f89cf6fe
--- /dev/null
+++ b/tools/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr
@@ -0,0 +1,94 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to both read the value of a single asset multiple times and assign a sequence of values to a single asset
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+LITERAL: "First value"
+SST-create from literal data: ""First value""
+Set SST command: ""First value""
+Set command: ""First value""
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "check"
+LITERAL: "Not this"
+SST-read check against literal: "Not this"
+Read SST command: ""Not this""
+Read command: ""Not this""
+IDENTIFIER: "fail"
+Expect error clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+LITERAL: "Second value"
+SST-create from literal data: ""Second value""
+Set SST command: ""Second value""
+Set command: ""Second value""
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "check"
+LITERAL: "Not this either"
+SST-read check against literal: "Not this either"
+Read SST command: ""Not this either""
+Read command: ""Not this either""
+IDENTIFIER: "fail"
+Expect error clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+SST-create from random data
+Set SST command: "*"
+Set command: "*"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+LITERAL: "Fourth value"
+SST-create from literal data: ""Fourth value""
+Set SST command: ""Fourth value""
+Set command: ""Fourth value""
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "check"
+LITERAL: "No dice on this either"
+SST-read check against literal: "No dice on this either"
+Read SST command: ""No dice on this either""
+Read command: ""No dice on this either""
+IDENTIFIER: "fail"
+Expect error clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+SST-create from random data
+Set SST command: "*"
+Set command: "*"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "data"
+SST-create from random data
+Set SST command: "*"
+Set command: "*"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+SST-asset identifier list: "print"
+SST-read log to test log: "print"
+Read SST command: "print"
+Read command: "print"
+Command with no expect: ";"
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Lines: Line number c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000018_000016_and_000017/exp_test.c b/tools/tf_fuzz/regression/000018_000016_and_000017/exp_test.c
new file mode 100644
index 000000000..4303eb14d
--- /dev/null
+++ b/tools/tf_fuzz/regression/000018_000016_and_000017/exp_test.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * Test purpose:
+ * to both read the value of a single asset multiple times and assign a sequence of values to a single asset
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "../sst/non_secure/ns_test_helpers.h"
+#include "psa/protected_storage.h"
+#include "test/framework/test_framework_helpers.h"
+#include "crypto_tests_common.h"
+#include "tfm_memory_utils.h"
+
+/* This is not yet right for how to run a test; need to register tests, etc. */
+
+void test_thread (struct test_result_t *ret) {
+ psa_status_t crypto_status; // result from Crypto calls
+ psa_status_t sst_status;
+
+ /* To prevent unused variable warning, as the variable might not be used
+ * in this testcase
+ */
+ (void)sst_status;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to both read the value of a single asset multiple times and assign a sequence of values to a single asset");
+
+
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t indecisive_set_data[] = "First value";
+ static uint32_t indecisive_set_length = 11;
+ static uint8_t indecisive_exp_data[] = "Not this";
+ static uint8_t indecisive_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t indecisive_act_length = \d+;
+ static uint8_t indecisive_set_data_1[] = "Second value";
+ static uint32_t indecisive_set_length_1 = 12;
+ static uint8_t indecisive_exp_data_1[] = "Not this either";
+ static uint8_t indecisive_set_data_2\[\] = "@@001@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t indecisive_set_length_2 = \d+;
+ static uint8_t indecisive_set_data_3[] = "Fourth value";
+ static uint32_t indecisive_set_length_3 = 12;
+ static uint8_t indecisive_exp_data_2[] = "No dice on this either";
+ static uint8_t indecisive_set_data_4\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t indecisive_set_length_4 = \d+;
+ static uint8_t indecisive_set_data_5\[\] = "@@003@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t indecisive_set_length_5 = \d+;
+
+
+ /* PSA calls to test: */
+
+ /* Creating SST asset "indecisive," with data "First valu...". */
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length, indecisive_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, 11, indecisive_act_data,
+ &indecisive_act_length);
+ if (sst_status != fail) {
+ TEST_FAIL("psa_ps_get() expected fail.");
+ return;
+ }
+ /* Check that the data is correct */
+ if (tfm_memcmp(indecisive_act_data, indecisive_exp_data,
+ indecisive_act_length\) != 0\) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ /* Resetting SST asset "indecisive," with data "Second val...". */
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_1, indecisive_set_data_1,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, 12, indecisive_act_data,
+ &indecisive_act_length);
+ if (sst_status != fail) {
+ TEST_FAIL("psa_ps_get() expected fail.");
+ return;
+ }
+ /* Check that the data is correct */
+ if (tfm_memcmp(indecisive_act_data, indecisive_exp_data_1,
+ indecisive_act_length) != 0) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ /\* Resetting SST asset "indecisive," with data "@@001@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_2, indecisive_set_data_2,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /* Resetting SST asset "indecisive," with data "Fourth val...". */
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_3, indecisive_set_data_3,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, 12, indecisive_act_data,
+ &indecisive_act_length);
+ if (sst_status != fail) {
+ TEST_FAIL("psa_ps_get() expected fail.");
+ return;
+ }
+ /* Check that the data is correct */
+ if (tfm_memcmp(indecisive_act_data, indecisive_exp_data_2,
+ indecisive_act_length) != 0) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ /\* Resetting SST asset "indecisive," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_4, indecisive_set_data_4,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ /\* Resetting SST asset "indecisive," with data "@@003@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, indecisive_set_length_5, indecisive_set_data_5,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, \d+, indecisive_act_data,
+ &indecisive_act_length);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
+ return;
+ }
+ TEST_LOG(indecisive_act_data);
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove\(@@@001@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tools/tf_fuzz/regression/000018_000016_and_000017/template b/tools/tf_fuzz/regression/000018_000016_and_000017/template
new file mode 100644
index 000000000..2f28e0ad7
--- /dev/null
+++ b/tools/tf_fuzz/regression/000018_000016_and_000017/template
@@ -0,0 +1,11 @@
+purpose to both read the value of a single asset multiple times and assign a sequence of values to a single asset;
+set sst name indecisive data "First value";
+read sst name indecisive check "Not this" expect fail;
+set sst name indecisive data "Second value";
+read sst name indecisive check "Not this either" expect fail;
+set sst name indecisive data *;
+set sst name indecisive data "Fourth value";
+read sst name indecisive check "No dice on this either" expect fail;
+set sst name indecisive data *;
+set sst name indecisive data *;
+read sst name indecisive print;
diff --git a/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/check.py b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/check.py
new file mode 100644
index 000000000..88c17261e
--- /dev/null
+++ b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+'''
+ Please read .../tf_fuzz/regression/README to understand this code.
+
+ Please also read the comments in .../tf_fuzz/regression/regress_lib/line_by_line.py.
+'''
+
+import sys, os, re, string, pdb
+sys.path.append ("../regress_lib")
+import line_by_line
+
+
+# Describe script usage:
+def usage():
+ print ('''
+ Command-line parameters:
+ 1. The test-template file, nominally named "template",
+ 2. The expected combined stdout/stderr output, nominally named "exp_stdout_stderr",
+ 3. The actual/generated combined stdout/stderr output, nominally named "stdout_stderr",
+ 4. The expected .c test file, nominally named "exp_test.c", and
+ 5. The actual, generated .c test file, nominally named "test.c".
+
+ Optionally, *before* these five arguments, you may add switches thus:
+ "--v" for verbose mode, to view line-by-line comparisons actual vs. expected,
+ "--q" to only print error messages and a successful-completion message,
+ "--qq" same as --q but not even printing out the completion message, and
+ "--s 12345" to run TF-Fuzz with seed value 12345 (or whatever).
+ ''')
+
+
+def main():
+ # See if we're supposed to be quiet:
+ loud = quiet = ultra_quiet = False
+ seed = ""
+ while sys.argv[1][0] == "-":
+ if sys.argv[1] == "--v":
+ loud = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--q":
+ quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--qq":
+ quiet = ultra_quiet = True
+ sys.argv.pop(1)
+ elif sys.argv[1] == "--s":
+ sys.argv.pop(1)
+ seed = sys.argv[1]
+ sys.argv.pop(1)
+ if not seed.isnumeric():
+ print ('The --s seed argument was not a number.')
+ usage()
+ sys.exit(1)
+
+ # Run TF-Fuzz:
+ if not quiet: print ("Running TF-Fuzz... ")
+ os.system ('rm -f stdout_stderr test.c')
+ command = '../../tfz -v ./' + sys.argv[1] + ' ./' + sys.argv[5]
+ command += ' ' + seed + ' >' + sys.argv[3] + ' 2>&1'
+ if loud:
+ print (command)
+ if os.system (command) == 0:
+ if not quiet: print ("TF-Fuzz run complete.")
+ else:
+ print ('Could not run TF-Fuzz; please see stdout_stderr file.')
+ sys.exit(2)
+
+ # Attempt to open files indicated on command line:
+ if len(sys.argv) != 6:
+ message = '{} requires 5 command-line arguments. Exiting.'
+ print (message.format(sys.argv[0]), file=sys.stderr)
+ usage()
+ sys.exit(3)
+ template_file_name = sys.argv[1]
+ exp_stdout_file_name = sys.argv[2]
+ act_stdout_file_name = sys.argv[3]
+ exp_test_file_name = sys.argv[4]
+ act_test_file_name = sys.argv[5]
+
+ try:
+ template_file = open (template_file_name, 'rt')
+ exp_stdout_file = open (exp_stdout_file_name, 'rt')
+ act_stdout_file = open (act_stdout_file_name, 'rt')
+ exp_test_file = open (exp_test_file_name, 'rt')
+ act_test_file = open (act_test_file_name, 'rt')
+ except FileNotFoundError:
+ print ('One or more files could not be found.')
+ usage();
+ sys.exit(4)
+ except:
+ print ('Something went wrong trying to open the input files.')
+ usage();
+ sys.exit(5)
+ else:
+ message = '\nInput files:\n {},\n {},\n {},\n'
+ message += ' {}, and\n {}\nopened successfully.\n'
+ if not quiet:
+ print (message.format (template_file_name, exp_stdout_file_name,
+ act_stdout_file_name, exp_test_file_name, act_test_file_name))
+
+ # Check it all:
+ if not quiet: print ("Checking stdout and stderr: ", end="")
+ line_by_line.check_file ( exp_stdout_file, exp_stdout_file_name,
+ act_stdout_file, act_stdout_file_name,
+ loud, quiet, ultra_quiet )
+ if not quiet: print ("\nChecking test C file: ", end="")
+ line_by_line.check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr
new file mode 100644
index 000000000..02817e0e5
--- /dev/null
+++ b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr
@@ -0,0 +1,60 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to read an asset into a named variable the set another asset from that variable
+ASSET_IDENTIFIER: "source"
+SST-asset identifier list: ";"
+SST-create from random data (no 'data *')
+Set SST command: ";"
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "source"
+SST-asset identifier list: "var"
+IDENTIFIER: "transfer"
+SST-read dump to variable: "transfer"
+Read SST command: "transfer"
+Read command: "transfer"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "intermediate"
+SST-asset identifier list: "var"
+IDENTIFIER: "transfer"
+SST-set set from variable: "transfer"
+Set SST command: "transfer"
+Set command: "transfer"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "intermediate"
+SST-asset identifier list: "var"
+IDENTIFIER: "transfer"
+SST-read dump to variable: "transfer"
+Read SST command: "transfer"
+Read command: "transfer"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "destination"
+SST-asset identifier list: "var"
+IDENTIFIER: "transfer"
+SST-set set from variable: "transfer"
+Set SST command: "transfer"
+Set command: "transfer"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "destination"
+SST-asset identifier list: "check"
+IDENTIFIER: "transfer"
+SST-read-arguments variable name: "transfer"
+SST-read check against variable: "transfer"
+Read SST command: "transfer"
+Read command: "transfer"
+Command with no expect: ";"
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Lines: Line number 8.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c
new file mode 100644
index 000000000..72a0cc31f
--- /dev/null
+++ b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * Test purpose:
+ * to read an asset into a named variable the set another asset from that variable
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "../sst/non_secure/ns_test_helpers.h"
+#include "psa/protected_storage.h"
+#include "test/framework/test_framework_helpers.h"
+#include "crypto_tests_common.h"
+#include "tfm_memory_utils.h"
+
+/* This is not yet right for how to run a test; need to register tests, etc. */
+
+void test_thread (struct test_result_t *ret) {
+ psa_status_t crypto_status; // result from Crypto calls
+ psa_status_t sst_status;
+
+ /* To prevent unused variable warning, as the variable might not be used
+ * in this testcase
+ */
+ (void)sst_status;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to read an asset into a named variable the set another asset from that variable");
+
+
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t source_set_data\[\] = "@@001@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t source_set_length = @@@004@@@;
+ static uint8_t source_exp_data\[\] = "@@001@10@@[a-z\ ]*[\.\?\!]";
+ static uint8_t transfer_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t transfer_length = \d+;
+ static uint8_t intermediate_exp_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint8_t destination_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t destination_act_length = \d+;
+
+
+ /* PSA calls to test: */
+
+ /\* Creating SST asset "source," with data "@@001@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, source_set_length, source_set_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@001@@@, 0, @@@004@@@, transfer_data,
+ &transfer_length);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Check that the data is correct */
+ if (tfm_memcmp(transfer_data, source_exp_data,
+ transfer_length) != 0) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ /\* Creating SST asset "intermediate," with data "@@002@10@@...". \*/
+ sst_status = psa_ps_set\(@@@002@@@, transfer_length, transfer_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@002@@@, 0, \d+, transfer_data,
+ &transfer_length);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Check that the data is correct */
+ if (tfm_memcmp(transfer_data, intermediate_exp_data,
+ transfer_length) != 0) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+ /\* Creating SST asset "destination," with data "[A-Z][a-z ]*...". \*/
+ sst_status = psa_ps_set\(@@@003@@@, transfer_length, transfer_data,
+ PSA_STORAGE_FLAG_[A-Z_]+\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+
+ sst_status = psa_ps_get\(@@@003@@@, 0, \d+, destination_act_data,
+ &destination_act_length);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Check that the data is correct */
+ if (tfm_memcmp(destination_act_data, transfer,
+ destination_act_length) != 0) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove\(@@@001@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove\(@@@002@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove\(@@@003@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/template b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/template
new file mode 100644
index 000000000..0111ba243
--- /dev/null
+++ b/tools/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/template
@@ -0,0 +1,7 @@
+purpose to read an asset into a named variable the set another asset from that variable;
+set sst name source; // shorthand for random data
+read sst name source var transfer;
+set sst name intermediate var transfer;
+read sst name intermediate var transfer;
+set sst name destination var transfer;
+read sst name destination check transfer;
diff --git a/tools/tf_fuzz/regression/README b/tools/tf_fuzz/regression/README
index d061dbacc..d4fbcb686 100644
--- a/tools/tf_fuzz/regression/README
+++ b/tools/tf_fuzz/regression/README
@@ -1,134 +1,8 @@
-.../tf_fuzz/tf_fuzz_regression directory contents:
+This is a regression suite for the TF-Fuzz tool.
- 000001_set_sst_uid_data_expect_pass
- 000002_set_sst_name_data_expect_nothing
- 000003_set_sst_name_data
- 000004_set_sst_name_rand_data
- 000005_set_sst_rand_name_rand_data
- 000006_set_sst_multi_name_rand_data
- 000007_set_sst_multi_uid_rand_data
- 000008_set_sst_name_rand_data_read_check_wrong
- 000009_set_sst_name_rand_data_read_check_var_read_print
- 000010_read_nonexistent_sst_check_string
- 000011_read_nonexistent_sst_check_string_expect_pass
- 000012_read_nonexistent_sst_check_string_expect_other
- 000013_set_sst_name_rand_data_remove_twice
- 000014_set_sst_name_rand_data_remove_other
- add_these_tests
- README
- regress
- regress_lib
+For more information, please browse to:
---------------------------------------------------------------------------------
-
-This is the beginnings of a regression suite for TF-Fuzz. That is, tests to
-make sure that tf_fuzz is still functioning properly after making changes.
-
-This is neither complete nor working yet, but is close to its first-pass
-implementation.
-
-Here's the basic scheme of it all:
-
-* "bash regress" from this directory runs regression. It will fail with an
- error if a problem is found. If it runs to completion, then regression has
- passed.
-
-* Each test is in its own sub-directory containing these files, by name (always
- same name):
-
- * template: The test-template file to be run though the TF-Fuzz under test,
- here called "the DUT TF-Fuzz" here.
-
- * exp_stdout_stderr: The *expected*, combined stdout and stderr from running
- TF-Fuzz in verbose mode (-v). This file contains wildcard expressions to
- be checked (more on that below).
-
- * exp_test.c: The *expected* output C code. This file also contains
- wildcard expressions to be resolved against the DUT TF-Fuzz output (again,
- more on that below).
-
- * stdout_stderr (if present): The combined stdout and stderr from running
- the DUT TF-Fuzz in verbose mode (-v), during regression testing.
-
- * test.c (if present): The output C code generated from running the DUT
- TF-Fuzz in verbose mode (-v), during regression testing.
-
- * diff_stdout_stderr (if present): The "diff" of stdout_stderr against
- exp_stdout_stderr. As mentioned above, there are wildcards in some lines
- of exp_stdout_stderr that have to be resolved against stdout_stderr.
-
- * diff_test.c (if present): The "diff" of test.c against exp_test.c. As
- mentioned above, there are wildcards in some lines of exp_test.c that have
- to be resolved against test.c.
-
- * check.py: This Python script doesn't yet, but will, resolve the wildcard
- differences in diff_stdout_stderr and diff_test.c. Each test directory
- has its own script customized to the needs of that particular test, but
- they all draw from functions in the regress_lib directory.
-
-To explain how check.py checks -- or will check! -- a regression test, consider
-one example of the ./000005_set_sst_rand_name_rand_data/diff_test.c file, below:
-
- 45,46c45,46
- < static uint8_t gibberish_data[] = "Gof jav ofdomviv wazauyicef zoc xut rus sekneiqiv eidzai yefrabxiyob abjie pah jashui ziuven qetuvraqwiu omwid xenmav fipwiy meftofc.";
- < int gibberish_data_size = 133;
- ---
- > static uint8_t gibberish_data[] = "@@002@10@@********";
- > int gibberish_data_size = ********;
- 51,52c51,52
- < /* Creating SST asset "gibberish," with data "Gof jav of...". */
- < sst_status = psa_ps_set(8617, gibberish_data_size, gibberish_data, PSA_PS_FLAG_NONE);
- ---
- > /* Creating SST asset "gibberish," with data "@@002@10@@...". */
- > sst_status = psa_ps_set(@@@001@@@, gibberish_data_size, gibberish_data, PSA_PS_FLAG_********);
- 60c60
- < psa_ps_remove(8617);
- ---
- > psa_ps_remove(@@@001@@@);
-
-So, by this process, a simple "diff" itself checks the vast majority of the
-correctness of the result. check.py has only to resolve the wildcards, and in
-the process will also immediately see cases where "diff" discovered disparities.
-
-The wildcards in the exp_stdout_stderr and exp_test.c files are of three basic
-natures, using the examples shown above (please reference them above to
-clearly understand the ideas here):
-
- ******** (exactly 8 *s):
- This denotes any pattern of characters, until the expected and actual
- character streams re-converge (sync up) again. The characters in the
- output from stdout_stderr or test.c from the DUT TF-Fuzz, that
- correspond to the ******** in the exp_stdout_stderr or exp_test.c files
- are *not* checked; anything in the output from the DUT TF-Fuzz at this
- position is acceptable.
-
- @@@001@@@ ("@@@", a pattern number, "@@@"):
- This denotes a particular pattern of characters, until the expected and
- actual character streams re-sync again. The important thing, however,
- is that what this wildcard stands for *must be consistent* throughout the
- comparison! In this case above, @@@001@@@ in the exp_test.c must consis-
- tently correspond to "8617" everywhere throughout the test.c file. The
- number between the two "@@@"s in the wildcard designates which pattern
- must consistently match.
-
- @@002@10@@ ("@@", a pattern number, "@", a pattern size, "@@"):
- This is a slight variant upon the previous wildcard, in which a specific
- match length is required. In lines 45 and 46 above, random data generated
- consists of 10 characters (thus the ...@10@@ in the wildcard) "Gof jav of"
- followed by other characters we don't care about; they can be anything.
- Thus "@@002@10@@********" in line 45 of exp_test.c: the "@@002@10@@"
- denotes a pattern number 002 for a length of 10 characters that must match
- "Gof jav of" in this case, followed by some arbitrary number of characters
- we don't care about, thus ******** in exp_test.c, line 45.
-
-After the check.py capability -- resolving these wildcards -- for this purpose
-is fleshed out, we shall have to figure out how to address "shuffle" and
-"2 to 5 of {}" randomizations.
-
---------------------------------------------------------------------------------
-
-The add_these_tests directory contains regression-test information of the above
-nature that the regression framework is not currently able to address.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/~regression_dir.html
--------------
diff --git a/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr b/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr
index 6bfbee20a..6b77de155 100644
--- a/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr
@@ -23,6 +23,8 @@ Command with no expect: ";"
Lines: Line number 4.
Lines: Line number 4.
Lines: Line number 4.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c b/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c
index 2d6e9e8c5..c52f44566 100644
--- a/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c
+++ b/tools/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c
@@ -41,50 +41,50 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t president_data[] = "read my lips";
- int president_data_size = 12;
- static uint8_t george_data[] = "read my lips";
- int george_data_size = 12;
- static uint8_t herbert_data[] = "read my lips";
- int herbert_data_size = 12;
- static uint8_t walker_data[] = "read my lips";
- int walker_data_size = 12;
- static uint8_t bush_data[] = "read my lips";
- int bush_data_size = 12;
+ static uint8_t president_set_data[] = "read my lips";
+ int president_set_length = 12;
+ static uint8_t george_set_data[] = "read my lips";
+ int george_set_length = 12;
+ static uint8_t herbert_set_data[] = "read my lips";
+ int herbert_set_length = 12;
+ static uint8_t walker_set_data[] = "read my lips";
+ int walker_set_length = 12;
+ static uint8_t bush_set_data[] = "read my lips";
+ int bush_set_length = 12;
/* PSA calls to test: */
/* Creating SST asset "president," with data "read my li...". */
- sst_status = psa_ps_set(@@@001@@@, president_data_size, president_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(@@@001@@@, president_set_length, president_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "george," with data "read my li...". */
- sst_status = psa_ps_set(5517, george_data_size, george_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(5517, george_set_length, george_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "herbert," with data "read my li...". */
- sst_status = psa_ps_set(4661, herbert_data_size, herbert_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(4661, herbert_set_length, herbert_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "walker," with data "read my li...". */
- sst_status = psa_ps_set(3441, walker_data_size, walker_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(3441, walker_set_length, walker_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "bush," with data "read my li...". */
- sst_status = psa_ps_set(5446, bush_data_size, bush_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(5446, bush_set_length, bush_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
diff --git a/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr b/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr
index fea48579a..d803732fd 100644
--- a/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr
+++ b/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr
@@ -41,6 +41,8 @@ Lines: Line number 7.
Lines: Line number 7.
Lines: Line number 7.
Lines: Line number 7.
-Writing test file, test.c.
+Call sequence generated.
+Simulating call sequence...
+Writing test file, ./test.c.
TF-Fuzz test generation complete.
diff --git a/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c b/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c
index c4ac4f3a8..1b506e802 100644
--- a/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c
+++ b/tools/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c
@@ -41,22 +41,22 @@ void test_thread (struct test_result_t *ret) {
/* Variables (etc.) to initialize and check PSA assets: */
- static uint8_t president_data[] = "no new taxes";
- int president_data_size = 12;
- static uint8_t george_data[] = "no new taxes";
- int george_data_size = 12;
- static uint8_t herbert_data[] = "no new taxes";
- int herbert_data_size = 12;
- static uint8_t walker_data[] = "no new taxes";
- int walker_data_size = 12;
- static uint8_t bush_data[] = "no new taxes";
- int bush_data_size = 12;
+ static uint8_t president_set_data[] = "no new taxes";
+ int president_set_length = 12;
+ static uint8_t george_set_data[] = "no new taxes";
+ int george_set_length = 12;
+ static uint8_t herbert_set_data[] = "no new taxes";
+ int herbert_set_length = 12;
+ static uint8_t walker_set_data[] = "no new taxes";
+ int walker_set_length = 12;
+ static uint8_t bush_set_data[] = "no new taxes";
+ int bush_set_length = 12;
/* PSA calls to test: */
/* Creating SST asset "president," with data "no new tax...". */
- sst_status = psa_ps_set(4713, president_data_size, president_data,
+ sst_status = psa_ps_set(4713, president_set_length, president_set_data,
PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
@@ -64,28 +64,28 @@ void test_thread (struct test_result_t *ret) {
}
/* Creating SST asset "george," with data "no new tax...". */
- sst_status = psa_ps_set(5517, george_data_size, george_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(5517, george_set_length, george_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "herbert," with data "no new tax...". */
- sst_status = psa_ps_set(4661, herbert_data_size, herbert_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(4661, herbert_set_length, herbert_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "walker," with data "no new tax...". */
- sst_status = psa_ps_set(3441, walker_data_size, walker_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(3441, walker_set_length, walker_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
}
/* Creating SST asset "bush," with data "no new tax...". */
- sst_status = psa_ps_set(5446, bush_data_size, bush_data, PSA_PS_FLAG_WRITE_ONCE);
+ sst_status = psa_ps_set(5446, bush_set_length, bush_data, PSA_PS_FLAG_WRITE_ONCE);
if (sst_status != PSA_PS_SUCCESS) {
TEST_FAIL("psa_ps_set() expected PSA_PS_SUCCESS, got #%d, (int) sst_status);
return;
diff --git a/tools/tf_fuzz/regression/regress b/tools/tf_fuzz/regression/regress
index ff51ba2be..1a2b59567 100644
--- a/tools/tf_fuzz/regression/regress
+++ b/tools/tf_fuzz/regression/regress
@@ -6,13 +6,17 @@ echo
echo TF-Fuzz Regression Testing
echo
for reg_test in `ls -F | grep \/$ | grep -v add_these_tests | grep -v regress_lib`; do
+ echo
echo Running "$reg_test"...
cd $reg_test
rm -f test.c stdout_stderr
- ../../tfz -v ./template test.c >stdout_stderr 2>&1
- rm -f diff_stdout_stderr diff_test.c
- diff stdout_stderr exp_stdout_stderr >diff_stdout_stderr
- diff test.c exp_test.c >diff_test.c
- python ./check.py diff_stdout_stderr diff_test.c stdout_stderr
+ python3 check.py --q template exp_stdout_stderr stdout_stderr exp_test.c test.c
+ if test $? -ne 0
+ then
+ exit
+ fi
cd ..
done
+echo
+echo
+echo All TF-Fuzz regression tests passed.
diff --git a/tools/tf_fuzz/regression/regress_lib/line_by_line.py b/tools/tf_fuzz/regression/regress_lib/line_by_line.py
new file mode 100644
index 000000000..1081fa20f
--- /dev/null
+++ b/tools/tf_fuzz/regression/regress_lib/line_by_line.py
@@ -0,0 +1,172 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+'''
+The functions here perform straight-forward line-by-line comparisons of regression
+TF-Fuzz regression tests. These are not sufficient to address cases where the PSA
+calls are randomized.
+
+Each given line of the expected files (exp_stdout_stderr and exp_test.c) functions as
+Python regex for the corresonding line in the actual/generated corresponding file.
+Actually, the expected-file lines may need a little bit of tweaking first. There are
+three scenarios:
+* The line in exp_* file contains no regex content at all. In this case, the two
+ lines must be exactly identical, character for character. The actual/generated
+ output files do not contain regexes, but can contain parentheses or other
+ characters that "look like" regex content, and thus confuse re.match(). So, it's
+ first checked for an exact string == match.
+* The line in the exp_* file contains one or more standard-Python regex patterns to
+ match. In this case, a Python re.match() will still report a match.
+* The line in the exp_* file contains one or more non-standard regex pattern, in
+ which case that non-standard regex pattern needs to be replaced with the actual,
+ expected character string.
+
+As described in the above-cited README, these non-standard regex wildcards in the
+exp_* files take either of two formats:
+* "@@@" a 3-digit pattern number "@@@" (e.g., "@@@005@@@"): This denotes a pattern
+ of no particular length that must match the same text every occurrence in the
+ actual/generated file.
+* "@@" a 3-digit pattern number "@" a 2-digit length in chars "@@": Same idea as
+ the previous pattern, except that it also has a specific length.
+
+To address these special regex wildcards, check_gen_test() below has to:
+1. Isolate the wildcard from the rest of the string,
+2. Check that wildcard against a Python dictionary relating the wildcard name to
+ its expected-text substitution value,
+3. If not present in the dictionary, create a new dictionary entry relating the
+ wildcard text to the text found in that spot in the actual/generated file,
+4. Replace that wildcard text with the expected value from the hash, then
+5. As with all lines, perform the re.match() between the two lines.
+'''
+
+import sys, os, re, string, pdb
+
+
+'''
+mask_other_wildcards(), used by resolve_wildcards() below, is used in harvesting
+the value of a certain wildcard of the sort described above. After the caller
+replaces the wildcard of interest with a regex to retrieve that data from actual-
+output file, it passes the string into here, to replace all other wildcards with
+"anything goes" regexes.
+'''
+def mask_other_wildcards (a_string):
+ # Unsized wildcards:
+ while True:
+ matchInfo = re.match ('.*(@@@\d\d\d@@@)', a_string)
+ if not matchInfo:
+ break
+ wildcard = matchInfo.group(1)
+ a_string = a_string.replace (wildcard, '.*')
+ # Sized wildcards:
+ while True:
+ matchInfo = re.match ('.*(@@\d\d\d@\d\d@@)', a_string)
+ if not matchInfo:
+ break
+ wildcard = matchInfo.group(1)
+ a_string = a_string.replace (wildcard, '.*')
+ return a_string
+
+
+'''
+resolve_wildcards() resolves wildcards of the sort described above, in an expected
+file line (exp) from a wildcard dictionary (wildcard_dict). In particular, it
+replaces them with what the wildcards are found to stand for in the actual test
+output (act). If it encounters a wildcard it has not seen before, it adds it to
+the dictionary, based upon what's in the test.c output. Further occurrences of that
+wildcard, it pulls from the wildcard dictionary, meaning that the subsequent
+occurrences must resolve to the same text string.
+'''
+def resolve_wildcards (exp, act, wildcard_dict):
+ # Loop through each wildcard on the line, filling them in with values from the
+ # wildcard dictionary, or filling them into the wildcard dictionary.
+
+ #pdb.set_trace()
+
+ while True:
+ wildcard_sized = False
+ matchInfo = re.match ('.*(@@@\d\d\d@@@)', exp)
+ if not matchInfo:
+ wildcard_sized = True
+ # 0 = sized, and we'll fill in that size below, if we don't already know
+ matchInfo = re.match ('.*(@@\d\d\d@\d\d@@)', exp)
+ if not matchInfo:
+ break
+ wildcard = matchInfo.group(1)
+ if wildcard in wildcard_dict:
+ # Previously-encountered wildcard:
+ wildcard_value = wildcard_dict[wildcard]
+ else:
+ # New wildcard:
+ if wildcard_sized: # find the size
+ size_str = re.match ("@@\d\d\d@(\d\d)@@",wildcard).group(1)
+ find_sub = exp.replace (wildcard, '(.{' + size_str + '})', 1)
+ else:
+ find_sub = exp.replace (wildcard, '(.*)', 1)
+ find_sub = mask_other_wildcards (find_sub)
+ matchInfo = re.match (find_sub, act)
+ wildcard_value = matchInfo.group(1)
+ wildcard_dict[wildcard] = wildcard_value
+ exp = exp.replace (wildcard, wildcard_value)
+ return exp
+
+'''
+check_file() checks that an actual-output test file (act_test_file) matches an
+expected-output file (exp_test_file), line by line, including resolving the wildcards
+of the nature described above.
+'''
+def check_file ( exp_test_file, exp_test_file_name,
+ act_test_file, act_test_file_name,
+ loud, quiet, ultra_quiet ):
+ # This is the dictionary of wildcards, of the nature described above.
+ wildcard_dict = dict()
+
+ line_no = 0
+ while True:
+ exp_line = exp_test_file.readline()
+ act_line = act_test_file.readline()
+ # Ignore the special case where a seed was specified in generating actual,
+ # but wasn't in expected file:
+ if exp_line == 'Info: random seed was not specified.\n' and act_line == '\n':
+ print ("(Note: Ignoring no-seed-specified message in expected.)")
+ exp_line = exp_test_file.readline()
+ line_no += 1
+ if not quiet and not loud: print (".", end="")
+ if not exp_line and act_line:
+ message = "\nError: More lines in file {} than in {}."
+ if not ultra_quiet:
+ print (message.format(act_test_file_name, exp_test_file_name))
+ sys.exit(8)
+ elif not act_line and exp_line:
+ message = "\nError: More lines in file {} than in {}."
+ if not ultra_quiet:
+ print (message.format(exp_test_file_name, act_test_file_name))
+ sys.exit(9)
+ # No line-count mismatch (so far); either both reads succeeded or both failed:
+ if not exp_line:
+ break # all lines read; kick out of the loop.
+ exp_line = exp_line.rstrip(); act_line = act_line.rstrip()
+ if loud and not quiet:
+ print ("\n" + str(line_no) + "\nExpect: '" + exp_line + "'")
+ print ("Actual: '" + act_line + "'")
+ # If the two lines match as raw strings then we're good:
+ if exp_line == act_line:
+ pass # this line passes
+ else:
+ # Before doing a re.match() on this line pair, replace any nontraditional
+ # wildcards with what they're expected to contain:
+ if re.match (".*@@\d\d\d@", exp_line): # just to save time if no wildcards
+ exp_line = resolve_wildcards (exp_line, act_line, wildcard_dict)
+ if (exp_line == "" and act_line != "") or not re.match (exp_line, act_line):
+ message = "\nError: At line {} mismatch between {} and {}:"
+ message1 = " Expected: {}"
+ message2 = " Got: {}\n"
+ if not ultra_quiet:
+ print (message.format(line_no, exp_test_file_name, act_test_file_name))
+ print (message1.format(exp_line))
+ print (message2.format(act_line))
+ sys.exit(10)
+ if not quiet: print ("\nGenerated file complies with expected file.")
+
+
diff --git a/tools/tf_fuzz/template/README b/tools/tf_fuzz/template/README
index 0d76e5460..3cfc30974 100644
--- a/tools/tf_fuzz/template/README
+++ b/tools/tf_fuzz/template/README
@@ -1,14 +1,10 @@
-.../tf_fuzz/template directory contents:
-
-crypto_template_line.cpp secure_template_line.hpp template_line.cpp
-crypto_template_line.hpp sst_template_line.cpp template_line.hpp
-secure_template_line.cpp sst_template_line.hpp
-
---------------------------------------------------------------------------------
-
These classes describe "tracker" objects for parsing test templates, and for
generating PSA calls from them.
+For more information, please browse to:
+
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/template_dir.html
+
--------------
*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
diff --git a/tools/tf_fuzz/template/crypto_template_line.cpp b/tools/tf_fuzz/template/crypto_template_line.cpp
index 8a1333b3e..62d28a569 100644
--- a/tools/tf_fuzz/template/crypto_template_line.cpp
+++ b/tools/tf_fuzz/template/crypto_template_line.cpp
@@ -35,19 +35,14 @@ set_policy_template_line::set_policy_template_line (tf_fuzz_info *resources)
return; // just to have something to pin a breakpoint onto
}
-bool set_policy_template_line::copy_template_to_asset (void)
-{
- // TODO: Should this ever be invoked?
- return true;
-}
-
bool set_policy_template_line::copy_template_to_call (void)
{
for (auto call : test_state->calls) {
- if (call->call_ser_no == call_ser_no && call->expect.pf_info_incomplete) {
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
- call->expect.pf_info_incomplete = true;
+ if (call->call_ser_no == call_ser_no && call->exp_data.pf_info_incomplete) {
+ call->asset_info.set_just_name (asset_info.get_name());
+ call->asset_info.id_n = asset_info.id_n;
+ call->random_asset = random_asset;
+ call->exp_data.pf_info_incomplete = true;
return true;
}
}
@@ -78,39 +73,14 @@ read_policy_template_line::read_policy_template_line (tf_fuzz_info *resources)
{
}
-bool read_policy_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- sst_asset* this_asset;
- // Find the call by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_sst_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, dont_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* an sst_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(108);
- }
- // Copy *the other way* on asset reads!
- if (how_found != asset_search::not_found) {
- this_asset = reinterpret_cast<sst_asset*>(*found_asset);
- set_data.string_specified = this_asset->set_data.string_specified;
- set_data.file_specified = this_asset->set_data.file_specified;
- flags_string = this_asset->flags_string;
- asset_id.id_n = this_asset->asset_id.id_n;
- asset_id.name_specified = this_asset->asset_id.name_specified;
- }
- return true;
-}
-
bool read_policy_template_line::copy_template_to_call (void)
{
for (auto call : test_state->calls) {
- if (call->call_ser_no == call_ser_no && call->expect.pf_info_incomplete) {
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
- call->expect.pf_info_incomplete = true;
+ if (call->call_ser_no == call_ser_no && call->exp_data.pf_info_incomplete) {
+ call->asset_info.set_just_name (asset_info.get_name());
+ call->asset_info.id_n = asset_info.id_n;
+ call->random_asset = random_asset;
+ call->exp_data.pf_info_incomplete = true;
return true;
}
}
@@ -141,48 +111,22 @@ set_key_template_line::set_key_template_line (tf_fuzz_info *resources)
// Nothing further to initialize.
}
-bool set_key_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- key_asset* this_asset;
-
- // Find the asset by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_key_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, yes_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* a key_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(109);
- }
- // Copy over everything relevant:
- if (how_found != asset_search::not_found) { // will be found for make calls, but not necessarily others
- this_asset = reinterpret_cast<key_asset*>(*found_asset);
- this_asset->set_data.string_specified = set_data.string_specified;
- this_asset->set_data.set (set_data.get());
- this_asset->set_data.file_specified = set_data.file_specified;
- this_asset->set_data.file_path = set_data.file_path;
- this_asset->flags_string = flags_string;
- }
- return true;
-}
-
bool set_key_template_line::copy_template_to_call (void)
{
- // Find the call by serial number (must search; may have moved).
for (auto call : test_state->calls) {
if (call->call_ser_no == call_ser_no) {
// Copy asset info to call object for creation code:
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
+ call->asset_info.set_just_name (asset_info.get_name());
+ call->asset_info.id_n = asset_info.id_n;
+ call->asset_info.asset_ser_no = asset_info.asset_ser_no;
+ call->asset_info.how_asset_found = asset_info.how_asset_found;
+ call->random_asset = random_asset;
call->set_data.string_specified = set_data.string_specified;
- call->set_data.set (set_data.get()); call->asset_ser_no = asset_ser_no;
+ call->set_data.set (set_data.get());
call->set_data.file_specified = set_data.file_specified;
call->set_data.file_path = set_data.file_path;
+ call->exp_data.pf_info_incomplete = true;
call->flags_string = flags_string;
- call->how_asset_found = how_asset_found;
- call->expect.pf_info_incomplete = true;
return true;
}
}
@@ -213,45 +157,20 @@ remove_key_template_line::remove_key_template_line (tf_fuzz_info *resources)
is_remove = true; // template_line's constructor defaults this to false
}
-bool remove_key_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- sst_asset* this_asset;
- // Find the call by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_sst_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, dont_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* an sst_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(108);
- }
- // Copy *the other way* on asset reads!
- if (how_found != asset_search::not_found) { // will be found for make calls, but not necessarily others
- this_asset = reinterpret_cast<sst_asset*>(*found_asset);
- set_data.string_specified = this_asset->set_data.string_specified;
- set_data.file_specified = this_asset->set_data.file_specified;
- flags_string = this_asset->flags_string;
- asset_id.id_n = this_asset->asset_id.id_n;
- asset_id.name_specified = this_asset->asset_id.name_specified;
- }
- return true;
-}
-
bool remove_key_template_line::copy_template_to_call (void)
{
- // Find the call by serial number (must search; may have moved).
for (auto call : test_state->calls) {
if (call->call_ser_no == call_ser_no) {
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
- call->expect.pf_nothing = expect.pf_nothing;
- call->expect.pf_pass = expect.pf_pass; call->asset_ser_no = asset_ser_no;
- call->expect.pf_specified = expect.pf_specified;
- call->expect.pf_result_string = expect.pf_result_string;
- call->how_asset_found = how_asset_found;
- call->expect.pf_info_incomplete = true;
+ call->asset_info.set_just_name (asset_info.get_name());
+ call->asset_info.id_n = asset_info.id_n;
+ call->asset_info.asset_ser_no = asset_info.asset_ser_no;
+ call->asset_info.how_asset_found = asset_info.how_asset_found;
+ call->random_asset = random_asset;
+ call->exp_data.pf_nothing = expect.pf_nothing;
+ call->exp_data.pf_pass = expect.pf_pass;
+ call->exp_data.pf_specified = expect.pf_specified;
+ call->exp_data.pf_result_string = expect.pf_result_string;
+ call->exp_data.pf_info_incomplete = true;
return true;
}
}
@@ -292,48 +211,23 @@ read_key_template_line::read_key_template_line (tf_fuzz_info *resources)
set_data.file_path = ""; // can't really devise a random path
}
-bool read_key_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- sst_asset* this_asset;
- // Find the call by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_sst_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, dont_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* an sst_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(108);
- }
- // Copy *the other way* on asset reads!
- if (how_found != asset_search::not_found) {
- this_asset = reinterpret_cast<sst_asset*>(*found_asset);
- set_data.string_specified = this_asset->set_data.string_specified;
- set_data.file_specified = this_asset->set_data.file_specified;
- flags_string = this_asset->flags_string;
- asset_id.id_n = this_asset->asset_id.id_n;
- asset_id.name_specified = this_asset->asset_id.name_specified;
- }
- return true;
-}
-
bool read_key_template_line::copy_template_to_call (void)
{
- // Find the call by serial number (must search; may have moved).
for (auto call : test_state->calls) {
if (call->call_ser_no == call_ser_no) {
// Copy expected results to the call object, to check:
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
+ call->asset_info.set_just_name (asset_info.get_name());
+ call->asset_info.id_n = asset_info.id_n;
+ call->asset_info.how_asset_found = asset_info.how_asset_found;
+ call->asset_info.asset_ser_no = asset_info.asset_ser_no;
+ call->random_asset = random_asset;
call->set_data.string_specified = set_data.string_specified;
- call->set_data.set (set_data.get()); call->asset_ser_no = asset_ser_no;
+ call->set_data.set (set_data.get());
call->set_data.file_specified = set_data.file_specified;
call->set_data.file_path = set_data.file_path;
- call->flags_string = flags_string;
call->set_data.string_specified = set_data.string_specified;
- call->how_asset_found = how_asset_found;
- call->expect.pf_info_incomplete = true;
+ call->exp_data.pf_info_incomplete = true;
+ call->flags_string = flags_string;
return true;
}
}
diff --git a/tools/tf_fuzz/template/crypto_template_line.hpp b/tools/tf_fuzz/template/crypto_template_line.hpp
index f79b0fddb..3bb4a51e6 100644
--- a/tools/tf_fuzz/template/crypto_template_line.hpp
+++ b/tools/tf_fuzz/template/crypto_template_line.hpp
@@ -26,7 +26,6 @@ class set_policy_template_line : public policy_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
@@ -52,7 +51,6 @@ class read_policy_template_line : public policy_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
@@ -78,7 +76,6 @@ class set_key_template_line : public key_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
@@ -103,7 +100,6 @@ class remove_key_template_line : public key_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
@@ -128,7 +124,6 @@ class read_key_template_line : public key_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
diff --git a/tools/tf_fuzz/template/secure_template_line.cpp b/tools/tf_fuzz/template/secure_template_line.cpp
index 0cf88e843..d9254b5bc 100644
--- a/tools/tf_fuzz/template/secure_template_line.cpp
+++ b/tools/tf_fuzz/template/secure_template_line.cpp
@@ -32,32 +32,27 @@
//**************** security_hash_template_line methods ****************
-bool security_hash_template_line::copy_template_to_asset (void)
-{
- // The assets are not directly involved in this call.
- return true;
-}
-
bool security_hash_template_line::copy_template_to_call (void)
{
- // Find the call by serial number (must search; may have moved).
for (auto call : test_state->calls) {
if (call->call_ser_no == call_ser_no) {
// Copy asset info to call object for creation code -- the entire vector:
- for (auto as_name : asset_id.asset_name_vector) {
+ for (auto as_name : asset_info.asset_name_vector) {
/* Also copy into template line object's local vector: */
- call->asset_id.asset_name_vector.push_back (as_name);
+ call->asset_info.asset_name_vector.push_back (as_name);
}
- call->asset_id.id_n = asset_id.id_n;
+ call->asset_info.id_n = asset_info.id_n;
// this call is currently limited to name-based
- call->asset_id.name_specified = true;
+ call->asset_info.name_specified = true;
+ call->asset_info.asset_ser_no = asset_info.asset_ser_no; // TODO: Does this make sense?
+ call->asset_info.how_asset_found = asset_search::found_active;
+ call->random_asset = random_asset;
call->set_data.string_specified = false; // shouldn't matter, but...
call->set_data.file_specified = false;
call->set_data.file_path.assign("");
- call->asset_ser_no = asset_ser_no; // TODO: Does this make sense?
- call->flags_string.assign (""); call->set_data.set("");
- call->how_asset_found = asset_search::found_active;
- call->expect.pf_info_incomplete = true;
+ call->set_data.set("");
+ call->exp_data.pf_info_incomplete = true;
+ call->flags_string.assign ("");
return true;
}
}
diff --git a/tools/tf_fuzz/template/secure_template_line.hpp b/tools/tf_fuzz/template/secure_template_line.hpp
index 302da1fee..8e5aee038 100644
--- a/tools/tf_fuzz/template/secure_template_line.hpp
+++ b/tools/tf_fuzz/template/secure_template_line.hpp
@@ -6,9 +6,9 @@
*/
/* Objects typed to subclasses of the these classes are constructed and filled in
- by the parser as it parses the template. Although these objects do fairly
- closely correspond to template lines, there's no real correlation to lines in
- the generated code. */
+ by the parser as it parses the test template. Although these objects do largely
+ correspond to template lines, there's no real correlation to lines in the
+ generated code. */
#ifndef SECURE_TEMPLATE_LINE_HPP
#define SECURE_TEMPLATE_LINE_HPP
@@ -42,7 +42,6 @@ public:
define_call<hash_call> (set_data, random_data,
fill_in_template, create_call, temLin, rsrc);
}
- bool copy_template_to_asset (void);
bool copy_template_to_call (void);
security_hash_template_line (tf_fuzz_info *resources); // (constructor)
~security_hash_template_line (void);
diff --git a/tools/tf_fuzz/template/sst_template_line.cpp b/tools/tf_fuzz/template/sst_template_line.cpp
index 338764b71..cd4e0cc10 100644
--- a/tools/tf_fuzz/template/sst_template_line.cpp
+++ b/tools/tf_fuzz/template/sst_template_line.cpp
@@ -20,8 +20,6 @@
#include "sst_call.hpp"
#include "sst_template_line.hpp"
#include "sst_asset.hpp"
-#include "crypto_asset.hpp"
-
/**********************************************************************************
@@ -71,60 +69,6 @@ set_sst_template_line::set_sst_template_line (tf_fuzz_info *resources)
}
-
-bool set_sst_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- sst_asset* this_asset;
- // Find the call by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_sst_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, yes_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* an sst_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(108);
- }
- // Copy over everything relevant:
- if (how_found != asset_search::not_found) { // will be found for make calls, but not necessarily others
- this_asset = reinterpret_cast<sst_asset*>(*found_asset);
- this_asset->set_data.string_specified = set_data.string_specified;
- this_asset->set_data.set (set_data.get());
- this_asset->set_data.file_specified = set_data.file_specified;
- this_asset->set_data.file_path.assign (set_data.file_path);
- this_asset->flags_string = flags_string;
- this_asset->set_uid (asset_id.id_n);
- this_asset->asset_id.name_specified = asset_id.name_specified;
- this_asset->asset_id.set_name (asset_id.get_name());
- }
- return true;
-}
-
-bool set_sst_template_line::copy_template_to_call (void)
-{
- // Find the call by serial number (must search; may have moved).
- for (auto call : test_state->calls) {
- if (call->call_ser_no == call_ser_no) {
- // Copy asset info to call object for creation code:
- call->asset_id.set_just_name (asset_id.get_name());
- // TODO: Question: Just call->asset_id = asset_id?
- call->asset_id.id_n = asset_id.id_n;
- call->asset_id.name_specified = asset_id.name_specified;
- call->set_data.string_specified = set_data.string_specified
- || set_data.random_data;
- call->set_data.file_specified = set_data.file_specified;
- call->set_data.file_path = set_data.file_path;
- call->asset_ser_no = asset_ser_no;
- call->flags_string = flags_string; call->set_data.set (set_data.get());
- call->how_asset_found = how_asset_found;
- call->expect.pf_info_incomplete = true;
- return true;
- }
- }
- return false; // somehow didn't find it the call.
-}
-
// Default destructor:
set_sst_template_line::~set_sst_template_line (void)
{
@@ -141,63 +85,27 @@ set_sst_template_line::~set_sst_template_line (void)
/**********************************************************************************
- Methods of class remove_sst_template_line follow:
+ Methods of class read_sst_template_line follow:
**********************************************************************************/
-remove_sst_template_line::remove_sst_template_line (tf_fuzz_info *resources)
+read_sst_template_line::read_sst_template_line (tf_fuzz_info *resources)
: sst_template_line (resources) // (constructor)
{
- is_remove = true; // template_line's constructor defaults this to false
-}
+ char gibberish_buffer[4096]; string databuff;
+ int data_length;
+ set_data.string_specified = (rand()%2) == 1? true : false;
-bool remove_sst_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- sst_asset* this_asset;
- // Find the call by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_sst_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, dont_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* an sst_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(108);
- }
- // Copy *the other way* on asset reads!
- if (how_found != asset_search::not_found) {
- this_asset = reinterpret_cast<sst_asset*>(*found_asset);
- // Note: The vector is of base-class type, but the assets *are* sst_asset.
- set_data.string_specified = this_asset->set_data.string_specified;
- set_data.file_specified = this_asset->set_data.file_specified;
- flags_string = this_asset->flags_string;
- asset_id.id_n = this_asset->asset_id.id_n;
- asset_id.name_specified = this_asset->asset_id.name_specified;
- }
- return true;
-}
+ // Go ahead and create a literal-data string even if not needed:
+ data_length = test_state->gibbergen.pick_sentence_len();
+ test_state->gibbergen.sentence (gibberish_buffer, gibberish_buffer + data_length);
+ databuff = gibberish_buffer; set_data.set (databuff);
-bool remove_sst_template_line::copy_template_to_call (void)
-{
- // Find the call by serial number (must search; may have moved).
- for (auto call : test_state->calls) {
- if (call->call_ser_no == call_ser_no) {
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
- call->set_data.string_specified = false;
- call->set_data.set (""); call->id_string = asset_name;
- call->set_data.file_specified = false;
- call->set_data.file_path = ""; call->asset_ser_no = asset_ser_no;
- call->how_asset_found = how_asset_found;
- call->expect.pf_info_incomplete = true;
- return true;
- }
- }
- return false; // somehow didn't find it the call.
+ set_data.file_specified = (!set_data.string_specified && (rand()%2) == 1)? true : false;
+ set_data.file_path = ""; // can't really devise a random path
}
// Default destructor:
-remove_sst_template_line::~remove_sst_template_line (void)
+read_sst_template_line::~read_sst_template_line (void)
{
return; // just to have something to pin a breakpoint onto
}
@@ -206,90 +114,22 @@ remove_sst_template_line::~remove_sst_template_line (void)
/**********************************************************************************
- End of methods of class remove_sst_template_line.
+ End of methods of class read_sst_template_line.
**********************************************************************************/
/**********************************************************************************
- Methods of class read_sst_template_line follow:
+ Methods of class remove_sst_template_line follow:
**********************************************************************************/
-read_sst_template_line::read_sst_template_line (tf_fuzz_info *resources)
+remove_sst_template_line::remove_sst_template_line (tf_fuzz_info *resources)
: sst_template_line (resources) // (constructor)
{
- char gibberish_buffer[4096]; string databuff;
- int data_length;
- set_data.string_specified = (rand()%2) == 1? true : false;
-
- // Go ahead and create a literal-data string even if not needed:
- data_length = test_state->gibbergen.pick_sentence_len();
- test_state->gibbergen.sentence (gibberish_buffer, gibberish_buffer + data_length);
- databuff = gibberish_buffer; set_data.set (databuff);
-
- set_data.file_specified = (!set_data.string_specified && (rand()%2) == 1)? true : false;
- set_data.file_path = ""; // can't really devise a random path
-}
-
-bool read_sst_template_line::copy_template_to_asset (void)
-{
- vector<psa_asset*>::iterator found_asset;
- sst_asset* this_asset;
- // Find the call by serial number (must search; may have moved).
- asset_search how_found = test_state->find_or_create_sst_asset (
- psa_asset_search::serial, psa_asset_usage::all, "", 0,
- asset_ser_no, dont_create_asset, found_asset );
- // The vector is base-class, but this itself *really is* an sst_asset object:
- if (how_found == asset_search::unsuccessful) {
- cerr << "\nError: Tool-internal: TF-Fuzz failed to find a required asset."
- << endl;
- exit(108);
- }
- // Copy *the other way* on asset reads!
- if (how_found != asset_search::not_found) { // will be found for make calls, but not necessarily others
- this_asset = reinterpret_cast<sst_asset*>(*found_asset);
- set_data.string_specified = this_asset->set_data.string_specified;
- set_data.file_specified = this_asset->set_data.file_specified;
- flags_string = this_asset->flags_string;
- asset_id.id_n = this_asset->asset_id.id_n;
- asset_id.name_specified = this_asset->asset_id.name_specified;
- }
- return true;
- // TODO: Shouldn't data be copied over?
-}
-
-bool read_sst_template_line::copy_template_to_call (void)
-{
- // Find the call by serial number (must search; may have moved).
- for (auto call : test_state->calls) {
- if (call->call_ser_no == call_ser_no) {
- call->asset_id.set_just_name (asset_id.get_name());
- call->asset_id.id_n = asset_id.id_n;
- call->set_data.string_specified
- = set_data.string_specified || set_data.random_data;
- call->set_data.set(set_data.get());
- call->assign_data_var = assign_data_var;
- call->assign_data_var_specified = assign_data_var_specified;
- // TODO: Just copy entire expect object? call->expect = expect;
- call->expect.data_var = expect.data_var;
- call->expect.data_var_specified = expect.data_var_specified;
- call->expect.data_specified = expect.data_specified;
- call->expect.data.assign(expect.data);
- call->expect.pf_info_incomplete = true;
- call->id_string = asset_name; // data = expected
- call->set_data.file_specified = set_data.file_specified;
- call->set_data.file_path = set_data.file_path; call->asset_ser_no = asset_ser_no;
- call->flags_string = flags_string;
- call->how_asset_found = how_asset_found;
- call->print_data = print_data;
- call->hash_data = hash_data;
- return true;
- }
- }
- return false; // somehow didn't find it the call
+ is_remove = true; // template_line's constructor defaults this to false
}
// Default destructor:
-read_sst_template_line::~read_sst_template_line (void)
+remove_sst_template_line::~remove_sst_template_line (void)
{
return; // just to have something to pin a breakpoint onto
}
@@ -298,6 +138,6 @@ read_sst_template_line::~read_sst_template_line (void)
/**********************************************************************************
- End of methods of class read_sst_template_line.
+ End of methods of class remove_sst_template_line.
**********************************************************************************/
diff --git a/tools/tf_fuzz/template/sst_template_line.hpp b/tools/tf_fuzz/template/sst_template_line.hpp
index 15703ba83..d51aa7a22 100644
--- a/tools/tf_fuzz/template/sst_template_line.hpp
+++ b/tools/tf_fuzz/template/sst_template_line.hpp
@@ -26,8 +26,6 @@ class set_sst_template_line : public sst_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
- bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call, template_line *temLin,
tf_fuzz_info *rsrc) {
@@ -52,8 +50,6 @@ class remove_sst_template_line : public sst_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
- bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
template_line *temLin, tf_fuzz_info *rsrc) {
@@ -77,8 +73,6 @@ class read_sst_template_line : public sst_template_line
public:
// Data members:
// Methods:
- bool copy_template_to_asset (void);
- bool copy_template_to_call (void);
void setup_call (set_data_info set_info, bool random_data,
bool fill_in_template, bool create_call,
template_line *temLin, tf_fuzz_info *rsrc) {
diff --git a/tools/tf_fuzz/template/template_line.cpp b/tools/tf_fuzz/template/template_line.cpp
index 6ba6274a8..759948f27 100644
--- a/tools/tf_fuzz/template/template_line.cpp
+++ b/tools/tf_fuzz/template/template_line.cpp
@@ -5,12 +5,11 @@
*
*/
- /* Objects of these types are new()ed as a test-template line is parsed, and are
- resolved to be the type of template command stated -- "create a key," "remove
- an SST asset," or similar. Parameters of the template line are parsed into
- the object's members, where specified, but those members are randomized upon
- construction. Thus, any parameters not "nailed down," get randomized.
- */
+/* Objects typed to subclasses of the these classes are constructed and filled in by
+ the parser as it parses test-template lines. There is not necessarily a one-to-one
+ correspondence between the template lines and either the PSA commands generated nor
+ PSA assets they manipulate. PSA assets (which persist through the test) and PSA
+ commands are therefore tracked in separate objects, but referenced here. */
#include <vector>
#include <algorithm> // for STL find()
@@ -59,8 +58,10 @@ template_line::template_line (tf_fuzz_info *resources) : test_state(resources)
template_line::~template_line (void)
{
// Destruct the vectors of asset names/IDs:
- asset_id.asset_name_vector.erase (asset_id.asset_name_vector.begin(), asset_id.asset_name_vector.end());
- asset_id.asset_id_n_vector.erase (asset_id.asset_id_n_vector.begin(), asset_id.asset_id_n_vector.end());
+ asset_info.asset_name_vector.erase (asset_info.asset_name_vector.begin(),
+ asset_info.asset_name_vector.end());
+ asset_info.asset_id_n_vector.erase (asset_info.asset_id_n_vector.begin(),
+ asset_info.asset_id_n_vector.end());
}
// (Default constructor not used)
@@ -74,10 +75,36 @@ template_line::~template_line (void)
Methods of class sst_template_line follow:
**********************************************************************************/
-sst_template_line::sst_template_line (tf_fuzz_info *resources) : template_line (resources)
+// (Currently, no need to specialize copy_template_to_call() for individual SST ops.)
+bool sst_template_line::copy_template_to_call (void)
{
- asset_type = psa_asset_type::sst;
- return; // just to have something to pin a breakpoint onto
+ for (auto call : test_state->calls) {
+ if (call->call_ser_no == call_ser_no) {
+ // Copy asset info to call object for creation code:
+ call->asset_info = asset_info;
+ call->set_data = set_data;
+ call->set_data.string_specified = set_data.string_specified
+ || set_data.random_data;
+ // not really right, but more convenient to combine these two cases
+ call->assign_data_var_specified = assign_data_var_specified;
+ call->assign_data_var = assign_data_var;
+ call->random_asset = random_asset;
+ call->flags_string = flags_string;
+ call->exp_data = expect;
+ call->exp_data.pf_info_incomplete = true;
+ call->id_string = asset_name; // data = expected
+ call->print_data = print_data;
+ call->hash_data = hash_data;
+ return true;
+ }
+ }
+ return false; // somehow didn't find it the call.
+}
+
+sst_template_line::sst_template_line (tf_fuzz_info *resources)
+ : template_line (resources)
+{
+ asset_info.asset_type = psa_asset_type::sst;
}
// Default destructor:
@@ -100,12 +127,13 @@ sst_template_line::~sst_template_line (void)
Methods of class key_template_line follow:
**********************************************************************************/
-key_template_line::key_template_line (tf_fuzz_info *resources) : template_line (resources)
+key_template_line::key_template_line (tf_fuzz_info *resources)
+ : template_line (resources)
{
// Note: Similar random initialization for asset and template
// Randomize handle:
// TODO: Key handles appear to be a lot more complex a question than the below
- asset_type = psa_asset_type::key;
+ asset_info.asset_type = psa_asset_type::key;
string wrong_data; // holder for random data to be overwritten
gibberish *gib = new gibberish;
handle_str = gib->word (false, const_cast<char*>(wrong_data.c_str()),
@@ -151,7 +179,7 @@ key_template_line::~key_template_line (void)
policy_template_line::policy_template_line (tf_fuzz_info *resources)
: template_line (resources)
{
- asset_type = psa_asset_type::policy;
+ asset_info.asset_type = psa_asset_type::policy;
// Randomize key-policy usage and algorithm:
policy_usage = rand_key_usage();
policy_algorithm = rand_key_algorithm();
diff --git a/tools/tf_fuzz/template/template_line.hpp b/tools/tf_fuzz/template/template_line.hpp
index ef843ac24..016d9070a 100644
--- a/tools/tf_fuzz/template/template_line.hpp
+++ b/tools/tf_fuzz/template/template_line.hpp
@@ -5,11 +5,11 @@
*
*/
-/* Objects typed to subclasses of the these classes are constructed and filled in
- by the parser as it parses template lines. There is not necessarily a one-to-one
- correspondence between the template lines and either the PSA commands generated
- nor PSA assets they manipulate. PSA assets (which persist through the test) and
- PSA commands are therefore tracked in separate objects, but referenced here. */
+/* Objects typed to subclasses of the these classes are constructed and filled in by
+ the parser as it parses test-template lines. There is not necessarily a one-to-one
+ correspondence between the template lines and either the PSA commands generated nor
+ PSA assets they manipulate. PSA assets (which persist through the test) and PSA
+ commands are therefore tracked in separate objects, but referenced here. */
#ifndef TEMPLATE_LINE_HPP
#define TEMPLATE_LINE_HPP
@@ -38,20 +38,14 @@ public:
/* Note: The following are pointers to the psa_asset and psa_call currently
being worked with. These objects these are first placed on the appropriate
vector in test_state of such objects, and then referenced here. */
- psa_asset_type asset_type; // SST vs. key vs. policy (etc.)
expect_info expect; // everything about expected results
set_data_info set_data; // everything about setting PSA-asset data
- asset_name_id_info asset_id; // everything about the asset(s) for this line
+ asset_name_id_info asset_info; // everything about the asset(s) for this line
long call_ser_no; // unique identifer for psa_call tracker object
- long asset_ser_no; // same for psa_asset objects
- /* Note: Regarding the above serial numbers, we can't save away iterators
- nor pointers, because STL vectors could get relocated. Must
- explicitly search immediately prior to using these objects! */
psa_asset_usage random_asset;
/* if asked to use some random asset from active or deleted, this says
which. psa_asset_usage::all if not using this feature. */
- asset_search how_asset_found;
- bool assign_data_var_specified;
+ bool assign_data_var_specified; // asset data to or from a named variable
string assign_data_var; // name of variable to dump (assign) data into
bool print_data; // true to print asset data to test log
bool hash_data; // true to hash data for later comparison
@@ -59,7 +53,6 @@ public:
PSA calls from a single template line. */
bool is_remove; // true if this template line is to remove an asset
// Methods (mostly for calling from within yyparse()):
- virtual bool copy_template_to_asset (void) = 0;
virtual bool copy_template_to_call (void) = 0;
virtual void setup_call (set_data_info set_data, bool random_data,
bool fill_in_template, bool create_call,
@@ -87,6 +80,7 @@ private:
tually, these subclasses might be more logically put in those sub-classing
files, but this gives a more-even balance of file size and complexity. */
+
class sst_template_line : public template_line
{
public:
@@ -94,6 +88,7 @@ public:
// SST-asset info:
// PSA-call info:
// Methods:
+ bool copy_template_to_call (void);
sst_template_line (tf_fuzz_info *resources); // (constructor)
~sst_template_line (void);
@@ -113,11 +108,13 @@ public:
// Data members:
string handle_str; // the text name of the key's "handle"
string key_type; // DES, AES, RAW, vendor, none, etc.
- string lifetime_str; // similarly, the text representation of the key's lifetime
+ string lifetime_str;
+ // similarly, the text representation of the key's lifetime
string expected_n_bits;
// for get_key_info call (possibly others) exected key size in bits
// Methods:
- string make_id_based_name (uint64_t id_n, string &name); // create ID-based asset name
+ string make_id_based_name (uint64_t id_n, string &name);
+ // create ID-based asset name
key_template_line (tf_fuzz_info *resources); // (constructor)
~key_template_line (void);
@@ -147,7 +144,8 @@ protected:
private:
// Data members:
// Methods:
- string make_id_based_name (uint64_t id_n, string &name); // create ID-based asset name
+ string make_id_based_name (uint64_t id_n, string &name);
+ // create ID-based asset name
};
diff --git a/tools/tf_fuzz/tests/README b/tools/tf_fuzz/tests/README
deleted file mode 100644
index 292acda5d..000000000
--- a/tools/tf_fuzz/tests/README
+++ /dev/null
@@ -1,12 +0,0 @@
-.../tf_fuzz/tests directory contents:
-
-example_template sstReads sstSets
-
---------------------------------------------------------------------------------
-
-These are perhaps more examples of test-template files, more than organized
-tests as such.
-
---------------
-
-*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
diff --git a/tools/tf_fuzz/tf_fuzz.cpp b/tools/tf_fuzz/tf_fuzz.cpp
index 4a153f64f..4457107a8 100644
--- a/tools/tf_fuzz/tf_fuzz.cpp
+++ b/tools/tf_fuzz/tf_fuzz.cpp
@@ -25,6 +25,7 @@
#include "crypto_asset.hpp"
#include "psa_call.hpp"
#include "tf_fuzz_grammar.tab.hpp"
+#include "variables.hpp"
extern FILE* yyin; // telling lex&yacc which file to parse
@@ -79,7 +80,7 @@ asset_search tf_fuzz_info::find_or_create_policy_asset (
uint64_t target_id, // also ignored unless searching on ID (e.g., SST UID)
long &serial_no, // search by asset's unique serial number
bool create_asset, // true to create the asset if it doesn't exist
- vector<psa_asset*>::iterator &asset // returns iterator to requested asset
+ vector<psa_asset*>::iterator &asset // iterator to requested asset
) {
return generic_find_or_create_asset<policy_asset>(
active_policy_asset, deleted_policy_asset,
@@ -121,6 +122,35 @@ asset_search tf_fuzz_info::find_or_create_psa_asset (
}
}
+// Return an iterator to a variable, if it exists. If not return variable.end().
+vector<variable_info>::iterator tf_fuzz_info::find_var (string var_name)
+{
+ vector<variable_info>::iterator the_var;
+ if (variable.empty()) {
+ return variable.end();
+ }
+ for (the_var = variable.begin(); the_var < variable.end(); the_var++) {
+ if (the_var->name == var_name) {
+ break;
+ }
+ }
+ return the_var;
+}
+// Add a variable to the vector if not already there; return true if already there.
+bool tf_fuzz_info::make_var (string var_name)
+{
+ bool found = false;
+ variable_info new_variable;
+
+ found = (find_var (var_name) != variable.end());
+ if (!found) {
+ new_variable.name.assign (var_name);
+ variable.push_back (new_variable);
+ }
+ return found;
+}
+
+
// Remove any PSA resources used in the test. Returns success==true, fail==false.
void tf_fuzz_info::teardown_test (void)
{
@@ -128,7 +158,7 @@ void tf_fuzz_info::teardown_test (void)
// Traverse through the SST-assets list, writing out remove commands:
for (auto &asset : active_sst_asset) {
call = bplate->bplate_string[teardown_sst];
- find_replace_1st ("$uid", to_string(asset->asset_id.id_n), call);
+ find_replace_1st ("$uid", to_string(asset->asset_info.id_n), call);
call.append (bplate->bplate_string[teardown_sst_check]);
output_C_file << call;
}
@@ -192,8 +222,45 @@ void tf_fuzz_info::write_test (void)
}
-/* Parse command-line parameters. exit() if error(s) found. Place results
- into resource object. */
+/* simulate_calls() goes through the vector of generated calls calculating expected
+ results for each. */
+void tf_fuzz_info::simulate_calls (void)
+{
+ bool asset_state_changed = false;
+
+ /* For now, much of the simulation "thinking" infrastructure is here for future
+ elaboration. The algorithm is to through each call one by one, copying
+ information to the asset in question. Then each currently-active asset is
+ allowed to react to that information until they all agree that they're
+ "quiescent." Finally, result information is copied from the asset back to
+ the call. */
+ for (auto this_call : calls) {
+ this_call->copy_call_to_asset();
+ /* Note: this_call->the_asset will now point to the asset
+ associated with this_call, if any such asset exists. */
+ if (this_call->asset_info.the_asset != nullptr) {
+ /* If the asset exists, allow changes to it to affect other active
+ assets. */
+ asset_state_changed = false;
+ do {
+ for (auto this_asset : active_sst_asset) {
+ asset_state_changed |= this_asset->simulate();
+ }
+ for (auto this_asset : active_policy_asset) {
+ asset_state_changed |= this_asset->simulate();
+ }
+ for (auto this_asset : active_key_asset) {
+ asset_state_changed |= this_asset->simulate();
+ }
+ } while (asset_state_changed);
+ }
+ this_call->copy_asset_to_call();
+ }
+}
+
+
+/* Parse command-line parameters. exit() if error(s) found. Place results into
+ the resource object. */
void tf_fuzz_info::parse_cmd_line_params (int argc, char* argv[])
{
int exit_val = 0; // the linux return value, default 0, meaning all-good
@@ -346,6 +413,10 @@ int main(int argc, char* argv[])
} else if (parse_result == 2) {
cerr << "\nError: Sorry, TF-Fuzz ran out of memory." << endl;
}
+ cout << "Call sequence generated." << endl;
+
+ cout << "Simulating call sequence..." << endl;
+ rsrc->simulate_calls();
cout << "Writing test file, " << rsrc->test_output_file_name << "." << endl;
rsrc->write_test();
diff --git a/tools/tf_fuzz/tf_fuzz.hpp b/tools/tf_fuzz/tf_fuzz.hpp
index 7668998ca..6353856d0 100644
--- a/tools/tf_fuzz/tf_fuzz.hpp
+++ b/tools/tf_fuzz/tf_fuzz.hpp
@@ -25,17 +25,15 @@
using namespace std;
-/* class tf_fuzz_info mostly just groups together everything needed to gather, then
- write out the test. This, so that they can be passed into the parser. */
-
+// class tf_fuzz_info mostly just groups together everything needed generate the test.
class tf_fuzz_info
{
- /* In creating a test, TF-Fuzz collects together a vector of strings cataloging
- data structures used by PSA commands, and a vector of PSA call objects. Once
- the template is completely parsed, write_test() writes it all out. The
+ /* In creating a test, TF-Fuzz parses the test template, creating a vector of
+ PSA-call-tracker objects. TF-Fuzz then performs a simulation of those calls
+ -- simulation only in enough detail to predict expected results of those PSA
+ calls. After that simulation phase, write_test() writes it all out. The
process of creating these structures also requires the boilerplate text
- strings. In the process of building the test, it must track PSA assets to
- "model" expected results of calls. */
+ strings. */
public:
// Data members (this class is mostly just to group stuff together, so public):
@@ -57,7 +55,16 @@ public:
vector<psa_asset*> active_policy_asset; // list of known, usable policies
vector<psa_asset*> deleted_policy_asset; // deleted policies
vector<psa_asset*> invalid_policy_asset; // policies with invalid attrs
- string test_purpose; // one text substitution to be performed at the top level
+ /* The "variable" vector tracks variables in the generated code. Actually,
+ it tracks variables explicitly named in the test template, and actual-data
+ holder variables from reading an asset. It does not track asset set-data
+ or asset expect-data variables, because there are multiple versions of
+ those, and it's easier to just to "count off" those multiple versions.
+ Notice that, unlike the above vectors, the variable vector is not a
+ vector of pointers to variable_info objects, but of the objects themselves.
+ This is because polymorphism is not of concern here. */
+ vector<variable_info> variable;
+ string test_purpose; // what the test tests
long rand_seed; // the original random seed, whether passed in or defaulted
string template_file_name, test_output_file_name;
FILE *template_file;
@@ -82,7 +89,7 @@ public:
psa_asset_search criterion, // what to search on
psa_asset_usage where, // where to search
string target_name, // ignored if not searching on name
- uint64_t target_id, // also ignored if not searching on ID (e.g., SST UID)
+ uint64_t target_id, // ignored if not searching on ID (e.g., SST UID)
long &serial_no, // search by asset's unique serial number
bool create_asset, // true to create the asset if it doesn't exist
vector<psa_asset*>:: iterator &asset // returns iterator to asset
@@ -106,8 +113,12 @@ public:
bool create_asset, // true to create the asset if it doesn't exist
vector<psa_asset*>::iterator &asset // returns iterator to asset
);
+ vector<variable_info>::iterator find_var (string var_name);
+ bool make_var (string var_name);
void teardown_test(void); // removes any PSA resources used in the test
- void write_test (void); // returns success==true, fail==false
+ void simulate_calls (void);
+ // goes through generated calls calculating expected results
+ void write_test (void); // writes out the test's .c file
void parse_cmd_line_params (int argc, char* argv[]);
// parse command-line parameters, and open files
tf_fuzz_info (void); // (constructor)
@@ -142,7 +153,7 @@ void define_call (set_data_info set_data, bool random_data, bool fill_in_templat
if (fill_in_template) {
if (set_data.literal_data_not_file) {
if (random_data) {
- int rand_data_length = 10 + (rand() % 800);
+ int rand_data_length = 12 + (rand() % 800);
gib.sentence (gib_buff, gib_buff + rand_data_length - 1);
t_string = gib_buff;
temLin->set_data.set_calculated (t_string);
@@ -158,15 +169,10 @@ void define_call (set_data_info set_data, bool random_data, bool fill_in_templat
}
}
if (create_call) {
- if (temLin->how_asset_found == asset_search::unsuccessful) {
- cerr << "Error: Tool-internal: Please report error "
- << "#401 to the TF-Fuzz developers." << endl;
- exit(401);
- }
the_call = new CALL_TYPE (rsrc, temLin->call_ser_no,
- temLin->how_asset_found);
- rsrc->calls.push_back(the_call); /* (note: this is not a memory leak!) */
- temLin->copy_template_to_asset();
+ temLin->asset_info.how_asset_found);
+ rsrc->calls.push_back(the_call); // (note: this is not a memory leak!)
+// temLin->copy_template_to_asset(); TODO: Remove this "note-to-self" comment
if (!temLin->copy_template_to_call()) {
cerr << "Error: Tool-internal: Please report error "
<< "#402 to the TF-Fuzz developers." << endl;
diff --git a/tools/tf_fuzz/utility/README b/tools/tf_fuzz/utility/README
index 012fefd67..5285fffce 100644
--- a/tools/tf_fuzz/utility/README
+++ b/tools/tf_fuzz/utility/README
@@ -1,14 +1,10 @@
-.../tf_fuzz/utility directory contents:
+As its name implies, this .../tf_fuzz/utility directory just contains
+various utility-compute code.
-compute.cpp find_or_create_asset.hpp randomization.cpp string_ops.hpp
-compute.hpp gibberish.cpp randomization.hpp
-data_blocks.cpp gibberish.hpp Source.cpp
-data_blocks.hpp interactive.c string_ops.cpp
---------------------------------------------------------------------------------
+For more information, please browse to:
-As its name implies, this .../utility directory just contains various utility-
-compute "stuff."
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/utility_dir.html
--------------
diff --git a/tools/tf_fuzz/utility/data_blocks.cpp b/tools/tf_fuzz/utility/data_blocks.cpp
index 172d67241..0bd0d7939 100644
--- a/tools/tf_fuzz/utility/data_blocks.cpp
+++ b/tools/tf_fuzz/utility/data_blocks.cpp
@@ -43,6 +43,7 @@ expect_info::expect_info (void) // (default constructor)
data_specified = false;
data.assign ("");
pf_info_incomplete = true;
+ n_exp_vars = -1; // so the first reference is 0 (no suffix), then _1, _2, ...
}
expect_info::~expect_info (void) // (destructor)
{}
@@ -68,17 +69,17 @@ void expect_info::set_pf_error (string error)
pf_pass = pf_nothing = false;
}
-/* What the call expects is not available from the parser until the call has already
- been created. The flag, pf_info_incomplete, that indicates whether or not the
- "expects" information has been filled in If not, fill it in from the template,
+/* The expected pass/fail results are not available from the parser until the call has
+ already been created. The flag, pf_info_incomplete, that indicates whether or not
+ the "expects" information has been filled in. If not, fill it in from the template,
once that info has been parsed. */
void expect_info::copy_expect_to_call (psa_call *the_call)
{
- the_call->expect.pf_nothing = pf_nothing;
- the_call->expect.pf_pass = pf_pass;
- the_call->expect.pf_specified = pf_specified;
- the_call->expect.pf_result_string = pf_result_string;
- the_call->expect.pf_info_incomplete = false;
+ the_call->exp_data.pf_nothing = pf_nothing;
+ the_call->exp_data.pf_pass = pf_pass;
+ the_call->exp_data.pf_specified = pf_specified;
+ the_call->exp_data.pf_result_string = pf_result_string;
+ the_call->exp_data.pf_info_incomplete = false;
}
/**********************************************************************************
@@ -98,6 +99,7 @@ set_data_info::set_data_info (void) // (default constructor)
random_data = false;
file_specified = false;
file_path.assign ("");
+ n_set_vars = -1; // so the first reference is 0 (no suffix), then _1, _2, ...
}
set_data_info::~set_data_info (void) // (destructor)
{}
@@ -131,6 +133,27 @@ void set_data_info::set_calculated (string set_val)
data.assign (set_val);
}
+/* randomize() establishes:
+ * An asset's data value as *not* taken from a template line, and
+ * *That* such a value was randomized.
+ Arguably, this method "has side effects," in that it not only sets a value, but
+ also "takes notes" about where that value came from.
+*/
+void set_data_info::randomize (void)
+{
+ gibberish gib;
+ char gib_buff[4096]; // spew gibberish into here
+ int rand_data_length = 0;
+
+ string_specified = false;
+ random_data = true;
+ literal_data_not_file = true;
+ rand_data_length = 40 + (rand() % 256);
+ /* Note: Multiple assets do get different random data */
+ gib.sentence (gib_buff, gib_buff + rand_data_length - 1);
+ data = gib_buff;
+}
+
/* Getter for protected member, data. Protected so that it can only be set by
set() or set_calculated(), above, to establish not only its value but
how it came about. */
@@ -171,6 +194,8 @@ asset_name_id_info::asset_name_id_info (void) // (default constructor)
id_n_specified = name_specified = false; // no ID info yet
asset_name_vector.clear();
asset_id_n_vector.clear();
+ asset_type = psa_asset_type::unknown;
+ the_asset = nullptr;
}
asset_name_id_info::~asset_name_id_info (void)
{
@@ -230,9 +255,25 @@ void asset_name_id_info::set_id_n (uint64_t set_val)
}
// Create ID-based name:
-string asset_name_id_info::make_id_n_based_name (uint64_t id_n, string &name)
+string asset_name_id_info::make_id_n_based_name (uint64_t id_n)
{
- string result = "SST_ID_";
+ string result;
+
+ switch (asset_type) {
+ case psa_asset_type::sst:
+ result = "SST_ID_";
+ break;
+ case psa_asset_type::key:
+ result = "Key_ID_";
+ break;
+ case psa_asset_type::policy:
+ result = "Policy_ID_";
+ break;
+ default:
+ cerr << "\nError: Tool-internal: Please report error "
+ << "#1223 to the TF-Fuzz developers." << endl;
+ exit(1223);
+ }
result.append(to_string(id_n));
return result;
}
diff --git a/tools/tf_fuzz/utility/data_blocks.hpp b/tools/tf_fuzz/utility/data_blocks.hpp
index 2822f57c8..709f7c8f7 100644
--- a/tools/tf_fuzz/utility/data_blocks.hpp
+++ b/tools/tf_fuzz/utility/data_blocks.hpp
@@ -39,23 +39,24 @@ class expect_info
{
public:
// Data members:
+ // Expected-result info:
bool pf_nothing; // true to not generate results-check(s)
bool pf_pass; // if !expect.pf_nothing, then pass is expected
bool pf_specified;
/* if !pf_nothing && !pf_pass, then
true == expected result was specified
- false == tf_fuzz must model expected result */
- bool data_specified; // (literal data specified)
- string data; // expected data from reading an asset
- bool data_var_specified;
+ false == tf_fuzz must model expected result, and
+ pf_result_string is the expected result */
+ string pf_result_string;
+ bool data_specified; // (literal expected data specified)
+ string data; // what test template expects data from reading an asset to be
+ int n_exp_vars; // how many check-value variables have been created
+ bool data_var_specified; // check against a variable
string data_var; // name of variable containing expected data
bool pf_info_incomplete;
/* In parsing the template, the expect information comes later than the
- rest of the call info. This flag tells us to fill in the expect
- info when it comes available. */
- // Expected-result info:
- string pf_result_string;
- // if !pf_nothing && !pf_pass then this is expected result
+ rest of the call info. This flag tells us to fill in the pass/fail
+ expect info when it comes available. */
// Methods:
expect_info (void); // (default constructor)
~expect_info (void); // (destructor)
@@ -89,12 +90,14 @@ public:
bool file_specified; // true if a file of expected data was specified
bool literal_data_not_file;
// true to use data strings rather than files as data source
+ int n_set_vars; // how many implicit set variables have been created
string file_path; // path to file, if specified
// Methods:
set_data_info (void); // (default constructor)
~set_data_info (void); // (destructor)
void set (string set_val);
void set_calculated (string set_val);
+ void randomize (void);
string get (void);
bool set_file (string file_name);
@@ -113,14 +116,22 @@ class asset_name_id_info
{
public:
// Data members (not much value in "hiding" these behind getters)
+ psa_asset *the_asset;
+ psa_asset_type asset_type; // SST vs. key vs. policy (etc.)
bool id_n_not_name; // true to create a PSA asset by ID
bool name_specified; // true iff template supplied human name
bool id_n_specified; // true iff template supplied ID #
vector<string> asset_name_vector;
vector<int> asset_id_n_vector;
+ long asset_ser_no; // unique ID for psa asset needed to find data string
+ /* Note: The original theory is that we can't save away iterators to
+ assets, because STL vectors could get relocated. However,
+ we've switched over to lists, which don't get moved around, so
+ we should be safe now. */
+ asset_search how_asset_found;
uint64_t id_n; // asset ID# (e.g., SST UID).
- /* Note: This is just a holder to pass ID from template-line to call.
- The IDs for a given template line are in asset_id.asset_id_n_vector. */
+ /* Note: This is just a holder to pass ID from template-line to call. The
+ IDs for a given template line are in asset_info.asset_id_n_vector. */
// Methods:
asset_name_id_info (void); // (default constructor)
~asset_name_id_info (void); // (destructor)
@@ -130,7 +141,7 @@ public:
string get_name (void);
void set_id_n (string set_val);
void set_id_n (uint64_t set_val);
- string make_id_n_based_name (uint64_t id_n, string &name);
+ string make_id_n_based_name (uint64_t id_n);
// create UID-based asset name
protected:
diff --git a/tools/tf_fuzz/utility/find_or_create_asset.hpp b/tools/tf_fuzz/utility/find_or_create_asset.hpp
index 866c9494d..2296dd839 100644
--- a/tools/tf_fuzz/utility/find_or_create_asset.hpp
+++ b/tools/tf_fuzz/utility/find_or_create_asset.hpp
@@ -8,6 +8,8 @@
#ifndef FIND_OR_CREATE_ASSET_HPP
#define FIND_OR_CREATE_ASSET_HPP
+using namespace std;
+
/* This enum defines possible results when asked to find an existing, or create a
new PSA asset. */
enum class asset_search
@@ -15,7 +17,7 @@ enum class asset_search
found_deleted, // found as a previously-used, but now-unusable asset
found_invalid, // found as a previously-used, but now-unusable asset
not_found, // if not found and if not allowed to create it
- created_new, // no such existing asset was found so created new one
+ created_new, // no such existing asset was found so created new, active asset
unsuccessful, // ran out of memory or whatever
something_wrong // something wrong with the code; shouldn't happen
};
@@ -37,7 +39,8 @@ enum class psa_asset_search
enum class psa_asset_type
{ sst, // (pretty obvious what each of these mean)
key,
- policy
+ policy,
+ unknown
};
@@ -72,13 +75,13 @@ asset_search generic_find_or_create_asset (
psa_asset *pass = *as;
switch (criterion) {
case psa_asset_search::name: // human-meaningful name
- match = (pass->asset_id.get_name() == target_name);
+ match = (pass->asset_info.get_name() == target_name);
break;
case psa_asset_search::id: // ID#
- match = (pass->asset_id.id_n == target_id);
+ match = (pass->asset_info.id_n == target_id);
break;
default: // psa_asset_search::serial
- match = (pass->asset_ser_no == serial_no);
+ match = (pass->asset_info.asset_ser_no == serial_no);
break;
}
if (match) {
@@ -94,18 +97,28 @@ asset_search generic_find_or_create_asset (
psa_asset *pass = *as;
switch (criterion) {
case psa_asset_search::name: // human-meaningful name
- match = (pass->asset_id.get_name() == target_name);
+ match = (pass->asset_info.get_name() == target_name);
break;
case psa_asset_search::id: // ID#
- match = (pass->asset_id.id_n == target_id);
+ match = (pass->asset_info.id_n == target_id);
break;
default: // psa_asset_search::serial
- match = (pass->asset_ser_no == serial_no);
+ match = (pass->asset_info.asset_ser_no == serial_no);
break;
}
if (match) {
asset = as;
- return asset_search::found_deleted;
+ if (create_asset) {
+ /* Asset previously existed, but has since been removed. Resur-
+ rect it into active assets, but zap its data: */
+ pass->set_data.set("");
+ pass->exp_data.data.assign("");
+ deleted_asset_vector.erase (as);
+ active_asset_vector.push_back (pass);
+ return asset_search::found_active; // it's active now anyway...
+ } else {
+ return asset_search::found_deleted;
+ }
}
}
}
@@ -116,13 +129,13 @@ asset_search generic_find_or_create_asset (
psa_asset *pass = *as;
switch (criterion) {
case psa_asset_search::name: // human-meaningful name
- match = (pass->asset_id.get_name() == target_name);
+ match = (pass->asset_info.get_name() == target_name);
break;
case psa_asset_search::id: // ID#
- match = (pass->asset_id.id_n == target_id);
+ match = (pass->asset_info.id_n == target_id);
break;
default: // psa_asset_search::serial
- match = (pass->asset_ser_no == serial_no);
+ match = (pass->asset_info.asset_ser_no == serial_no);
break;
}
if (match) {
@@ -136,7 +149,7 @@ asset_search generic_find_or_create_asset (
try {
new_asset = new ASSET_TYPE;
if (criterion == psa_asset_search::id) {
- new_asset->asset_id.id_n = target_id;
+ new_asset->asset_info.id_n = target_id;
} // TO DO: probably should do the same for its name in a name search!
active_asset_vector.push_back(new_asset);
asset = prev(active_asset_vector.end());
diff --git a/tools/tf_fuzz/utility/gibberish.cpp b/tools/tf_fuzz/utility/gibberish.cpp
index 45ce22309..658c1c4d5 100644
--- a/tools/tf_fuzz/utility/gibberish.cpp
+++ b/tools/tf_fuzz/utility/gibberish.cpp
@@ -153,7 +153,7 @@ void gibberish::sentence (char *string_ptr, char *stop)
*parser++ = ' ';
}
}
- parser--;
+ parser--;
if (*parser == ' ') {
*parser = vowel(); // just to not have a blank at the end
}
diff --git a/tools/tf_fuzz/utility/randomization.cpp b/tools/tf_fuzz/utility/randomization.cpp
index 8abfe5cc5..7b6d7509c 100644
--- a/tools/tf_fuzz/utility/randomization.cpp
+++ b/tools/tf_fuzz/utility/randomization.cpp
@@ -109,7 +109,7 @@ string rand_key_algorithm (void)
*/
string rand_key_type (void)
{
- switch (rand() % 22) {
+ switch (rand() % 24) {
case 0: return "PSA_KEY_TYPE_NONE";
case 1: return "PSA_KEY_TYPE_VENDOR_FLAG";
case 2: return "PSA_KEY_TYPE_CATEGORY_MASK";
@@ -125,15 +125,19 @@ string rand_key_type (void)
case 12: return "PSA_KEY_TYPE_DES";
case 13: return "PSA_KEY_TYPE_CAMELLIA";
case 14: return "PSA_KEY_TYPE_ARC4";
- case 15: return "PSA_KEY_TYPE_RSA_PUBLIC_KEY";
- case 16: return "PSA_KEY_TYPE_RSA_KEYPAIR";
- case 17: return "PSA_KEY_TYPE_DSA_PUBLIC_KEY";
- case 18: return "PSA_KEY_TYPE_DSA_KEYPAIR";
- case 19: return "PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE";
- case 20: return "PSA_KEY_TYPE_ECC_KEYPAIR_BASE";
- case 21: return "PSA_KEY_TYPE_ECC_CURVE_MASK";
+ case 15: return "PSA_KEY_TYPE_CHACHA20";
+ case 16: return "PSA_KEY_TYPE_RSA_PUBLIC_KEY";
+ case 17: return "PSA_KEY_TYPE_RSA_KEY_PAIR";
+ case 18: return "PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE";
+ case 19: return "PSA_KEY_TYPE_ECC_KEY_PAIR_BASE";
+ case 20: return "PSA_KEY_TYPE_ECC_CURVE_MASK";
+ case 21: return "PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE";
+ case 22: return "PSA_KEY_TYPE_DH_KEY_PAIR_BASE";
+ case 23: return "PSA_KEY_TYPE_DH_GROUP_MASK";
default: return "";
}
return ""; /* placate compiler */
}
+
+
diff --git a/tools/tf_fuzz/utility/variables.cpp b/tools/tf_fuzz/utility/variables.cpp
new file mode 100644
index 000000000..ab2a823eb
--- /dev/null
+++ b/tools/tf_fuzz/utility/variables.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/* This file defines information to track regarding variables in the generated test
+ code. */
+
+#include <string>
+#include <vector>
+#include <list>
+#include <iostream>
+#include <fstream>
+
+#include "class_forwards.hpp"
+
+#include "data_blocks.hpp"
+#include "psa_asset.hpp"
+#include "crypto_asset.hpp"
+#include "psa_call.hpp"
+#include "find_or_create_asset.hpp"
+#include "variables.hpp"
+#include "gibberish.hpp"
+
+/* This project's header files #including other project headers quickly becomes
+ unrealistically complicated. The only solution is for each .cpp to include
+ the headers it needs. However these in particular are mostly axiomatic: Not
+ dependent upon other classes. */
+
+
+using namespace std;
+
+
+/**********************************************************************************
+ Methods of class variable_info follow:
+**********************************************************************************/
+
+variable_info::variable_info (void) // (default constructor)
+{
+ gibberish *gib = new gibberish;
+
+ hash_declared = value_known = false;
+ name = "";
+ length = 100 + (rand() % 800);
+ gib->sentence ((char*) value, (char*) value + length);
+ // TODO: Sizes of random data neesds to be strategized better
+ type = psa_asset_type::unknown;
+ delete gib;
+}
+
+variable_info::variable_info (string var_name, psa_asset_type var_type)
+{ // (constructor with known name and type)
+ gibberish *gib = new gibberish;
+
+ hash_declared = value_known = false;
+ name.assign (var_name);
+ length = 100 + (rand() % 800);
+ gib->sentence ((char*) value, (char*) value + length);
+ // TODO: Sizes of random data needs to be strategized better
+ type = var_type;
+ delete gib;
+}
+
+variable_info::~variable_info (void) // (destructor)
+{}
+
+
+/**********************************************************************************
+ End of methods of class variable_info.
+**********************************************************************************/
diff --git a/tools/tf_fuzz/utility/variables.hpp b/tools/tf_fuzz/utility/variables.hpp
new file mode 100644
index 000000000..886acc355
--- /dev/null
+++ b/tools/tf_fuzz/utility/variables.hpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <string>
+#include <vector>
+
+/* This file defines information to track regarding variables in the generated test
+ code. */
+
+#ifndef VARIABLES_HPP
+#define VARIABLES_HPP
+
+/* This project's header files #including other project headers quickly becomes
+ unrealistically complicated. The only solution is for each .cpp to include
+ the headers it needs. However these in particular are mostly axiomatic: Not
+ dependent upon other classes. */
+
+
+using namespace std;
+
+
+/**********************************************************************************
+ Class variable_info tracks everything we know about a given variable in the
+ generated C code.
+**********************************************************************************/
+
+class variable_info
+{
+public:
+ // Data members:
+ /* The existence of this variable tracker means that the data variable and
+ the length variable have been declared, but there are other variants on
+ this variable that may or may not have been declared already. Thus
+ the *_declared bool(s) below. */
+ bool hash_declared; // true if the hash of this variable has been declared
+ bool value_known; // true if the variable's value can be known in simulation
+ string name; // variable name
+ unsigned char value[2048]; // the current value of the variable
+ int length; // of the variable's value
+ psa_asset_type type; // type of info contained in the variable
+
+ // Methods:
+ variable_info (void); // (default constructor)
+ variable_info ( // (constructor with known name and type)
+ string var_name, psa_asset_type var_type
+ );
+ ~variable_info (void); // (destructor)
+
+protected:
+ // Data members:
+};
+
+
+#endif // VARIABLES_HPP
+
diff --git a/tools/tf_fuzz/visualStudio/README b/tools/tf_fuzz/visualStudio/README
index 58c40f5b5..faa99b288 100644
--- a/tools/tf_fuzz/visualStudio/README
+++ b/tools/tf_fuzz/visualStudio/README
@@ -1,15 +1,9 @@
-.../tf_fuzz/visualStudio directory contents:
+This is just things to support running and debug under Microsoft Visual Studio
+(tm).
-unistd.c unistd.h
+For more information, please browse to:
---------------------------------------------------------------------------------
-
-This is just things to support running and debug under Microsoft Visual Studio.
-So far, it contains a "stand-in" for the unistd.h library, and more specifically,
-the isatty() call in that library, which is used by Lex&YACC. Other functions
-may be added later as needed. At some time in the future, an up-coming "inter-
-active mode" for interactively creating test templates may need an actual working
-isatty(), but that's not ready yet.
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/visualStudio_dir.html
--------------