oe-selftest 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2013-2017 Intel Corporation
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. # DESCRIPTION
  7. # This script runs tests defined in meta/lib/oeqa/selftest/
  8. # It's purpose is to automate the testing of different bitbake tools.
  9. # To use it you just need to source your build environment setup script and
  10. # add the meta-selftest layer to your BBLAYERS.
  11. # Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/
  12. # Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test
  13. # E.g: "oe-selftest -r bblayers.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/oeqa/selftest/bblayers.py
  14. import os
  15. import sys
  16. import argparse
  17. import logging
  18. scripts_path = os.path.dirname(os.path.realpath(__file__))
  19. lib_path = scripts_path + '/lib'
  20. sys.path = sys.path + [lib_path]
  21. import argparse_oe
  22. import scriptutils
  23. import scriptpath
  24. scriptpath.add_oe_lib_path()
  25. scriptpath.add_bitbake_lib_path()
  26. from oeqa.utils import load_test_components
  27. from oeqa.core.exception import OEQAPreRun
  28. logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True)
  29. def main():
  30. description = "Script that runs unit tests against bitbake and other Yocto related tools. The goal is to validate tools functionality and metadata integrity. Refer to https://wiki.yoctoproject.org/wiki/Oe-selftest for more information."
  31. parser = argparse_oe.ArgumentParser(description=description)
  32. comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
  33. comp.register_commands(logger, parser)
  34. try:
  35. args = parser.parse_args()
  36. results = args.func(logger, args)
  37. ret = 0 if results.wasSuccessful() else 1
  38. except SystemExit as err:
  39. if err.code != 0:
  40. raise err
  41. ret = err.code
  42. except OEQAPreRun as pr:
  43. ret = 1
  44. return ret
  45. if __name__ == '__main__':
  46. try:
  47. ret = main()
  48. except Exception:
  49. ret = 1
  50. import traceback
  51. traceback.print_exc()
  52. sys.exit(ret)