Tamas Ban | afc4f3c | 2024-08-13 11:46:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | #include "dice_protection_environment.h" |
| 12 | #include "tfm_sp_log.h" |
| 13 | |
Tamas Ban | 545bb5c | 2024-08-13 12:00:52 +0200 | [diff] [blame] | 14 | #include "extra_s_tests.h" |
| 15 | #include "test_framework.h" |
| 16 | |
Tamas Ban | afc4f3c | 2024-08-13 11:46:58 +0200 | [diff] [blame] | 17 | #include "cmd.h" |
| 18 | |
Tamas Ban | 545bb5c | 2024-08-13 12:00:52 +0200 | [diff] [blame] | 19 | static struct test_suite_t test_suites[] = { |
| 20 | {®ister_testsuite_extra_s_interface, 0, 0, 0}, |
| 21 | /* End of test suites */ |
| 22 | {0, 0, 0, 0} |
| 23 | }; |
| 24 | |
| 25 | |
Tamas Ban | afc4f3c | 2024-08-13 11:46:58 +0200 | [diff] [blame] | 26 | static int read_cmd(const char path[], char *cmd_buf, size_t *cmd_buf_size) |
| 27 | { |
| 28 | FILE *fd; |
| 29 | size_t cmd_size; |
| 30 | |
| 31 | if ((fd = fopen(path, "r")) == NULL) { |
| 32 | printf("ERROR: File (%s) cannot be opened.\n", path); |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | fseek(fd, 0, SEEK_END); |
| 37 | cmd_size = ftell(fd); |
| 38 | rewind(fd); |
| 39 | |
| 40 | if (*cmd_buf_size < cmd_size) { |
| 41 | printf("ERROR: cmd_buf is too small\n"); |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | for (size_t i = 0; i < cmd_size; ++i) { |
| 46 | cmd_buf[i] = fgetc(fd); |
| 47 | } |
| 48 | *cmd_buf_size = cmd_size; |
| 49 | |
| 50 | fclose(fd); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | int main(int argc, char **argv) |
| 56 | { |
| 57 | int context_handle; |
| 58 | int ret; |
| 59 | char cmd_in_buf[4096] = {0}; |
| 60 | size_t cmd_in_size = sizeof(cmd_in_buf); |
| 61 | dpe_error_t err; |
| 62 | |
| 63 | dpe_lib_init(&context_handle); |
| 64 | |
Tamas Ban | 545bb5c | 2024-08-13 12:00:52 +0200 | [diff] [blame] | 65 | /* Process command line arguments */ |
| 66 | if (argc == 1) { |
| 67 | /*************** Invoked without any command line parameter ************/ |
| 68 | printf("Execute DPE regression test\n"); |
| 69 | /* Regression test prints the result to the console */ |
| 70 | (void)run_test("DPE Regression", test_suites); |
| 71 | |
| 72 | } else if (argc == 2) { |
Tamas Ban | afc4f3c | 2024-08-13 11:46:58 +0200 | [diff] [blame] | 73 | ret = read_cmd(argv[1], cmd_in_buf, &cmd_in_size); |
| 74 | if (ret < 0) { |
| 75 | exit(1); |
| 76 | } |
| 77 | |
| 78 | err = exec_dpe_cmd(CBOR, cmd_in_buf, cmd_in_size, &context_handle); |
| 79 | if (err != DPE_NO_ERROR) { |
| 80 | printf("DPE command decode/execution failed (%d)\n", ret); |
| 81 | exit(1); |
| 82 | } |
| 83 | } else { |
Tamas Ban | 545bb5c | 2024-08-13 12:00:52 +0200 | [diff] [blame] | 84 | printf("Wrong number of input params! It must be either 0 or 1!\n"); |
Tamas Ban | afc4f3c | 2024-08-13 11:46:58 +0200 | [diff] [blame] | 85 | exit(1); |
| 86 | } |
| 87 | |
| 88 | exit(0); |
| 89 | } |