aboutsummaryrefslogtreecommitdiff
path: root/tools/tf_fuzz/calls/psa_call.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/tf_fuzz/calls/psa_call.cpp')
-rw-r--r--tools/tf_fuzz/calls/psa_call.cpp91
1 files changed, 79 insertions, 12 deletions
diff --git a/tools/tf_fuzz/calls/psa_call.cpp b/tools/tf_fuzz/calls/psa_call.cpp
index 51060e102d..108a276fad 100644
--- a/tools/tf_fuzz/calls/psa_call.cpp
+++ b/tools/tf_fuzz/calls/psa_call.cpp
@@ -31,7 +31,7 @@ psa_call::psa_call (tf_fuzz_info *test_state, long &call_ser_no, // (construct
asset_search how_asset_found)
{
this->test_state = test_state;
- this->how_asset_found = how_asset_found;
+ this->asset_info.how_asset_found = how_asset_found;
set_data.string_specified = false;
set_data.set (""); // actual data
assign_data_var.assign (""); // name of variable assigned (dumped) to
@@ -61,7 +61,7 @@ void psa_call::write_out_command (ofstream &test_file)
void psa_call::write_out_check_code (ofstream &test_file)
{
- if (!expect.pf_nothing) {
+ if (!exp_data.pf_nothing) {
test_file << check_code;
} else {
test_file << " /* (No checks for this PSA call.) */" << endl;
@@ -84,18 +84,18 @@ void psa_call::write_out_check_code (ofstream &test_file)
so lots of room for further refinement here. */
void sst_call::calc_result_code (void)
{
- if (!expect.pf_nothing) {
- if (expect.pf_pass) {
+ if (!exp_data.pf_nothing) {
+ if (exp_data.pf_pass) {
find_replace_all ("$expect",
test_state->bplate->bplate_string[sst_pass_string],
check_code);
} else {
- if (expect.pf_specified) {
- find_replace_all ("$expect", expect.pf_result_string,
+ if (exp_data.pf_specified) {
+ find_replace_all ("$expect", exp_data.pf_result_string,
check_code);
} else {
// Figure out what the message should read:
- switch (how_asset_found) {
+ switch (asset_info.how_asset_found) {
case asset_search::found_active:
case asset_search::created_new:
find_replace_all ("$expect",
@@ -124,10 +124,70 @@ void sst_call::calc_result_code (void)
}
}
+vector<psa_asset*>::iterator sst_call::resolve_asset (bool create_asset_bool,
+ psa_asset_usage where) {
+ vector<psa_asset*>::iterator found_asset;
+ vector<psa_asset*> *asset_vector;
+ int asset_pick;
+
+ if (random_asset != psa_asset_usage::all) {
+ // != psa_asset_usage::all means to choose some known asset at random:
+ if (random_asset == psa_asset_usage::active) {
+ asset_vector = &(test_state->active_sst_asset);
+ asset_info.how_asset_found = asset_search::found_active;
+ } else if (random_asset == psa_asset_usage::deleted) {
+ asset_vector = &(test_state->deleted_sst_asset);
+ asset_info.how_asset_found = asset_search::found_deleted;
+ } else {
+ // "invalid" assets are not currently used.
+ cerr << "\nError: Tool-internal: Please report error 1101 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(1101);
+ }
+ if (asset_vector->size() > 0) {
+ /* Pick an active or deleted asset at random: */
+ asset_pick = rand() % asset_vector->size();
+ found_asset = asset_vector->begin() + asset_pick;
+ /* Copy asset information into template tracker: */
+ asset_info.id_n = (*found_asset)->asset_info.id_n;
+ asset_info.asset_ser_no
+ = (*found_asset)->asset_info.asset_ser_no;
+ } else {
+ if (random_asset == psa_asset_usage::active) {
+ cerr << "\nError: An sst call asks for a "
+ << "randomly chosen active asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1008);
+ } else if (random_asset == psa_asset_usage::deleted) {
+ cerr << "\nError: An sst call asks for a "
+ << "randomly chosen deleted asset, when none " << endl
+ << "is currently defined." << endl;
+ exit(1009);
+ } // "invalid" assets are not currently used.
+ }
+ } else {
+ // Find the asset by name:
+ asset_info.how_asset_found = test_state->find_or_create_sst_asset (
+ psa_asset_search::name, where,
+ asset_info.get_name(), 0, asset_info.asset_ser_no,
+ create_asset_bool, found_asset );
+ if ( asset_info.how_asset_found == asset_search::unsuccessful
+ || asset_info.how_asset_found == asset_search::something_wrong ) {
+ cerr << "\nError: Tool-internal: Please report error 108 to " << endl
+ << "TF-Fuzz developers."
+ << endl;
+ exit(108);
+ }
+ }
+ return found_asset;
+}
+
sst_call::sst_call (tf_fuzz_info *test_state, long &call_ser_no, // (constructor)
asset_search how_asset_found)
: psa_call(test_state, call_ser_no, how_asset_found)
{
+ asset_info.the_asset = nullptr;
return; // just to have something to pin a breakpoint onto
}
sst_call::~sst_call (void)
@@ -151,16 +211,16 @@ sst_call::~sst_call (void)
method, (starting around line 20ish). */
void crypto_call::calc_result_code (void)
{
- if (!expect.pf_nothing) {
- if (expect.pf_pass) {
+ if (!exp_data.pf_nothing) {
+ if (exp_data.pf_pass) {
find_replace_1st ("$expect", "PSA_SUCCESS", check_code);
} else {
- if (expect.pf_specified) {
- find_replace_1st ("$expect", expect.pf_result_string,
+ if (exp_data.pf_specified) {
+ find_replace_1st ("$expect", exp_data.pf_result_string,
check_code);
} else {
// Figure out what the message should read:
- switch (how_asset_found) {
+ switch (asset_info.how_asset_found) {
case asset_search::found_active:
case asset_search::created_new:
find_replace_all ("$expect", "PSA_SUCCESS",
@@ -218,6 +278,13 @@ security_call::~security_call (void)
return; // just to have something to pin a breakpoint onto
}
+// resolve_asset() doesn't do anything for security_calls, since there's no asset involved.
+vector<psa_asset*>::iterator security_call::resolve_asset (bool create_asset_bool,
+ psa_asset_usage where)
+{
+ return test_state->active_sst_asset.end(); // (anything)
+}
+
/* calc_result_code() fills in the check_code string member with the correct result
code (e.g., "PSA_SUCCESS" or whatever).