random_sanity.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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,demosoc", 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('--run_target', default="qemu", help="Run target which program will run, such as hardware, qemu or xlspike")
  30. parser.add_argument('--randtimes', default=1, help="Random run times")
  31. args = parser.parse_args()
  32. soc_choices = args.socs.split(",")
  33. download_choices = args.downloads.split(",")
  34. stdclib_choices = args.stdclibs.split(",")
  35. for i in range(int(args.randtimes)):
  36. soc = random.choice(soc_choices)
  37. download = random.choice(download_choices)
  38. stdclib = random.choice(stdclib_choices)
  39. # when use newlib full, some case might link fail due size issue, so change to other download mode
  40. if stdclib == "newlib_full" and download in ("ilm", "flash"):
  41. download = random("ddr", "flashxip")
  42. makeopts = "SOC=%s DOWNLOAD=%s STDCLIB=%s" % (soc, download, stdclib)
  43. logdir = args.logdir + "/%s/%s/%s" % (soc, download, stdclib)
  44. print("Random select choice: %s" % (makeopts))
  45. sys.stdout.flush()
  46. appcfg = args.appcfg
  47. hwcfg = args.hwcfg
  48. if "libncrt" in stdclib:
  49. hwcfg = hwcfg + ".libncrt"
  50. ret = run_nsdk_bench(appcfg, hwcfg, logdir, makeopts, args.run_target)
  51. if ret == False:
  52. print("Choice %s Failed!" % (makeopts))
  53. break
  54. else:
  55. print("Choice %s Passed!" % (makeopts))
  56. # Sanity check exit
  57. if ret == False:
  58. sys.exit(1)
  59. sys.exit(0)