oe-selftest 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. scripts_path = os.path.dirname(os.path.realpath(__file__))
  17. lib_path = scripts_path + '/lib'
  18. sys.path = sys.path + [lib_path]
  19. import argparse_oe
  20. import scriptutils
  21. import scriptpath
  22. scriptpath.add_oe_lib_path()
  23. scriptpath.add_bitbake_lib_path()
  24. from oeqa.utils import load_test_components
  25. from oeqa.core.exception import OEQAPreRun
  26. logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True)
  27. def main():
  28. 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."
  29. parser = argparse_oe.ArgumentParser(description=description)
  30. comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
  31. comp.register_commands(logger, parser)
  32. try:
  33. args = parser.parse_args()
  34. results = args.func(logger, args)
  35. ret = 0 if results.wasSuccessful() else 1
  36. except SystemExit as err:
  37. if err.code != 0:
  38. raise err
  39. ret = err.code
  40. except OEQAPreRun as pr:
  41. ret = 1
  42. return ret
  43. if __name__ == '__main__':
  44. try:
  45. ret = main()
  46. except Exception:
  47. ret = 1
  48. import traceback
  49. traceback.print_exc()
  50. sys.exit(ret)