Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Google, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
Remove address from GPLv2 headers
As per discussion with lawyers[tm], it's not a good idea to
shorten the license header too much - not for legal reasons
but because there are tools that look for them, and giving
them a standard pattern simplifies things.
However, we got confirmation that we don't have to update
every file ever added to coreboot whenever the FSF gets a
new lease, but can drop the address instead.
util/kconfig is excluded because that's imported code that
we may want to synchronize every now and then.
$ find * -type f -exec sed -i "s:Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *MA[, ]*02110-1301[, ]*USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 59 Temple Place[-, ]*Suite 330, Boston, MA *02111-1307[, ]*USA:Foundation, Inc.:" {} +
$ find * -type f -exec sed -i "s:Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.:Foundation, Inc.:" {} +
$ find * -type f
-a \! -name \*.patch \
-a \! -name \*_shipped \
-a \! -name LICENSE_GPL \
-a \! -name LGPL.txt \
-a \! -name COPYING \
-a \! -name DISCLAIMER \
-exec sed -i "/Foundation, Inc./ N;s:Foundation, Inc.* USA\.* *:Foundation, Inc. :;s:Foundation, Inc. $:Foundation, Inc.:" {} +
Change-Id: Icc968a5a5f3a5df8d32b940f9cdb35350654bef9
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: http://review.coreboot.org/9233
Tested-by: build bot (Jenkins)
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
2015-03-26 15:17:45 +01:00
|
|
|
* Foundation, Inc.
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2013-04-24 23:28:52 +02:00
|
|
|
#include <bootstate.h>
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
#include <cbmem.h>
|
|
|
|
|
|
|
|
typedef struct file {
|
|
|
|
uint32_t magic;
|
|
|
|
struct file *next;
|
|
|
|
char *filename;
|
|
|
|
char *data;
|
|
|
|
int offset;
|
|
|
|
int len;
|
|
|
|
} FILE;
|
|
|
|
|
|
|
|
#define SEEK_SET 0 /* Seek from beginning of file. */
|
|
|
|
|
|
|
|
#define DIR_SEPARATOR '/'
|
|
|
|
#define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
|
|
|
|
#define HAS_DRIVE_SPEC(f) (0)
|
|
|
|
|
|
|
|
#define COVERAGE_SIZE (32*1024)
|
|
|
|
|
|
|
|
static FILE *current_file = NULL;
|
|
|
|
static FILE *previous_file = NULL;
|
|
|
|
|
|
|
|
static FILE *fopen(const char *path, const char *mode)
|
|
|
|
{
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
|
|
|
printk(BIOS_DEBUG, "fopen %s with mode %s\n",
|
|
|
|
path, mode);
|
|
|
|
#endif
|
|
|
|
if (!current_file) {
|
|
|
|
current_file = cbmem_add(CBMEM_ID_COVERAGE, 32*1024);
|
|
|
|
} else {
|
|
|
|
previous_file = current_file;
|
|
|
|
current_file = (FILE *)(ALIGN(((unsigned long)previous_file->data + previous_file->len), 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO check if we're at the end of the CBMEM region (ENOMEM)
|
|
|
|
if (current_file) {
|
|
|
|
current_file->magic = 0x584d4153;
|
|
|
|
current_file->next = NULL;
|
|
|
|
if (previous_file)
|
|
|
|
previous_file->next = current_file;
|
|
|
|
current_file->filename = (char *)¤t_file[1];
|
|
|
|
strcpy(current_file->filename, path);
|
|
|
|
current_file->data = (char *)ALIGN(((unsigned long)current_file->filename + strlen(path) + 1), 16);
|
|
|
|
current_file->offset = 0;
|
|
|
|
current_file->len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return current_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fclose(FILE *stream)
|
|
|
|
{
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
|
|
|
printk(BIOS_DEBUG, "fclose %s\n", stream->filename);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fseek(FILE *stream, long offset, int whence)
|
|
|
|
{
|
|
|
|
/* fseek should only be called with offset==0 and whence==SEEK_SET
|
|
|
|
* to a freshly opened file. */
|
|
|
|
gcc_assert (offset == 0 && whence == SEEK_SET);
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
2013-04-05 22:49:55 +02:00
|
|
|
printk(BIOS_DEBUG, "fseek %s offset=%ld whence=%d\n",
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
stream->filename, offset, whence);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long ftell(FILE *stream)
|
|
|
|
{
|
|
|
|
/* ftell should currently not be called */
|
|
|
|
gcc_assert(0);
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
|
|
|
printk(BIOS_DEBUG, "ftell %s\n", stream->filename);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
|
|
|
{
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
|
|
|
printk(BIOS_DEBUG, "fread: ptr=%p size=%zd nmemb=%zd FILE*=%p\n",
|
|
|
|
ptr, size, nmemb, stream);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
|
|
|
{
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
|
|
|
printk(BIOS_DEBUG, "fwrite: %zd * 0x%zd bytes to file %s\n",
|
|
|
|
nmemb, size, stream->filename);
|
|
|
|
#endif
|
|
|
|
// TODO check if file is last opened file and fail otherwise.
|
|
|
|
|
|
|
|
memcpy(stream->data + stream->offset, ptr, size * nmemb);
|
|
|
|
stream->len += (nmemb * size) - (stream->len - stream->offset);
|
|
|
|
stream->offset += nmemb * size;
|
|
|
|
return nmemb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setbuf(FILE *stream, char *buf)
|
|
|
|
{
|
|
|
|
gcc_assert(buf == 0);
|
|
|
|
}
|
|
|
|
|
2013-04-24 23:28:52 +02:00
|
|
|
static void coverage_init(void *unused)
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
{
|
|
|
|
extern long __CTOR_LIST__;
|
|
|
|
typedef void (*func_ptr)(void) ;
|
|
|
|
func_ptr *ctor = (func_ptr*) &__CTOR_LIST__;
|
|
|
|
if (ctor == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for ( ; *ctor != (func_ptr) 0; ctor++) {
|
|
|
|
(*ctor)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __gcov_flush(void);
|
2013-04-24 23:28:52 +02:00
|
|
|
static void coverage_exit(void *unused)
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
{
|
|
|
|
#if CONFIG_DEBUG_COVERAGE
|
|
|
|
printk(BIOS_DEBUG, "Syncing coverage data.\n");
|
|
|
|
#endif
|
|
|
|
__gcov_flush();
|
|
|
|
}
|
|
|
|
|
2015-03-16 23:30:09 +01:00
|
|
|
BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, coverage_init, NULL);
|
|
|
|
BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, coverage_exit, NULL);
|
|
|
|
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, coverage_exit, NULL);
|