Skip to content

Commit

Permalink
Adds new module API test to test the scripting engine module API
Browse files Browse the repository at this point in the history
This commit adds a simple test to test the new module API that allows to
implement new scripting engines as modules.

Signed-off-by: Ricardo Dias <[email protected]>
  • Loading branch information
rjd15372 committed Nov 11, 2024
1 parent c7afe80 commit 1a22451
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif
all: helloworld.so hellotype.so helloblock.so hellocluster.so hellotimer.so hellodict.so hellohook.so helloacl.so helloscripting.so

.c.xo:
$(CC) -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@
$(CC) -I.. -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@

helloworld.xo: ../valkeymodule.h

Expand Down
2 changes: 1 addition & 1 deletion src/modules/helloscripting.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../valkeymodule.h"
#include "valkeymodule.h"

#include <string.h>
#include <ctype.h>
Expand Down
3 changes: 2 additions & 1 deletion tests/modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ TEST_MODULES = \
moduleauthtwo.so \
rdbloadsave.so \
crash.so \
cluster.so
cluster.so \
helloscripting.so

.PHONY: all

Expand Down
1 change: 1 addition & 0 deletions tests/modules/helloscripting.c
38 changes: 38 additions & 0 deletions tests/unit/moduleapi/scriptingengine.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set testmodule [file normalize tests/modules/helloscripting.so]

set HELLO_PROGRAM "#!hello name=mylib\nFUNCTION foo\nARGS 0\nRETURN\nFUNCTION bar\nCONSTI 432\nRETURN"

start_server {tags {"modules"}} {
r module load $testmodule

r function load $HELLO_PROGRAM

test {Call scripting engine function: calling foo works} {
r fcall foo 0 134
} {134}

test {Call scripting engine function: calling bar works} {
r fcall bar 0
} {432}

test {Replace function library and call functions} {
set result [r function load replace "#!hello name=mylib\nFUNCTION foo\nARGS 0\nRETURN\nFUNCTION bar\nCONSTI 500\nRETURN"]
assert_equal $result "mylib"

set result [r fcall foo 0 132]
assert_equal $result 132

set result [r fcall bar 0]
assert_equal $result 500
}

test {List scripting engine functions} {
r function load replace "#!hello name=mylib\nFUNCTION foobar\nARGS 0\nRETURN"
r function list
} {{library_name mylib engine HELLO functions {{name foobar description {} flags {}}}}}

test {Unload scripting engine module} {
set result [r module unload helloengine]
assert_equal $result "OK"
}
}

0 comments on commit 1a22451

Please sign in to comment.