test_lua.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. import infra.basetest
  3. class TestLuaBase(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_TARGET_ROOTFS_CPIO=y
  7. # BR2_TARGET_ROOTFS_TAR is not set
  8. """
  9. def login(self):
  10. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  11. self.emulator.boot(arch="armv5",
  12. kernel="builtin",
  13. options=["-initrd", cpio_file])
  14. self.emulator.login()
  15. def version_test(self, version):
  16. cmd = "lua -v"
  17. output, exit_code = self.emulator.run(cmd)
  18. self.assertEqual(exit_code, 0)
  19. self.assertIn(version, output[0])
  20. def g_version_test(self, expected):
  21. cmd = "lua -e 'print(_G._VERSION)'"
  22. output, exit_code = self.emulator.run(cmd)
  23. self.assertEqual(exit_code, 0)
  24. self.assertEqual(output[0], expected)
  25. def module_test(self, module, script="a=1"):
  26. cmd = "lua -l {} -e '{}'".format(module, script)
  27. self.assertRunOk(cmd)
  28. class TestLua(TestLuaBase):
  29. config = TestLuaBase.config + \
  30. """
  31. BR2_PACKAGE_LUA=y
  32. """
  33. def test_run(self):
  34. self.login()
  35. self.version_test('Lua 5.4')
  36. self.g_version_test('Lua 5.4')
  37. class TestLuajit(TestLuaBase):
  38. config = TestLuaBase.config + \
  39. """
  40. BR2_PACKAGE_LUAJIT=y
  41. """
  42. def test_run(self):
  43. self.login()
  44. self.version_test('LuaJIT 2')
  45. self.g_version_test('Lua 5.1')