Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests: about spawn load cells #22

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion script/src/verify/tests/ckb_latest/features_since_v2023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@ proptest! {
#[test]
fn check_spawn_close_invalid_fd() {
let result = simple_spawn_test("testdata/spawn_cases", &[12]);
println!("--- err: {:?}", result);
assert_eq!(result.is_ok(), SCRIPT_VERSION == ScriptVersion::V2);
}

Expand Down Expand Up @@ -1221,3 +1220,15 @@ fn check_spawn_huge_swap() {
assert!(result.is_err())
}
}

#[test]
fn check_spawn_invaild_index() {
let result = simple_spawn_test("testdata/spawn_cases", &[17]);
assert_eq!(result.is_ok(), SCRIPT_VERSION == ScriptVersion::V2);
}

#[test]
fn check_spawn_index_out_of_bound() {
let result = simple_spawn_test("testdata/spawn_cases", &[18]);
assert_eq!(result.is_ok(), SCRIPT_VERSION == ScriptVersion::V2);
}
Binary file modified script/testdata/spawn_cases
Binary file not shown.
46 changes: 45 additions & 1 deletion script/testdata/spawn_cases.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ int parent_spawn_length_out_of_bound(uint64_t* pid) {

const char* argv[] = {"", 0};
spawn_args_t spgs = {.argc = 1, .argv = argv, .process_id = pid, .inherited_fds = NULL};
uint64_t offset = 1024 * 14;
uint64_t offset = 1024 * 15;
uint64_t length = 1024;
uint64_t bounds = (offset << 32) + length;

Expand All @@ -507,6 +507,46 @@ int parent_spawn_length_out_of_bound(uint64_t* pid) {
return err;
}

int parent_invaild_index(uint64_t* pid) {
int err = 0;
const char* argv[] = {"", 0};
uint64_t inherited_fds[11] = {0};
for (size_t i = 0; i < 5; i++) {
err = ckb_pipe(&inherited_fds[i * 2]);
CHECK(err);
}
spawn_args_t spgs = {.argc = 1,
.argv = argv,
.process_id = pid,
.inherited_fds = inherited_fds};
err = ckb_spawn(0xFFFFFFFFF, CKB_SOURCE_CELL_DEP, 0, 0, &spgs);
CHECK2(err == 1, -1); // INDEX_OUT_OF_BOUND
err = 0;

exit:
return err;
}

int parent_index_out_of_bound(uint64_t* pid) {
int err = 0;
const char* argv[] = {"", 0};
uint64_t inherited_fds[11] = {0};
for (size_t i = 0; i < 5; i++) {
err = ckb_pipe(&inherited_fds[i * 2]);
CHECK(err);
}
spawn_args_t spgs = {.argc = 1,
.argv = argv,
.process_id = pid,
.inherited_fds = inherited_fds};
err = ckb_spawn(2, CKB_SOURCE_CELL_DEP, 0, 0, &spgs);
CHECK2(err == 1, -1); // INDEX_OUT_OF_BOUND
err = 0;

exit:
return err;
}

int parent_entry(int case_id) {
int err = 0;
uint64_t pid = 0;
Expand Down Expand Up @@ -544,6 +584,10 @@ int parent_entry(int case_id) {
return parent_spawn_offset_out_of_bound(&pid);
} else if (case_id == 16) {
return parent_spawn_length_out_of_bound(&pid);
} else if (case_id == 17) {
return parent_invaild_index(&pid);
} else if (case_id == 18) {
return parent_index_out_of_bound(&pid);
} else {
CHECK2(false, -2);
}
Expand Down
Loading