Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/69266 )
(
13 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: tests: Detect gcov run and redirect to real I/O functions
......................................................................
tests: Detect gcov run and redirect to real I/O functions
Code coverage writes data to disk, we need to use real io functions at
this point so that the data is really written.
BUG=b:187647884
BRANCH=None
TEST=meson test
TEST=ninja coverage
Change-Id: If06053ecd78e886c8f7fc55813f4b5635be78c6b
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69266
Reviewed-by: Anastasia Klimchuk <aklm(a)chromium.org>
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
---
M Documentation/building.md
M tests/tests.c
2 files changed, 35 insertions(+), 0 deletions(-)
Approvals:
build bot (Jenkins): Verified
Anastasia Klimchuk: Looks good to me, approved
diff --git a/Documentation/building.md b/Documentation/building.md
index aabb45b..81daeb0 100644
--- a/Documentation/building.md
+++ b/Documentation/building.md
@@ -48,6 +48,18 @@
ninja -C builddir test
```
+### Run unit tests with code coverage
+#### gcov
+Due to a bug in lcov, the html file will only be correct if lcov is not
+installed and gcovr is installed. See
+https://github.com/linux-test-project/lcov/issues/168
+https://github.com/mesonbuild/meson/issues/6747
+```
+meson setup buildcov -Db_coverage=true
+ninja -C buildcov test
+ninja -C buildcov coverage
+```
+
## System specific information
### Ubuntu / Debian (Linux)
* __linux-headers__ are version specific
diff --git a/tests/tests.c b/tests/tests.c
index 41972ba..b11f642 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -17,6 +17,7 @@
#include "io_mock.h"
#include "tests.h"
#include "wraps.h"
+#include "io_real.h"
#include <stdio.h>
#include <string.h>
@@ -77,6 +78,7 @@
static int mock_open(const char *pathname, int flags, mode_t mode)
{
+ maybe_unmock_io(pathname);
if (get_io() && get_io()->iom_open)
return get_io()->iom_open(get_io()->state, pathname, flags, mode);
--
To view, visit https://review.coreboot.org/c/flashrom/+/69266
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If06053ecd78e886c8f7fc55813f4b5635be78c6b
Gerrit-Change-Number: 69266
Gerrit-PatchSet: 15
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-MessageType: merged
Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/69539 )
Change subject: tests: Redirect to real I/O to support coverage run
......................................................................
tests: Redirect to real I/O to support coverage run
Implement a check that redirects mock io functions to the real
implementations. Real I/O functions are needed for the coverage tool to
be able to create and write files.
BUG=None
BRANCH=None
TEST=None
Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69539
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm(a)chromium.org>
---
A tests/io_real.c
A tests/io_real.h
M tests/meson.build
M tests/wraps.h
4 files changed, 112 insertions(+), 0 deletions(-)
Approvals:
build bot (Jenkins): Verified
Anastasia Klimchuk: Looks good to me, approved
diff --git a/tests/io_real.c b/tests/io_real.c
new file mode 100644
index 0000000..9f9e9d6
--- /dev/null
+++ b/tests/io_real.c
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2022 Google LLC
+ *
+ * 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.
+ */
+
+#include "io_mock.h"
+#include "wraps.h"
+
+#include "io_real.h"
+#include <string.h>
+
+static int io_real_open(void *state, const char *pathname, int flags, mode_t mode)
+{
+ LOG_ME;
+ return __real_open(pathname, flags, mode);
+}
+
+static FILE *io_real_fdopen(void *state, int fd, const char *mode)
+{
+ LOG_ME;
+ return __real_fdopen(fd, mode);
+}
+
+static size_t io_real_fwrite(void *state, const void *ptr, size_t size, size_t nmemb, FILE *fp)
+{
+ return __real_fwrite(ptr, size, nmemb, fp);
+}
+
+/* Mock ios that defer to the real io functions.
+ * These exist so that code coverage can print to real files on disk.
+ */
+static const struct io_mock real_io = {
+ .iom_open = io_real_open,
+ .iom_fwrite = io_real_fwrite,
+ .iom_fdopen = io_real_fdopen,
+};
+
+/* Return 0 if string ends with suffix. */
+static int check_suffix(const char *string, const char *suffix)
+{
+ int len_l = strlen(string);
+ int len_r = strlen(suffix);
+ if (len_l > len_r)
+ return strcmp(string + len_l - len_r, suffix);
+ return 1;
+}
+
+void maybe_unmock_io(const char *pathname)
+{
+ const char *gcov_suffix = ".gcda";
+ if (!check_suffix(pathname, gcov_suffix))
+ io_mock_register(&real_io);
+}
diff --git a/tests/io_real.h b/tests/io_real.h
new file mode 100644
index 0000000..f2491c3
--- /dev/null
+++ b/tests/io_real.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2022 Google LLC
+ *
+ * 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.
+ */
+
+#ifndef IO_REAL_H
+#define IO_REAL_H
+
+/* Detect file io that should not be mocked, for example code coverage writing
+ * gcda files. Call io_mock_register with functions that defer to real io.
+ */
+void maybe_unmock_io(const char* pathname);
+
+#endif /* IO_REAL_H */
diff --git a/tests/meson.build b/tests/meson.build
index b8a5ba8..0d605d2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -23,6 +23,7 @@
'chip.c',
'chip_wp.c',
'selfcheck.c',
+ 'io_real.c',
)
if not programmer.get('dummy').get('active')
diff --git a/tests/wraps.h b/tests/wraps.h
index e224d79..92b0c42 100644
--- a/tests/wraps.h
+++ b/tests/wraps.h
@@ -29,6 +29,7 @@
void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data);
uint8_t __wrap_sio_read(uint16_t port, uint8_t reg);
int __wrap_open(const char *pathname, int flags, ...);
+int __real_open(const char *pathname, int flags, ...);
int __wrap_open64(const char *pathname, int flags, ...);
int __wrap___open64_2(const char *pathname, int flags, ...);
int __wrap_ioctl(int fd, unsigned long int request, ...);
@@ -37,6 +38,7 @@
FILE *__wrap_fopen(const char *pathname, const char *mode);
FILE *__wrap_fopen64(const char *pathname, const char *mode);
FILE *__wrap_fdopen(int fd, const char *mode);
+FILE *__real_fdopen(int fd, const char *mode);
int __wrap_stat(const char *path, void *buf);
int __wrap_stat64(const char *path, void *buf);
int __wrap___xstat(const char *path, void *buf);
@@ -49,6 +51,7 @@
char *__wrap___fgets_chk(char *buf, int len, FILE *fp);
size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *fp);
size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp);
+size_t __real_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *fp);
int __wrap_fflush(FILE *fp);
int __wrap_fileno(FILE *fp);
int __wrap_fsync(int fd);
--
To view, visit https://review.coreboot.org/c/flashrom/+/69539
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Gerrit-Change-Number: 69539
Gerrit-PatchSet: 6
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-MessageType: merged
Attention is currently required from: Thomas Heijligen, Evan Benn.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/69539 )
Change subject: tests: Redirect to real I/O to support coverage run
......................................................................
Patch Set 5: Code-Review+2
--
To view, visit https://review.coreboot.org/c/flashrom/+/69539
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Gerrit-Change-Number: 69539
Gerrit-PatchSet: 5
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Evan Benn <evanbenn(a)google.com>
Gerrit-Comment-Date: Fri, 09 Dec 2022 00:19:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: Edward O'Callaghan, Angel Pons.
Nikolai Artemiev has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/70128 )
Change subject: flashrom: Skip read/write/erase/verify ops on inaccessable flash regions
......................................................................
Patch Set 20:
(1 comment)
Commit Message:
https://review.coreboot.org/c/flashrom/+/70128/comment/993a208d_8490e962
PS6, Line 11: platforms with active an CSME coprocessor.
> Ack, we can handle the cases differently. […]
Ok I've uploaded a new patchset with some flags to control this behavior. I think it's best to have two flags, one for skipping read protected regions and one for skipping write protected regions.
That way it's possible to configure the exact behavior you want, e.g. for verify:
```
strictly verify everything -> skip_unreadable=false, skip_unwriteable=false
verify everything we can read -> skip_unreadable=true, skip_unwriteable=false
verify only RW regions -> skip_unreadable=true, skip_unwriteable=true
```
--
To view, visit https://review.coreboot.org/c/flashrom/+/70128
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I9b96fb04b863625d2c9f9a00b97c35b3ddb0871b
Gerrit-Change-Number: 70128
Gerrit-PatchSet: 20
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Comment-Date: Fri, 09 Dec 2022 00:08:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Comment-In-Reply-To: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-MessageType: comment
Attention is currently required from: Edward O'Callaghan, Angel Pons, Nikolai Artemiev.
Hello build bot (Jenkins), Edward O'Callaghan,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/70128
to look at the new patch set (#20).
Change subject: flashrom: Skip read/write/erase/verify ops on inaccessable flash regions
......................................................................
flashrom: Skip read/write/erase/verify ops on inaccessable flash regions
Skip flash regions that get_region() indicates are inaccessable. This
fixes transaction errors due to accessing unreadable flash regions on
Intel platforms with active an CSME coprocessor.
BUG=b:260440773
BRANCH=none
TEST=flashrom -{r,w,E,v} on dedede (JSL)
Change-Id: I9b96fb04b863625d2c9f9a00b97c35b3ddb0871b
CoAuthored-by: Edward O'Callaghan <quasisec(a)google.com>
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
Signed-off-by: Nikolai Artemiev <nartemiev(a)google.com>
---
M flashrom.c
M include/flash.h
M include/libflashrom.h
M libflashrom.c
4 files changed, 229 insertions(+), 26 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/28/70128/20
--
To view, visit https://review.coreboot.org/c/flashrom/+/70128
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I9b96fb04b863625d2c9f9a00b97c35b3ddb0871b
Gerrit-Change-Number: 70128
Gerrit-PatchSet: 20
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-MessageType: newpatchset
Attention is currently required from: Thomas Heijligen, Evan Benn.
Hello build bot (Jenkins), Thomas Heijligen, Edward O'Callaghan, Anastasia Klimchuk,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/69268
to look at the new patch set (#17).
Change subject: tests: Add llvm-cov option and run target for code coverage
......................................................................
tests: Add llvm-cov option and run target for code coverage
Code coverage can be requested with -Dllvm_cov and run with ninja
llvm-cov-tests or llvm-cov-cli.
BUG=b:187647884
BRANCH=None
TEST=meson test; ninja llvm-cov-tests
TEST=ran test_build.sh with coverage enabled
Change-Id: Id6c73bff46e7b88d425956a80def97082b201f56
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
---
M Documentation/building.md
M meson.build
M meson_options.txt
A scripts/llvm-cov
M tests/meson.build
5 files changed, 45 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/68/69268/17
--
To view, visit https://review.coreboot.org/c/flashrom/+/69268
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id6c73bff46e7b88d425956a80def97082b201f56
Gerrit-Change-Number: 69268
Gerrit-PatchSet: 17
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Evan Benn <evanbenn(a)google.com>
Gerrit-MessageType: newpatchset
Attention is currently required from: Thomas Heijligen, Evan Benn.
Hello build bot (Jenkins), Thomas Heijligen, Edward O'Callaghan, Anastasia Klimchuk,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/69539
to look at the new patch set (#5).
Change subject: tests: Redirect to real I/O to support coverage run
......................................................................
tests: Redirect to real I/O to support coverage run
Implement a check that redirects mock io functions to the real
implementations. Real I/O functions are needed for the coverage tool to
be able to create and write files.
BUG=None
BRANCH=None
TEST=None
Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Signed-off-by: Evan Benn <evanbenn(a)chromium.org>
---
A tests/io_real.c
A tests/io_real.h
M tests/meson.build
M tests/wraps.h
4 files changed, 109 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/39/69539/5
--
To view, visit https://review.coreboot.org/c/flashrom/+/69539
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805
Gerrit-Change-Number: 69539
Gerrit-PatchSet: 5
Gerrit-Owner: Evan Benn <evanbenn(a)google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Evan Benn <evanbenn(a)google.com>
Gerrit-MessageType: newpatchset