Skip to content

Select Lua version #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Select Lua version #17

wants to merge 3 commits into from

Conversation

S-S-X
Copy link
Member

@S-S-X S-S-X commented Jan 15, 2024

Background

Most of previous release versions of Mineunit were shipped with Lua 5.1.

With latest 0.10 tried with LuaJIT again which at first seemed to work just fine.
However, turns out it doesn't.

Issues

While testing performace impact of new features I got around 30-40% test set failures with beerchat tests.

Interesting thing was that it seemed like if some stuff was executed in separate threads and resulted in race conditions, most of time just randomizing order of output like chat messages sent during tests. I suspected this might be some mistake with async stuff but there should not really be any async stuff there.
Seems this never happens with previous Lua 5.1 version and also not with 0.10 after switching implementation from LuaJIT to Lua 5.1.

Additionally it seems for some reason LuaCov is reporting way lower coverage for technic tests. For this have to investigate further to see if something in Mineunit actually gets disabled or is altered in such way that could affect execution of actual program or if it is LuaJIT / LuaCCov issue (possibly because of aggressive LuaJIT optimizations affecting debugger).

Weird LuaJIT behavior needs more investigation and preferably.

"solution"

Allow selecting Lua implementation with lua-version switch. It accepts either luajit or lua51.
Default is lua51 for now.

Configuration examples

Example configuration to explicitly select LuaJIT:

name: mineunit
on: [push, pull_request]
jobs:
  mineunit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - id: mineunit
      uses: mt-mods/mineunit-actions@master
      with:
        lua-version: luajit

Example configuration to explicitly select Lua 5.1:

name: mineunit
on: [push, pull_request]
jobs:
  mineunit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - id: mineunit
      uses: mt-mods/mineunit-actions@master
      with:
        lua-version: lua51

Example configuration to use default Lua implementation (follow default setting of mt-mods/mineunit-actions):

name: mineunit
on: [push, pull_request]
jobs:
  mineunit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - id: mineunit
      uses: mt-mods/mineunit-actions@master

action.yml Outdated
@@ -71,4 +75,4 @@ outputs:

runs:
using: docker
image: Dockerfile
image: Dockerfile.${{ inputs.lua-version }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this work, depends if image: Dockerfile is some special trigger to start docker build instead of attempting docker pull.

Probably better to test before breaking tests of every project that is using this runner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it isn't working as documented, here's even example that isn't far from this use case (and should be exactly same for expressions): https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action#creating-an-action-metadata-file

Failure is not with docker runner but with expression evaluation, either with inputs or github:

Unrecognized named-value: 'inputs'. Located at position 1 within expression: inputs.lua-version

and

Unrecognized named-value: 'github'. Located at position 1 within expression: github.event.inputs.lua-version

@BuckarooBanzay BuckarooBanzay added the enhancement New feature or request label Jan 16, 2024
@S-S-X S-S-X marked this pull request as draft January 19, 2024 18:20
@S-S-X
Copy link
Member Author

S-S-X commented Jan 19, 2024

Coverage differences Lua 5.1 - LuaJIT

Because of past compatibility issues Mineunit releases been using Busted 2.0.
Test results for luacov.busted-2.2.out is with LuaJIT but using Busted 2.2.
Test results for luacov.luajit.out (LuaJIT) and luacov.lua51.out (Lua 5.1) are both using Busted 2.0.

$ luacov-stats.sh luacov.busted-2.2.out 
# Source files in report: 97/97
# Total coverage percent: 62.32%

$ luacov-stats.sh luacov.luajit.out 
# Source files in report: 97/97
# Total coverage percent: 62.32%

$ luacov-stats.sh luacov.lua51.out 
# Source files in report: 97/97
# Total coverage percent: 71.36%

$ grep '^\*\+0' luacov.lua51.out | wc -l
2244 # total misses in all source files

$ grep '^\*\+0' luacov.busted-2.2.out | wc -l
2564 # total misses in all source files

$ grep '^\*\+0' luacov.luajit.out | wc -l
2564 # total misses in all source files

Matching coverage for source files Lua 5.1 - LuaJIT

Considers hits, misses and total coverage of lines with at least one hit.

Source file hit miss total
max_lag.lua 12 0 100.00%
materials.lua 71 0 100.00%
machines/register/init.lua 15 0 100.00%
machines/other/init.lua 6 0 100.00%
machines/MV/init.lua 17 0 100.00%
machines/LV/init.lua 17 0 100.00%
machines/HV/init.lua 12 0 100.00%
tools/init.lua 13 1 92.86%
init.lua 25 2 92.59%
register.lua 28 4 87.50%
util/throttle.lua 9 2 81.82%
machines/other/coal_furnace.lua 3 1 75.00%
machines/overload.lua 12 5 70.59%
machines/switching_station_globalstep.lua 28 16 63.64%
machines/compat/api.lua 16 34 32.00%
machines/compat/digtron.lua 4 41 8.89%

Coverage differences for source files Lua 5.1 - LuaJIT

Considers hits, misses and total coverage of lines with at least one hit.

Source file hit miss total jit hit jit miss jit total
machines/register/freezer_recipes.lua 16 0 100.00% 14 0 100.00%
machines/MV/solar_array.lua 12 0 100.00% 9 1 90.00%
machines/MV/grinder.lua 17 0 100.00% 11 1 91.67%
machines/MV/generator.lua 9 0 100.00% 8 0 100.00%
machines/MV/freezer.lua 17 0 100.00% 11 1 91.67%
machines/MV/extractor.lua 17 0 100.00% 11 1 91.67%
machines/MV/electric_furnace.lua 17 0 100.00% 11 1 91.67%
machines/MV/compressor.lua 17 0 100.00% 11 1 91.67%
machines/MV/centrifuge.lua 17 0 100.00% 11 0 100.00%
machines/MV/cables.lua 40 0 100.00% 29 0 100.00%
machines/MV/battery_box.lua 17 0 100.00% 8 0 100.00%
machines/MV/alloy_furnace.lua 19 0 100.00% 13 0 100.00%
machines/LV/solar_array.lua 11 0 100.00% 8 1 88.89%
machines/LV/led.lua 81 0 100.00% 58 1 98.31%
machines/LV/grinder.lua 17 0 100.00% 13 1 92.86%
machines/LV/generator.lua 11 0 100.00% 9 0 100.00%
machines/LV/electric_furnace.lua 16 0 100.00% 12 1 92.31%
machines/LV/compressor.lua 22 0 100.00% 17 1 94.44%
machines/LV/cables.lua 44 0 100.00% 30 0 100.00%
machines/LV/battery_box.lua 15 0 100.00% 8 0 100.00%
machines/LV/alloy_furnace.lua 18 0 100.00% 14 0 100.00%
machines/HV/solar_array.lua 11 0 100.00% 8 1 88.89%
machines/HV/grinder.lua 17 0 100.00% 11 1 91.67%
machines/HV/generator.lua 9 0 100.00% 8 0 100.00%
machines/HV/electric_furnace.lua 17 0 100.00% 11 1 91.67%
machines/HV/compressor.lua 17 0 100.00% 11 1 91.67%
machines/HV/cables.lua 39 0 100.00% 28 0 100.00%
machines/HV/battery_box.lua 17 0 100.00% 8 0 100.00%
legacy.lua 33 0 100.00% 8 0 100.00%
crafts.lua 153 0 100.00% 109 1 99.09%
items.lua 133 1 99.25% 85 2 97.70%
machines/register/grindings.lua 41 1 97.62% 36 1 97.30%
machines/register/compressor_recipes.lua 45 1 97.83% 39 1 97.50%
config.lua 48 1 97.96% 23 1 95.83%
machines/register/recipes.lua 156 5 96.89% 131 14 90.34%
machines/LV/geothermal.lua 84 3 96.55% 69 3 95.83%
machines/register/solar_array.lua 47 2 95.92% 46 2 95.83%
machines/network.lua 403 21 95.05% 400 21 95.01%
machines/LV/solar_panel.lua 46 2 95.83% 36 2 94.74%
machines/register/cables.lua 108 6 94.74% 97 8 92.38%
machines/register/alloy_recipes.lua 41 3 93.18% 32 9 78.05%
machines/LV/water_mill.lua 73 6 92.41% 54 6 90.00%
machines/compat/tools.lua 58 6 90.62% 58 6 90.63%
machines/register/machine_base.lua 212 25 89.45% 167 52 76.26%
machines/LV/lamp.lua 138 16 89.61% 93 17 84.55%
machines/register/grinder_recipes.lua 116 16 87.88% 100 16 86.21%
machines/register/battery_box.lua 261 42 86.14% 235 55 81.03%
tools/flashlight.lua 66 13 83.54% 56 14 80.00%
radiation.lua 308 71 81.27% 96 81 54.24%
machines/power_monitor.lua 72 16 81.82% 52 19 73.24%
machines/other/injector.lua 107 26 80.45% 70 45 60.87%
machines/init.lua 38 9 80.85% 34 9 79.07%
machines/LV/extractor.lua 18 5 78.26% 14 6 70.00%
machines/register/centrifuge_recipes.lua 23 7 76.67% 20 7 74.07%
machines/switching_station.lua 90 30 75.00% 73 32 69.52%
machines/MV/tool_workshop.lua 80 27 74.77% 59 43 57.84%
machines/register/generator.lua 158 59 72.81% 115 83 58.08%
effects.lua 5 2 71.43% 3 2 60.00%
machines/MV/wind_mill.lua 51 22 69.86% 37 22 62.71%
machines/supply_converter.lua 100 46 68.49% 91 46 66.42%
machines/other/coal_alloy_furnace.lua 104 53 66.24% 70 65 51.85%
machines/MV/hydro_turbine.lua 49 26 65.33% 31 26 54.39%
tools/multimeter.lua 130 78 62.50% 125 79 61.27%
tools/tree_tap.lua 34 23 59.65% 18 30 37.50%
tools/mining_lasers.lua 44 30 59.46% 32 35 47.76%
machines/other/constructor.lua 93 64 59.24% 61 78 43.88%
tools/cans.lua 59 44 57.28% 39 48 44.83%
machines/register/common.lua 66 49 57.39% 51 64 44.35%
machines/LV/music_player.lua 52 43 54.74% 44 47 48.35%
machines/HV/nuclear_reactor.lua 175 184 48.75% 107 214 33.33%
machines/HV/quarry.lua 195 215 47.56% 129 251 33.95%
machines/HV/forcefield.lua 131 146 47.29% 84 158 34.71%
tools/vacuum.lua 16 20 44.44% 14 20 41.18%
tools/sonic_screwdriver.lua 21 29 42.00% 15 33 31.25%
helpers.lua 55 96 36.42% 53 98 35.10%
tools/chainsaw.lua 39 80 32.77% 37 80 31.62%
tools/mining_drill.lua 82 182 31.06% 60 195 23.53%
chatcommands.lua 19 45 29.69% 13 45 22.41%
machines/other/anchor.lua 22 68 24.44% 12 74 13.95%
tools/prospector.lua 19 96 16.52% 12 100 10.71%
machines/register/extractor_recipes.lua 8 77 9.41% 7 77 8.33%

Could maybe next take a bit closed look at it, where exactly are differences and is there something in common among them?

@S-S-X
Copy link
Member Author

S-S-X commented Jan 20, 2024

LuaCov with LuaJIT

    12 minetest.register_chatcommand("technic_get_active_networks", {
       	params = "[minlag]",
       	description = "Lists all active networks with additional network data",
    12 	privs = { [technic.config:get("admin_priv")] = true },
       	func = function(name, minlag)

LuaCov with Lua 5.1

     84 minetest.register_chatcommand("technic_get_active_networks", {
     30 	params = "[minlag]",
     30 	description = "Lists all active networks with additional network data",
     54 	privs = { [technic.config:get("admin_priv")] = true },
        	func = function(name, minlag)

Reason for this seems to be simply that LuaJIT just isn't triggering the debug hook at all for some things.
Because of this, totals in LuaCov get messed up badly and calculations are all wrong when running with LuaJIT.

LuaCov still counts those "missed" lines and add those to totals so total coverage can only ever reach 100% in files where debug hooks get triggered at least once for every line that is also counted by LuaCov.

For this reason LuaCov reports cannot really be compared between LuaJIT and Lua 5.1 runs.

Fix: not so simple, either patch core of LuaCov or core of LuaJIT and hope it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants