Skip to content

Commit

Permalink
lib: Fix Lua script unit test
Browse files Browse the repository at this point in the history
When building for big-endian architectures, this is failing because of
long long / int casting issues, let's use a separate integer to get the
results.

This is especially important when building the Docker images for multiple arches.

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Nov 18, 2024
1 parent 724624a commit 77df36c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/lib/test_frrscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ int main(int argc, char **argv)
long long *ansptr =
frrscript_get_result(fs, "fact", "ans", lua_tolonglongp);
assert(*ansptr == 120);
XFREE(MTYPE_SCRIPT_RES, ansptr);

/* check consecutive call + get_result without re-loading */
n = 4;
result = frrscript_call(fs, "fact", ("n", &n));
assert(result == 0);
ansptr = frrscript_get_result(fs, "fact", "ans", lua_tointegerp);
assert(*ansptr == 24);
int *ansptr_c = frrscript_get_result(fs, "fact", "ans", lua_tointegerp);

XFREE(MTYPE_SCRIPT_RES, ansptr);
assert(*ansptr_c == 24);
XFREE(MTYPE_SCRIPT_RES, ansptr_c);

/* Negative testing */

Expand All @@ -70,9 +71,9 @@ int main(int argc, char **argv)
assert(result == 1);

/* Get result from a function that was not loaded */
long long *llptr =
frrscript_get_result(fs, "does_not_exist", "c", lua_tointegerp);
assert(llptr == NULL);
int *intptr = frrscript_get_result(fs, "does_not_exist", "c", lua_tointegerp);

assert(intptr == NULL);

/* Function returns void */
result = frrscript_call(fs, "bad_return1");
Expand All @@ -85,9 +86,9 @@ int main(int argc, char **argv)
/* Get non-existent result from a function */
result = frrscript_call(fs, "bad_return3");
assert(result == 1);
long long *cllptr =
frrscript_get_result(fs, "bad_return3", "c", lua_tointegerp);
assert(cllptr == NULL);
intptr = frrscript_get_result(fs, "bad_return3", "c", lua_tointegerp);
assert(intptr == NULL);
XFREE(MTYPE_SCRIPT_RES, intptr);

/* Function throws exception */
result = frrscript_call(fs, "bad_return4");
Expand Down

0 comments on commit 77df36c

Please sign in to comment.