diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/builtin/linux_bare/old/.checks | |
download | cli-tools-windows-master.tar.gz cli-tools-windows-master.tar.bz2 cli-tools-windows-master.zip |
Diffstat (limited to 'v_windows/v/vlib/builtin/linux_bare/old/.checks')
9 files changed, 519 insertions, 0 deletions
diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/.gitignore b/v_windows/v/vlib/builtin/linux_bare/old/.checks/.gitignore new file mode 100644 index 0000000..4132964 --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/.gitignore @@ -0,0 +1,5 @@ +checks +linuxsys/linuxsys +string/string +consts/consts +structs/structs diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/checks.v b/v_windows/v/vlib/builtin/linux_bare/old/.checks/checks.v new file mode 100644 index 0000000..8fd3575 --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/checks.v @@ -0,0 +1,32 @@ +module main + +import os + +fn failed (msg string) { + println ("!!! failed: $msg") +} + +fn passed (msg string) { + println (">>> passed: $msg") +} + + +fn vcheck(vfile string) { + run_check := "v -user_mod_path . -freestanding run " + if 0 == os.system("$run_check $vfile/${vfile}.v") { + passed(run_check) + } else { + failed(run_check) + } + os.system("ls -lh $vfile/$vfile") + os.system("rm -f $vfile/$vfile") +} + +fn main() { + vcheck("linuxsys") + vcheck("string") + vcheck("consts") + vcheck("structs") + exit(0) +} + diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/consts/consts.v b/v_windows/v/vlib/builtin/linux_bare/old/.checks/consts/consts.v new file mode 100644 index 0000000..eee2c61 --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/consts/consts.v @@ -0,0 +1,22 @@ +module main +import forkedtest + +const ( + integer1 = 111 + integer2 = 222 + integer3 = integer1+integer2 + integer9 = integer3 * 3 + abc = "123" +) + +fn check_const_initialization() { + assert abc == "123" + assert integer9 == 999 +} + +fn main(){ + mut fails := 0 + fails += forkedtest.normal_run(check_const_initialization, "check_const_initialization") + assert fails == 0 + sys_exit(0) +} diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/forkedtest/forkedtest.v b/v_windows/v/vlib/builtin/linux_bare/old/.checks/forkedtest/forkedtest.v new file mode 100644 index 0000000..6d9272c --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/forkedtest/forkedtest.v @@ -0,0 +1,49 @@ +module forkedtest + +pub fn run (op fn(), label string, code Wi_si_code, status int) int { + child := sys_fork() + if child == 0 { + op() + sys_exit(0) + } + + siginfo := []int{len:int(Sig_index.si_size)} + + e := sys_waitid(.p_pid, child, intptr(&siginfo[0]), .wexited, 0) + + assert e == .enoerror + assert siginfo[int(Sig_index.si_pid)] == child + assert siginfo[int(Sig_index.si_signo)] == int(Signo.sigchld) + assert siginfo[int(Sig_index.si_uid)] == sys_getuid() + + r_code := siginfo[Sig_index.si_code] + r_status := siginfo[Sig_index.si_status] + + print("+++ ") + print(label) + if (int(code) == r_code) && (status == r_status) { + println(" PASSED") + return 0 + } + println(" FAILED") + + if int(code) != r_code { + print(">> Expecting si_code 0x") + println(i64_str(int(code),16)) + print(">> Got 0x") + println(i64_str(r_code,16)) + } + + if status != r_status { + print(">> Expecting status 0x") + println(i64_str(status,16)) + print(">> Got 0x") + println(i64_str(r_status,16)) + } + + return 1 +} + +pub fn normal_run (op fn(), label string) int { + return run (op, label, .cld_exited, 0) +} diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/linuxsys/linuxsys.v b/v_windows/v/vlib/builtin/linux_bare/old/.checks/linuxsys/linuxsys.v new file mode 100644 index 0000000..cca5cb6 --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/linuxsys/linuxsys.v @@ -0,0 +1,300 @@ +module main +import forkedtest + +const ( + sample_text_file1 = "" +) + +fn check_fork_minimal () { + child := sys_fork() + ec := 100 + if child == 0 { + println("child") + sys_exit(ec) + } + siginfo := [ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0] + + e := sys_waitid(.p_pid, child, intptr(siginfo.data) , .wexited, 0) + + assert e == .enoerror + //println(i64_tos(buffer0,80,siginfo[Sig_index.si_code],16)) + assert siginfo[Sig_index.si_code] == int(Wi_si_code.cld_exited) + assert siginfo[Sig_index.si_pid] == child + assert siginfo[Sig_index.si_status] == ec + assert siginfo[Sig_index.si_signo] == int(Signo.sigchld) + assert siginfo[Sig_index.si_uid] == sys_getuid() +} + +fn check_read_write_pipe() { + // Checks the following system calls: + // sys_pipe + // sys_write + // sys_read + // sys_close + // + buffer0 := []byte{len:(128)} + buffer := byteptr(buffer0.data) + + fd := [-1, -1] + + assert fd[0] == -1 + assert fd[1] == -1 + + a := sys_pipe(intptr(&fd[0])) + + assert a == .enoerror + + assert fd[0] != -1 + assert fd[1] != -1 + + test_data := "test_data" + b := test_data.len + 1 + c1, e1 := sys_write (fd[1], test_data.str, u64(b)) + + assert e1 == .enoerror + assert c1 == b + + c2, e2 := sys_read(fd[0], buffer, u64(b)) + + assert e2 == .enoerror + assert c2 == b + + assert buffer[b-1] == 0 + + for i in 0..b { + assert test_data[i] == buffer[i] + } + + assert sys_close(fd[0]) == .enoerror + assert sys_close(fd[1]) == .enoerror + + assert sys_close(-1) == .ebadf +} + +fn check_read_file() { + /* + Checks the following system calls: + sys_read + sys_write + sys_close + sys_open + */ + buffer0 := []byte{len:(128)} + buffer := byteptr(buffer0.data) + + test_file := "sample_text1.txt" + sample_text := "Do not change this text.\n" + fd, ec := sys_open(test_file.str, .o_rdonly, 0) + assert fd > 0 + assert ec == .enoerror + n := sample_text.len + c, e := sys_read(fd, buffer, u64(n*2)) + assert e == .enoerror + assert c == n + for i in 0..n { + assert sample_text[i] == buffer[i] + } + assert sys_close(fd) == .enoerror +} + +fn check_open_file_fail() { + fd1, ec1 := sys_open("./nofilehere".str, .o_rdonly, 0) + assert fd1 == -1 + assert ec1 == .enoent +} + +/* +fn check_print() { + println ("checking print and println") + + a := sys_pipe(intptr(fd)) + assert a != -1 + assert fd[0] != -1 + assert fd[1] != -1 + + //sys_dup2 + println ("print and println passed") +} +*/ + +fn check_munmap_fail() { + ec := sys_munmap(-16384,8192) + assert ec == .einval +} + +fn check_mmap_one_page() { + mp := int(Mm_prot.prot_read) | int(Mm_prot.prot_write) + mf := int(Map_flags.map_private) | int(Map_flags.map_anonymous) + mut a, e := sys_mmap(0, u64(Linux_mem.page_size), Mm_prot(mp), Map_flags(mf), -1, 0) + + assert e == .enoerror + assert a != byteptr(-1) + + for i in 0..int(Linux_mem.page_size) { + b := i & 0xFF + a[i] = b + assert a[i] == b + } + + ec := sys_munmap(a, u64(Linux_mem.page_size)) + assert ec == .enoerror +} + +fn check_mm_pages() { + for i in 0 .. int(Linux_mem.page_size)-4 { + assert u32(1) == mm_pages(u64(i)) + } + for i in int(Linux_mem.page_size)-3 .. (int(Linux_mem.page_size)*2)-4 { + assert u32(2) == mm_pages(u64(i)) + } + for i in (int(Linux_mem.page_size)*2)-3 .. (int(Linux_mem.page_size)*3)-4 { + assert u32(3) == mm_pages(u64(i)) + } +} + +//pub fn mm_alloc(size u64) (voidptr, Errno) + +fn check_mm_alloc() { + for i in 1 .. 2000 { + size := u64(i*1000) + pages := mm_pages(size) + mut a, e := mm_alloc(size) + + assert e == .enoerror + ap := intptr(a-4) + assert *ap == int(pages) + assert e == .enoerror + assert !isnil(a) + + if (i%111) == 0 { + for j in 0 .. int(size) { + b := j & 0xFF + a[j] = b + assert b == int(a[j]) + } + } + + mfa := mm_free(a) + + assert mfa == .enoerror + } +} + +fn check_int_array_ro() { + a := [100,110,120,130] + assert a.len == 4 + assert a[0] == 100 + assert a[1] == 110 + assert a[2] == 120 + assert a[3] == 130 +} + +fn check_int_array_rw() { + mut a := [-10,-11,-12,-13] + assert a.len == 4 + assert a[0] == -10 + assert a[1] == -11 + assert a[2] == -12 + assert a[3] == -13 + for i in 0..a.len { + b := -a[i] * 10 + a[i] = b + assert a[i] == b + } + assert a[3] == 130 +} + +fn check_int64_array_ro() { + a := [i64(1000),1100,1200,1300,1400] + assert a.len == 5 + assert a[0] == 1000 + assert a[1] == 1100 + assert a[2] == 1200 + assert a[3] == 1300 + assert a[4] == 1400 +} + +fn check_voidptr_array_ro() { + a := [ + voidptr(10000), + voidptr(11000), + voidptr(12000), + voidptr(13000), + voidptr(14000), + voidptr(15000) + ] + assert a.len == 6 + assert a[0] == voidptr(10000) + assert a[1] == voidptr(11000) + assert a[2] == voidptr(12000) + assert a[3] == voidptr(13000) + assert a[4] == voidptr(14000) + assert a[5] == voidptr(15000) +} + +fn check_voidptr_array_rw() { + mut a := [ + voidptr(-1), + voidptr(-1), + voidptr(-1), + voidptr(-1), + voidptr(-1), + voidptr(-1) + ] + assert a.len == 6 + + assert a[0] == voidptr(-1) + assert a[1] == voidptr(-1) + assert a[2] == voidptr(-1) + assert a[3] == voidptr(-1) + assert a[4] == voidptr(-1) + assert a[5] == voidptr(-1) + + a[0] = voidptr(100000) + assert a[0] == voidptr(100000) + + a[1] = voidptr(110000) + assert a[1] == voidptr(110000) + + a[2] = voidptr(120000) + assert a[2] == voidptr(120000) + + a[3] = voidptr(130000) + assert a[3] == voidptr(130000) + + a[4] = voidptr(140000) + assert a[4] == voidptr(140000) + + a[5] = voidptr(150000) + assert a[5] == voidptr(150000) +} + + +fn main() { + mut fails := 0 + fails += forkedtest.normal_run(check_fork_minimal, "check_fork_minimal") + fails += forkedtest.normal_run(check_munmap_fail, "check_munmap_fail") + fails += forkedtest.normal_run(check_mmap_one_page, "check_mmap_one_page") + fails += forkedtest.normal_run(check_mm_pages, "check_mm_pages") + fails += forkedtest.normal_run(check_mm_alloc, "check_mm_alloc") + fails += forkedtest.normal_run(check_read_write_pipe, "check_read_write_pipe") + fails += forkedtest.normal_run(check_read_file, "check_read_file") + // check_print() + fails += forkedtest.normal_run(check_open_file_fail, "check_open_file_fail") + fails += forkedtest.normal_run(check_int_array_ro, "check_int_array_ro") + fails += forkedtest.normal_run(check_int_array_rw, "check_int_array_rw") + fails += forkedtest.normal_run(check_int64_array_ro, "check_int64_array_ro") + fails += forkedtest.normal_run(check_voidptr_array_ro, "check_voidptr_array_ro") + fails += forkedtest.normal_run(check_voidptr_array_rw, "check_voidptr_array_rw") + + assert fails == 0 + sys_exit(0) +} diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/readme.md b/v_windows/v/vlib/builtin/linux_bare/old/.checks/readme.md new file mode 100644 index 0000000..03c1b30 --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/readme.md @@ -0,0 +1,5 @@ +In this directory: +``` +v run checks.v +``` + diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/sample_text1.txt b/v_windows/v/vlib/builtin/linux_bare/old/.checks/sample_text1.txt new file mode 100644 index 0000000..f06e75a --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/sample_text1.txt @@ -0,0 +1 @@ +Do not change this text. diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/string/string.v b/v_windows/v/vlib/builtin/linux_bare/old/.checks/string/string.v new file mode 100644 index 0000000..54c06e7 --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/string/string.v @@ -0,0 +1,63 @@ +module main +import forkedtest + +fn check_string_eq () { + assert "monkey" != "rat" + some_animal := "a bird" + assert some_animal == "a bird" +} + +fn check_i64_tos() { + buffer0 := []byte{len:(128)} + buffer := byteptr(buffer0.data) + + s0 := i64_tos(buffer, 70, 140, 10) + assert s0 == "140" + + s1 := i64_tos(buffer, 70, -160, 10) + assert s1 == "-160" + + s2 := i64_tos(buffer, 70, 65537, 16) + assert s2 == "10001" + + s3 := i64_tos(buffer, 70, -160000, 10) + assert s3 == "-160000" +} + +fn check_i64_str() { + assert "141" == i64_str(141, 10) + assert "-161" == i64_str(-161, 10) + assert "10002" == i64_str(65538, 16) + assert "-160001" == i64_str(-160001, 10) +} + +fn check_str_clone() { + a := i64_str(1234,10) + b := a.clone() + assert a == b + c := i64_str(-6789,10).clone() + assert c == "-6789" +} + +fn check_string_add_works(){ + abc := 'abc' + combined := 'a' + 'b' + 'c' + assert abc.len == combined.len + assert abc[0] == combined[0] + assert abc[1] == combined[1] + assert abc[2] == combined[2] + assert abc[0] == `a` + assert abc == combined +} + +fn main () { + mut fails := 0 + fails += forkedtest.normal_run(check_string_eq, "check_string_eq") + fails += forkedtest.normal_run(check_i64_tos, "check_i64_tos") + fails += forkedtest.normal_run(check_i64_str, "check_i64_str") + fails += forkedtest.normal_run(check_str_clone, "check_str_clone") + fails += forkedtest.normal_run(check_string_add_works, "check_string_add_works") + assert fails == 0 + sys_exit(0) +} + diff --git a/v_windows/v/vlib/builtin/linux_bare/old/.checks/structs/structs.v b/v_windows/v/vlib/builtin/linux_bare/old/.checks/structs/structs.v new file mode 100644 index 0000000..f63285d --- /dev/null +++ b/v_windows/v/vlib/builtin/linux_bare/old/.checks/structs/structs.v @@ -0,0 +1,42 @@ +module main +import forkedtest + +struct SimpleEmptyStruct{ +} + +struct NonEmptyStruct{ + x int + y int + z int +} + +fn check_simple_empty_struct(){ + s := SimpleEmptyStruct{} + addr_s := &s + str_addr_s := ptr_str( addr_s ) + assert !isnil(addr_s) + assert str_addr_s.len > 3 + println(str_addr_s) +} + +fn check_non_empty_struct(){ + a := NonEmptyStruct{1,2,3} + b := NonEmptyStruct{4,5,6} + assert sizeof(NonEmptyStruct) > 0 + assert sizeof(SimpleEmptyStruct) < sizeof(NonEmptyStruct) + assert a.x == 1 + assert a.y == 2 + assert a.z == 3 + assert b.x + b.y + b.z == 15 + assert ptr_str(&a) != ptr_str(&b) + println('sizeof SimpleEmptyStruct:' + i64_str( sizeof(SimpleEmptyStruct) , 10 )) + println('sizeof NonEmptyStruct:' + i64_str( sizeof(NonEmptyStruct) , 10 )) +} + +fn main(){ + mut fails := 0 + fails += forkedtest.normal_run(check_simple_empty_struct, "check_simple_empty_struct") + fails += forkedtest.normal_run(check_non_empty_struct, "check_non_empty_struct") + assert fails == 0 + sys_exit(0) +} |