oe-selftest 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2013-2017 Intel Corporation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License version 2 as
  6. # published by the Free Software Foundation.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along
  14. # with this program; if not, write to the Free Software Foundation, Inc.,
  15. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. # DESCRIPTION
  17. # This script runs tests defined in meta/lib/oeqa/selftest/
  18. # It's purpose is to automate the testing of different bitbake tools.
  19. # To use it you just need to source your build environment setup script and
  20. # add the meta-selftest layer to your BBLAYERS.
  21. # Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/
  22. # Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test
  23. # E.g: "oe-selftest -r bblayers.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/oeqa/selftest/bblayers.py
  24. import os
  25. import sys
  26. import argparse
  27. import logging
  28. scripts_path = os.path.dirname(os.path.realpath(__file__))
  29. lib_path = scripts_path + '/lib'
  30. sys.path = sys.path + [lib_path]
  31. import argparse_oe
  32. import scriptutils
  33. import scriptpath
  34. scriptpath.add_oe_lib_path()
  35. scriptpath.add_bitbake_lib_path()
  36. from oeqa.utils import load_test_components
  37. from oeqa.core.exception import OEQAPreRun
  38. logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout)
  39. def main():
  40. 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."
  41. parser = argparse_oe.ArgumentParser(description=description)
  42. comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
  43. comp.register_commands(logger, parser)
  44. try:
  45. args = parser.parse_args()
  46. results = args.func(logger, args)
  47. ret = 0 if results.wasSuccessful() else 1
  48. except SystemExit as err:
  49. if err.code != 0:
  50. raise err
  51. ret = err.code
  52. except OEQAPreRun as pr:
  53. ret = 1
  54. return ret
  55. if __name__ == '__main__':
  56. try:
  57. ret = main()
  58. except Exception:
  59. ret = 1
  60. import traceback
  61. traceback.print_exc()
  62. sys.exit(ret)