tf_fuzz: refactor expected value storage and simulation flow

Refactor the storage of expected values (expected_info), and add a
simulate function to psa_call, allowing expected value modelling and
call simulation code to be eventually combined into a single method.

* expected_info currently uses a set of mutually-exclusive boolean flags
  to model the different possible return codes. As the flags are checked
  in different orders across the code-base, failing to unset the right
  flags could cause different areas of the code to use different
  expected values.

  In this commit, an enum is used instead. This allows expected result
  checking to be performed by a single switch statement. This also makes
  checking to see if the value needs to be simulated much clearer --
  currently, this is denoted by both pf_nothing and pf_pass being false.

* Remove expected_info fields with no use.

* There is no one place where call simulation and expected error code
  modelling occurs. Expected return code modelling currently occur in
  fill_in_command and calc_result_code, and call simulation in
  copy_call_to_asset.

  The new psa_call::simulate() method is intended as the singular home
  for all call simulation code. Combining the simulation of a call's
  actions and its expected result should make modelling easier. This
  also makes expected value modelling happen in the simulation step
  only instead of in both the simulation and code-generation steps
  (fill_in_command and calc_result_code are code generation methods).

  Due to upcoming changes to the crypto simulation, moving call
  simulation code to simulate() has been left for future commits.

Change-Id: I1173164f07a3615c157845ed3abfebefde675c89
Signed-off-by: Nik Dewally <Nik.Dewally@arm.com>
diff --git a/tf_fuzz/tfz-cpp/calls/crypto_call.cpp b/tf_fuzz/tfz-cpp/calls/crypto_call.cpp
index 4ff2ce3..b800baa 100644
--- a/tf_fuzz/tfz-cpp/calls/crypto_call.cpp
+++ b/tf_fuzz/tfz-cpp/calls/crypto_call.cpp
@@ -237,7 +237,7 @@
     // (call_code already loaded by constructor)
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -280,7 +280,7 @@
     // (call_code already loaded by constructor)
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -326,7 +326,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$flag", policy.usage_string, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -373,7 +373,7 @@
                                          : "PSA_KEY_LIFETIME_VOLATILE",
                       call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -417,7 +417,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$size", to_string (policy.n_bits), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -461,7 +461,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$type", policy.key_type, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -505,7 +505,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$algorithm", policy.key_algorithm, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -548,7 +548,7 @@
     find_replace_1st ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$usage", "0", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -602,7 +602,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$life", asset_info.get_name() + "_life", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -657,7 +657,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$size", asset_info.get_name() + "_size", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -711,7 +711,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$type", asset_info.get_name() + "_type", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -765,7 +765,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$algorithm", asset_info.get_name() + "_algo", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -819,7 +819,7 @@
     find_replace_all ("$policy", asset_info.get_name(), call_code);
     find_replace_1st ("$usage", asset_info.get_name() + "_usage", call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -881,7 +881,7 @@
     find_replace_1st ("$print_usage_false_string", policy.print_usage_false_string,
                       call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -927,7 +927,7 @@
     find_replace_all ("key", asset_info.get_name(), call_code);
     find_replace_all ("$policy", policy.asset_2_name, call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -982,7 +982,7 @@
     find_replace_all ("$policy", policy.asset_2_name, call_code);
     find_replace_all ("$key", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1055,7 +1055,7 @@
     find_replace_all ("$length", to_string (policy.n_bits), call_code);
     find_replace_all ("$key", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1111,6 +1111,8 @@
     find_replace_all ("$policy", policy.asset_2_name, call_code);
     find_replace_all ("$copy", asset_info.get_name(), call_code);
 
+    // TODO:: move error code modelling code to simulate().
+
     // Calculate the expected results:
     asset_search find_result;
     vector<psa_asset*>::iterator asset;
@@ -1120,10 +1122,10 @@
         find_or_create_key_asset (psa_asset_search::name, psa_asset_usage::active,
                                   policy.asset_3_name, (uint64_t) 0, dummy,
                                   dont_create_asset, asset);
+
+
     if (find_result != asset_search::found_active) {
-        exp_data.pf_specified = true;
-        exp_data.pf_result_string = "PSA_ERROR_INVALID_ARGUMENT";
-            // TODO:  Pull this in from boilerplate file
+        exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT");
     } else {
         // See if the new policy does not exist:
         find_result = test_state->
@@ -1131,17 +1133,15 @@
                                          policy.asset_2_name, (uint64_t) 0, dummy,
                                          dont_create_asset, asset);
         if (find_result != asset_search::found_active) {
-            exp_data.pf_specified = true;
-            exp_data.pf_result_string = "PSA_ERROR_INVALID_ARGUMENT";
-                // TODO:  Pull this in from boilerplate file
+            exp_data.expect_error_code("PSA_ERROR_INVALID_ARGUMENT");
+
         } else if (!(*asset)->policy.copyable) {
             // See if the source key does not support export:
             // TODO:  Or wait, it's the original policy for the key, right?
-            exp_data.pf_specified = true;
-            exp_data.pf_result_string = "PSA_ERROR_NOT_PERMITTED";
+            exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
         }
     }
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1286,15 +1286,16 @@
     find_replace_1st ("$act_size", actual_length_var_name, call_code);
     find_replace_1st ("$length", length_var_name, call_code);
 
+    // TODO: move error checking code to simulate().
+
     // TODO:  check data?
 
     // See if the source key did not exist:
     if (!policy.exportable) {
         // See if the source key does not support export:
-        exp_data.pf_specified = true;
-        exp_data.pf_result_string = "PSA_ERROR_NOT_PERMITTED";
+        exp_data.expect_error_code("PSA_ERROR_NOT_PERMITTED");
     }
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************
@@ -1339,7 +1340,7 @@
     // (call_code already loaded by constructor)
     find_replace_all ("$key", asset_info.get_name(), call_code);
     // Calculate the expected results:
-    calc_result_code();
+    fill_in_result_code();
 }
 
 /**********************************************************************************