Attention is currently required from: Edward O'Callaghan, Angel Pons.
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/52024 )
Change subject: [RFC] Makefile: Deflate dependency handling
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
There are some more classes that could be extracted, e.g.
NEEDS_RAW_ACCESS, NEEDS_TTY.
--
To view, visit https://review.coreboot.org/c/flashrom/+/52024
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I33049474a95d288c9a84e412633c99fbc251ac03
Gerrit-Change-Number: 52024
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <edward.ocallaghan(a)koparo.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Edward O'Callaghan <edward.ocallaghan(a)koparo.com>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Comment-Date: Thu, 01 Apr 2021 12:35:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: Angel Pons, Anastasia Klimchuk.
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51487 )
Change subject: Add unit test to run init/shutdown for enabled drivers
......................................................................
Patch Set 1:
(1 comment)
File mec1308.c:
https://review.coreboot.org/c/flashrom/+/51487/comment/8440124f_ff22057f
PS1, Line 115: #endif /* UNIT_TEST_ENV */
> I was thinking about separate compilation units for a while, how exactly to do this. […]
I guess we could have something like a `hwaccess_unittest.h`, yes. It could be
hooked up via `-include` and `#define __HW_ACCESS_H__`. This way the original
`hwaccess.h` would be bypassed.
It could provide a single definition for the used macros, e.g.
#define OUTB(v, p) test_outb(v, p)
#define INB(p) test_inb(p)
etc.
However, the original `hwaccess.h` provides more than the I/O macros. Maybe
we should split that out?
There are probably many ways to solve the per-driver mocking issue. Two ideas
from the top of my head:
1. Build multiple test binaries, each with its own versions of test_outb() etc.
2. Provide some abstraction via function pointers. e.g. a struct per test with
struct test_io {
void (*outb)(unsigned char value, unsigned short port);
unsigned char (*inb)(unsigned short port);
/* etc. */
}
extern const struct test_io *test_io;
And then before each test, set
test_io = test_io_mec1308;
The test_*() functions would then simply call the respective function in
`test_io`, e.g.:
void test_outb(unsigned char value, unsigned short port)
{
test_io->outb(value, port);
}
--
To view, visit https://review.coreboot.org/c/flashrom/+/51487
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3af612defe1af3850dfc1626a208d873e3a3eddc
Gerrit-Change-Number: 51487
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-CC: Nico Huber <nico.h(a)gmx.de>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Comment-Date: Thu, 01 Apr 2021 10:32:51 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/51243 )
Change subject: Enable dynamic memory allocation checks for cmocka unit tests
......................................................................
Enable dynamic memory allocation checks for cmocka unit tests
This commit enables the feature and makes changes to existing
files and tests. I am writing more new tests with this.
Commit includes tests/flashrom.c because after enabling memory
checks the test started to fail (it used to leak memory indeed).
If you are wondering how to verify it works (because at the moment
all tests [still] pass so it’s not obvious that anything has
changed), then for example:
1) Remove free’s in flashbuses_to_text_test_success test, and it
will fail with message similar to this (line numbers from your local
source)
[ ERROR ] --- Blocks allocated...
../flashrom.c:1239: note: block 0x55f42304b640 allocated here
../flashrom.c:1239: note: block 0x55f42304b5c0 allocated here
../flashrom.c:1239: note: block 0x55f42304b3d0 allocated here
../flashrom.c:1239: note: block 0x55f42304b700 allocated here
../flashrom.c:1239: note: block 0x55f42304b780 allocated here
../flashrom.c:1239: note: block 0x55f42304bb00 allocated here
../flashrom.c:1239: note: block 0x55f42304b810 allocated here
ERROR: flashbuses_to_text_test_success leaked 7 block(s)
2) Add char *temp = malloc just before return from strcat_realloc
[ ERROR ] --- Blocks allocated...
../helpers.c:88: note: block 0x55a51307b6c0 allocated here
../helpers.c:88: note: block 0x55a51307b9e0 allocated here
ERROR: strcat_realloc_test_success leaked 2 block(s)
BUG=b:181803212
TEST=builds and ninja test
nm builddir/tests/flashrom_unit_tests.p/.._flashrom.c.o
nm builddir/tests/flashrom_unit_tests.p/flashrom.c.o
nm builddir/flashrom.p/flashrom.c.o
Change-Id: I0c6b6b8dc17aaee28640e3fca3d1fc9f7feabf5f
Signed-off-by: Anastasia Klimchuk <aklm(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/51243
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Nico Huber <nico.h(a)gmx.de>
Reviewed-by: Angel Pons <th3fanbus(a)gmail.com>
---
M meson.build
M tests/flashrom.c
M tests/helpers.c
A unittest_env.h
4 files changed, 81 insertions(+), 12 deletions(-)
Approvals:
build bot (Jenkins): Verified
Nico Huber: Looks good to me, approved
Angel Pons: Looks good to me, approved
diff --git a/meson.build b/meson.build
index d5895d8..5b339e0 100644
--- a/meson.build
+++ b/meson.build
@@ -472,6 +472,10 @@
'cli_output.c',
'flashrom.c',
],
+ compile_args : [
+ '-includestdlib.h',
+ '-includeunittest_env.h',
+ ],
dependencies : [
deps,
],
diff --git a/tests/flashrom.c b/tests/flashrom.c
index 50464dd..c3508c5 100644
--- a/tests/flashrom.c
+++ b/tests/flashrom.c
@@ -17,35 +17,54 @@
#include "programmer.h"
+#define assert_equal_and_free(text, expected) \
+ do { \
+ assert_string_equal(text, expected); \
+ free(text); \
+ } while (0)
+
+#define assert_not_equal_and_free(text, expected) \
+ do { \
+ assert_string_not_equal(text, expected); \
+ free(text); \
+ } while (0)
+
+
void flashbuses_to_text_test_success(void **state)
{
(void) state; /* unused */
enum chipbustype bustype;
+ char *text;
bustype = BUS_NONSPI;
- assert_string_equal(flashbuses_to_text(bustype), "Non-SPI");
+ text = flashbuses_to_text(bustype);
+ assert_equal_and_free(text, "Non-SPI");
bustype |= BUS_PARALLEL;
- assert_string_not_equal(flashbuses_to_text(bustype), "Non-SPI, Parallel");
+ text = flashbuses_to_text(bustype);
+ assert_not_equal_and_free(text, "Non-SPI, Parallel");
bustype = BUS_PARALLEL;
bustype |= BUS_LPC;
- assert_string_equal(flashbuses_to_text(bustype), "Parallel, LPC");
+ text = flashbuses_to_text(bustype);
+ assert_equal_and_free(text, "Parallel, LPC");
bustype |= BUS_FWH;
//BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
- assert_string_equal(flashbuses_to_text(bustype), "Non-SPI");
+ text = flashbuses_to_text(bustype);
+ assert_equal_and_free(text, "Non-SPI");
bustype |= BUS_SPI;
- assert_string_equal(flashbuses_to_text(bustype), "Parallel, LPC, FWH, SPI");
+ text = flashbuses_to_text(bustype);
+ assert_equal_and_free(text, "Parallel, LPC, FWH, SPI");
bustype |= BUS_PROG;
- assert_string_equal(
- flashbuses_to_text(bustype),
- "Parallel, LPC, FWH, SPI, Programmer-specific"
- );
+ text = flashbuses_to_text(bustype);
+ assert_equal_and_free(text,
+ "Parallel, LPC, FWH, SPI, Programmer-specific");
bustype = BUS_NONE;
- assert_string_equal(flashbuses_to_text(bustype), "None");
+ text = flashbuses_to_text(bustype);
+ assert_equal_and_free(text, "None");
}
diff --git a/tests/helpers.c b/tests/helpers.c
index a920c15..4376eee 100644
--- a/tests/helpers.c
+++ b/tests/helpers.c
@@ -18,8 +18,6 @@
#include "flash.h"
#include <stdint.h>
-#include <stdlib.h>
-
void address_to_bits_test_success(void **state)
{
diff --git a/unittest_env.h b/unittest_env.h
new file mode 100644
index 0000000..9bd7509
--- /dev/null
+++ b/unittest_env.h
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2021 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.
+ */
+
+/*
+ * This header is included in all files when they are built for unit test
+ * environment, for all the files to be covered by dynamic memory allocation
+ * checks (checks for memory leaks, buffer overflows and underflows).
+ *
+ * See flashrom_test_dep in meson.build for more details.
+ *
+ * https://api.cmocka.org/group__cmocka__alloc.html
+ */
+
+extern void* _test_malloc(const size_t size, const char* file, const int line);
+extern void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
+extern void* _test_calloc(const size_t number_of_elements, const size_t size,
+ const char* file, const int line);
+extern void _test_free(void* const ptr, const char* file, const int line);
+
+#ifdef malloc
+#undef malloc
+#endif
+#ifdef calloc
+#undef calloc
+#endif
+#ifdef realloc
+#undef realloc
+#endif
+#ifdef free
+#undef free
+#endif
+
+#define malloc(size) _test_malloc(size, __FILE__, __LINE__)
+#define realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__)
+#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
+#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
--
To view, visit https://review.coreboot.org/c/flashrom/+/51243
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c6b6b8dc17aaee28640e3fca3d1fc9f7feabf5f
Gerrit-Change-Number: 51243
Gerrit-PatchSet: 8
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Daniel Kurtz <djkurtz(a)google.com>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Daniel Kurtz <djkurtz(a)chromium.org>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-CC: Thomas Heijligen <src(a)posteo.de>
Gerrit-CC: Victor Ding <victording(a)chromium.org>
Gerrit-MessageType: merged
Attention is currently required from: Edward O'Callaghan, Angel Pons, Daniel Campello.
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51930 )
Change subject: Makefile,meson.build: Fix dependency issues with raiden_debug_spi
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
> No worries, luckily I saw the email in my uncontrollable corp inbox. […]
Yes, a line like this. I couldn't find it.
--
To view, visit https://review.coreboot.org/c/flashrom/+/51930
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I2d6a8c33a2228abf006a9b278bcb7133765c7074
Gerrit-Change-Number: 51930
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Daniel Campello <campello(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Daniel Campello <campello(a)chromium.org>
Gerrit-Comment-Date: Thu, 01 Apr 2021 10:09:45 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Peter Marheine.
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51967 )
Change subject: lspcon_i2c_spi: support a devpath option
......................................................................
Patch Set 2: Code-Review+1
(5 comments)
File lspcon_i2c_spi.c:
https://review.coreboot.org/c/flashrom/+/51967/comment/c7b42129_979dcfe0
PS1, Line 486: msg_perr("%s: one of devpath or bus must be specified\n", __func__);
> Revised further so invalid bus values are distinct from unspecified, allowing the two options to be […]
Looks pretty good, thanks!
File lspcon_i2c_spi.c:
https://review.coreboot.org/c/flashrom/+/51967/comment/1d761af6_038e166e
PS2, Line 457: __func__);
nit: `__func__` probably fits on the previous line
https://review.coreboot.org/c/flashrom/+/51967/comment/1ed569e8_6344b581
PS2, Line 463: __func__);
nit: `__func__` most likely fits on the previous line
https://review.coreboot.org/c/flashrom/+/51967/comment/595e213a_008dcb85
PS2, Line 489:
nit: replace 8 spaces with a tab
https://review.coreboot.org/c/flashrom/+/51967/comment/9d92aef5_92a9d149
PS2, Line 492: } else if (device_path != NULL) {
The first two cases are error paths that return an error, whereas the last two cases are the "normal" paths. I wouldn't use `else` with the former, in order to differentiate both kinds of paths:
if (device_path != NULL && bus_number >= 0) {
msg_perr("%s: only one of bus and devpath may be specified\n", __func__);
free(device_path);
return SPI_GENERIC_ERROR;
}
if (device_path == NULL && bus_number < 0) {
msg_perr("%s: one of bus and devpath must be specified\n", __func__);
return SPI_GENERIC_ERROR;
}
if (device_path != NULL) {
fd = i2c_open_path(device_path, REGISTER_ADDRESS, 0);
free(device_path);
} else {
fd = i2c_open(bus_number, REGISTER_ADDRESS, 0);
}
--
To view, visit https://review.coreboot.org/c/flashrom/+/51967
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id2adf8a307b9205ce5e5804a6c3e22f19d0c34c9
Gerrit-Change-Number: 51967
Gerrit-PatchSet: 2
Gerrit-Owner: Peter Marheine <pmarheine(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Daniel Campello <campello(a)chromium.org>
Gerrit-Attention: Peter Marheine <pmarheine(a)chromium.org>
Gerrit-Comment-Date: Thu, 01 Apr 2021 07:35:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Comment-In-Reply-To: Peter Marheine <pmarheine(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: David Hendricks, Edward O'Callaghan.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51243 )
Change subject: Enable dynamic memory allocation checks for cmocka unit tests
......................................................................
Patch Set 7:
(1 comment)
Patchset:
PS7:
I wanted to say thank you to all my reviewers! I see +2s so if you think this can be submitted, could you please submit? (I can’t do it myself).
--
To view, visit https://review.coreboot.org/c/flashrom/+/51243
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c6b6b8dc17aaee28640e3fca3d1fc9f7feabf5f
Gerrit-Change-Number: 51243
Gerrit-PatchSet: 7
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Daniel Kurtz <djkurtz(a)google.com>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Daniel Kurtz <djkurtz(a)chromium.org>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-CC: Thomas Heijligen <src(a)posteo.de>
Gerrit-CC: Victor Ding <victording(a)chromium.org>
Gerrit-Attention: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Comment-Date: Thu, 01 Apr 2021 01:59:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: David Hendricks, Edward O'Callaghan.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51243 )
Change subject: Enable dynamic memory allocation checks for cmocka unit tests
......................................................................
Patch Set 7:
(1 comment)
File meson.build:
https://review.coreboot.org/c/flashrom/+/51243/comment/af2e565f_3972543d
PS6, Line 477: -include
> Ah, sorry. I'm still very used to the comfort and pain of having […]
I am fine with no-spaces, it aligns with -D definitions (like the ones above -DCONFIG_DEFAULT_PROGRAMMER_ARGS="" there is no space between D and the rest).
--
To view, visit https://review.coreboot.org/c/flashrom/+/51243
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c6b6b8dc17aaee28640e3fca3d1fc9f7feabf5f
Gerrit-Change-Number: 51243
Gerrit-PatchSet: 7
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Daniel Kurtz <djkurtz(a)google.com>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Daniel Kurtz <djkurtz(a)chromium.org>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-CC: Thomas Heijligen <src(a)posteo.de>
Gerrit-CC: Victor Ding <victording(a)chromium.org>
Gerrit-Attention: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Comment-Date: Thu, 01 Apr 2021 00:49:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Huber <nico.h(a)gmx.de>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment