Skip to content
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

Lua extension #414

Merged
merged 31 commits into from
Jan 17, 2024
Merged

Lua extension #414

merged 31 commits into from
Jan 17, 2024

Conversation

schnepe2
Copy link
Contributor

@schnepe2 schnepe2 commented Jan 15, 2024

PR to resolve #404 &
to resolve #405.

This PR has currently only one unresolved issue:
The automatic (headless) tests currently can not run MFD tests.
Still I like to have at least some kind of Test, therefore I've added that Test-Scanario in a sub-folder .\Scenarios\Tests\Manual\ which should not be run automatically (I think).
An alternative might be to change the according file(GLOB ...) section in .\Tests\CMakeLists.txt to exclude some "special names".

I am not an expert in CMake setups, so I didn't took that approach.

Changes:

  • added following file i/o functions to Lua interface:

    • openfile(fname,mode,root)
    • closefile(fname,mode)
    • savescenario(name,descr)
    • writeline(f,line)
    • writescenario_string(scn,item,str)
    • writescenario_int(scn,item,i)
    • writescenario_float(scn,item,d)
    • writescenario_vec(scn,item,vec)
    • readscenario_nextline(scn)
    • readitem_string(f,item)
    • readitem_float(f,item)
    • readitem_int(f,item)
    • readitem_bool(f,item)
    • readitem_vec(f,item)
    • writeitem_string(f,item,str)
    • writeitem_float(f,item,d)
    • writeitem_int(f,item,i)
    • writeitem_bool(f,item,b)
    • writeitem_vec(f,item,vec)
  • added following utility functions to Lua interface:

    • formatvalue(val,prec)
  • added Lua tests for generic API functions

  • added Lua test for ScriptMFD (manual test)

@schnepe2
Copy link
Contributor Author

CI Tests seem to fail 😞
I'll have to guess what's wrong as I can't access the Orbiter.log file to get details.
I will try to remove all "write-access" as 1st guess.

- os.remove() disabled
- all writes disabled
- further tests disabled
- not much testing left :(
@schnepe2
Copy link
Contributor Author

I am out of ideas 😞
Maybe tomorrow

- another wild guess: Scenario maybe?
@jarmonik
Copy link
Contributor

Does it give any error report if you run the "test" from a command console ?
ctest --preset windows-${{ matrix.architecture }}-release --jobs 2

which might be:
ctest --preset windows-x86-release --jobs 2

@schnepe2
Copy link
Contributor Author

schnepe2 commented Jan 15, 2024

Do I have to be in a Visual-Studio console?
Those CI magic things are nice if they work as expected, but it seem it makes "local development" almost impossible.
I'll try and report back.

@schnepe2
Copy link
Contributor Author

Result:

**********************************************************************
** Visual Studio 2019 Developer PowerShell v16.11.33
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
PS D:\Programme\Orbiter\orbiter-git-schnepe2> ctest --preset windows-x86-release --jobs 2
CMake Error: Could not read presets from D:/Programme/Orbiter/orbiter-git-schnepe2: Unrecognized "version" field
PS D:\Programme\Orbiter\orbiter-git-schnepe2>

- removed MFD_(Left|Right) completely from Scenario.
@jarmonik
Copy link
Contributor

I got it to run some tests with:
ctest -C Release
But 2 of 3 tests fails even in a branch that works otherwise, so, I have no idea how to run the tests locally. Yeah, automation can really be a pain when it fails.

@jarmonik
Copy link
Contributor

Looks like the problem is somewhere in:
Start 3: Scenario.GeneralApiTest
3/4 Test #3: Scenario.GeneralApiTest ..........***Timeout 60.01 sec

@schnepe2
Copy link
Contributor Author

schnepe2 commented Jan 15, 2024

I think it might have to do with "what CMake" we are using. The one included in Visual Studio might not be 100% compatible...
But I also have no idea how to fix that 😢

Looks like the problem is somewhere in:
Start 3: Scenario.GeneralApiTest
3/4 Test #3: Scenario.GeneralApiTest ..........***Timeout 60.01 sec

Yes, that's easy to see, but why Timeout? The current Test is almost empty now and can only succeed!

It would be enough (I think) if I could get the Orbiter.log from the failed test. Something a CMake guru could do, right?

@schnepe2
Copy link
Contributor Author

This is what I would expect (run locally in a "normal" cmd):

D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x86-release>.\Modules\Server\Orbiter.exe --scenariox=Tests/GeneralApiTest
Module Sun.dll ............... [Build 240115, API 240111]
VSOP87(E) Sun: Precision 1.0e-06, Terms 554/6634
Module Mercury.dll ........... [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\jgmess_160a_sha.tab LOADED, Terms 65/13040
VSOP87(B) Mercury: Precision 1.0e-05, Terms 167/7123
Module Venus.dll ............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\mod_shgj120p.a01 LOADED, Terms 65/7380
Module VenusAtm2006.dll ...... [Build 240115, API 240111]
Loading module VenusAtm2006 (legacy interface)
VSOP87(B) Venus: Precision 1.0e-05, Terms 79/1710
Module Earth.dll ............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\egm96_to360.tab LOADED, Terms 65/65340
Module EarthAtmJ71G.dll ...... [Build 240115, API 240111]
Loading module EarthAtmJ71G (legacy interface)
VSOP87(B) Earth: Precision 1.0e-08, Terms 2564/2564
Module Moon.dll .............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\jgl165p1.sha LOADED, Terms 65/13860
ELP82: Precision 1.0e-05, Terms 116/829
Module Mars.dll .............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\jgmro_120f_sha.tab LOADED, Terms 65/7380
Module MarsAtm2006.dll ....... [Build 240115, API 240111]
Loading module MarsAtm2006 (legacy interface)
VSOP87(B) Mars: Precision 1.0e-05, Terms 405/6400
Module Phobos.dll ............ [Build ******, API 060425]
Module Deimos.dll ............ [Build ******, API 060425]
GRAVITY MODEL: GravityModels\JGDWN_VES20H_SHA.TAB LOADED, Terms 65/230
Module Galsat.dll ............ [Build 240115, API 240111]
Module Jupiter.dll ........... [Build 240115, API 240111]
VSOP87(B) Jupiter: Precision 1.0e-06, Terms 1624/3625
Module Io.dll ................ [Build 240115, API 240111]
Module Europa.dll ............ [Build 240115, API 240111]
Module Ganymede.dll .......... [Build 240115, API 240111]
Module Callisto.dll .......... [Build 240115, API 240111]
Module Satsat.dll ............ [Build 240115, API 240111]
Module Saturn.dll ............ [Build 240115, API 240111]
VSOP87(B) Saturn: Precision 1.0e-06, Terms 2904/6365
Module Mimas.dll ............. [Build 240115, API 240111]
SATSAT Mimas: Terms 113
Module Enceladus.dll ......... [Build 240115, API 240111]
SATSAT Enceladus: Terms 33
Module Tethys.dll ............ [Build 240115, API 240111]
SATSAT Tethys: Terms 101
Module Dione.dll ............. [Build 240115, API 240111]
SATSAT Dione: Terms 59
Module Rhea.dll .............. [Build 240115, API 240111]
SATSAT Rhea: Terms 68
Module Titan.dll ............. [Build 240115, API 240111]
SATSAT Titan: Terms 100
Module Iapetus.dll ........... [Build 240115, API 240111]
SATSAT Iapetus: Terms 605
Module Uranus.dll ............ [Build 240115, API 240111]
VSOP87(B) Uranus: Precision 1.0e-06, Terms 1827/5269
Module Miranda.dll ........... [Build ******, API 060425]
Module Ariel.dll ............. [Build ******, API 060425]
Module Umbriel.dll ........... [Build ******, API 060425]
Module Titania.dll ........... [Build ******, API 060425]
Module Oberon.dll ............ [Build ******, API 060425]
Module Neptune.dll ........... [Build 240115, API 240111]
VSOP87(B) Neptune: Precision 1.0e-06, Terms 391/2024
Finished initialising world
Module DeltaGlider.dll ....... [Build 240115, API 240111]
Module LuaInline.dll ......... [Build 240115, API 240111]
Loading module LuaInline
Finished initialising status
Finished initialising camera
Finished setting up render state
-----------------
Orbiter NG (no graphics)
Running in server mode (no graphics client attached).
Type "help" for a list of commands.
Type "exit" to return to the Launchpad dialog.

=== Lua script unit tests ===
>
--- oapi module ---
Test: oapi.openfile(fname,mode,root) read
   ...ROOT Orbiter main directory
   ...CONFIG Orbiter config folder
   ...SCENARIOS Orbiter scenarios folder
   ...TEXTURES Orbiter standard texture folder
   ...TEXTURES2 Orbiter high-res texture folder
   ...MESHES Orbiter mesh folder
   ...MODULES Orbiter module folder
   ...FILE_IN vs. FILE_IN_ZEROONFAIL on non-existing file
 - passed
Test: oapi.openfile(fname,mode,root) write
   ...FILE_OUT write (overwrite)
   ...FILE_APP write (append)
 - passed
Test: oapi.writeline(f,line)
 - passed
Test: oapi.writeitem_xxx(f,item,value)
   ...oapi.writeitem_string()
   ...oapi.writeitem_float()
   ...oapi.writeitem_int()
   ...oapi.writeitem_bool()
   ...oapi.writeitem_vec()
 - passed
Test: oapi.readitem_xxx(f,item)
   ...oapi.readitem_vec()
   ...oapi.readitem_bool()
   ...oapi.readitem_int()
   ...oapi.readitem_float()
   ...oapi.readitem_string()
 - passed
Test: oapi.rand()
 - passed
Test: oapi.deflate()
 - passed
Test: oapi.inflate()
 - passed
Test: oapi.formatvalue(f,p)
 - passed
=== All tests passed ===
LuaInline: timeout while waiting for interpreter thread
>
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x86-release>

For reference (Tests/VesselApiTest):

D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x86-release>.\Modules\Server\Orbiter.exe --scenariox=Tests/VesselApiTest
Module Sun.dll ............... [Build 240115, API 240111]
VSOP87(E) Sun: Precision 1.0e-06, Terms 554/6634
Module Mercury.dll ........... [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\jgmess_160a_sha.tab LOADED, Terms 65/13040
VSOP87(B) Mercury: Precision 1.0e-05, Terms 167/7123
Module Venus.dll ............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\mod_shgj120p.a01 LOADED, Terms 65/7380
Module VenusAtm2006.dll ...... [Build 240115, API 240111]
Loading module VenusAtm2006 (legacy interface)
VSOP87(B) Venus: Precision 1.0e-05, Terms 79/1710
Module Earth.dll ............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\egm96_to360.tab LOADED, Terms 65/65340
Module EarthAtmJ71G.dll ...... [Build 240115, API 240111]
Loading module EarthAtmJ71G (legacy interface)
VSOP87(B) Earth: Precision 1.0e-08, Terms 2564/2564
Module Moon.dll .............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\jgl165p1.sha LOADED, Terms 65/13860
ELP82: Precision 1.0e-05, Terms 116/829
Module Mars.dll .............. [Build 240115, API 240111]
GRAVITY MODEL: GravityModels\jgmro_120f_sha.tab LOADED, Terms 65/7380
Module MarsAtm2006.dll ....... [Build 240115, API 240111]
Loading module MarsAtm2006 (legacy interface)
VSOP87(B) Mars: Precision 1.0e-05, Terms 405/6400
Module Phobos.dll ............ [Build ******, API 060425]
Module Deimos.dll ............ [Build ******, API 060425]
GRAVITY MODEL: GravityModels\JGDWN_VES20H_SHA.TAB LOADED, Terms 65/230
Module Galsat.dll ............ [Build 240115, API 240111]
Module Jupiter.dll ........... [Build 240115, API 240111]
VSOP87(B) Jupiter: Precision 1.0e-06, Terms 1624/3625
Module Io.dll ................ [Build 240115, API 240111]
Module Europa.dll ............ [Build 240115, API 240111]
Module Ganymede.dll .......... [Build 240115, API 240111]
Module Callisto.dll .......... [Build 240115, API 240111]
Module Satsat.dll ............ [Build 240115, API 240111]
Module Saturn.dll ............ [Build 240115, API 240111]
VSOP87(B) Saturn: Precision 1.0e-06, Terms 2904/6365
Module Mimas.dll ............. [Build 240115, API 240111]
SATSAT Mimas: Terms 113
Module Enceladus.dll ......... [Build 240115, API 240111]
SATSAT Enceladus: Terms 33
Module Tethys.dll ............ [Build 240115, API 240111]
SATSAT Tethys: Terms 101
Module Dione.dll ............. [Build 240115, API 240111]
SATSAT Dione: Terms 59
Module Rhea.dll .............. [Build 240115, API 240111]
SATSAT Rhea: Terms 68
Module Titan.dll ............. [Build 240115, API 240111]
SATSAT Titan: Terms 100
Module Iapetus.dll ........... [Build 240115, API 240111]
SATSAT Iapetus: Terms 605
Module Uranus.dll ............ [Build 240115, API 240111]
VSOP87(B) Uranus: Precision 1.0e-06, Terms 1827/5269
Module Miranda.dll ........... [Build ******, API 060425]
Module Ariel.dll ............. [Build ******, API 060425]
Module Umbriel.dll ........... [Build ******, API 060425]
Module Titania.dll ........... [Build ******, API 060425]
Module Oberon.dll ............ [Build ******, API 060425]
Module Neptune.dll ........... [Build 240115, API 240111]
VSOP87(B) Neptune: Precision 1.0e-06, Terms 391/2024
Finished initialising world
Module DeltaGlider.dll ....... [Build 240115, API 240111]
Module LuaInline.dll ......... [Build 240115, API 240111]
Loading module LuaInline
Module ShuttleA.dll .......... [Build 240115, API 240111]
Module ShuttlePB.dll ......... [Build 240115, API 240111]
Finished initialising status
Finished initialising camera
Finished setting up render state
-----------------
Orbiter NG (no graphics)
Running in server mode (no graphics client attached).
Type "help" for a list of commands.
Type "exit" to return to the Launchpad dialog.

Time acceleration set to 10.0
=== Lua script unit tests ===
>
--- vessel module ---
Test: vessel.get_focusinterface()
 - passed
Test: vessel.get_interface(name)
 - passed
Test: vessel.get_interface(idx)
 - passed
Test: vessel.get_focushandle()
 - passed
Test: vessel.get_handle(name)
 - passed
Test: vessel.get_handle(idx)
 - passed
Test: vessel.get_interface(handle)
 - passed
Test: vessel.get_count()
 - passed
>
--- vessel class ---
Test: vessel:get_handle()
 - passed
Test: vessel:version()
 - passed
Test: vessel:get_name()
 - passed
Test: vessel:get_classname()
 - passed
Test: vessel:get_enablefocus()
 - passed
Test: vessel:set_enablefocus()
 - passed
Test: vessel:get_size()
 - passed
Test: vessel:set_size(number)
 - passed
Test: vessel:get_emptymass()
 - passed
Test: vessel:set_emptymass(number)
 - passed
Test: vessel:get_pmi()
 - passed
Test: vessel:set_pmi(vector)
 - passed
Test: vessel:get_crosssections()
 - passed
Test: vessel:set_crosssections(vector)
 - passed
Test: vessel:get_touchdownpoints()
 - passed
Test: vessel:get_touchdownpointcount()
 - passed
Test: vessel:get_touchdownpoints(GEARUP "NewAPI")
 - passed
Test: vessel:get_touchdownpoints(GEARDOWN "NewAPI")
 - passed
Test: vessel:get_touchdownpoints(GEARUP2 "NewAPI")
 - passed
Test: vessel:set_touchdownpoints("NewAPI")
 - passed
=== All tests passed ===
LuaInline: timeout while waiting for interpreter thread
>
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x86-release>

@jarmonik
Copy link
Contributor

Ok, so, you have written that GeneralAPITest. Then you probably know much more about the tests than I do.

- added time-acceleration to Lua-Script, similar to VesselApiTest.lua (desperate I am)
@schnepe2
Copy link
Contributor Author

I am tending to believe, that the "Test suite" was never able to run more than one Lua-based test...
But that's just my uneducated guess 😁

Can we invite someone with knowledge about this?

Tomorrow I will likely commit an exact 1 to 1 copy of the working VesselApiTest, just renamed to GenericApiTest, to see what will happen.

@jarmonik
Copy link
Contributor

jarmonik commented Jan 16, 2024

Can we invite someone with knowledge about this?

Sure, Of course, why would that be a problem.

@schnepe2
Copy link
Contributor Author

...not a general problem 😉 just one that is caused by: I don't know "someone" 😁

@jarmonik
Copy link
Contributor

That would be @DarkWanderer

@schnepe2
Copy link
Contributor Author

@jarmonik : Do you have a orbiter-forum name of @DarkWanderer ?
(Although, mentioning him in this PR should have notified him...)

@DarkWanderer
Copy link
Contributor

Yes, I got the notification. Am I correct in assuming the issue is that 2 or more tests cannot be executed in parallel? If yes, I can take a look later - it is probably something about Orbiter not being able to run 2 instances at same time

@schnepe2
Copy link
Contributor Author

Wow! commit d60513c did let the test(s) pass 😮 ...
Now I have to do tiny litte steps to see what exactly is wrong with my test(s).

@schnepe2
Copy link
Contributor Author

schnepe2 commented Jan 16, 2024

Yes, I got the notification. Am I correct in assuming the issue is that 2 or more tests cannot be executed in parallel? If yes, I can take a look later - it is probably something about Orbiter not being able to run 2 instances at same time

That was just my uneducated guess 😊 ...I just found out, that that is not the general case.
Although file-i/o with 2 parallel running tests might be an issue. I have not thought about that possibility.

Here are my questions to you:

  • Is there a way to get the Orbiter.log from a failed test?
  • I am not able to run the test-suite locally on my machine (Windows 64 - Visual Studio 2019). Do you have any thoughts on that? running "test --preset windows-x86-release" just results in something like this:
    **********************************************************************
    ** Visual Studio 2019 Developer PowerShell v16.11.33
    ** Copyright (c) 2021 Microsoft Corporation
    **********************************************************************
    PS D:\Programme\Orbiter\orbiter-git-schnepe2> ctest --preset windows-x86-release --jobs 2
    CMake Error: Could not read presets from D:/Programme/Orbiter/orbiter-git-schnepe2: Unrecognized "version" field
    

- oapi.get_orbiter_version()
- oapi.rand()
- oapi.deflate()
- oapi.inflate()
- oapi.formatvalue()
- oapi.openfile() with "write-first" to have a known file in root.
@schnepe2
Copy link
Contributor Author

O.K. here we fail again!
It seems like any file i/o at all is crashing the test-suite.
I'll revert to last working state.

@schnepe2
Copy link
Contributor Author

schnepe2 commented Jan 16, 2024

Aaaaargh! This trial & error thing drives me nuts! It seems it's not (only) the file-i/o.
I hate this, but as I am unable to check this locally I have to do it via CI

@schnepe2
Copy link
Contributor Author

schnepe2 commented Jan 16, 2024

Phew! That was ugly.
But the PR itself is ready to merge now 🥳

Final results

  • The tests failed due to tests of oapi.formatvalue() using rediculous precisions (I believe a division by zero in a library).
    On my local machine they ran without problems up to 60! In both 32-bit & 64-bit builds...
    Those tests for 'precisions' of up to 60 are not really relevant, so testing up to 42 is fine.
  • One file-i/o test assumed that the file keymap.cfg is present, but that file is only generated when the Launchpad is shown.
    So now a dummy file (named __delete_me__.txt) is created first - and removed at end of the test.

@schnepe2 schnepe2 marked this pull request as ready for review January 16, 2024 22:10
@jarmonik jarmonik merged commit b0b72f3 into orbitersim:main Jan 17, 2024
3 checks passed
@schnepe2 schnepe2 deleted the Lua_extension branch January 17, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants