Skip to content

Commit

Permalink
Add case with saturate memory
Browse files Browse the repository at this point in the history
128M peak memory in a script
  • Loading branch information
XuJiandong committed May 20, 2024
1 parent 379684d commit f67e460
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
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.
// Internally, it is cached before being read out.
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;
}

0 comments on commit f67e460

Please sign in to comment.