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