1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 07:02:34 +02:00

tests/: Add CMocka unit-test infrastructure

This adds the CMocka unit-testing infrastructure into
the meson build system which we will latter follow up
with unit-tests for flashrom's core logic.

BUG=b:157280555
BRANCH=none
TEST=builds

Change-Id: I66665f56627b3d99049176bfbebbd771b080370a
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/41622
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Edward O'Callaghan 2020-05-20 20:10:20 +10:00 committed by Edward O'Callaghan
parent 6f793e4500
commit 46f2d4e488
6 changed files with 105 additions and 0 deletions

View File

@ -424,3 +424,23 @@ executable(
)
subdir('util')
# unit-test framework
cmocka_dep = dependency(
'cmocka',
fallback: ['cmocka', 'cmocka_dep']
)
flashrom_test_dep = declare_dependency(
include_directories : include_directories('.'),
sources : [
srcs,
'cli_common.c',
'cli_output.c',
'flashrom.c',
],
dependencies : [
deps,
],
)
subdir('tests')

10
subprojects/cmocka.wrap Normal file
View File

@ -0,0 +1,10 @@
[wrap-file]
directory = cmocka-1.1.5
source_url = https://cmocka.org/files/1.1/cmocka-1.1.5.tar.xz
source_filename = cmocka-1.1.5.tar.xz
source_hash = f0ccd8242d55e2fd74b16ba518359151f6f8383ff8aef4976e48393f77bba8b6
patch_url = https://wrapdb.mesonbuild.com/v1/projects/cmocka/1.1.5/3/get_zip
patch_filename = cmocka-1.1.5-3-wrap.zip
patch_hash = 81ce48613680d3c3a0b396ac570c852b290adcd18202fb16aaf703a9493f4348

18
tests/include/test.h Normal file
View File

@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */
#ifndef _TESTS_TEST_H
#define _TESTS_TEST_H
/*
* Standard test header that should be included in all tests. For now it just encapsulates the
* include dependencies for Cmocka. Test-specific APIs that are so generic we would want them
* available everywhere could also be added here.
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#endif /* _TESTS_TEST_H */

28
tests/meson.build Normal file
View File

@ -0,0 +1,28 @@
root_includes = include_directories('../subprojects')
srcs = [
'tests.c',
]
mocks = [
'-Wl,--wrap=physunmap',
'-Wl,--wrap=physmap',
'-Wl,--gc-sections',
]
flashrom_tests = executable('flashrom_unit_tests',
srcs,
include_directories : root_includes,
c_args : [
cargs,
'-ffunction-sections',
'-fdata-sections',
# '-DSTANDALONE',
'-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_DUMMY',
'-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
],
export_dynamic : true,
link_args : mocks,
dependencies : [cmocka_dep, flashrom_test_dep],
)
test('cmocka test flashrom', flashrom_tests)

25
tests/tests.c Normal file
View File

@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */
#include <include/test.h>
#include "tests.h"
#include <stdio.h>
/* redefinitions/wrapping */
void __wrap_physunmap(void *virt_addr, size_t len)
{
fprintf(stderr, "%s\n", __func__);
}
void *__wrap_physmap(const char *descr, uintptr_t phys_addr, size_t len)
{
fprintf(stderr, "%s\n", __func__);
return NULL;
}
int main(void)
{
int ret = 0;
return ret;
}

4
tests/tests.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef TESTS_H
#define TESTS_H
#endif /* TESTS_H */