test_lua.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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="armv7",
  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. _, exit_code = self.emulator.run(cmd)
  28. self.assertEqual(exit_code, 0)
  29. class TestLua(TestLuaBase):
  30. config = TestLuaBase.config + \
  31. """
  32. BR2_PACKAGE_LUA=y
  33. """
  34. def test_run(self):
  35. self.login()
  36. self.version_test('Lua 5.3')
  37. self.g_version_test('Lua 5.3')
  38. class TestLuajit(TestLuaBase):
  39. config = TestLuaBase.config + \
  40. """
  41. BR2_PACKAGE_LUAJIT=y
  42. """
  43. def test_run(self):
  44. self.login()
  45. self.version_test('LuaJIT 2')
  46. self.g_version_test('Lua 5.1')