Skip to content

Commit

Permalink
xtest: add command to get system time
Browse files Browse the repository at this point in the history
Command format: xtest --stats --time

Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Weizhao Jiang <weizhaoj@amazon.com>
Signed-off-by: Weizhao Jiang <weizhaoj@amazon.com>
  • Loading branch information
weizhaojiang committed Sep 27, 2023
1 parent 1013c49 commit fd2c790
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions host/xtest/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define STATS_CMD_ALLOC_STATS 1
#define STATS_CMD_MEMLEAK_STATS 2
#define STATS_CMD_TA_STATS 3
#define STATS_CMD_GET_TIME 4

#define TEE_ALLOCATOR_DESC_LENGTH 32
struct malloc_stats {
Expand Down Expand Up @@ -312,6 +313,36 @@ static int stat_loaded_ta(int argc, char *argv[])
return close_sess(&ctx, &sess);
}

static int stat_system_time(int argc, char *argv[])
{
TEEC_Context ctx = { };
TEEC_Session sess = { };
TEEC_Result res = TEEC_ERROR_GENERIC;
uint32_t eo = 0;
TEEC_Operation op = { };

UNUSED(argv);
if (argc != 1)
return usage();

open_sess(&ctx, &sess);
op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
TEEC_VALUE_OUTPUT,
TEEC_NONE, TEEC_NONE);
res = TEEC_InvokeCommand(&sess, STATS_CMD_GET_TIME, &op, &eo);
if (res != TEEC_SUCCESS)
errx(EXIT_FAILURE,
"TEEC_InvokeCommand: res %#"PRIx32" err_orig %#"PRIx32,
res, eo);

printf("REE time: %"PRId32" seconds, %"PRId32" milliseconds\n",
op.params[0].value.a, op.params[0].value.b);
printf("TEE time: %"PRId32" seconds, %"PRId32" milliseconds\n",
op.params[1].value.a, op.params[1].value.b);

return close_sess(&ctx, &sess);
}

int stats_runner_cmd_parser(int argc, char *argv[])
{
if (argc > 1) {
Expand All @@ -323,6 +354,8 @@ int stats_runner_cmd_parser(int argc, char *argv[])
return stat_memleak(argc - 1, argv + 1);
if (!strcmp(argv[1], "--ta"))
return stat_loaded_ta(argc - 1, argv + 1);
if (!strcmp(argv[1], "--time"))
return stat_system_time(argc - 1, argv + 1);
}

return usage();
Expand Down

0 comments on commit fd2c790

Please sign in to comment.