Thomas Heijligen has uploaded this change for review.
meson: use static library for tests
Change-Id: If10ed70e3bf629a6eb7e2c5bef3318d1e259dadd
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
---
M meson.build
M tests/chip.c
M tests/flashrom.c
M tests/helpers.c
M tests/lifecycle.c
M tests/meson.build
M tests/tests.c
7 files changed, 39 insertions(+), 55 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/31/64031/1
diff --git a/meson.build b/meson.build
index dbee971..aee07b7 100644
--- a/meson.build
+++ b/meson.build
@@ -492,32 +492,5 @@
subdir('util')
if get_option('tests').auto() or get_option('tests').enabled() # .allowed() is introduced in 0.59.0
-# unit-test framework
-cmocka_dep = dependency(
- 'cmocka',
- fallback: ['cmocka', 'cmocka_dep'],
- required : get_option('tests')
- )
-
- flashrom_test_dep = declare_dependency(
- include_directories : include_dir,
- sources : [
- srcs,
- 'cli_common.c',
- 'cli_output.c',
- 'flashrom.c',
- ],
- compile_args : [
- '-includestdlib.h',
- '-includeunittest_env.h',
- '-includehwaccess_x86_io_unittest.h'
- ],
- dependencies : [
- deps,
- ],
- )
-
- if cmocka_dep.found()
- subdir('tests')
- endif
+ subdir('tests')
endif
diff --git a/tests/chip.c b/tests/chip.c
index 6f03172..ce6b53c 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -27,6 +27,7 @@
#include <include/test.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "tests.h"
diff --git a/tests/flashrom.c b/tests/flashrom.c
index cc88831..ecab69c 100644
--- a/tests/flashrom.c
+++ b/tests/flashrom.c
@@ -12,7 +12,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
-
+#include <stdlib.h>
#include <include/test.h>
#include "tests.h"
diff --git a/tests/helpers.c b/tests/helpers.c
index e2e652e..81cb1cd 100644
--- a/tests/helpers.c
+++ b/tests/helpers.c
@@ -19,6 +19,7 @@
#include "flash.h"
#include <stdint.h>
+#include <stdlib.h>
void address_to_bits_test_success(void **state)
{
diff --git a/tests/lifecycle.c b/tests/lifecycle.c
index 63fcc3c..99c360a 100644
--- a/tests/lifecycle.c
+++ b/tests/lifecycle.c
@@ -14,6 +14,7 @@
*/
#include <include/test.h>
+#include <stdlib.h>
#include <string.h>
#include <linux/spi/spidev.h>
diff --git a/tests/meson.build b/tests/meson.build
index d3b46b1..a2ac78e 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -11,20 +11,6 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-root_includes = include_directories('../subprojects')
-
-srcs = [
- 'io_mock.c',
- 'tests.c',
- 'libusb_wraps.c',
- 'helpers.c',
- 'flashrom.c',
- 'spi25.c',
- 'lifecycle.c',
- 'layout.c',
- 'chip.c',
-]
-
mocks = [
'-Wl,--wrap=strdup',
'-Wl,--wrap=physunmap',
@@ -95,16 +81,37 @@
'-Wl,--gc-sections',
]
-flashrom_tests = executable('flashrom_unit_tests',
- srcs,
- include_directories : root_includes,
- c_args : [
- cargs,
- '-ffunction-sections',
- '-fdata-sections',
- ],
- export_dynamic : true,
- link_args : mocks,
- dependencies : [cmocka_dep, flashrom_test_dep],
+cmocka = dependency(
+ 'cmocka',
+ fallback: ['cmocka', 'cmocka_dep'],
+ required : get_option('tests'),
)
-test('cmocka test flashrom', flashrom_tests)
+
+if cmocka.found()
+ flashrom_tests = executable(
+ 'flashrom_unit_tests',
+ files(
+ 'io_mock.c',
+ 'tests.c',
+ 'libusb_wraps.c',
+ 'helpers.c',
+ 'flashrom.c',
+ 'spi25.c',
+ 'lifecycle.c',
+ 'layout.c',
+ 'chip.c',
+ ),
+ c_args : [
+ cargs,
+ '-ffunction-sections',
+ '-fdata-sections',
+ ],
+ dependencies : [ cmocka, deps ],
+ export_dynamic : true,
+ include_directories : include_dir,
+ link_args : mocks,
+ link_with : libflashrom.get_static_lib(),
+ )
+
+ test('cmocka test flashrom', flashrom_tests)
+endif
\ No newline at end of file
diff --git a/tests/tests.c b/tests/tests.c
index 6aabd90..d0fc6af 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <stdint.h>
void *not_null(void)
To view, visit change 64031. To unsubscribe, or for help writing mail filters, visit settings.