diff options
author | Morten Borup Petersen <morten.petersen@arm.com> | 2019-05-16 22:18:50 +0100 |
---|---|---|
committer | Tushar Khandelwal <tushar.khandelwal@arm.com> | 2019-05-29 09:40:44 +0100 |
commit | 640c5d0282edb691ceb3e97ab3ffd17839219694 (patch) | |
tree | 7fb07e649ffb97808f1d830bc3069432e5b6d1cc | |
parent | c41fef8f206258d54bac99b9bc5cf83bddba42aa (diff) |
add test application for testing features in corstone700CORSTONE-700-19.02corstone700-19.02
this test application currently tests
1. Host to Boot processor communication through Non secure MHU
2. Host timer interrupts reaching boot processor through
interupt router and interrupt collator
Change-Id: I8435e27fefdebcdc30e4a9e5e022450abbaeb0a5
Signed-off-by: Morten Borup Petersen <morten.petersen@arm.com>
-rw-r--r-- | license.md | 39 | ||||
-rw-r--r-- | test-app.c | 180 |
2 files changed, 219 insertions, 0 deletions
diff --git a/license.md b/license.md new file mode 100644 index 0000000..35c5088 --- /dev/null +++ b/license.md @@ -0,0 +1,39 @@ +License +======= + +Copyright (c) 2019, Arm Limited and Contributors. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +- Neither the name of Arm nor the names of its contributors may be used to + endorse or promote products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--- + +__Note:__ +Individual files contain the following tag instead of the full license text. + + SPDX-License-Identifier: BSD-3-Clause + +This enables machine processing of license information based on the SPDX +License Identifiers that are available here: http://spdx.org/licenses/ diff --git a/test-app.c b/test-app.c new file mode 100644 index 0000000..145d51a --- /dev/null +++ b/test-app.c @@ -0,0 +1,180 @@ +/* + * + * Copyright (c) 2019, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Description: + * File containing various unit tests for the Corstone-700 test platform. + * The contents of this file utilize handling of the transmitted commands + * on respectively the ES and SE sides. + * Test verification is not performed by this program. Instead, all test + * variables are printed to the console, which will then be used to externally + * verify the test. + * Tests may be selected by providing the test index as an argument of this + * program. +*/ + +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> + +enum test_apps +{ + INVALID, + SE_MHU, + SE_TIMER, + NUM_TEST_APPS +}; + +/* Macros for executing API commands, which will fail the test if the + command fails. */ +#define TRY_OPEN(FD, DEVICE, ...) \ + int FD = open(DEVICE, ##__VA_ARGS__); \ + if (FD == -1) \ + { \ + printf("Could not open " DEVICE " device, exiting...\n"); \ + return 1; \ + } + +#define TRY_CLOSE(FD, ...) \ + FD = close(FD, ##__VA_ARGS__); \ + if (FD == -1) \ + { \ + printf("Could not close file descriptor " #FD " device, exiting...\n"); \ + return 1; \ + } + +#define TRY_IOCTL(STATUS, FD, ...) \ + STATUS = ioctl(FD, ##__VA_ARGS__); \ + if (STATUS != 0) \ + { \ + printf("ioctl on file descriptor '" #FD "' failed with status code: %d", STATUS); \ + return 1; \ + } + +/** + * struct rpmsg_endpoint_info - endpoint info representation + * @name: name of service + * @src: local address + * @dst: destination address + */ +struct rpmsg_endpoint_info +{ + char name[32]; + u_int32_t src; + u_int32_t dst; +}; + +#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info) +#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2) + +/* MHU test command encoding */ +#define BITMASK(x) ((unsigned)-1 >> ((sizeof(int) * CHAR_BIT) - x)) +#define CMD_WIDTH 4 +#define COMMAND(message) (message & BITMASK(CMD_WIDTH)) +#define VALUE(message) ((unsigned)message >> CMD_WIDTH) +#define ENCODE(command, value) ((command & BITMASK(CMD_WIDTH)) | (value << CMD_WIDTH)) + +enum se_command +{ + SE_NONE, + // Send the value to the PE, the PE will then increment the value + // and send it back to here (Host) + SE_INC_RETURN, + // Start a single-shot timer which will be routed to the boot processor + SE_TIMER_ONCE, + SE_NUM_COMMANDS +}; + + +/* Test MHU connection between HOST <=> BP MHU 1 */ +int se_mhu_test() +{ + int status; + struct rpmsg_endpoint_info semhu1_eptinfo = {"semhu1", 0XFFFFFFFF, 0xFFFFFFFF}; + TRY_OPEN(fd, "/dev/rpmsg_ctrl0", O_RDWR); + + // Create endpoint interface + TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &semhu1_eptinfo); // /dev/rpmsg0 is created + + // create endpoint + TRY_OPEN(fd_semhu1_ept, "/dev/rpmsg0", O_RDWR); + + int message; + const int value = 0xABCDEF; + + /* ========== BP < = > HOST TESTS ========== */ + message = ENCODE(SE_INC_RETURN, value); + write(fd_semhu1_ept, &message, sizeof(message)); + sleep(1); + read(fd_semhu1_ept, &message, sizeof(message)); + printf("Received %x from boot processor\n", message); + + // destroy endpoints + TRY_IOCTL(status, fd_semhu1_ept, RPMSG_DESTROY_EPT_IOCTL); + + TRY_CLOSE(fd_semhu1_ept); + TRY_CLOSE(fd); + return 0; +} + +/* Test timer and interrupt driver in boot processor */ +int se_timer_test() +{ + int status; + struct rpmsg_endpoint_info semhu1_eptinfo = {"semhu1", 0XFFFFFFFF, 0xFFFFFFFF}; + TRY_OPEN(fd, "/dev/rpmsg_ctrl0", O_RDWR); + + // Create endpoint interface + TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &semhu1_eptinfo); // /dev/rpmsg0 is created + + // create endpoint + TRY_OPEN(fd_semhu1_ept, "/dev/rpmsg0", O_RDWR); + + int message = ENCODE(SE_TIMER_ONCE, 0); + write(fd_semhu1_ept, &message, sizeof(message)); + printf("Sent timer test command to boot processor\n", message); + + // destroy endpoints + TRY_IOCTL(status, fd_semhu1_ept, RPMSG_DESTROY_EPT_IOCTL); + TRY_CLOSE(fd_semhu1_ept); + TRY_CLOSE(fd); + return 0; +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) + { + printf("Usage: ./test-app <test app number>\n"); + printf("\t test app number : 1 for boot processor MHU.\n"); + printf("\t\tThis tests MHU communication between Host and Boot processor\n"); + printf("\t test app number : 2 for boot processor Timer.\n"); + printf("\t\tThis test Host Timer usage on Boot processor\n"); + printf("\t\tusing interrupt router and interrupt collator \n"); + return 1; + } + + switch (atoi(argv[1])) + { + default: + case INVALID: + printf("Invalid test app specified\n"); + printf("%d test apps are available\n", NUM_TEST_APPS - 1); + break; + case SE_MHU: + return se_mhu_test(); + case SE_TIMER: + return se_timer_test(); + } + + return 0; +} |