Add tf_fuzz tool
This is fully derived from tf-m repo.
Signed-off-by: Karl Zhang <karl.zhang@arm.com>
Change-Id: I8d35e70eda9081af66d8fa3f3cb4beb1d953060e
diff --git a/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr
new file mode 100644
index 0000000..1976f7b
--- /dev/null
+++ b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_stdout_stderr
@@ -0,0 +1,24 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to create an SST asset
+ASSET_NUMBER: "104"
+SST-asset UID list: "data"
+LITERAL string: "Very simple test"
+Create from literal data: ""Very simple test""
+Set SST command: "expect"
+Appended to end of call sequence: SST-set call.
+Set command: "expect"
+Expect pass clause: "pass"
+Command with expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset SST_ID_104
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c
new file mode 100644
index 0000000..04b84e9
--- /dev/null
+++ b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/exp_test.c
@@ -0,0 +1,61 @@
+/*
+ * Test purpose:
+ * to create an SST 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t SST_ID_104_set_data[] = "Very simple test";
+ static uint32_t SST_ID_104_set_length = 16;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to create an SST asset");
+
+
+ /* PSA calls to test: */
+ /\* 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;
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove(104);
+ 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/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/template b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/template
new file mode 100644
index 0000000..7b84f11
--- /dev/null
+++ b/tf_fuzz/regression/000001_set_sst_uid_data_expect_pass/template
@@ -0,0 +1,2 @@
+purpose to create an SST asset;
+set sst uid 104 data "Very simple test" expect pass;
diff --git a/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr
new file mode 100644
index 0000000..97c20e8
--- /dev/null
+++ b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_stdout_stderr
@@ -0,0 +1,24 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to give assets a human name
+ASSET_IDENTIFIER: "forecast"
+Asset identifier list: "data"
+LITERAL string: "sunny with a 30% chance of weather!"
+Create from literal data: ""sunny with a 30% chance of weather!""
+Set SST command: "expect"
+Appended to end of call sequence: SST-set call.
+Set command: "expect"
+Expect nothing clause: "nothing"
+Command with expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset forecast
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c
new file mode 100644
index 0000000..e792c9b
--- /dev/null
+++ b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/exp_test.c
@@ -0,0 +1,58 @@
+/*
+ * Test purpose:
+ * to give assets a human name
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t forecast_set_data[] = "sunny with a 30% chance of weather!";
+ static uint32_t forecast_set_length = 35;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to give assets a human name");
+
+
+ /* PSA calls to test: */
+ /\* 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@@@\);
+ 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/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/template b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/template
new file mode 100644
index 0000000..7292031
--- /dev/null
+++ b/tf_fuzz/regression/000002_set_sst_name_data_expect_nothing/template
@@ -0,0 +1,2 @@
+purpose to give assets a human name;
+set sst name forecast data "sunny with a 30% chance of weather!" expect nothing;
diff --git a/tf_fuzz/regression/000003_set_sst_name_data/check.py b/tf_fuzz/regression/000003_set_sst_name_data/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000003_set_sst_name_data/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr b/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr
new file mode 100644
index 0000000..19a9bdb
--- /dev/null
+++ b/tf_fuzz/regression/000003_set_sst_name_data/exp_stdout_stderr
@@ -0,0 +1,23 @@
+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\"
+ASSET_IDENTIFIER: "jonathan"
+Asset identifier list: "data"
+LITERAL string: "I am the man"
+Create from literal data: ""I am the man""
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset jonathan
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c b/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c
new file mode 100644
index 0000000..9dc4d24
--- /dev/null
+++ b/tf_fuzz/regression/000003_set_sst_name_data/exp_test.c
@@ -0,0 +1,61 @@
+/*
+ * Test purpose:
+ * to show that TF-Fuzz can \"infer\" \"results\"
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t jonathan_set_data[] = "I am the man";
+ static uint32_t jonathan_set_length = 12;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show that TF-Fuzz can \"infer\" \"results\"");
+
+
+ /* PSA calls to test: */
+ /\* 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;
+ }
+
+
+ /* 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/tf_fuzz/regression/000003_set_sst_name_data/template b/tf_fuzz/regression/000003_set_sst_name_data/template
new file mode 100644
index 0000000..820e3ab
--- /dev/null
+++ b/tf_fuzz/regression/000003_set_sst_name_data/template
@@ -0,0 +1,2 @@
+purpose to show that TF-Fuzz can "infer" \"results\";
+set sst name jonathan data "I am the man";
diff --git a/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py b/tf_fuzz/regression/000004_set_sst_name_rand_data/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000004_set_sst_name_rand_data/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr b/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr
new file mode 100644
index 0000000..916f354
--- /dev/null
+++ b/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_stdout_stderr
@@ -0,0 +1,22 @@
+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 how to randomize data
+ASSET_IDENTIFIER: "gibberish"
+Asset identifier list: "data"
+Create from random data
+Set SST command: "*"
+Appended to end of call sequence: SST-set call.
+Set command: "*"
+Command with no expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset gibberish
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c b/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c
new file mode 100644
index 0000000..2f56e4e
--- /dev/null
+++ b/tf_fuzz/regression/000004_set_sst_name_rand_data/exp_test.c
@@ -0,0 +1,61 @@
+/*
+ * Test purpose:
+ * to show how to randomize data
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t gibberish_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t gibberish_set_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show how to randomize data");
+
+
+ /* PSA calls to test: */
+ /\* 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;
+ }
+
+
+ /* 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/tf_fuzz/regression/000004_set_sst_name_rand_data/template b/tf_fuzz/regression/000004_set_sst_name_rand_data/template
new file mode 100644
index 0000000..912c23a
--- /dev/null
+++ b/tf_fuzz/regression/000004_set_sst_name_rand_data/template
@@ -0,0 +1,2 @@
+purpose to show how to randomize data;
+set sst name gibberish data *;
diff --git a/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr
new file mode 100644
index 0000000..5ead6c6
--- /dev/null
+++ b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_stdout_stderr
@@ -0,0 +1,21 @@
+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 how to randomize name and data
+Asset random identifier: "*"
+Create from random data
+Set SST command: "*"
+Appended to end of call sequence: SST-set call.
+Set command: "*"
+Command with no expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset [a-z]+
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c
new file mode 100644
index 0000000..288cb19
--- /dev/null
+++ b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/exp_test.c
@@ -0,0 +1,61 @@
+/*
+ * Test purpose:
+ * to show how to randomize name and data
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t @@@003@@@_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t @@@003@@@_set_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show how to randomize name and data");
+
+
+ /* PSA calls to test: */
+ /\* 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;
+ }
+
+
+ /* 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/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/template b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/template
new file mode 100644
index 0000000..5290f27
--- /dev/null
+++ b/tf_fuzz/regression/000005_set_sst_rand_name_rand_data/template
@@ -0,0 +1,2 @@
+purpose to show how to randomize name and data;
+set sst name * data *;
diff --git a/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr
new file mode 100644
index 0000000..4e76308
--- /dev/null
+++ b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_stdout_stderr
@@ -0,0 +1,34 @@
+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 a nice party trick
+ASSET_IDENTIFIER: "john"
+ASSET_IDENTIFIER: "paul"
+ASSET_IDENTIFIER: "george"
+ASSET_IDENTIFIER: "and"
+ASSET_IDENTIFIER: "ringo"
+Asset identifier list: "data"
+Create from random data
+Set SST command: "*"
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Set command: "*"
+Command with no expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset john
+ SST-set call for asset paul
+ SST-set call for asset george
+ SST-set call for asset and
+ SST-set call for asset ringo
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c
new file mode 100644
index 0000000..84026ac
--- /dev/null
+++ b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/exp_test.c
@@ -0,0 +1,117 @@
+/*
+ * Test purpose:
+ * to show a nice party trick
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ 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+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show a nice party trick");
+
+
+ /* PSA calls to test: */
+ /\* 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_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_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_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_set_length, ringo_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\(@@@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;
+ }
+ 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@@@\);
+ 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/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/template b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/template
new file mode 100644
index 0000000..2e86d75
--- /dev/null
+++ b/tf_fuzz/regression/000006_set_sst_multi_name_rand_data/template
@@ -0,0 +1,2 @@
+purpose to show a nice party trick;
+set sst name john paul george and ringo data *;
diff --git a/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr
new file mode 100644
index 0000000..5e9e362
--- /dev/null
+++ b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_stdout_stderr
@@ -0,0 +1,37 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: same with UIDs
+ASSET_NUMBER: "17"
+ASSET_NUMBER: "19"
+ASSET_NUMBER: "24"
+ASSET_NUMBER: "31"
+ASSET_NUMBER: "34"
+ASSET_NUMBER: "41"
+SST-asset UID list: "data"
+Create from random data
+Set SST command: "*"
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Appended to end of call sequence: SST-set call.
+Set command: "*"
+Command with no expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset SST_ID_17
+ SST-set call for asset SST_ID_19
+ SST-set call for asset SST_ID_24
+ SST-set call for asset SST_ID_31
+ SST-set call for asset SST_ID_34
+ SST-set call for asset SST_ID_41
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c
new file mode 100644
index 0000000..02055e8
--- /dev/null
+++ b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/exp_test.c
@@ -0,0 +1,131 @@
+/*
+ * Test purpose:
+ * same with UIDs
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ 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+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test same with UIDs");
+
+
+ /* PSA calls to test: */
+ /\* 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_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_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_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_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_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;
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove(17);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove(19);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove(24);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove(31);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove(34);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion.");
+ return;
+ }
+ psa_ps_remove(41);
+ 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/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/template b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/template
new file mode 100644
index 0000000..903027e
--- /dev/null
+++ b/tf_fuzz/regression/000007_set_sst_multi_uid_rand_data/template
@@ -0,0 +1,2 @@
+purpose same with UIDs;
+set sst uid 17 19 24 31 34 41 data *;
diff --git a/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr
new file mode 100644
index 0000000..a138dc4
--- /dev/null
+++ b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_stdout_stderr
@@ -0,0 +1,34 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to create and show an asset
+ASSET_IDENTIFIER: "snortwaggle"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "snortwaggle"
+Asset identifier list: "check"
+LITERAL string: "almost certainly not *this*"
+Read check against literal: "almost certainly not *this*"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+Lines: Line number 4.
+Lines: Line number 4.
+Lines: Line number 4.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset snortwaggle
+ SST-get call for asset snortwaggle
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c
new file mode 100644
index 0000000..5f8486c
--- /dev/null
+++ b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/exp_test.c
@@ -0,0 +1,76 @@
+/*
+ * Test purpose:
+ * to create and show an 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ 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\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t snortwaggle_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to create and show an asset");
+
+
+ /* PSA calls to test: */
+ /\* 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, @@@003@@@, snortwaggle_act_data
+ &snortwaggle_act_length);
+ if (sst_status == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ return;
+ }
+ /* Check that the data is correct */
+ 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@@@\);
+ 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/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/template b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/template
new file mode 100644
index 0000000..03b22d9
--- /dev/null
+++ b/tf_fuzz/regression/000008_set_sst_name_rand_data_read_check_wrong/template
@@ -0,0 +1,3 @@
+purpose to create and show an asset;
+set sst name snortwaggle data *;
+read sst name snortwaggle check "almost certainly not *this*" expect fail;
diff --git a/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr
new file mode 100644
index 0000000..844cb17
--- /dev/null
+++ b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_stdout_stderr
@@ -0,0 +1,44 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to check against a variable or dump into the log
+ASSET_IDENTIFIER: "greebledorf"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "greebledorf"
+Asset identifier list: "chk"
+IDENTIFIER: "a_variable"
+Read-arguments variable name: "a_variable"
+Read check against variable: "a_variable"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "greebledorf"
+Asset identifier list: "print"
+Read log to test log: "print"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+Command with no expect: ";"
+Lines: Line number 5.
+Lines: Line number 5.
+Lines: Line number 5.
+Lines: Line number 5.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset greebledorf
+ SST-get call for asset greebledorf
+ SST-get call for asset greebledorf
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c
new file mode 100644
index 0000000..f745c1f
--- /dev/null
+++ b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/exp_test.c
@@ -0,0 +1,83 @@
+/*
+ * Test purpose:
+ * to check against a variable or dump into the log
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ 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 uint8_t greebledorf_act_data\[2048\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t greebledorf_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to check against a variable or dump into the log");
+
+
+ /* PSA calls to test: */
+ /\* 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, \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_data,
+ greebledorf_act_length) != 0) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+ 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;
+ }
+ TEST_LOG\(\"greebledorf_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/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template
new file mode 100644
index 0000000..a1a4d61
--- /dev/null
+++ b/tf_fuzz/regression/000009_set_sst_name_rand_data_read_check_var_read_print/template
@@ -0,0 +1,4 @@
+purpose to check against a variable or dump into the log;
+set sst name greebledorf data *;
+read sst name greebledorf chk a_variable;
+read sst name greebledorf print;
diff --git a/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr
new file mode 100644
index 0000000..b8316fc
--- /dev/null
+++ b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_stdout_stderr
@@ -0,0 +1,24 @@
+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 what happens when you 'read' a non-existent asset
+ASSET_IDENTIFIER: "napoleon"
+Asset identifier list: "check"
+LITERAL string: "this won't work"
+Read check against literal: "this won't work"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+Command with no expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-get call for asset napoleon
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c
new file mode 100644
index 0000000..2048a69
--- /dev/null
+++ b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/exp_test.c
@@ -0,0 +1,62 @@
+/*
+ * Test purpose:
+ * to show what happens when you 'read' a non-existent 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show what happens when you 'read' a non-existent asset");
+
+
+ /* PSA calls to test: */
+ 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,
+ napoleon_act_length\) != 0\) {
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/template b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/template
new file mode 100644
index 0000000..3e70099
--- /dev/null
+++ b/tf_fuzz/regression/000010_read_nonexistent_sst_check_string/template
@@ -0,0 +1,2 @@
+purpose to show what happens when you 'read' a non-existent asset;
+read sst name napoleon check "this won't work";
diff --git a/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_stdout_stderr
new file mode 100644
index 0000000..2a7d593
--- /dev/null
+++ b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/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 illustrate that you can override TF-Fuzz's expected result
+ASSET_IDENTIFIER: "napoleon"
+Asset identifier list: "chk"
+LITERAL string: "this won't work"
+Read check against literal: "this won't work"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect pass clause: "pass"
+Command with expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-get call for asset napoleon
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c
new file mode 100644
index 0000000..d5d3e40
--- /dev/null
+++ b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/exp_test.c
@@ -0,0 +1,62 @@
+/*
+ * Test purpose:
+ * to illustrate that you can override TF-Fuzz's expected result
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to illustrate that you can override TF-Fuzz's expected result");
+
+
+ /* PSA calls to test: */
+ 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,
+ napoleon_act_length\) != 0\) \{
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/template b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/template
new file mode 100644
index 0000000..6372bad
--- /dev/null
+++ b/tf_fuzz/regression/000011_read_nonexistent_sst_check_string_expect_pass/template
@@ -0,0 +1,2 @@
+purpose to illustrate that you can override TF-Fuzz's expected result;
+read sst name napoleon chk "this won't work" expect pass;
diff --git a/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr
new file mode 100644
index 0000000..44bc211
--- /dev/null
+++ b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_stdout_stderr
@@ -0,0 +1,26 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to more-specifically override TF-Fuzz's expected result
+ASSET_IDENTIFIER: "napoleon"
+Asset identifier list: "check"
+LITERAL string: "this won't work"
+Read check against literal: "this won't work"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+IDENTIFIER: "PSA_ERROR_GENERIC_ERROR"
+Expect error clause: "PSA_ERROR_GENERIC_ERROR"
+Command with expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-get call for asset napoleon
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c
new file mode 100644
index 0000000..359dd8a
--- /dev/null
+++ b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/exp_test.c
@@ -0,0 +1,62 @@
+/*
+ * Test purpose:
+ * to more-specifically override TF-Fuzz's expected result
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to more-specifically override TF-Fuzz's expected result");
+
+
+ /* PSA calls to test: */
+ 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,
+ napoleon_act_length\) != 0\) \{
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/template b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/template
new file mode 100644
index 0000000..c7825c5
--- /dev/null
+++ b/tf_fuzz/regression/000012_read_nonexistent_sst_check_string_expect_other/template
@@ -0,0 +1,2 @@
+purpose to more-specifically override TF-Fuzz's expected result;
+read sst name napoleon check "this won't work" expect PSA_ERROR_GENERIC_ERROR;
diff --git a/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr
new file mode 100644
index 0000000..f10b04d
--- /dev/null
+++ b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_stdout_stderr
@@ -0,0 +1,38 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to illustrate deleting assets
+ASSET_IDENTIFIER: "george"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "george"
+Asset identifier list: ";"
+Remove SST command: ";"
+Appended to end of call sequence: SST-remove call.
+Remove command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "george"
+Asset identifier list: ";"
+Remove SST command: ";"
+Appended to end of call sequence: SST-remove call.
+Remove command: ";"
+Command with no expect: ";"
+Lines: Line number 5.
+Lines: Line number 5.
+Lines: Line number 5.
+Lines: Line number 5.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset george
+ SST-remove call for asset george
+ SST-remove call for asset george
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c
new file mode 100644
index 0000000..efc6bf1
--- /dev/null
+++ b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/exp_test.c
@@ -0,0 +1,66 @@
+/*
+ * Test purpose:
+ * to illustrate deleting assets
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t george_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t george_set_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to illustrate deleting assets");
+
+
+ /* PSA calls to test: */
+ /\* 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@@@\);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_remove() expected PSA_SUCCESS.");
+ return;
+ }
+ 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;
+ }
+
+
+ /* Removing assets left over from testing: */
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/template b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/template
new file mode 100644
index 0000000..7edb72e
--- /dev/null
+++ b/tf_fuzz/regression/000013_set_sst_name_rand_data_remove_twice/template
@@ -0,0 +1,4 @@
+purpose to illustrate deleting assets;
+set sst name george data *;
+remove sst name george;
+rm sst name george;
diff --git a/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr
new file mode 100644
index 0000000..1c447b7
--- /dev/null
+++ b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_stdout_stderr
@@ -0,0 +1,30 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to remove something that doesn't exist
+ASSET_IDENTIFIER: "george"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "ringo"
+Asset identifier list: ";"
+Remove SST command: ";"
+Appended to end of call sequence: SST-remove call.
+Remove command: ";"
+Command with no expect: ";"
+Lines: Line number 4.
+Lines: Line number 4.
+Lines: Line number 4.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset george
+ SST-remove call for asset ringo
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c
new file mode 100644
index 0000000..85d51bb
--- /dev/null
+++ b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/exp_test.c
@@ -0,0 +1,66 @@
+/*
+ * Test purpose:
+ * to remove something that doesn't exist
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t george_set_data\[\] = "@@002@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t george_set_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to remove something that doesn't exist");
+
+
+ /* PSA calls to test: */
+ /\* 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\(\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@@@\);
+ 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/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/template b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/template
new file mode 100644
index 0000000..5b9485c
--- /dev/null
+++ b/tf_fuzz/regression/000014_set_sst_name_rand_data_remove_other/template
@@ -0,0 +1,3 @@
+purpose to remove something that doesn't exist;
+set sst name george data *;
+remove sst name ringo;
diff --git a/tf_fuzz/regression/000015_set_sst_name_only/check.py b/tf_fuzz/regression/000015_set_sst_name_only/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr b/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr
new file mode 100644
index 0000000..318a125
--- /dev/null
+++ b/tf_fuzz/regression/000015_set_sst_name_only/exp_stdout_stderr
@@ -0,0 +1,30 @@
+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"
+Asset identifier list: ";"
+SST-create from random data (no 'data *')
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+Asset random identifier: "*"
+SST-create from random data (no 'data *')
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+Lines: Line number 4.
+Lines: Line number 4.
+Lines: Line number 4.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset random
+ SST-set call for asset [a-z]+
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c b/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c
new file mode 100644
index 0000000..900d9e2
--- /dev/null
+++ b/tf_fuzz/regression/000015_set_sst_name_only/exp_test.c
@@ -0,0 +1,75 @@
+/*
+ * 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ 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");
+
+
+ /* 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/tf_fuzz/regression/000015_set_sst_name_only/template b/tf_fuzz/regression/000015_set_sst_name_only/template
new file mode 100644
index 0000000..63220db
--- /dev/null
+++ b/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/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/check.py b/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr b/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr
new file mode 100644
index 0000000..a85de7d
--- /dev/null
+++ b/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_stdout_stderr
@@ -0,0 +1,66 @@
+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"
+Asset identifier list: "data"
+LITERAL string: "First value"
+Create from literal data: ""First value""
+SST no storage flag: none"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+LITERAL string: "Second value"
+Create from literal data: ""Second value""
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+LITERAL string: "Fourth value"
+Create from literal data: ""Fourth value""
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+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...
+Call sequence:
+ SST-set call for asset indecisive
+ SST-set call for asset indecisive
+ SST-set call for asset indecisive
+ SST-set call for asset indecisive
+ SST-set call for asset indecisive
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c b/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c
new file mode 100644
index 0000000..224c85c
--- /dev/null
+++ b/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/exp_test.c
@@ -0,0 +1,97 @@
+/*
+ * 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ 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");
+
+
+ /* 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/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/template b/tf_fuzz/regression/000016_set_sst_single_asset_set_multiple_times/template
new file mode 100644
index 0000000..0127a29
--- /dev/null
+++ b/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" flag none;
+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/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/check.py b/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr b/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr
new file mode 100644
index 0000000..990480d
--- /dev/null
+++ b/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_stdout_stderr
@@ -0,0 +1,68 @@
+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"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+Asset identifier list: "check"
+LITERAL string: "Not this"
+Read check against literal: "Not this"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+Asset identifier list: "check"
+LITERAL string: "Not this either"
+Read check against literal: "Not this either"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+Asset identifier list: "check"
+LITERAL string: "No dice on this either"
+Read check against literal: "No dice on this either"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "just_checking"
+Asset identifier list: "print"
+Read log to test log: "print"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+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...
+Call sequence:
+ SST-set call for asset just_checking
+ SST-get call for asset just_checking
+ SST-get call for asset just_checking
+ SST-get call for asset just_checking
+ SST-get call for asset just_checking
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c b/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c
new file mode 100644
index 0000000..aa333ab
--- /dev/null
+++ b/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/exp_test.c
@@ -0,0 +1,109 @@
+/*
+ * 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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";
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ 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");
+
+
+ /* 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 == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ 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 == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ 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 == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ 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/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/template b/tf_fuzz/regression/000017_read_sst_check_single_asset_multiple_times/template
new file mode 100644
index 0000000..9f10122
--- /dev/null
+++ b/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/tf_fuzz/regression/000018_000016_and_000017/check.py b/tf_fuzz/regression/000018_000016_and_000017/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr b/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr
new file mode 100644
index 0000000..e9fad8a
--- /dev/null
+++ b/tf_fuzz/regression/000018_000016_and_000017/exp_stdout_stderr
@@ -0,0 +1,121 @@
+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"
+Asset identifier list: "data"
+LITERAL string: "First value"
+Create from literal data: ""First value""
+SST no storage flag: none"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "check"
+LITERAL string: "Not this"
+Read check against literal: "Not this"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+LITERAL string: "Second value"
+Create from literal data: ""Second value""
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "check"
+LITERAL string: "Not this either"
+Read check against literal: "Not this either"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+LITERAL string: "Fourth value"
+Create from literal data: ""Fourth value""
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "check"
+LITERAL string: "No dice on this either"
+Read check against literal: "No dice on this either"
+SST-read arguments: expect"
+Read SST command: "expect"
+Appended to end of call sequence: SST-get call.
+Read command: "expect"
+Expect fail clause: "fail"
+Command with expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "indecisive"
+Asset identifier list: "print"
+Read log to test log: "print"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+Command with no expect: ";"
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Lines: Line number 12.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset indecisive
+ SST-get call for asset indecisive
+ SST-set call for asset indecisive
+ SST-get call for asset indecisive
+ SST-set call for asset indecisive
+ SST-set call for asset indecisive
+ SST-get call for asset indecisive
+ SST-set call for asset indecisive
+ SST-set call for asset indecisive
+ SST-get call for asset indecisive
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000018_000016_and_000017/exp_test.c b/tf_fuzz/regression/000018_000016_and_000017/exp_test.c
new file mode 100644
index 0000000..ca1ba06
--- /dev/null
+++ b/tf_fuzz/regression/000018_000016_and_000017/exp_test.c
@@ -0,0 +1,154 @@
+/*
+ * 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ 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");
+
+
+ /* 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_NONE);
+ 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 == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ 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_NONE);
+ 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 == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ 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_NONE);
+ 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_NONE);
+ 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 == PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected not PSA_SUCCESS.");
+ 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_NONE);
+ 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_NONE);
+ 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/tf_fuzz/regression/000018_000016_and_000017/template b/tf_fuzz/regression/000018_000016_and_000017/template
new file mode 100644
index 0000000..662a252
--- /dev/null
+++ b/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" flag none;
+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/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/check.py b/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/check.py
new file mode 100644
index 0000000..1bc5cbe
--- /dev/null
+++ b/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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr b/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr
new file mode 100644
index 0000000..ca4b2ed
--- /dev/null
+++ b/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_stdout_stderr
@@ -0,0 +1,76 @@
+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"
+Asset identifier list: ";"
+SST-create from random data (no 'data *')
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "source"
+Asset identifier list: "var"
+IDENTIFIER: "transfer"
+Read dump to variable: "transfer"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "intermediate"
+Asset identifier list: "var"
+IDENTIFIER: "transfer"
+SST-set set from variable: "transfer"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "intermediate"
+Asset identifier list: "var"
+IDENTIFIER: "transfer"
+Read dump to variable: "transfer"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "destination"
+Asset identifier list: "var"
+IDENTIFIER: "transfer"
+SST-set set from variable: "transfer"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "destination"
+Asset identifier list: "check"
+IDENTIFIER: "transfer"
+Read-arguments variable name: "transfer"
+Read check against variable: "transfer"
+SST-read arguments: ;"
+Read SST command: ";"
+Appended to end of call sequence: SST-get call.
+Read command: ";"
+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...
+Call sequence:
+ SST-set call for asset source
+ SST-get call for asset source
+ SST-set call for asset intermediate
+ SST-get call for asset intermediate
+ SST-set call for asset destination
+ SST-get call for asset destination
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c b/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c
new file mode 100644
index 0000000..6131299
--- /dev/null
+++ b/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/exp_test.c
@@ -0,0 +1,127 @@
+/*
+ * 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ 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");
+
+
+ /* 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_data,
+ 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/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/template b/tf_fuzz/regression/000019_read_asset_to_variable_set_other_asset/template
new file mode 100644
index 0000000..0111ba2
--- /dev/null
+++ b/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/tf_fuzz/regression/000020_no_purpose/check.py b/tf_fuzz/regression/000020_no_purpose/check.py
new file mode 100644
index 0000000..2027be8
--- /dev/null
+++ b/tf_fuzz/regression/000020_no_purpose/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019-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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000020_no_purpose/exp_stdout_stderr b/tf_fuzz/regression/000020_no_purpose/exp_stdout_stderr
new file mode 100644
index 0000000..3a87ce6
--- /dev/null
+++ b/tf_fuzz/regression/000020_no_purpose/exp_stdout_stderr
@@ -0,0 +1,17 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+ASSET_NUMBER: "104"
+SST-asset UID list: "data"
+LITERAL string: "Very simple test"
+Create from literal data: ""Very simple test""
+Set SST command: "expect"
+Appended to end of call sequence: SST-set call.
+Set command: "expect"
+Expect pass clause: "pass"
+Command with expect: "
+
+Error: Please begin your test with the "purpose" directive.
+ For example, "purpose to exercise crypto and SST..."
diff --git a/tf_fuzz/regression/000020_no_purpose/exp_test.c b/tf_fuzz/regression/000020_no_purpose/exp_test.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tf_fuzz/regression/000020_no_purpose/exp_test.c
diff --git a/tf_fuzz/regression/000020_no_purpose/template b/tf_fuzz/regression/000020_no_purpose/template
new file mode 100644
index 0000000..7b7fd92
--- /dev/null
+++ b/tf_fuzz/regression/000020_no_purpose/template
@@ -0,0 +1,2 @@
+// purpose to make sure it complains if you don't provide a purpose
+set sst uid 104 data "Very simple test" expect pass;
diff --git a/tf_fuzz/regression/000021_abbreviated_result_codes/check.py b/tf_fuzz/regression/000021_abbreviated_result_codes/check.py
new file mode 100644
index 0000000..2027be8
--- /dev/null
+++ b/tf_fuzz/regression/000021_abbreviated_result_codes/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019-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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000021_abbreviated_result_codes/exp_stdout_stderr b/tf_fuzz/regression/000021_abbreviated_result_codes/exp_stdout_stderr
new file mode 100644
index 0000000..c4af682
--- /dev/null
+++ b/tf_fuzz/regression/000021_abbreviated_result_codes/exp_stdout_stderr
@@ -0,0 +1,26 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to more-specifically override TF-Fuzz's expected result
+ASSET_IDENTIFIER: "napoleon"
+Asset identifier list: "chk"
+LITERAL string: "this won't work"
+Read check against literal: "this won't work"
+SST-read arguments: exp"
+Read SST command: "exp"
+Appended to end of call sequence: SST-get call.
+Read command: "exp"
+IDENTIFIER: "generic_error"
+Expect error clause: "generic_error"
+Command with expect: ";"
+Lines: Line number 3.
+Lines: Line number 3.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-get call for asset napoleon
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000021_abbreviated_result_codes/exp_test.c b/tf_fuzz/regression/000021_abbreviated_result_codes/exp_test.c
new file mode 100644
index 0000000..359dd8a
--- /dev/null
+++ b/tf_fuzz/regression/000021_abbreviated_result_codes/exp_test.c
@@ -0,0 +1,62 @@
+/*
+ * Test purpose:
+ * to more-specifically override TF-Fuzz's expected result
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* 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\] = "[A-Z][a-z ]*[\.\?\!]";
+ static size_t napoleon_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to more-specifically override TF-Fuzz's expected result");
+
+
+ /* PSA calls to test: */
+ 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,
+ napoleon_act_length\) != 0\) \{
+ TEST_FAIL("Read data should be equal to result data");
+ return;
+ }
+
+
+ /* Removing assets left over from testing: */
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/000021_abbreviated_result_codes/template b/tf_fuzz/regression/000021_abbreviated_result_codes/template
new file mode 100644
index 0000000..67b05b3
--- /dev/null
+++ b/tf_fuzz/regression/000021_abbreviated_result_codes/template
@@ -0,0 +1,2 @@
+purpose to more-specifically override TF-Fuzz's expected result;
+read sst name napoleon chk "this won't work" exp generic_error;
diff --git a/tf_fuzz/regression/000022_SST_offset/check.py b/tf_fuzz/regression/000022_SST_offset/check.py
new file mode 100644
index 0000000..2027be8
--- /dev/null
+++ b/tf_fuzz/regression/000022_SST_offset/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019-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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000022_SST_offset/exp_stdout_stderr b/tf_fuzz/regression/000022_SST_offset/exp_stdout_stderr
new file mode 100644
index 0000000..c9d1a0f
--- /dev/null
+++ b/tf_fuzz/regression/000022_SST_offset/exp_stdout_stderr
@@ -0,0 +1,35 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to set an offset on psa_ps_get()
+ASSET_IDENTIFIER: "whoNose"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "whoNose"
+Asset identifier list: "print"
+Read log to test log: "print"
+SST-data offset: "10"
+SST data offset
+10"
+SST-read arguments: 10"
+Read SST command: "10"
+Appended to end of call sequence: SST-get call.
+Read command: "10"
+Command with no expect: ";"
+Lines: Line number 4.
+Lines: Line number 4.
+Lines: Line number 4.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset whoNose
+ SST-get call for asset whoNose
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000022_SST_offset/exp_test.c b/tf_fuzz/regression/000022_SST_offset/exp_test.c
new file mode 100644
index 0000000..03523dc
--- /dev/null
+++ b/tf_fuzz/regression/000022_SST_offset/exp_test.c
@@ -0,0 +1,70 @@
+/*
+ * Test purpose:
+ * to set an offset on psa_ps_get()
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t whoNose_set_data\[\] = "@@012@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t whoNose_set_length = \d+;
+ static uint8_t whoNose_act_data\[2048\] = "[A-Z][a-z\ ]*[\.\?\!]";
+ static size_t whoNose_act_length = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to set an offset on psa_ps_get()");
+
+
+ /* PSA calls to test: */
+ /\* Creating SST asset "whoNose," with data "@@012@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, whoNose_set_length, whoNose_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@@@, 10, \d+, whoNose_act_data,
+ &whoNose_act_length);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_get() expected PSA_SUCCESS.");
+ return;
+ }
+ TEST_LOG\(\"whoNose_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/tf_fuzz/regression/000022_SST_offset/template b/tf_fuzz/regression/000022_SST_offset/template
new file mode 100644
index 0000000..9fa46e9
--- /dev/null
+++ b/tf_fuzz/regression/000022_SST_offset/template
@@ -0,0 +1,3 @@
+purpose to set an offset on psa_ps_get();
+set sst name whoNose data *;
+read sst name whoNose print offset 10;
diff --git a/tf_fuzz/regression/000023_SST_creation_flags/check.py b/tf_fuzz/regression/000023_SST_creation_flags/check.py
new file mode 100644
index 0000000..2027be8
--- /dev/null
+++ b/tf_fuzz/regression/000023_SST_creation_flags/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019-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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000023_SST_creation_flags/exp_stdout_stderr b/tf_fuzz/regression/000023_SST_creation_flags/exp_stdout_stderr
new file mode 100644
index 0000000..2b6ab80
--- /dev/null
+++ b/tf_fuzz/regression/000023_SST_creation_flags/exp_stdout_stderr
@@ -0,0 +1,89 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to set SST creation flags
+ASSET_IDENTIFIER: "hasCF"
+Asset identifier list: "data"
+LITERAL string: "this asset has write-once"
+Create from literal data: ""this asset has write-once""
+SST write-once flag: write_once"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "hasCF2"
+Asset identifier list: "data"
+LITERAL string: "this asset has also write-once"
+Create from literal data: ""this asset has also write-once""
+SST write-once flag: wo"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "alsoHasCF"
+Asset identifier list: "data"
+LITERAL string: "this asset has no flags"
+Create from literal data: ""this asset has no flags""
+SST no storage flag: none"
+SST creation flag
+expect"
+SST creation flags
+expect"
+Set SST command: "expect"
+Appended to end of call sequence: SST-set call.
+Set command: "expect"
+Expect pass clause: "pass"
+Command with expect: ";"
+ASSET_IDENTIFIER: "alsoHasCF2"
+Asset identifier list: "data"
+LITERAL string: "this asset has NO_CONFIDENTIALITY"
+Create from literal data: ""this asset has NO_CONFIDENTIALITY""
+SST no-confidentiality flag: ncf"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "yetAnother"
+Asset identifier list: "data"
+LITERAL string: "this asset has NO_REPLAY_PROTECTION"
+Create from literal data: ""this asset has NO_REPLAY_PROTECTION""
+SST no-replay-protection flag: nrp"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+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...
+Call sequence:
+ SST-set call for asset hasCF
+ SST-set call for asset hasCF2
+ SST-set call for asset alsoHasCF
+ SST-set call for asset alsoHasCF2
+ SST-set call for asset yetAnother
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000023_SST_creation_flags/exp_test.c b/tf_fuzz/regression/000023_SST_creation_flags/exp_test.c
new file mode 100644
index 0000000..9dbe4cf
--- /dev/null
+++ b/tf_fuzz/regression/000023_SST_creation_flags/exp_test.c
@@ -0,0 +1,117 @@
+/*
+ * Test purpose:
+ * to set SST creation flags
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t hasCF_set_data[] = "this asset has write-once";
+ static uint32_t hasCF_set_length = 25;
+ static uint8_t hasCF2_set_data[] = "this asset has also write-once";
+ static uint32_t hasCF2_set_length = 30;
+ static uint8_t alsoHasCF_set_data[] = "this asset has no flags";
+ static uint32_t alsoHasCF_set_length = 23;
+ static uint8_t alsoHasCF2_set_data[] = "this asset has NO_CONFIDENTIALITY";
+ static uint32_t alsoHasCF2_set_length = 33;
+ static uint8_t yetAnother_set_data[] = "this asset has NO_REPLAY_PROTECTION";
+ static uint32_t yetAnother_set_length = 35;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to set SST creation flags");
+
+
+ /* PSA calls to test: */
+ /* Creating SST asset "hasCF," with data "this asset...". */
+ sst_status = psa_ps_set\(@@@001@@@, hasCF_set_length, hasCF_set_data,
+ PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Creating SST asset "hasCF2," with data "this asset...". */
+ sst_status = psa_ps_set\(@@@002@@@, hasCF2_set_length, hasCF2_set_data,
+ PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Creating SST asset "alsoHasCF," with data "this asset...". */
+ sst_status = psa_ps_set\(@@@003@@@, alsoHasCF_set_length, alsoHasCF_set_data,
+ PSA_STORAGE_FLAG_NONE);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Creating SST asset "alsoHasCF2," with data "this asset...". */
+ sst_status = psa_ps_set\(@@@004@@@, alsoHasCF2_set_length, alsoHasCF2_set_data,
+ PSA_STORAGE_FLAG_NO_CONFIDENTIALITY);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+ /* Creating SST asset "yetAnother," with data "this asset...". */
+ sst_status = psa_ps_set\(@@@005@@@, yetAnother_set_length, yetAnother_set_data,
+ PSA_STORAGE_FLAG_NO_REPLAY_PROTECTION);
+ 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\(@@@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;
+ }
+ 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@@@\);
+ 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/tf_fuzz/regression/000023_SST_creation_flags/template b/tf_fuzz/regression/000023_SST_creation_flags/template
new file mode 100644
index 0000000..5cfa287
--- /dev/null
+++ b/tf_fuzz/regression/000023_SST_creation_flags/template
@@ -0,0 +1,6 @@
+purpose to set SST creation flags;
+set sst name hasCF data "this asset has write-once" flag write_once;
+set sst name hasCF2 data "this asset has also write-once" flag wo;
+set sst name alsoHasCF data "this asset has no flags" flag none expect pass;
+set sst name alsoHasCF2 data "this asset has NO_CONFIDENTIALITY" flag ncf;
+set sst name yetAnother data "this asset has NO_REPLAY_PROTECTION" flag nrp;
diff --git a/tf_fuzz/regression/000024_SST_write_once/check.py b/tf_fuzz/regression/000024_SST_write_once/check.py
new file mode 100644
index 0000000..2027be8
--- /dev/null
+++ b/tf_fuzz/regression/000024_SST_write_once/check.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019-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 ("\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 )
+ 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 )
+
+ # Ran to completion normally, so pass:
+ if not ultra_quiet: print ("Regression test passed.")
+ sys.exit(0)
+
+if __name__ == "__main__": main()
diff --git a/tf_fuzz/regression/000024_SST_write_once/exp_stdout_stderr b/tf_fuzz/regression/000024_SST_write_once/exp_stdout_stderr
new file mode 100644
index 0000000..2273c23
--- /dev/null
+++ b/tf_fuzz/regression/000024_SST_write_once/exp_stdout_stderr
@@ -0,0 +1,45 @@
+Trusted Firmware Fuzzer (TF-Fuzz) starting...
+
+Info: random seed was not specified.
+
+Using seed value of \d+ \(0x[a-f\d]+\).
+Purpose line: to verify we can't write multiple times to a write-once SST asset
+ASSET_IDENTIFIER: "writeOnce"
+Asset identifier list: "data"
+Create from random data
+SST write-once flag: wo"
+SST creation flag
+;"
+SST creation flags
+;"
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "writeOnce"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+ASSET_IDENTIFIER: "writeOnce"
+Asset identifier list: "data"
+Create from random data
+Set SST command: ";"
+Appended to end of call sequence: SST-set call.
+Set command: ";"
+Command with no expect: ";"
+Lines: Line number 5.
+Lines: Line number 5.
+Lines: Line number 5.
+Lines: Line number 5.
+Call sequence generated.
+Simulating call sequence...
+Call sequence:
+ SST-set call for asset writeOnce
+ SST-set call for asset writeOnce
+ SST-set call for asset writeOnce
+Writing test file, ./test.c.
+
+TF-Fuzz test generation complete.
diff --git a/tf_fuzz/regression/000024_SST_write_once/exp_test.c b/tf_fuzz/regression/000024_SST_write_once/exp_test.c
new file mode 100644
index 0000000..02d0530
--- /dev/null
+++ b/tf_fuzz/regression/000024_SST_write_once/exp_test.c
@@ -0,0 +1,79 @@
+/*
+ * Test purpose:
+ * to verify we can't write multiple times to a write-once SST 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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.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;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ static uint8_t writeOnce_set_data\[\] = "@@012@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t writeOnce_set_length = \d+;
+ static uint8_t writeOnce_set_data_1\[\] = "@@013@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t writeOnce_set_length_1 = \d+;
+ static uint8_t writeOnce_set_data_2\[\] = "@@014@10@@[a-z\ ]*[\.\?\!]";
+ static uint32_t writeOnce_set_length_2 = \d+;
+ (void)sst_status;
+ /* "void" to prevent unused-variable warning, since the variable may not
+ * be used in this particular test case.
+ */
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to verify we can't write multiple times to a write-once SST asset");
+
+
+ /* PSA calls to test: */
+ /\* Creating SST asset "writeOnce," with data "@@012@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, writeOnce_set_length, writeOnce_set_data,
+ PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (sst_status != PSA_SUCCESS) {
+ TEST_FAIL("psa_ps_set() expected PSA_SUCCESS.");
+ return;
+ }
+ /\* Resetting SST asset "writeOnce," with data "@@013@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, writeOnce_set_length_1, writeOnce_set_data_1,
+ PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (sst_status != PSA_ERROR_NOT_PERMITTED) {
+ TEST_FAIL("psa_ps_set() expected PSA_ERROR_NOT_PERMITTED.");
+ return;
+ }
+ /\* Resetting SST asset "writeOnce," with data "@@014@10@@...". \*/
+ sst_status = psa_ps_set\(@@@001@@@, writeOnce_set_length_2, writeOnce_set_data_2,
+ PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (sst_status != PSA_ERROR_NOT_PERMITTED) {
+ TEST_FAIL("psa_ps_set() expected PSA_ERROR_NOT_PERMITTED.");
+ 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/tf_fuzz/regression/000024_SST_write_once/template b/tf_fuzz/regression/000024_SST_write_once/template
new file mode 100644
index 0000000..60fc978
--- /dev/null
+++ b/tf_fuzz/regression/000024_SST_write_once/template
@@ -0,0 +1,4 @@
+purpose to verify we can't write multiple times to a write-once SST asset;
+set sst name writeOnce data * flag wo;
+set sst name writeOnce data *;
+set sst name writeOnce data *;
diff --git a/tf_fuzz/regression/README b/tf_fuzz/regression/README
new file mode 100644
index 0000000..d4fbcb6
--- /dev/null
+++ b/tf_fuzz/regression/README
@@ -0,0 +1,9 @@
+This is a regression suite for the TF-Fuzz tool.
+
+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/~regression_dir.html
+
+--------------
+
+*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
diff --git a/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr b/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr
new file mode 100644
index 0000000..3c5de35
--- /dev/null
+++ b/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_stdout_stderr
@@ -0,0 +1,30 @@
+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 a more-interesting removal case
+ASSET_IDENTIFIER: "president"
+ASSET_IDENTIFIER: "george"
+ASSET_IDENTIFIER: "herbert"
+ASSET_IDENTIFIER: "walker"
+ASSET_IDENTIFIER: "bush"
+Asset identifier list: "data"
+LITERAL string: "read my lips"
+Create from literal data: ""read my lips""
+Set SST command: ""read my lips""
+Set command: ""read my lips""
+Command with no expect: ";"
+SST-asset random active: "active"
+SST-remove arguments: "active"
+Remove SST command: "active"
+Remove command: "active"
+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/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c b/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c
new file mode 100644
index 0000000..c0eddcd
--- /dev/null
+++ b/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/exp_test.c
@@ -0,0 +1,117 @@
+/*
+ * Test purpose:
+ * to show a more-interesting removal case
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.h"
+/* For now, just a single test_result_t struct is sufficient.*/
+static struct test_result_t ret;
+
+/* 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_ps_status_t sst_status;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ 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;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show a more-interesting removal case");
+
+
+
+
+ /* PSA calls to test: */
+
+ /* Creating SST asset "president," with data "read my li...". */
+ 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_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_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_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_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;
+ }
+
+ sst_status = psa_ps_remove(5517);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("psa_ps_remove() expected PSA_PS_SUCCESS, got #%d", (int) sst_status);
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove(@@@001@@@);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion!");
+ return;
+ }
+ psa_ps_remove(4661);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion!");
+ return;
+ }
+ psa_ps_remove(3441);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion!");
+ return;
+ }
+ psa_ps_remove(5446);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion!");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/template b/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/template
new file mode 100644
index 0000000..613439e
--- /dev/null
+++ b/tf_fuzz/regression/add_these_tests/000015_set_sst_multi_name_remove_rand_active/template
@@ -0,0 +1,3 @@
+purpose to show a more-interesting removal case;
+set sst name president george herbert walker bush data "read my lips";
+remove sst *active; // remove *some* active asset
diff --git a/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr b/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr
new file mode 100644
index 0000000..bdeffb7
--- /dev/null
+++ b/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_stdout_stderr
@@ -0,0 +1,48 @@
+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 a more-interesting removal case
+ASSET_IDENTIFIER: "president"
+ASSET_IDENTIFIER: "george"
+ASSET_IDENTIFIER: "herbert"
+ASSET_IDENTIFIER: "walker"
+ASSET_IDENTIFIER: "bush"
+Asset identifier list: "data"
+LITERAL string: "no new taxes"
+Create from literal data: ""no new taxes""
+Set SST command: ""no new taxes""
+Set command: ""no new taxes""
+Command with no expect: ";"
+SST-asset random active: "active"
+SST-remove arguments: "active"
+Remove SST command: "active"
+Remove command: "active"
+Command with no expect: ";"
+SST-asset random active: "active"
+SST-remove arguments: "active"
+Remove SST command: "active"
+Remove command: "active"
+Command with no expect: ";"
+SST-asset random active: "active"
+SST-remove arguments: "active"
+Remove SST command: "active"
+Remove command: "active"
+Command with no expect: ";"
+SST-asset random deleted: "deleted"
+SST-remove arguments: "deleted"
+Remove SST command: "deleted"
+Remove command: "deleted"
+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/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c b/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c
new file mode 100644
index 0000000..c2752fb
--- /dev/null
+++ b/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/exp_test.c
@@ -0,0 +1,123 @@
+/*
+ * Test purpose:
+ * to show a more-interesting removal case
+ *
+ */
+
+#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 "tfm_memory_utils.h"
+#include "psa/crypto.h"
+#include "psa/crypto_sizes.h"
+/* For now, just a single test_result_t struct is sufficient.*/
+static struct test_result_t ret;
+
+/* 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_ps_status_t sst_status;
+ /* Variables (etc.) to initialize and check PSA assets: */
+ 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;
+
+ crypto_status = psa_crypto_init();
+ if (crypto_status != PSA_SUCCESS) {
+ TEST_FAIL("Could not initialize Crypto.");
+ return;
+ }
+
+ TEST_LOG("Test to show a more-interesting removal case");
+
+
+
+
+ /* PSA calls to test: */
+
+ /* Creating SST asset "president," with data "no new tax...". */
+ 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);
+ return;
+ }
+
+ /* Creating SST asset "george," with data "no new tax...". */
+ 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_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_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_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;
+ }
+
+ sst_status = psa_ps_remove(5517);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("psa_ps_remove() expected PSA_PS_SUCCESS, got #%d", (int) sst_status);
+ }
+
+ sst_status = psa_ps_remove(4713);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("psa_ps_remove() expected PSA_PS_SUCCESS, got #%d", (int) sst_status);
+ }
+
+ sst_status = psa_ps_remove(3441);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("psa_ps_remove() expected PSA_PS_SUCCESS, got #%d", (int) sst_status);
+ }
+
+ sst_status = psa_ps_remove(3441);
+ if (sst_status != PSA_PS_ERROR_UID_NOT_FOUND) {
+ TEST_FAIL("psa_ps_remove() expected PSA_PS_ERROR_UID_NOT_FOUND, got #%d", (int) sst_status);
+ }
+
+
+ /* Removing assets left over from testing: */
+ psa_ps_remove(4661);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion!");
+ return;
+ }
+ psa_ps_remove(5446);
+ if (sst_status != PSA_PS_SUCCESS) {
+ TEST_FAIL("Failed to tear down an SST asset upon test completion!");
+ return;
+ }
+
+ /* Test completed */
+ ret->val = TEST_PASSED;
+}
diff --git a/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/template b/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/template
new file mode 100644
index 0000000..2bf82b0
--- /dev/null
+++ b/tf_fuzz/regression/add_these_tests/000016_set_sst_multi_name_remove_multi_rand_active_remove_rand_deleted/template
@@ -0,0 +1,6 @@
+purpose to show a more-interesting removal case;
+set sst name president george herbert walker bush data "no new taxes";
+remove sst *active; // remove *some* active asset
+rm sst *active; // remove *some other* active asset
+rm sst *act; // remove *yet another* active asset
+remove sst *del; // attempt to remove some asset that's already been removed
diff --git a/tf_fuzz/regression/regress b/tf_fuzz/regression/regress
new file mode 100644
index 0000000..1a2b595
--- /dev/null
+++ b/tf_fuzz/regression/regress
@@ -0,0 +1,22 @@
+# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+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
+ 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/tf_fuzz/regression/regress_lib/line_by_line.py b/tf_fuzz/regression/regress_lib/line_by_line.py
new file mode 100644
index 0000000..f09a038
--- /dev/null
+++ b/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.")
+
+