Skip to content
Guilherme Salazar edited this page Apr 9, 2016 · 1 revision

Lua + NetBSD

This is a port of Lua userspace test suite [1] to NetBSD kernel Lua [2, 3]. Work on this began as a Google Summer of Code '15 project. Back then, kernel Lua was based on Lua 5.3.0; I'm now reworking the port, making improvements and porting the 5.3.2 test suite. If you have any suggestions, please email me or open an issue.

THE PORT

The overall diferences among user and kernel space Lua are that kernel Lua does not support standard libraries that rely on the operating system, such as io and os; it also lacks support for floating-point numbers.

In order to bring the test suite to kernel space, test scripts had to be adapted, either to isolate tests specific to floating-point or to make them integer-only. These changes were made using a _KERNEL constant that is 'true' when running in kernel space.

It was also needed to port certain parts of Lua standard libraries to kernel Lua:

  • io: open, close, read, write
  • os: time, clock, tmpname, remove
  • math: random, randomseed, fmod, sin, cos, min, max, type, huge, maxinteger, mininteger
  • base: dofile, loadfile

The kernel directory contains some artifacts produced during the project. kernel/modules contains the loadable modules for each of the libraries; kernel/patches contains patches that need to be applied to the NetBSD tree to run the tests; preload.lua is used to set up the state in which the tests are to be run; exec-tests.sh and open-state.sh are helper scripts that I frequently used.

HOW TO RUN

  1. In order to run the tests, you must apply the following patches (which can be found under 'kernel/patches') against your NetBSD-current tree

    • 'lua-lauxlib.patch' - enables a few declarations not available by default in Kernel Lua
    • 'lua-parser.patch' - fixes a bug in the Kernel Lua parser
    • 'openlibs.patch' - adds a command ('openlibs') to luactl(8) in order to allow the loading of standard libraries into a Lua state
  2. Compile and install the kernel modules available in 'kernel/modules'

    • luabase
    • luaio
    • luamath
    • luaos
  3. The script 'kernel/open-state.sh' allows you to load the modules installed in step (2) and to create a Lua state

    $ ./kernel/open-state stateName

  4. Load the preload script from 'kernel/preload.lua'

    $ luactl load stateName ./kernel/preload.lua

  5. Finally, load 'all.lua'. This will load and execute the tests in kernel Lua

    $ luactl load stateName ./all.lua

  6. Use dmesg(8) to see the output

  • Internal tests

    • To run internal tests, copy the files in ltests to Lua distribution in the NetBSD source tree (i.e., external/mit/lua/dist/src), recompile and install kernel Lua

    • Recompile and install the modules as in step (2), but this time using the 'tests' target (i.e., 'make tests' & make install for each module)

    • NOTICE: A kernel panic occurs when Lua is compiled with the internal tests enabled

====== [1] http://lua.org/tests/
[2] https://www.phoronix.com/scan.php?page=news_item&px=MTMwMTU
[3] https://www.phoronix.com/scan.php?page=news_item&px=MTQ4ODk

Clone this wiki locally