Merge pull request #17456 from opensourcerouting/fix/lua_unit_test

Lua casting
This commit is contained in:
Donald Sharp 2024-11-19 09:24:40 -05:00 committed by GitHub
commit 9b50371965
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View File

@ -457,8 +457,7 @@ route_match_script(void *rule, const struct prefix *prefix, void *object)
return RMAP_NOMATCH;
}
long long *action = frrscript_get_result(fs, routematch_function,
"action", lua_tointegerp);
int *action = frrscript_get_result(fs, routematch_function, "action", lua_tointegerp);
int status = RMAP_NOMATCH;

View File

@ -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 */
@ -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");
@ -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");