random_sanity.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/env python3
  2. import os
  3. import sys
  4. import time
  5. import tempfile
  6. import random
  7. import argparse
  8. SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
  9. SDK_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, "../../../"))
  10. def run_nsdk_bench(appcfg, hwcfg, logdir, makeopts, runtarget):
  11. nsdk_benchpy = os.path.join(SDK_ROOT, "tools/scripts/nsdk_cli/nsdk_bench.py")
  12. benchcmd = "%s %s --appcfg %s --hwcfg %s --logdir %s --make_options \"%s\" --run_target %s --run" \
  13. % (sys.executable, nsdk_benchpy, appcfg, hwcfg, logdir, makeopts, runtarget)
  14. print("Run command: %s" % (benchcmd))
  15. sys.stdout.flush()
  16. ret = os.system(benchcmd)
  17. sys.stdout.flush()
  18. if ret != 0:
  19. return False
  20. return True
  21. if __name__ == '__main__':
  22. parser = argparse.ArgumentParser(description="Nuclei SDK Sanity Random Checker")
  23. parser.add_argument('--appcfg', required=True, help="Application JSON Configuration File")
  24. parser.add_argument('--hwcfg', help="Hardware Target JSON Configuration File, if specified, will overwrite configuration defined in appcfg")
  25. parser.add_argument('--logdir', required=True, help="logs directory where saved the report json files")
  26. parser.add_argument('--socs', default="evalsoc", help="SOC choices")
  27. parser.add_argument('--downloads', default="ilm,flash,flashxip,ddr", help="DOWNLOAD choices")
  28. parser.add_argument('--stdclibs', default="newlib_small,newlib_full,libncrt_small,libncrt_balanced,libncrt_fast", help="STDCLIB choices")
  29. parser.add_argument('--toolchains', default="nuclei_gnu,nuclei_llvm", help="TOOLCHAIN choices")
  30. parser.add_argument('--run_target', default="qemu", help="Run target which program will run, such as hardware, qemu or xlspike")
  31. parser.add_argument('--randtimes', default=1, help="Random run times")
  32. args = parser.parse_args()
  33. soc_choices = args.socs.split(",")
  34. download_choices = args.downloads.split(",")
  35. stdclib_choices = args.stdclibs.split(",")
  36. toolchain_choices = args.toolchains.split(",")
  37. for i in range(int(args.randtimes)):
  38. soc = random.choice(soc_choices)
  39. download = random.choice(download_choices)
  40. stdclib = random.choice(stdclib_choices)
  41. toolchain = random.choice(toolchain_choices)
  42. # when use newlib full, some case might link fail due size issue, so change to other download mode
  43. if stdclib == "newlib_full" and download in ("ilm", "flash"):
  44. download = random.choice(["ddr", "flashxip"])
  45. makeopts = "SOC=%s DOWNLOAD=%s STDCLIB=%s TOOLCHAIN=%s" % (soc, download, stdclib, toolchain)
  46. logdir = args.logdir + "/%s/%s/%s" % (soc, download, stdclib)
  47. print("Random select choice: %s" % (makeopts))
  48. sys.stdout.flush()
  49. appcfg = args.appcfg
  50. hwcfg = args.hwcfg
  51. if "libncrt" in stdclib:
  52. hwcfg = hwcfg + ".libncrt"
  53. ret = run_nsdk_bench(appcfg, hwcfg, logdir, makeopts, args.run_target)
  54. if ret == False:
  55. print("Choice %s Failed!" % (makeopts))
  56. break
  57. else:
  58. print("Choice %s Passed!" % (makeopts))
  59. # Sanity check exit
  60. if ret == False:
  61. sys.exit(1)
  62. sys.exit(0)