Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtest: Add test of gcov #457

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions host/xtest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ srcs += gp_7000.c \
gp_9000.c
endif

# Should be the last object added to be able to capture the code coverage
# of the test suite
ifeq ($(CFG_GCOV_SUPPORT),y)
srcs += gcov.c
endif

objs := $(patsubst %.c,$(out-dir)/xtest/%.o, $(srcs))

CFLAGS += -I./
Expand All @@ -136,6 +142,9 @@ CFLAGS += -I../../ta/aes_perf/include
CFLAGS += -I../../ta/socket/include
CFLAGS += -I../../ta/sdp_basic/include
CFLAGS += -I../../ta/tpm_log_test/include
ifeq ($(CFG_GCOV_SUPPORT),y)
CFLAGS += -I../../ta/gcov/include
endif

ifdef CFG_GP_PACKAGE_PATH
CFLAGS += -I../../ta/GP_TTA_Arithmetical
Expand Down
15 changes: 15 additions & 0 deletions host/xtest/adbg/include/adbg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* Copyright 2020 NXP
*/

#ifndef ADBG_H
Expand Down Expand Up @@ -59,6 +60,20 @@ typedef struct adbg_suite_def {
&case_def, link); \
}

#define ADBG_CASE_DEFINE_FRONT(Suite, TestID, Run, Title) \
__attribute__((constructor)) static void \
__adbg_test_case_ ## TestID(void) \
{ \
static ADBG_Case_Definition_t case_def = { \
.TestID_p = #Suite "_" #TestID, \
.Title_p = Title, \
.Run_fp = Run, \
}; \
\
TAILQ_INSERT_HEAD(&(ADBG_Suite_ ## Suite).cases, \
&case_def, link); \
}

/*
* Suite definitions
*/
Expand Down
160 changes: 160 additions & 0 deletions host/xtest/gcov.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// SPDX-License-Identifier: GPL-2.0
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license tag? (bsd2? gpl2?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add the GPL tags to all the files

* Copyright 2020 NXP
*/
#include <string.h>

#include <adbg.h>
#include <pta_gcov.h>
#include <ta_gcov.h>
#include <tee_client_api.h>
#include <xtest_helpers.h>
#include <xtest_test.h>

struct gcov_dump_conf {
const char *desc;
TEEC_UUID *uuid;
unsigned int cmd;
};


static void do_get_version_command(ADBG_Case_t *c, TEEC_UUID *uuid,
unsigned int cmd)
{
TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
uint32_t ret_orig = 0;

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, uuid, NULL, &ret_orig)))
return;

op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);

(void)ADBG_EXPECT_TEEC_SUCCESS(c,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove (void).

TEEC_InvokeCommand(&session, cmd, &op, &ret_orig));

ADBG_EXPECT_TRUE(c, (op.params[0].value.a != 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can drop inner parentheses.


TEEC_CloseSession(&session);
}

static void xtest_tee_test_31001(ADBG_Case_t *c)
{
TEEC_UUID pta_uuid = PTA_GCOV_UUID;

do_get_version_command(c, &pta_uuid, PTA_CMD_GCOV_GET_VERSION);
}

static void xtest_tee_test_31002(ADBG_Case_t *c)
{
TEEC_UUID ta_uuid = TA_GCOV_UUID;

do_get_version_command(c, &ta_uuid, TA_GCOV_CMD_GET_VERSION);
}

static void do_dump_command(ADBG_Case_t *c, const struct gcov_dump_conf *conf)
{
TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
uint32_t ret_orig = 0;

ADBG_EXPECT_NOT_NULL(c, conf);

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, conf->uuid, NULL,
&ret_orig)))
return;

op.params[0].tmpref.buffer = (char *)conf->desc;
op.params[0].tmpref.size = strlen(conf->desc) + 1;
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);

(void)ADBG_EXPECT_TEEC_SUCCESS(c,
TEEC_InvokeCommand(&session, conf->cmd, &op, &ret_orig));

TEEC_CloseSession(&session);
}

static void xtest_tee_test_31003(ADBG_Case_t *c)
{
TEEC_UUID pta_uuid = PTA_GCOV_UUID;

struct gcov_dump_conf conf = {"boot", &pta_uuid,
PTA_CMD_GCOV_CORE_DUMP_ALL};

do_dump_command(c, &conf);
}

static void do_core_reset_command(ADBG_Case_t *c)
{
TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
TEEC_UUID pta_uuid = PTA_GCOV_UUID;
uint32_t ret_orig = 0;

if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &pta_uuid, NULL, &ret_orig)))
return;

op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE,
TEEC_NONE);

(void)ADBG_EXPECT_TEEC_SUCCESS(c,
TEEC_InvokeCommand(&session, PTA_CMD_GCOV_CORE_RESET, &op,
&ret_orig));

TEEC_CloseSession(&session);
}

static void xtest_tee_test_31004(ADBG_Case_t *c)
{
do_core_reset_command(c);
}

/*
* Add the test at the front of the test suite to capture the code coverage
* of the test suite
*/
ADBG_CASE_DEFINE_FRONT(regression, 31004, xtest_tee_test_31004,
"Reset core code coverage data");

ADBG_CASE_DEFINE_FRONT(regression, 31003, xtest_tee_test_31003,
"Dump boot code coverage data of core");

ADBG_CASE_DEFINE_FRONT(regression, 31002, xtest_tee_test_31002,
"Get version of code coverage data for TA");

ADBG_CASE_DEFINE_FRONT(regression, 31001, xtest_tee_test_31001,
"Get version of code coverage data for the core");

static void xtest_tee_test_31005(ADBG_Case_t *c)
{
long unsigned int i = 0;
TEEC_UUID ta_uuid = TA_GCOV_UUID;
TEEC_UUID pta_uuid = PTA_GCOV_UUID;

struct gcov_dump_conf list_conf[] = {
{"xtest_core_from_ca", &pta_uuid, PTA_CMD_GCOV_CORE_DUMP_ALL},
{"xtest_core_from_ta", &ta_uuid, TA_GCOV_CMD_DUMP_CORE},
{"xtest_ta_from_ta", &ta_uuid, TA_GCOV_CMD_DUMP_TA},
};

for (i = 0; i < sizeof(list_conf) / sizeof(list_conf[0]); i++) {
struct gcov_dump_conf *conf = &list_conf[i];

Do_ADBG_BeginSubCase(c, "Dump %s", conf->desc);

/* TODO delete the folder in FS */

do_dump_command(c, conf);

/* TODO check the folder is created in FS with files */

Do_ADBG_EndSubCase(c, "Dump %s", conf->desc);
}
}
ADBG_CASE_DEFINE(regression, 31005, xtest_tee_test_31005,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regression tests are currently all from regression_.c source files.
Either use a new suite gcov (for this gcov.c)?
or more simply rename gcov.c to regression_3000.c? where we maybe start putting debug tools tests in regression 3xxx.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a few constraints I want to have for the gcov test:

  • Dump the coverage of the core at boot
  • Clear the core code coverage
  • execute xtest
  • Dump the code coverage of the core

This way, running gcov allowed to dump the relevent code coverage without the need for another app called by the user.
this is why the tests for gcov are added last as object file so I can place the test 1 to 4 at the start of the list to run (ADBG_CASE_DEFINE_FRONT) and the 5th at the end.

I could make an implementation more flexible by having the following:

  • current tests in regression_3000.c
  • test suite gcov with copy of test 3 and 5
    So the user would have to do:
  • xtest gcov 0 (dump core code coverage and clean)
  • xtest
  • xtest gcov 1 (dump core code coverage corresponding to the execution of xtest)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having extra xtest arguments would be flexible, i.e.:
xtest --gcov-version to get the 2 gcov version info
xtest --gcov-core to collect gcov data for the core
xtest --gcov-clean to clean gcov data
xtest --gcov-collect to collect gcov data

"Dump code coverage data of xtest");
1 change: 1 addition & 0 deletions ta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target_include_directories(${PROJECT_NAME}
INTERFACE create_fail_test/include
INTERFACE crypt/include
INTERFACE enc_fs/include
INTERFACE gcov/include
INTERFACE os_test/include
INTERFACE rpc_test/include
INTERFACE sdp_basic/include
Expand Down
4 changes: 4 additions & 0 deletions ta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ TA_DIRS := create_fail_test \
aes_perf \
socket

ifeq ($(CFG_GCOV_SUPPORT),y)
TA_DIRS += gcov
endif

ifeq ($(CFG_SECURE_DATA_PATH),y)
TA_DIRS += sdp_basic
endif
Expand Down
4 changes: 4 additions & 0 deletions ta/gcov/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LOCAL_PATH := $(call my-dir)

local_module := a424901c-4810-4e4d-aa76-62ef0045343f
include $(BUILD_OPTEE_MK)
3 changes: 3 additions & 0 deletions ta/gcov/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BINARY = a424901c-4810-4e4d-aa76-62ef0045343f

include ../ta_common.mk
35 changes: 35 additions & 0 deletions ta/gcov/include/ta_gcov.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright 2020 NXP
*/

#ifndef TA_GCOV_H
#define TA_GCOV_H

#define TA_GCOV_UUID { 0xa424901c, 0x4810, 0x4e4d, \
{ 0xaa, 0x76, 0x62, 0xef, 0x00, 0x45, 0x34, 0x3f} }

/*
* TA_GCOV_CMD_GET_VERSION - Proxy function which calls gcov_get_version()
*
* [out] value[0].a version of gcov
*/
#define TA_GCOV_CMD_GET_VERSION 0

/*
* TA_GCOV_CMD_DUMP_CORE - Proxy function which invoke
* PTA_CMD_GCOV_CORE_DUMP_ALL from gcov PTA
*
* [in] memref[0] Name of the dump
*/
#define TA_GCOV_CMD_DUMP_CORE 1

/*
* TA_GCOV_CMD_DUMP_TA - Proxy function which calls
* gcov_dump_all_coverage_data()
*
* [in] memref[0] Name of the dump
*/
#define TA_GCOV_CMD_DUMP_TA 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide the ABI

Here, it would be:

/*
 * TA_GCOV_CMD_GET_VERSION - Proxy function which calls gcov_get_version()
 *
 * [out]    value[0].a	    version of gcov
*/
#define TA_GCOV_CMD_GET_VERSION	0

/*
 * TA_GCOV_CMD_DUMP_CORE - Proxy function which calls gcov_get_version()
 *
 * [out]    value[0].a	    version of gcov
*/
#define TA_GCOV_CMD_DUMP_CORE	1

 *          [in]     memref[0]	    description


 *          [in]     memref[0]	    filepath
 *          [in]     memref[1]	    code coverage data
#define TA_GCOV_CMD_DUMP_TA	2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


#endif /* TA_GCOV_H */
18 changes: 18 additions & 0 deletions ta/gcov/include/user_ta_header_defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright 2020 NXP
*/

#ifndef USER_TA_HEADER_DEFINES_H
#define USER_TA_HEADER_DEFINES_H

#include "ta_gcov.h"

#define TA_UUID TA_GCOV_UUID

#define TA_FLAGS 0

#define TA_STACK_SIZE (2 * 1024)
#define TA_DATA_SIZE (32 * 1024)

#endif
2 changes: 2 additions & 0 deletions ta/gcov/sub.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global-incdirs-y += include
srcs-y += ta_gcov.c
Loading