build_kernel_tests.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #! /usr/bin/env python
  2. # Copyright (c) 2021, The Linux Foundation. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following
  11. # disclaimer in the documentation and/or other materials provided
  12. # with the distribution.
  13. # * Neither the name of The Linux Foundation nor the names of its
  14. # contributors may be used to endorse or promote products derived
  15. # from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import os
  29. import os.path
  30. import subprocess
  31. import sys
  32. import shutil
  33. install_dir = '/ipa-kernel-tests' # unlikely to ever change, so 'file constant'
  34. def get_args():
  35. class Args:
  36. pass
  37. args = Args()
  38. try:
  39. args.cc_path = os.path.dirname(os.environ['CROSS_COMPILE'])
  40. except:
  41. args.cc_path = None
  42. try:
  43. args.arch = os.environ['ARCH']
  44. except:
  45. raise Exception("ARCH must be set")
  46. try:
  47. args.kdir = os.environ['KDIR']
  48. except:
  49. raise Exception("KDIR must be set")
  50. try:
  51. args.dest = os.environ['DESTDIR']
  52. except:
  53. raise Exception("DESTDIR must be set")
  54. return args
  55. def do(cmd, wdir=None):
  56. cwd = None
  57. if wdir:
  58. cwd = os.getcwd()
  59. os.chdir(wdir)
  60. subprocess.check_call(cmd)
  61. if cwd:
  62. os.chdir(cwd)
  63. def build(args):
  64. if args.cc_path:
  65. os.environ['PATH'] = args.cc_path + ':' + os.environ['PATH']
  66. args.uapi = args.kdir + '/usr/include'
  67. args.src = args.kdir + '/techpack/dataipa/kernel-tests'
  68. args.inc = args.kdir + '/techpack/dataipa/drivers/platform/msm/ipa/ipa_test_module'
  69. full_uapi = os.path.abspath(args.uapi)
  70. os.environ['CPPFLAGS'] = ('-I' + full_uapi)
  71. full_inc = os.path.abspath(args.inc)
  72. os.environ['CPPFLAGS'] += (' -I' + full_inc)
  73. configure(args, args.src)
  74. do(['make'], args.src)
  75. do(['make', 'DESTDIR=' + args.dest, 'install'], args.src)
  76. def configure(args, wdir):
  77. if os.path.isfile(os.path.join(wdir, 'config.h')):
  78. return
  79. do(['libtoolize'], wdir)
  80. do(['./autogen.sh'], wdir)
  81. full_idir = os.path.abspath(os.path.join(wdir, install_dir))
  82. host_str = 'arm-linux-gnueabihf'
  83. config_extra = ''
  84. if args.arch == 'arm64':
  85. host_str = 'aarch64-linux-gnu'
  86. config_extra = '--disable-swp'
  87. do(['./configure',
  88. '--host=' + host_str,
  89. '--prefix=' + full_idir,
  90. config_extra], wdir)
  91. def main():
  92. rc = 0
  93. try:
  94. args = get_args()
  95. build(args)
  96. except Exception as e:
  97. rc = 1
  98. print(e)
  99. sys.exit(rc)
  100. if __name__ == '__main__':
  101. main()