Skip to content

Instantly share code, notes, and snippets.

@hannesm
Created Jun 1, 2018
Embed
What would you like to do?
bigstringaf test
open Mirage
let main =
foreign
~packages:[package "bigstringaf"]
"Unikernel.Hello" (time @-> job)
let () =
register "hello" [main $ default_time]
open Lwt.Infix
open Bigstringaf
module Hello (Time : Mirage_time_lwt.S) = struct
let getters () =
let string = "\xde\xad\xbe\xef\x8b\xad\xf0\x0d" in
let buffer = of_string ~off:0 ~len:(String.length string) string in
Logs.info (fun m -> m "get buffer 0 should be 0xde %02x" (int_of_char (get buffer 0))) ;
Logs.info (fun m -> m "get buffer 2 should be 0xbe %02x" (int_of_char (get buffer 2))) ;
Logs.info (fun m -> m "get_int16_be 0 should be 0xdead %04x" (get_int16_be buffer 0)) ;
Logs.info (fun m -> m "get_int16_be 2 should be 0xbeef %04x" (get_int16_be buffer 2)) ;
Logs.info (fun m -> m "get_int16_le 0 should be 0xadde %04x" (get_int16_le buffer 0)) ;
Logs.info (fun m -> m "get_int16_le 2 should be 0xefbe %04x" (get_int16_le buffer 2)) ;
Logs.info (fun m -> m "get_int16_sign_extended_be should be 0x7fffffffffffdead %x" (get_int16_sign_extended_be buffer 0)) ;
Logs.info (fun m -> m "get_int16_sign_extended_le should be 0x7fffffffffffadde %x" (get_int16_sign_extended_le buffer 0)) ;
Logs.info (fun m -> m "get_int16_sign_extended_le should be 0x0df0 %x" (get_int16_sign_extended_le buffer 6)) ;
Logs.info (fun m -> m "get_int32_be 0 should be 0xdeadbeefl %lx" (get_int32_be buffer 0)) ;
Logs.info (fun m -> m "get_int32_be 2 should be 0xbeef8badl %lx" (get_int32_be buffer 2)) ;
Logs.info (fun m -> m "get_int32_le 0 should be 0xefbeaddel %lx" (get_int32_le buffer 0)) ;
Logs.info (fun m -> m "get_int32_le 2 should be 0xad8befbel %lx" (get_int32_le buffer 2)) ;
Logs.info (fun m -> m "get_int64_be 0 should be 0xdeadbeef8badf00dL %Lx" (get_int64_be buffer 0)) ;
Logs.info (fun m -> m "get_int64_le 0 should be 0x0df0ad8befbeaddeL %Lx" (get_int64_le buffer 0))
let setters () =
let string = Bytes.make 16 '_' |> Bytes.unsafe_to_string in
let with_buffer ~f =
let buffer = of_string ~off:0 ~len:(String.length string) string in
f buffer
in
let substring ~len buffer = substring ~off:0 ~len buffer in
with_buffer ~f:(fun buffer ->
set buffer 0 '\xde';
Logs.info (fun m -> m "set should be \xde___ %s" (substring ~len:4 buffer)));
with_buffer ~f:(fun buffer ->
set buffer 2 '\xbe';
Logs.info (fun m -> m "set should be __\xbe_ %s" (substring ~len:4 buffer)));
with_buffer ~f:(fun buffer ->
set_int16_be buffer 0 0xdead;
Logs.info (fun m -> m "set_int16_be should be \xde\xad__ %s" (substring ~len:4 buffer)));
with_buffer ~f:(fun buffer ->
set_int16_be buffer 2 0xbeef;
Logs.info (fun m -> m "set_int16_be should be __\xbe\xef %s" (substring ~len:4 buffer)));
with_buffer ~f:(fun buffer ->
set_int16_le buffer 0 0xdead;
Logs.info (fun m -> m "set_int16_le should be \xad\xde__ %s" (substring ~len:4 buffer)));
with_buffer ~f:(fun buffer ->
set_int16_le buffer 2 0xbeef;
Logs.info (fun m -> m "set_int16_le should be __\xef\xbe %s" (substring ~len:4 buffer)));
with_buffer ~f:(fun buffer ->
set_int32_be buffer 0 0xdeadbeefl;
Logs.info (fun m -> m "set_int32_be should be \xde\xad\xbe\xef____ %s" (substring ~len:8 buffer)));
with_buffer ~f:(fun buffer ->
set_int32_le buffer 0 0xdeadbeefl;
Logs.info (fun m -> m "set_int32_le should be \xef\xbe\xad\xde____ %s" (substring ~len:8 buffer)));
with_buffer ~f:(fun buffer ->
set_int32_be buffer 2 0xbeef8badl;
Logs.info (fun m -> m "set_int32_be should be __\xbe\xef\x8b\xad__ %s" (substring ~len:8 buffer)));
with_buffer ~f:(fun buffer ->
set_int32_le buffer 2 0xbeef8badl;
Logs.info (fun m -> m "set_int32_le should be __\xad\x8b\xef\xbe__ %s" (substring ~len:8 buffer)));
with_buffer ~f:(fun buffer ->
set_int64_be buffer 0 0xdeadbeef8badf00dL;
Logs.info (fun m -> m "set_int64_be should be \xde\xad\xbe\xef\x8b\xad\xf0\x0d %s" (substring ~len:8 buffer)));
with_buffer ~f:(fun buffer ->
set_int64_le buffer 0 0xdeadbeef8badf00dL;
Logs.info (fun m -> m "set_int64_le should be \x0d\xf0\xad\x8b\xef\xbe\xad\xde %s" (substring ~len:8 buffer)))
let start _time =
getters () ;
setters () ;
Lwt.return_unit
end
@hannesm

This comment has been minimized.

Copy link
Owner Author

@hannesm hannesm commented Jun 1, 2018

output:

            |      ___|
  __|  _ \  |  _ \ __ \
\__ \ (   | | (   |  ) |
____/\___/ _|\___/____/
Solo5: Memory map: 512 MB addressable:
Solo5:     unused @ (0x0 - 0xfffff)
Solo5:       text @ (0x100000 - 0x1f2fff)
Solo5:     rodata @ (0x1f3000 - 0x222fff)
Solo5:       data @ (0x223000 - 0x2e0fff)
Solo5:       heap >= 0x2e1000 < stack < 0x20000000
2018-06-01 10:27:13 -00:00: INF [application] get buffer 0 should be 0xde de
2018-06-01 10:27:13 -00:00: INF [application] get buffer 2 should be 0xbe be
2018-06-01 10:27:13 -00:00: INF [application] get_int16_be 0 should be 0xdead dead
2018-06-01 10:27:13 -00:00: INF [application] get_int16_be 2 should be 0xbeef beef
2018-06-01 10:27:13 -00:00: INF [application] get_int16_le 0 should be 0xadde adde
2018-06-01 10:27:13 -00:00: INF [application] get_int16_le 2 should be 0xefbe efbe
2018-06-01 10:27:13 -00:00: INF [application] get_int16_sign_extended_be should be 0x7fffffffffffdead 7fffffffffffdead
2018-06-01 10:27:13 -00:00: INF [application] get_int16_sign_extended_le should be 0x7fffffffffffadde 7fffffffffffadde
2018-06-01 10:27:13 -00:00: INF [application] get_int16_sign_extended_le should be 0x0df0 df0
2018-06-01 10:27:13 -00:00: INF [application] get_int32_be 0 should be 0xdeadbeefl deadbeef
2018-06-01 10:27:13 -00:00: INF [application] get_int32_be 2 should be 0xbeef8badl beef8bad
2018-06-01 10:27:13 -00:00: INF [application] get_int32_le 0 should be 0xefbeaddel efbeadde
2018-06-01 10:27:13 -00:00: INF [application] get_int32_le 2 should be 0xad8befbel ad8befbe
2018-06-01 10:27:13 -00:00: INF [application] get_int64_be 0 should be 0xdeadbeef8badf00dL deadbeef8badf00d
2018-06-01 10:27:13 -00:00: INF [application] get_int64_le 0 should be 0x0df0ad8befbeaddeL df0ad8befbeadde
2018-06-01 10:27:13 -00:00: INF [application] set should be �___ �___
2018-06-01 10:27:13 -00:00: INF [application] set should be __�_ __�_
2018-06-01 10:27:13 -00:00: INF [application] set_int16_be should be ޭ__ ޭ__
2018-06-01 10:27:13 -00:00: INF [application] set_int16_be should be __�� __��
2018-06-01 10:27:13 -00:00: INF [application] set_int16_le should be ��__ ��__
2018-06-01 10:27:13 -00:00: INF [application] set_int16_le should be __� __�
2018-06-01 10:27:13 -00:00: INF [application] set_int32_be should be ޭ��____ ޭ��____
2018-06-01 10:27:13 -00:00: INF [application] set_int32_le should be ᆳ�____ ᆳ�____
2018-06-01 10:27:13 -00:00: INF [application] set_int32_be should be __�__ __�__
2018-06-01 10:27:13 -00:00: INF [application] set_int32_le should be __���__ __���__
 ޭ��-06-01 10:27:13 -00:00: INF [application] set_int64_be should be ޭ��
���� 06-01 10:27:13 -00:00: INF [application] set_int64_le should be 
Solo5: solo5_exit(0) called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment