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 test case with spawn saturate memory #24

Merged
merged 2 commits into from
May 20, 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
6 changes: 6 additions & 0 deletions script/src/verify/tests/ckb_latest/features_since_v2023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,3 +1320,9 @@ fn check_spawn_io_cycles() {

assert_eq!(cycles2 - cycles1, offset_size / 2);
}

#[test]
fn check_spawn_saturate_memory() {
let result = simple_spawn_test("testdata/spawn_saturate_memory", &[0]);
assert_eq!(result.is_ok(), SCRIPT_VERSION == ScriptVersion::V2);
}
4 changes: 3 additions & 1 deletion script/testdata/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ ALL_BINS := jalr_zero \
spawn_fuzzing \
spawn_huge_swap \
spawn_cycles \
spawn_io_cycles
spawn_io_cycles \
spawn_saturate_memory

ALL_LIBS := is_even.lib \
add1.lib sub1.lib mul2.lib div2.lib
Expand Down Expand Up @@ -162,3 +163,4 @@ spawn_fuzzing: spawn_fuzzing.c spawn_utils.h
spawn_huge_swap: spawn_huge_swap.c spawn_utils.h
spawn_cycles: spawn_cycles.c spawn_utils.h
spawn_io_cycles: spawn_io_cycles.c spawn_utils.h
spawn_saturate_memory: spawn_saturate_memory.c spawn_utils.h
Binary file added script/testdata/spawn_saturate_memory
Binary file not shown.
45 changes: 45 additions & 0 deletions script/testdata/spawn_saturate_memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "spawn_utils.h"

#define MAX_MEMORY (4 * 1024 * 1024)
#define PAGE_SIZE (4 * 1024)

extern char _end[];

void dirty_all_pages() {
uint64_t addr = (uint64_t)_end;
while (addr < MAX_MEMORY) {
uint8_t* ptr = (uint8_t*)addr;
*ptr = 0;
addr += PAGE_SIZE;
}
}

int main(int argc, const char* argv[]) {
int err = 0;
if (argc > 0) {
// child
dirty_all_pages();
uint64_t inherited_fds[2];
size_t inherited_fds_length = 2;
err = ckb_inherited_file_descriptors(inherited_fds, &inherited_fds_length);
uint64_t length = MAX_MEMORY;
// Write a piece of data starting from address 0 with a size of 4M.
// It should not consume any memory.
err = ckb_write(inherited_fds[CKB_STDOUT], 0, &length);
// should be blocked forever since there is no reading on other end
CHECK(err);
} else {
// parent
for (size_t i = 0; i < 15; i++) {
uint64_t pid = 0;
const char* argv[] = {"", 0};
uint64_t fds[2] = {0};
err = full_spawn(0, 1, argv, fds, &pid);
CHECK(err);
}
dirty_all_pages();
}

exit:
return err;
}
Loading