diff options
author | Emekcan <emekcan.aras@arm.com> | 2022-09-22 16:52:50 +0100 |
---|---|---|
committer | Rui Miguel Silva <rui.silva@linaro.org> | 2022-09-23 09:58:37 +0100 |
commit | 22a54ff7ccedaca73dcf6553596ad5a778111768 (patch) | |
tree | 2262f4491f90aef2ab954d7ff524af5e6827b5a0 | |
parent | ecd93a275d11cf08f670a97783110bd698250963 (diff) |
Fixing style violations
Fix several issues in code format, detected by checkpatch.
Signed-off-by: Emekcan Aras <emekcan.aras@arm.com>
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
-rw-r--r--[-rwxr-xr-x] | test-app.c | 211 |
1 files changed, 115 insertions, 96 deletions
diff --git a/test-app.c b/test-app.c index c959126..07fea06 100755..100644 --- a/test-app.c +++ b/test-app.c @@ -1,9 +1,7 @@ +// SPDX-License-Identifier: BSD-3-Clause /* - * * 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 @@ -13,7 +11,7 @@ * 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> @@ -26,8 +24,7 @@ #include <stdlib.h> #include <limits.h> -enum test_apps -{ +enum test_apps { INVALID, ES_RESET, ES_MHU, @@ -36,57 +33,62 @@ enum test_apps NUM_TEST_APPS }; -enum es_command -{ +enum es_command { ES_NONE, - /* Send the value to the PE, the PE will then increment the value - and send it back to here (Host) */ + /* + * Send the value to the PE, the PE will then increment the value + * and send it back to here (Host) + */ ES_INC_RETURN, - /* Send the value to the ES, the ES will then increment the value - and send it to Secure enclave*/ + /* + * Send the value to the ES, the ES will then increment the value + * and send it to Secure enclave + */ ES_INC_SEND_TO_SE, - /* Send the value to the ES, make the ES send this - * value to the secure enclave, and make the secure enclave increment and echo - * the value back to the ES + /* + * Send the value to the ES, make the ES send this value to the secure + * enclave, and make the secure enclave increment and echo the value + * back to the ES */ ES_INC_ECHO_SE, ES_NUM_COMMANDS, }; -/* 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; \ - } - +/* + * 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, ...) \ +do { \ + FD = close(FD, ##__VA_ARGS__); \ + if (FD == -1) { \ + printf("Could not close file descriptor " #FD " device, exiting...\n"); \ + return 1; \ + } \ +} while (0) \ + +#define TRY_IOCTL(STATUS, FD, ...) \ +do { \ + STATUS = ioctl(FD, ##__VA_ARGS__); \ + if (STATUS != 0) { \ + printf("ioctl on file descriptor '" #FD "' failed with status code: %d", STATUS); \ + return 1; \ + } \ +} while (0) /** * struct rpmsg_endpoint_info - endpoint info representation * @name: name of service * @src: local address * @dst: destination address */ -struct rpmsg_endpoint_info -{ +struct rpmsg_endpoint_info { char name[32]; u_int32_t src; u_int32_t dst; @@ -98,25 +100,27 @@ struct rpmsg_endpoint_info #define EXTSYS_CPU_WAIT_DISABLE 0x0 /* MHU test command encoding */ -#define BITMASK(x) ((unsigned)-1 >> ((sizeof(int) * CHAR_BIT) - x)) +#define BITMASK(x) ((unsigned int)-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 +#define VALUE(message) ((unsigned int)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 single-shot timer which will be routed to the boot processor */ + SE_TIMER_ONCE, + SE_NUM_COMMANDS }; /* Desassert the reset signal of the external system#0 harness */ -int es_reset_test() +int es_reset_test(void) { int status; /* Bring external system out of reset */ @@ -126,58 +130,70 @@ int es_reset_test() return 0; } -/* Test MHU connection between HOST <=> ES0 MHU 0 and 1, and SE <=> ES0 MHU 0 and 1 */ -int es_mhu_test() +/* + * Test MHU connection between HOST <=> ES0 MHU 0 and 1, + * and SE <=> ES0 MHU 0 and 1 + */ +int es_mhu_test(void) { int status; int message; + int epts[2]; const int value = 0xABCDEF; - struct rpmsg_endpoint_info es0mhu0_eptinfo = {"es0mhu0", 0XFFFFFFFF, 0xFFFFFFFF}; - struct rpmsg_endpoint_info es0mhu1_eptinfo = {"es0mhu1", 0XFFFFFFFF, 0xFFFFFFFF}; + struct rpmsg_endpoint_info es0mhu0_eptinfo = {"es0mhu0", 0XFFFFFFFF, + 0xFFFFFFFF}; + struct rpmsg_endpoint_info es0mhu1_eptinfo = {"es0mhu1", 0XFFFFFFFF, + 0xFFFFFFFF}; TRY_OPEN(fd, "/dev/rpmsg_ctrl0", O_RDWR); /* Create endpoint interfaces for each MHU */ - TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &es0mhu0_eptinfo); /* /dev/rpmsg1 is created */ - TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &es0mhu1_eptinfo); /* /dev/rpmsg2 is created */ + /* /dev/rpmsg0 is created */ + TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &es0mhu0_eptinfo); + /* /dev/rpmsg1 is created */ + TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &es0mhu1_eptinfo); /* create endpoints for each mhu */ TRY_OPEN(fd_es0mhu0_ept, "/dev/rpmsg0", O_RDWR); TRY_OPEN(fd_es0mhu1_ept, "/dev/rpmsg1", O_RDWR); - int epts[2]; epts[0] = fd_es0mhu0_ept; epts[1] = fd_es0mhu1_ept; /* Bring external system out of reset */ es_reset_test(); - /* Await es system boot. Currently there is no signalling mechanism for - * this, so revert to sleeping */ + + /* + * Await ES system boot. Currently there is no signalling mechanism for + * this, so revert to sleeping + */ sleep(1); + /* External system test */ - for (int i = 0; i < 2; i++) - { + for (int i = 0; i < 2; i++) { int ept = epts[i]; char *name; /* ========== ES < = > HOST TESTS ========== */ - /* Make ES echo the value back to host with the incremented value */ + /* Make ES echo the value back to host with incremented value */ message = ENCODE(ES_INC_RETURN, value); write(ept, &message, sizeof(message)); - /* External system cannot execute the test command within an interrupt - * handler. Since no command buffering has been implemented on the ES, a - * sleep allows the ES to process a command before the host transmits - * subsequent commands. - */ + /* + * External system cannot execute the test command within an + * interrupt handler. Since no command buffering has been + * implemented on the ES, a sleep allows the ES to process + * a command before the host transmits subsequent commands. + */ sleep(1); /* Read the data transmitted by the previous command */ read(ept, &message, sizeof(message)); printf("Received %x from %s\n", message, ept == fd_es0mhu0_ept ? "es0mhu0" : "es0mhu1"); /* ================== ES < = > SE ================== */ - /* Make ES send a message to the SE with the incremented value */ + /* Make ES send a message to the SE with incremented value */ message = ENCODE(ES_INC_SEND_TO_SE, value); write(ept, &message, sizeof(message)); sleep(1); } + /* destroy endpoints */ TRY_IOCTL(status, fd_es0mhu0_ept, RPMSG_DESTROY_EPT_IOCTL); TRY_IOCTL(status, fd_es0mhu1_ept, RPMSG_DESTROY_EPT_IOCTL); @@ -188,21 +204,23 @@ int es_mhu_test() } /* Test MHU connection between HOST <=> BP MHU 1 */ -int se_mhu_test() +int se_mhu_test(void) { int status; - struct rpmsg_endpoint_info semhu1_eptinfo = {"semhu1", 0XFFFFFFFF, 0xFFFFFFFF}; + int message; + const int value = 0xABCDEF; + 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 interface */ + /* /dev/rpmsg0 is created */ + TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &semhu1_eptinfo); - // create endpoint + /* 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)); @@ -210,7 +228,7 @@ int se_mhu_test() read(fd_semhu1_ept, &message, sizeof(message)); printf("Received %x from boot processor\n", message); - // destroy endpoints + /* destroy endpoints */ TRY_IOCTL(status, fd_semhu1_ept, RPMSG_DESTROY_EPT_IOCTL); TRY_CLOSE(fd_semhu1_ept); @@ -219,23 +237,26 @@ int se_mhu_test() } /* Test timer and interrupt driver in boot processor */ -int se_timer_test() +int se_timer_test(void) { int status; - struct rpmsg_endpoint_info semhu1_eptinfo = {"semhu1", 0XFFFFFFFF, 0xFFFFFFFF}; + int message = ENCODE(SE_TIMER_ONCE, 0); + 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 interface */ + /* /dev/rpmsg0 is created */ + TRY_IOCTL(status, fd, RPMSG_CREATE_EPT_IOCTL, &semhu1_eptinfo); - // create endpoint + /* 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 + /* destroy endpoints */ TRY_IOCTL(status, fd_semhu1_ept, RPMSG_DESTROY_EPT_IOCTL); TRY_CLOSE(fd_semhu1_ept); TRY_CLOSE(fd); @@ -244,14 +265,13 @@ int se_timer_test() int main(int argc, char *argv[]) { - if (argc != 2) - { + if (argc != 2) { printf("Usage: ./test-app <test app number>\n"); printf(" test app number : 1 for External System reset.\n"); printf(" This test resets the External System\n"); printf(" test app number : 2 for External System MHU.\n"); printf(" This tests MHU communication between External System <=> Boot Processor\n"); - printf(" and also between External System <=> Host System \n"); + printf(" and also between External System <=> Host System\n"); printf(" test app number : 3 for Boot Processor MHU.\n"); printf(" This tests MHU communication between Boot Processor <=> Host System\n"); printf(" test app number : 4 for Boot Processor Timer.\n"); @@ -261,8 +281,7 @@ int main(int argc, char *argv[]) return 1; } - switch (atoi(argv[1])) - { + switch (atoi(argv[1])) { default: case INVALID: printf("Invalid test app specified\n"); |