test/py: Allow using buildman to build U-Boot

It is a pain to have to set the CROSS_COMPILE environment variable when
using test.py's --build option. It is possible to get this using the -A
option from buildman. But it seems better to just use buildman to do the
build when it is available.

However using buildman adds a new dependency to the test system which we
want to avoid. So leave the default as is and add a flag to make it use
buildman.

Note that most of these changes relate to test.py and the parts of the
travis/gitlab/azure scripts which relate to running test and building a
suitable U-Boot to run the tests on.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Simon Glass 2020-03-18 09:43:01 -06:00 committed by Tom Rini
parent 7ec1255cea
commit f5ec7eebf7
2 changed files with 33 additions and 10 deletions

View file

@ -138,6 +138,9 @@ command-line option; see the next section.
before running the tests. If using this option, make sure that any before running the tests. If using this option, make sure that any
environment variables required by the build process are already set, such as environment variables required by the build process are already set, such as
`$CROSS_COMPILE`. `$CROSS_COMPILE`.
- `--buildman` indicates that `--build` should use buildman to build U-Boot.
There is no need to set $CROSS_COMPILE` in this case since buildman handles
it.
- `--build-dir` sets the directory containing the compiled U-Boot binaries. - `--build-dir` sets the directory containing the compiled U-Boot binaries.
If omitted, this is `${source_dir}/build-${board_type}`. If omitted, this is `${source_dir}/build-${board_type}`.
- `--result-dir` sets the directory to write results, such as log files, - `--result-dir` sets the directory to write results, such as log files,
@ -333,7 +336,7 @@ PATH=$HOME/ubtest/bin:$PATH \
If you want the test script to compile U-Boot for you too, then you likely If you want the test script to compile U-Boot for you too, then you likely
need to set `$CROSS_COMPILE` to allow this, and invoke the test script as need to set `$CROSS_COMPILE` to allow this, and invoke the test script as
follow: follows:
```bash ```bash
CROSS_COMPILE=arm-none-eabi- \ CROSS_COMPILE=arm-none-eabi- \
@ -342,6 +345,14 @@ CROSS_COMPILE=arm-none-eabi- \
./test/py/test.py --bd seaboard --build ./test/py/test.py --bd seaboard --build
``` ```
or, using buildman to handle it:
```bash
PATH=$HOME/ubtest/bin:$PATH \
PYTHONPATH=${HOME}/ubtest/py/${HOSTNAME}:${PYTHONPATH} \
./test/py/test.py --bd seaboard --build --buildman
```
## Writing tests ## Writing tests
Please refer to the pytest documentation for details of writing pytest tests. Please refer to the pytest documentation for details of writing pytest tests.

View file

@ -70,6 +70,8 @@ def pytest_addoption(parser):
help='U-Boot board identity/instance') help='U-Boot board identity/instance')
parser.addoption('--build', default=False, action='store_true', parser.addoption('--build', default=False, action='store_true',
help='Compile U-Boot before running tests') help='Compile U-Boot before running tests')
parser.addoption('--buildman', default=False, action='store_true',
help='Use buildman to build U-Boot (assuming --build is given)')
parser.addoption('--gdbserver', default=None, parser.addoption('--gdbserver', default=None,
help='Run sandbox under gdbserver. The argument is the channel '+ help='Run sandbox under gdbserver. The argument is the channel '+
'over which gdbserver should communicate, e.g. localhost:1234') 'over which gdbserver should communicate, e.g. localhost:1234')
@ -140,16 +142,26 @@ def pytest_configure(config):
log = multiplexed_log.Logfile(result_dir + '/test-log.html') log = multiplexed_log.Logfile(result_dir + '/test-log.html')
if config.getoption('build'): if config.getoption('build'):
if build_dir != source_dir: if config.getoption('buildman'):
o_opt = 'O=%s' % build_dir if build_dir != source_dir:
dest_args = ['-o', build_dir, '-w']
else:
dest_args = ['-i']
cmds = (['buildman', '--board', board_type] + dest_args,)
name = 'buildman'
else: else:
o_opt = '' if build_dir != source_dir:
cmds = ( o_opt = 'O=%s' % build_dir
['make', o_opt, '-s', board_type + '_defconfig'], else:
['make', o_opt, '-s', '-j8'], o_opt = ''
) cmds = (
with log.section('make'): ['make', o_opt, '-s', board_type + '_defconfig'],
runner = log.get_runner('make', sys.stdout) ['make', o_opt, '-s', '-j8'],
)
name = 'make'
with log.section(name):
runner = log.get_runner(name, sys.stdout)
for cmd in cmds: for cmd in cmds:
runner.run(cmd, cwd=source_dir) runner.run(cmd, cwd=source_dir)
runner.close() runner.close()