-
Notifications
You must be signed in to change notification settings - Fork 3k
Add a new PSA Internal Trusted Storage APIs #8730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
TESTS/psa/prot_internal_storage/its_reset/COMPONENT_PSA_SRV_EMUL/test_pits.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright (c) 2018 ARM Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef TARGET_PSA | ||
#error [NOT_SUPPORTED] ITS tests can run only on PSA-enabled targets. | ||
#endif // TARGET_PSA | ||
|
||
#include "test_pits.h" | ||
#include "test_pits_impl.h" | ||
|
||
psa_its_status_t test_psa_its_reset(void) | ||
{ | ||
return test_psa_its_reset_impl(); | ||
} |
59 changes: 59 additions & 0 deletions
59
TESTS/psa/prot_internal_storage/its_reset/COMPONENT_PSA_SRV_IMPL/test_pits_impl.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* Copyright (c) 2018 ARM Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include "psa_prot_internal_storage.h" | ||
#include "test_pits_impl.h" | ||
#include "kv_config.h" | ||
#include "KVMap.h" | ||
#include "KVStore.h" | ||
#include "mbed_error.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
using namespace mbed; | ||
|
||
#define STR_EXPAND(tok) #tok | ||
|
||
psa_its_status_t test_psa_its_reset_impl(void) | ||
{ | ||
psa_its_status_t status = PSA_ITS_SUCCESS; | ||
|
||
int kv_status = kv_init_storage_config(); | ||
if (kv_status != MBED_SUCCESS) { | ||
return PSA_ITS_ERROR_STORAGE_FAILURE; | ||
} | ||
|
||
KVMap &kv_map = KVMap::get_instance(); | ||
KVStore *kvstore = kv_map.get_main_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV)); | ||
if (!kvstore) { | ||
return PSA_ITS_ERROR_STORAGE_FAILURE; | ||
} | ||
|
||
if (kvstore->reset() != MBED_SUCCESS) { | ||
status = PSA_ITS_ERROR_STORAGE_FAILURE; | ||
} | ||
|
||
return status; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
34 changes: 34 additions & 0 deletions
34
TESTS/psa/prot_internal_storage/its_reset/COMPONENT_PSA_SRV_IMPL/test_pits_impl.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright (c) 2018 ARM Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __PITS_IMPL_H__ | ||
#define __PITS_IMPL_H__ | ||
|
||
#include "psa_prot_internal_storage.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
psa_its_status_t test_psa_its_reset_impl(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __PITS_IMPL_H__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright (c) 2018 ARM Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __TEST_INTERNAL_TRUSTED_STORAGE_H__ | ||
#define __TEST_INTERNAL_TRUSTED_STORAGE_H__ | ||
|
||
/** @file | ||
@brief This file describes the PSA Internal Trusted Storage API | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include "psa_prot_internal_storage.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
/** | ||
* \brief Remove the provided key and its associated data from the storage | ||
* | ||
* \param[in] uid The uid value | ||
* | ||
* \return A status indicating the success/failure of the operation | ||
* | ||
* \retval PSA_ITS_SUCCESS The operation completed successfully | ||
* \retval PSA_ITS_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) | ||
*/ | ||
psa_its_status_t test_psa_its_reset(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __TEST_INTERNAL_TRUSTED_STORAGE_H__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright (c) 2018 ARM Limited. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef TARGET_PSA | ||
#error [NOT_SUPPORTED] ITS tests can run only on PSA-enabled targets. | ||
#endif // TARGET_PSA | ||
|
||
#include "greentea-client/test_env.h" | ||
#include "unity/unity.h" | ||
#include "utest/utest.h" | ||
#include "psa_prot_internal_storage.h" | ||
#include "test_pits.h" | ||
|
||
using namespace utest::v1; | ||
|
||
#define TEST_BUFF_SIZE 16 | ||
|
||
static void pits_test() | ||
{ | ||
psa_its_status_t status = PSA_ITS_SUCCESS; | ||
uint8_t write_buff[TEST_BUFF_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; | ||
uint8_t read_buff[TEST_BUFF_SIZE] = {0}; | ||
struct psa_its_info_t info = {0, PSA_ITS_WRITE_ONCE_FLAG}; | ||
memset(read_buff, 0, TEST_BUFF_SIZE); | ||
|
||
status = psa_its_get_info(5, &info); | ||
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_KEY_NOT_FOUND, status); | ||
|
||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, 0); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
status = psa_its_get_info(5, &info); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size); | ||
TEST_ASSERT_EQUAL(0, info.flags); | ||
|
||
status = psa_its_get(5, 0, TEST_BUFF_SIZE, read_buff); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
TEST_ASSERT_EQUAL_MEMORY(write_buff, read_buff, TEST_BUFF_SIZE); | ||
|
||
memset(read_buff, 0, TEST_BUFF_SIZE); | ||
status = psa_its_get(5, 1, TEST_BUFF_SIZE, read_buff); | ||
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
status = psa_its_get(5, 1, TEST_BUFF_SIZE - 1, read_buff); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
TEST_ASSERT_EQUAL_MEMORY(write_buff + 1, read_buff, TEST_BUFF_SIZE - 1); | ||
|
||
status = psa_its_remove(5); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
status = psa_its_get_info(5, &info); | ||
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_KEY_NOT_FOUND, status); | ||
} | ||
|
||
static void pits_write_once_test() | ||
{ | ||
psa_its_status_t status = PSA_ITS_SUCCESS; | ||
uint8_t write_buff[TEST_BUFF_SIZE] = {0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00}; | ||
uint8_t read_buff[TEST_BUFF_SIZE] = {0}; | ||
struct psa_its_info_t info = {0, 0}; | ||
|
||
status = test_psa_its_reset(); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
status = psa_its_get_info(5, &info); | ||
TEST_ASSERT_EQUAL(PSA_ITS_ERROR_KEY_NOT_FOUND, status); | ||
|
||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, PSA_ITS_WRITE_ONCE_FLAG); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
info.size = 0; | ||
info.flags = 0; | ||
status = psa_its_get_info(5, &info); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size); | ||
TEST_ASSERT_EQUAL(PSA_ITS_WRITE_ONCE_FLAG, info.flags); | ||
|
||
status = psa_its_get(5, 0, TEST_BUFF_SIZE, read_buff); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
TEST_ASSERT_EQUAL_MEMORY(write_buff, read_buff, TEST_BUFF_SIZE); | ||
|
||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, PSA_ITS_WRITE_ONCE_FLAG); | ||
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
status = psa_its_set(5, TEST_BUFF_SIZE, write_buff, 0); | ||
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
status = psa_its_remove(5); | ||
TEST_ASSERT_NOT_EQUAL(PSA_ITS_SUCCESS, status); | ||
|
||
info.size = 0; | ||
info.flags = 0; | ||
status = psa_its_get_info(5, &info); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
TEST_ASSERT_EQUAL(TEST_BUFF_SIZE, info.size); | ||
TEST_ASSERT_EQUAL(PSA_ITS_WRITE_ONCE_FLAG, info.flags); | ||
|
||
status = test_psa_its_reset(); | ||
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status); | ||
} | ||
|
||
Case cases[] = { | ||
Case("PSA prot internal storage - Basic", pits_test), | ||
Case("PSA prot internal storage - Write-once", pits_write_once_test), | ||
}; | ||
|
||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) | ||
{ | ||
#ifndef NO_GREENTEA | ||
GREENTEA_SETUP(60, "default_auto"); | ||
#endif | ||
return greentea_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); | ||
|
||
int main() | ||
{ | ||
return !Harness::run(specification); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.