blob: bc3402f69bd3e7d8bc74e6b7edda6d8b39b2ef8d [file] [log] [blame]
Tamas Banafc4f3c2024-08-13 11:46:58 +02001/*
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 Ban545bb5c2024-08-13 12:00:52 +020014#include "extra_s_tests.h"
15#include "test_framework.h"
16
Tamas Banafc4f3c2024-08-13 11:46:58 +020017#include "cmd.h"
18
Tamas Ban545bb5c2024-08-13 12:00:52 +020019static struct test_suite_t test_suites[] = {
20 {&register_testsuite_extra_s_interface, 0, 0, 0},
21 /* End of test suites */
22 {0, 0, 0, 0}
23};
24
25
Tamas Banafc4f3c2024-08-13 11:46:58 +020026static 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
55int 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 Ban545bb5c2024-08-13 12:00:52 +020065 /* 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 Banafc4f3c2024-08-13 11:46:58 +020073 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 Ban545bb5c2024-08-13 12:00:52 +020084 printf("Wrong number of input params! It must be either 0 or 1!\n");
Tamas Banafc4f3c2024-08-13 11:46:58 +020085 exit(1);
86 }
87
88 exit(0);
89}