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 8, 2024
1 parent d3293dd commit 4a2e223
Show file tree
Hide file tree
Showing 5 changed files with 35 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
30 changes: 30 additions & 0 deletions tests/unit/moduleapi/scriptingengine.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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"} overrides {{save ""}}} {
r module load $testmodule

r function load $HELLO_PROGRAM

test {Call scripting engine function: calling foo works} {
set result [r fcall foo 0 134]
assert_equal $result 134
}

test {Call scripting engine function: calling bar works} {
set result [r fcall bar 0]
assert_equal $result 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
}
}

0 comments on commit 4a2e223

Please sign in to comment.