test_nodejs.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import os
  2. import infra.basetest
  3. class TestNodeJSBasic(infra.basetest.BRTest):
  4. config = \
  5. """
  6. BR2_arm=y
  7. BR2_cortex_a9=y
  8. BR2_ARM_ENABLE_VFP=y
  9. BR2_TOOLCHAIN_EXTERNAL=y
  10. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  11. BR2_PACKAGE_NODEJS=y
  12. BR2_TARGET_ROOTFS_CPIO=y
  13. # BR2_TARGET_ROOTFS_TAR is not set
  14. BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
  15. BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
  16. """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
  17. infra.filepath("tests/package/sample_nodejs_basic.js"))
  18. def test_run(self):
  19. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  20. self.emulator.boot(arch="armv7",
  21. kernel="builtin",
  22. options=["-initrd", cpio_file])
  23. self.emulator.login()
  24. self.assertRunOk("node sample_nodejs_basic.js")
  25. class TestNodeJSModuleHostBin(infra.basetest.BRTest):
  26. config = \
  27. """
  28. BR2_arm=y
  29. BR2_cortex_a9=y
  30. BR2_ARM_ENABLE_VFP=y
  31. BR2_TOOLCHAIN_EXTERNAL=y
  32. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  33. BR2_PACKAGE_NODEJS=y
  34. BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL="lodash"
  35. BR2_PACKAGE_HOST_NODEJS_BIN=y
  36. BR2_TARGET_ROOTFS_CPIO=y
  37. # BR2_TARGET_ROOTFS_TAR is not set
  38. BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
  39. BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
  40. """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
  41. infra.filepath("tests/package/sample_nodejs_module.js"))
  42. def test_run(self):
  43. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  44. self.emulator.boot(arch="armv7",
  45. kernel="builtin",
  46. options=["-initrd", cpio_file])
  47. self.emulator.login()
  48. self.assertRunOk("node sample_nodejs_module.js")
  49. class TestNodeJSModuleHostSrc(infra.basetest.BRTest):
  50. config = \
  51. """
  52. BR2_arm=y
  53. BR2_cortex_a9=y
  54. BR2_ARM_ENABLE_VFP=y
  55. BR2_TOOLCHAIN_EXTERNAL=y
  56. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  57. BR2_PACKAGE_NODEJS=y
  58. BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL="lodash"
  59. BR2_PACKAGE_HOST_NODEJS_SRC=y
  60. BR2_TARGET_ROOTFS_CPIO=y
  61. # BR2_TARGET_ROOTFS_TAR is not set
  62. BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
  63. BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
  64. """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
  65. infra.filepath("tests/package/sample_nodejs_module.js"))
  66. def test_run(self):
  67. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  68. self.emulator.boot(arch="armv7",
  69. kernel="builtin",
  70. options=["-initrd", cpio_file])
  71. self.emulator.login()
  72. self.assertRunOk("node sample_nodejs_module.js")