Skip to content

Commit a0574c0

Browse files
committed
test(strings): match new __src binding in assignment template
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 3b029d3 commit a0574c0

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

tests/test_string_codegen.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ fn main() -> i32 {
7474

7575
(* Should generate runtime length checking to avoid truncation warnings *)
7676
check bool "has strlen check" true (contains_pattern result "strlen.*__src_len");
77-
check bool "has strcpy for safe case" true (contains_pattern result "strcpy.*var_.*\"Hello\"");
77+
check bool "binds source literal" true (contains_pattern result "__src = \"Hello\"");
78+
check bool "has strcpy for safe case" true (contains_pattern result "strcpy.*var_.*__src");
7879
check bool "has strncpy for truncation case" true (contains_pattern result "strncpy.*var_");
7980
check bool "has explicit null termination" true (contains_pattern result "\\[.*\\].*=.*'\\\\0'");
8081

@@ -166,8 +167,8 @@ fn main() -> i32 {
166167
check bool "uses comparison variable in if" true (contains_pattern result "if.*(__binop_");
167168

168169
(* Should have proper string assignments *)
169-
check bool "has Alice assignment" true (contains_pattern result "strcpy.*var_.*\"Alice\"");
170-
check bool "has Bob assignment" true (contains_pattern result "strcpy.*var_.*\"Bob\"");
170+
check bool "has Alice assignment" true (contains_pattern result "__src = \"Alice\"");
171+
check bool "has Bob assignment" true (contains_pattern result "__src = \"Bob\"");
171172
) else (
172173
failwith "Failed to generate userspace code file"
173174
)
@@ -222,9 +223,9 @@ fn main() -> i32 {
222223
let result = generate_userspace_code_from_program program_text "test_string_truncation" in
223224

224225
(* Should handle all cases safely *)
225-
check bool "has strlen checks" true (contains_pattern result "strlen.*\"toolong\"");
226-
check bool "has safe strcpy path" true (contains_pattern result "strcpy.*var_.*\"exact\"");
227-
check bool "has truncation path" true (contains_pattern result "strncpy.*var_.*\"toolong\".*[0-9]+.*-.*1");
226+
check bool "has strlen checks" true (contains_pattern result "__src = \"toolong\"");
227+
check bool "has safe strcpy path" true (contains_pattern result "__src = \"exact\"");
228+
check bool "has truncation path" true (contains_pattern result "strncpy.*var_.*__src.*[0-9]+.*-.*1");
228229
check bool "explicit null termination" true (contains_pattern result "var_.*\\[.*-.*1\\].*=.*'\\\\0'");
229230

230231
(* Should have proper size checking - the runtime checks use the declared buffer size *)
@@ -291,13 +292,13 @@ fn main() -> i32 {
291292
let result = generate_userspace_code_from_program program_text "test_edge_strings" in
292293

293294
(* Should handle small strings safely *)
294-
check bool "handles single char" true (contains_pattern result "strlen.*\"A\"");
295-
check bool "handles empty string" true (contains_pattern result "strlen.*\"\"");
295+
check bool "handles single char" true (contains_pattern result "__src = \"A\"");
296+
check bool "handles empty string" true (contains_pattern result "__src = \"\"");
296297
check bool "size check for single" true (contains_pattern result "__src_len.*<.*2");
297298
check bool "size check for empty buffer" true (contains_pattern result "__src_len.*<.*1");
298299

299300
(* Should still use safe string handling *)
300-
check bool "safe assignment for single" true (contains_pattern result "strcpy.*var_.*\"A\"");
301+
check bool "safe assignment for single" true (contains_pattern result "__src = \"A\"");
301302
with
302303
| exn -> fail ("Empty and single char strings test failed: " ^ Printexc.to_string exn)
303304

0 commit comments

Comments
 (0)