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

Add processing of code coverage for optee core #4192

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Commits on Nov 2, 2020

  1. core: add configuration flags for gcov

    This patch adds the flags to configure the use of gcov:
     - CFG_CORE_GCOV_SUPPORT: enable the coverage for the core
     - CFG_TA_GCOV_SUPPORT: enable the coverage for TAs
    
    If any of them is enabled, CFG_GCOV_SUPPORT is enabled
    
    These flags are exported to the devkit.
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    cb8cd11 View commit details
    Browse the repository at this point in the history
  2. compil: Fix link error TEE_RAM_VA_SIZE is too small

    For imx 6 qnd 7 targets, the build fails because TEE_RAM_VA_SIZE
    is too small. This patch increase it from 512ko to 2 Mo when coverage
    is enabled.
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    89e521c View commit details
    Browse the repository at this point in the history
  3. libgcov: Add library adding the gcov support

    The code coverage is a metric measuring the lines of code
    executed in a code base during execution.
    If the code coverage is generated after a test suite is
    ran, it will give the coverage of code tested by the
    test suite. It gives the possibility to identify the code
    which is not tested.
    
    The gcov code coverage is supported by different compiler:
     - GCC (gcc.gnu.org/onlinedocs/gcc/Gcov.html)
     - clang compiler (clang.llvm.org/docs/SourceBasedCodeCoverage.html)
    It allows to analyze which part of the code is executed.
    The interface with a specific implementation of gcov is defined
    usign the structure gcov_impl_t.
    
    The library implements the symbol required for gcov:
     - __gcov_init: called by each coverage unit
     - __gcov_merge_add
     - __gcov_exit
    The calls to these symbols are redirected to the implementation
    for the compiler used.
    
    The library role is to transform the coverage data in program
    memory to a valid gcov data file. For this it interacts with:
     - user/TA: Control (Reset or Dump) the coverage data
     - Function to store data: Send the data to it for storage in REE FS
    
    In order to retrieve the coverage (*.gcda) for a specific UC,
    it is recommended to do the following actions:
     - clear the coverage
     - perform the UC
     - save the coverage
    
    Note: The core and the TAs are linked against different instances
    of the libgcov. The libgcov of the core can be controlled by the
    gcov PTA. The TA instances are controlled calling the libgcov API.
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    ad40ae8 View commit details
    Browse the repository at this point in the history
  4. libgcov: Add implementation of gcov for GCC

    The compiler GCC implements gcov code coverage and this patch
    adds the support to handle the structure in memory generated
    by the compiler. It also handles the transformation of the
    structure in memory into gcov data files.
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    ce426d3 View commit details
    Browse the repository at this point in the history
  5. core: Add writer of coverage data to REE FS

    The coverage data are generated during execution, in order to
    exploit it, the data can be stored to REE FS in clear text
    which is done by the writer.
    
    The writer receives the data to store and call the dedicated
    RPC to instruct the TEE client to store it in REE FS.
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    db065b3 View commit details
    Browse the repository at this point in the history
  6. pta: gcov: Add gcov pta

    The PTA has two main purposes:
     - Control the code coverage of the core:
       - PTA_CMD_GCOV_GET_VERSION
       - PTA_CMD_GCOV_CORE_RESET
       - PTA_CMD_GCOV_CORE_DUMP_ALL
     - Write code coverage data from a TA (called by libgcov)
       - PTA_CMD_GCOV_DUMP
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    e5d442f View commit details
    Browse the repository at this point in the history
  7. core: Add support for code coverage compilation

    The code coverage is performed at runtime by keeping in memory
    structures holding the releveant data:
    
    In order to generate the code coverage, two steps are required:
     - Instruct the compiler to generate coverage information structure
       and functions to initialize them: flag --coverage.
     - Call the constructors added to initialize the coverage information
       and register them to the libgcov (modification of boot.c)
    
    When an object file (.o) is created with code coverage support, a note
    (.gcno) file is created with it. The note file contains informations
    used when creating the code coverage report.
    
    The support of code coverage in compiled code increases its size (~15%)
    and the compilation time (~25%).
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    92afa01 View commit details
    Browse the repository at this point in the history
  8. coverage.py: Add script to process code coverage

    This script ease the generation of code coverage report. A report
    is based on a codebase, note files (generated at compilation) and
    data files (generated at runtime).
    The report is generated using lcov and present the code coverage as
    a percentage of lines executed compared to the total number of lines
    in the codebase.
    
    The script will copy all the note and data files in a temporary
    directory allowing to reuse the generated artifact and checks that
    the note and data file are correctly organised (the files must be
    in the same directory).
    
    The script also allow to generate an html output using genhtml and
    to view it.
    
    Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
    lenormandfranck committed Nov 2, 2020
    Configuration menu
    Copy the full SHA
    08d97f1 View commit details
    Browse the repository at this point in the history