check bool"Analysis should contain summary"true (String.length analysis.analysis_summary >0)
(** Test function registration *)
lettest_function_registration()=
let program_text = {|
@helper
fn helper(x: u32, y: u32) -> u32 {
return x + y
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var result = helper(10, 20)
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"function registration test"true (Kernelscript.Symbol_table.lookup_symbol st "helper"<>None)
with
|e -> fail ("Failed to test function registration: "^Printexc.to_string e)
(** Test function signature validation *)
lettest_function_signature_validation()=
let program_text = {|
@helper
fn valid_function(x: u32, y: u32) -> u32 {
return x + y
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var result = valid_function(10, 20)
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"function signature validation test"true (Kernelscript.Symbol_table.lookup_symbol st "valid_function"<>None)
with
|e -> fail ("Failed to test function signature validation: "^Printexc.to_string e)
(** Test function call resolution *)
lettest_function_call_resolution()=
let program_text = {|
@helper
fn multiply(x: u32, y: u32) -> u32 {
return x * y
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var result = multiply(10, 2)
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"function call resolution test"true (Kernelscript.Symbol_table.lookup_symbol st "multiply"<>None)
with
|e -> fail ("Failed to test function call resolution: "^Printexc.to_string e)
(** Test recursive function detection *)
lettest_recursive_function_detection()=
let program_text = {|
@helper
fn helper() -> u32 {
return 42
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var result = helper()
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"recursive function detection test"true (Kernelscript.Symbol_table.lookup_symbol st "helper"<>None)
with
|e -> fail ("Failed to test recursive function detection: "^Printexc.to_string e)
(** Test function dependency analysis *)
lettest_function_dependency_analysis()=
let program_text = {|
@helper
fn level1() -> u32 {
return 10
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var result = level1()
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"function dependency analysis test"true (Kernelscript.Symbol_table.lookup_symbol st "level1"<>None)
with
|e -> fail ("Failed to test function dependency analysis: "^Printexc.to_string e)
(** Test function optimization *)
lettest_function_optimization()=
let program_text = {|
@helper
fn simple_math(x: u32) -> u32 {
return x *2
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var const_val =10
var result = simple_math(const_val)
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"function optimization test"true (Kernelscript.Symbol_table.lookup_symbol st "simple_math"<>None)
with
|e -> fail ("Failed to test function optimization: "^Printexc.to_string e)
(** Test comprehensive function system *)
lettest_comprehensive_function_system()=
let program_text = {|
@helper
fn add(x: u32, y: u32) -> u32 {
return x + y
}
@helper
fn multiply(x: u32, y: u32) -> u32 {
return x * y
}
@xdp fn test(ctx: *xdp_md) -> xdp_action {
var a =10
var b =20
var sum = add(a, b)
var product = multiply(sum, 2)
return 2
}
|} in
try
let ast = parse_string program_text in
let st =Kernelscript.Symbol_table.build_symbol_table ast in
check bool"comprehensive function system test"true (Kernelscript.Symbol_table.lookup_symbol st "add"<>None&&Kernelscript.Symbol_table.lookup_symbol st "multiply"<>None)
with
|e -> fail ("Failed to test comprehensive function system: "^Printexc.to_string e)