mbed-os/TESTS/psa/spm_server/COMPONENT_SPE/server_tests_partition1.c

93 lines
3.1 KiB
C
Raw Normal View History

/* Copyright (c) 2017-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"
2019-02-24 08:50:24 +00:00
#include "psa/client.h"
#include "psa/service.h"
2019-02-24 08:50:24 +00:00
#include "psa_server_tests_part1_partition.h"
#include "server_tests.h"
extern psa_test_server_side_func test_list[];
static size_t num_of_tests = 0;
static psa_msg_t msg = {0};
static void init_num_of_tests()
{
size_t i = 0;
2018-11-18 09:04:51 +00:00
while (test_list[i] != NULL) {
i++;
}
num_of_tests = i;
}
2019-02-24 08:50:24 +00:00
void server_part1_main(void *ptr)
{
2019-02-22 18:31:48 +00:00
psa_signal_t signals = 0;
psa_status_t test_status = PSA_SUCCESS; // status of the api calls during the test
psa_status_t test_result = PSA_SUCCESS; // result of the critical section of the test
test_action_t action;
uint32_t test_idx = 0;
init_num_of_tests();
while (1) {
2019-02-22 18:31:48 +00:00
signals = psa_wait(CONTROL_MSK, PSA_BLOCK);
if (0 == (signals & CONTROL_MSK)) {
2019-02-22 18:31:48 +00:00
SPM_PANIC("returned from psa_wait without CONTROL_ROT_SRV bit on signals=(0x%08x)\n", signals);
}
if (PSA_SUCCESS != psa_get(CONTROL_MSK, &msg)) {
SPM_PANIC("psa_get() failed\n");
}
switch (msg.type) {
2018-11-18 09:04:51 +00:00
case PSA_IPC_CALL:
if (msg.in_size[0] == 0) {
SPM_PANIC("got a zero message size to CONTROL ROT_SRV\n");
}
2018-11-18 09:04:51 +00:00
if (psa_read(msg.handle, 0, &action, sizeof(action)) != sizeof(action)) {
SPM_PANIC("could not read the entire test payload structure\n");
}
2018-11-18 09:04:51 +00:00
switch (action) {
case START_TEST:
if ((test_idx >= num_of_tests) || (test_list[test_idx] == NULL)) {
SPM_PANIC("Invalid test ID was sent!\n");
}
2018-11-18 09:04:51 +00:00
psa_reply(msg.handle, PSA_SUCCESS);
test_status = test_list[test_idx](&test_result);
break;
case GET_TEST_RESULT:
test_idx++;
psa_write(msg.handle, 0, &test_result, sizeof(test_result));
psa_reply(msg.handle, test_status);
break;
default:
SPM_PANIC("Got illegal Value in test action");
}
2018-11-18 09:04:51 +00:00
break;
case PSA_IPC_CONNECT:
case PSA_IPC_DISCONNECT:
psa_reply(msg.handle, PSA_SUCCESS);
break;
default:
2019-02-24 10:31:04 +00:00
SPM_PANIC("Unexpected message type %lu!", msg.type);
}
}
}