1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
#directory "../../src/rpc";;
#load "rtypes.cmo";;
open Rtypes;;
let test name f =
print_string ("Test " ^ name ^ ": ");
flush stdout;
begin try
if f() then
print_endline "OK"
else
print_endline "FAILED"
with
ex ->
print_endline ("FAILED WITH " ^ Printexc.to_string ex)
end;
flush stdout
;;
let overflow f x =
try ignore(f x); false
with
Cannot_represent _ -> true
;;
let test_sth_of_int4 () =
let n1 = mk_int4 ('\000', '\000', '\000', '\001') in
let n2 = mk_int4 ('\000', '\000', '\001', '\000') in
let n3 = mk_int4 ('\000', '\001', '\000', '\000') in
let n4 = mk_int4 ('\001', '\000', '\000', '\000') in
let n5 = mk_int4 ('\032', '\000', '\000', '\000') in
let n6 = mk_int4 ('\064', '\000', '\000', '\000') in
let n7 = mk_int4 ('\128', '\000', '\000', '\000') in
let n8 = mk_int4 ('\255', '\255', '\255', '\255') in
(int_of_int4 n1 = 1) &&
(int_of_int4 n2 = 256) &&
(int_of_int4 n3 = 65536) &&
(int_of_int4 n4 = 0x01000000) &&
(int_of_int4 n5 = 0x20000000) &&
(overflow int_of_int4 n6) &&
(overflow int_of_int4 n7) &&
(int_of_int4 n8 = -1) &&
(int32_of_int4 n1 = Int32.of_int 1) &&
(int32_of_int4 n2 = Int32.of_int 256) &&
(int32_of_int4 n3 = Int32.of_int 65536) &&
(int32_of_int4 n4 = Int32.of_int 0x01000000) &&
(int32_of_int4 n5 = Int32.of_int 0x20000000) &&
(int32_of_int4 n6 = Int32.shift_left (Int32.of_int 0x20000000) 1) &&
(int32_of_int4 n7 = Int32.shift_left (Int32.of_int 0x20000000) 2) &&
(int32_of_int4 n8 = Int32.of_int (-1)) &&
(int64_of_int4 n1 = Int64.of_int 1) &&
(int64_of_int4 n2 = Int64.of_int 256) &&
(int64_of_int4 n3 = Int64.of_int 65536) &&
(int64_of_int4 n4 = Int64.of_int 0x01000000) &&
(int64_of_int4 n5 = Int64.of_int 0x20000000) &&
(int64_of_int4 n6 = Int64.shift_left (Int64.of_int 0x20000000) 1) &&
(int64_of_int4 n7 = Int64.pred (Int64.neg (Int64.of_int32 (Int32.max_int))))&&
(int64_of_int4 n8 = Int64.of_int (-1))
;;
let test_int4_of_sth() =
let n1 = mk_int4 ('\000','\000','\000','\001') in
let n2 = mk_int4 ('\032','\000','\000','\000') in
let n3 = mk_int4 ('\064','\000','\000','\000') in
let n4 = mk_int4 ('\255','\255','\255','\255') in
(int4_of_int 1 = n1) &&
(int4_of_int 0x20000000 = n2) &&
(int4_of_int (-1) = n4) &&
(int4_of_int32 (Int32.of_string "1") = n1) &&
(int4_of_int32 (Int32.of_string "0x20000000") = n2) &&
(int4_of_int32 (Int32.of_string "0x40000000") = n3) &&
(int4_of_int32 (Int32.of_string "-1") = n4) &&
(int4_of_int64 (Int64.of_string "1") = n1) &&
(int4_of_int64 (Int64.of_string "0x20000000") = n2) &&
(int4_of_int64 (Int64.of_string "0x40000000") = n3) &&
(overflow int4_of_int64 (Int64.of_string "0x80000000")) &&
(int4_of_int64 (Int64.of_string "-1") = n4)
;;
let test_sth_of_uint4 () =
let n1 = mk_uint4 ('\000', '\000', '\000', '\001') in
let n2 = mk_uint4 ('\000', '\000', '\001', '\000') in
let n3 = mk_uint4 ('\000', '\001', '\000', '\000') in
let n4 = mk_uint4 ('\001', '\000', '\000', '\000') in
let n5 = mk_uint4 ('\032', '\000', '\000', '\000') in
let n6 = mk_uint4 ('\064', '\000', '\000', '\000') in
let n7 = mk_uint4 ('\128', '\000', '\000', '\000') in
let n8 = mk_uint4 ('\255', '\255', '\255', '\255') in
(int_of_uint4 n1 = 1) &&
(int_of_uint4 n2 = 256) &&
(int_of_uint4 n3 = 65536) &&
(int_of_uint4 n4 = 0x01000000) &&
(int_of_uint4 n5 = 0x20000000) &&
(overflow int_of_uint4 n6) &&
(overflow int_of_uint4 n7) &&
(overflow int_of_uint4 n8) &&
(int32_of_uint4 n1 = Int32.of_int 1) &&
(int32_of_uint4 n2 = Int32.of_int 256) &&
(int32_of_uint4 n3 = Int32.of_int 65536) &&
(int32_of_uint4 n4 = Int32.of_int 0x01000000) &&
(int32_of_uint4 n5 = Int32.of_int 0x20000000) &&
(int32_of_uint4 n6 = Int32.shift_left (Int32.of_int 0x20000000) 1) &&
(overflow int32_of_uint4 n7) &&
(overflow int32_of_uint4 n8) &&
(int64_of_uint4 n1 = Int64.of_int 1) &&
(int64_of_uint4 n2 = Int64.of_int 256) &&
(int64_of_uint4 n3 = Int64.of_int 65536) &&
(int64_of_uint4 n4 = Int64.of_int 0x01000000) &&
(int64_of_uint4 n5 = Int64.of_int 0x20000000) &&
(int64_of_uint4 n6 = Int64.shift_left (Int64.of_int 0x20000000) 1) &&
(int64_of_uint4 n7 = Int64.shift_left (Int64.of_int 0x20000000) 2) &&
(int64_of_uint4 n8 = Int64.logor
(Int64.of_int 0xffff)
(Int64.shift_left (Int64.of_int 0xffff) 16))
;;
let test_uint4_of_sth() =
let n1 = mk_uint4 ('\000','\000','\000','\001') in
let n2 = mk_uint4 ('\032','\000','\000','\000') in
let n3 = mk_uint4 ('\064','\000','\000','\000') in
let n4 = mk_uint4 ('\192','\000','\000','\000') in
(uint4_of_int 1 = n1) &&
(uint4_of_int 0x20000000 = n2) &&
(overflow uint4_of_int (-1)) &&
(uint4_of_int32 (Int32.of_string "1") = n1) &&
(uint4_of_int32 (Int32.of_string "0x20000000") = n2) &&
(uint4_of_int32 (Int32.of_string "0x40000000") = n3) &&
(overflow uint4_of_int32 (Int32.of_string "-1")) ;; (*&&
(uint4_of_int64 (Int64.of_string "1") = n1) &&
(uint4_of_int64 (Int64.of_string "0x20000000") = n2) &&
(uint4_of_int64 (Int64.of_string "0x40000000") = n3) &&
(uint4_of_int64 (Int64.of_string "0xc0000000") = n4) &&
(overflow uint4_of_int64 (Int64.of_string "0x100000000")) &&
(overflow uint4_of_int64 (Int64.of_string "-1"))
;;*)
let test_sth_of_int8 () =
let n1 = mk_int8 ('\000','\000','\000','\000','\000','\000','\000','\001') in
let n2 = mk_int8 ('\000','\000','\000','\000','\001','\000','\000','\000') in
let n3 = mk_int8 ('\000','\000','\000','\000','\064','\000','\000','\000') in
let n4 = mk_int8 ('\000','\000','\000','\000','\128','\000','\000','\000') in
let n5 = mk_int8 ('\001','\000','\000','\000','\000','\000','\000','\000') in
let n6 = mk_int8 ('\128','\000','\000','\000','\000','\000','\000','\000') in
let n7 = mk_int8 ('\255','\255','\255','\255','\255','\255','\255','\255') in
(int_of_int8 n1 = 1) &&
(int_of_int8 n2 = 0x01000000) &&
(overflow int_of_int8 n3) &&
(overflow int_of_int8 n4) &&
(overflow int_of_int8 n5) &&
(overflow int_of_int8 n6) &&
(int_of_int8 n7 = -1) &&
(int32_of_int8 n1 = Int32.of_int 1) &&
(int32_of_int8 n2 = Int32.of_int 0x01000000) &&
(int32_of_int8 n3 = Int32.shift_left (Int32.of_int 0x20000000) 1) &&
(overflow int32_of_int8 n4) &&
(overflow int32_of_int8 n5) &&
(overflow int32_of_int8 n6) &&
(int32_of_int8 n7 = Int32.of_int (-1)) &&
(int64_of_int8 n1 = Int64.of_int 1) &&
(int64_of_int8 n2 = Int64.of_int 0x01000000) &&
(int64_of_int8 n3 = Int64.shift_left (Int64.of_int 1) 30) &&
(int64_of_int8 n4 = Int64.shift_left (Int64.of_int 1) 31) &&
(int64_of_int8 n5 = Int64.shift_left (Int64.of_int 1) 56) &&
(int64_of_int8 n6 = Int64.shift_left (Int64.of_int 1) 63) &&
(int64_of_int8 n7 = Int64.of_int (-1))
;;
let test_int8_of_sth() =
let n1 = mk_int8 ('\000','\000','\000','\000','\000','\000','\000','\001') in
let n2 = mk_int8 ('\000','\000','\000','\000','\032','\000','\000','\000') in
let n3 = mk_int8 ('\000','\000','\000','\000','\064','\000','\000','\000') in
let n4 = mk_int8 ('\064','\000','\000','\000','\000','\000','\000','\000') in
let n5 = mk_int8 ('\255','\255','\255','\255','\255','\255','\255','\255') in
(int8_of_int 1 = n1) &&
(int8_of_int 0x20000000 = n2) &&
(int8_of_int (-1) = n5) &&
(int8_of_int32 (Int32.of_string "1") = n1) &&
(int8_of_int32 (Int32.of_string "0x20000000") = n2) &&
(int8_of_int32 (Int32.of_string "0x40000000") = n3) &&
(int8_of_int32 (Int32.of_string "-1") = n5) &&
(int8_of_int64 (Int64.of_string "1") = n1) &&
(int8_of_int64 (Int64.of_string "0x20000000") = n2) &&
(int8_of_int64 (Int64.of_string "0x40000000") = n3) &&
(int8_of_int64 (Int64.of_string "0x4000000000000000") = n4) &&
(int8_of_int64 (Int64.of_string "-1") = n5)
;;
let test_sth_of_uint8 () =
let n1 = mk_uint8 ('\000','\000','\000','\000','\000','\000','\000','\001') in
let n2 = mk_uint8 ('\000','\000','\000','\000','\001','\000','\000','\000') in
let n3 = mk_uint8 ('\000','\000','\000','\000','\064','\000','\000','\000') in
let n4 = mk_uint8 ('\000','\000','\000','\000','\128','\000','\000','\000') in
let n5 = mk_uint8 ('\001','\000','\000','\000','\000','\000','\000','\000') in
let n6 = mk_uint8 ('\128','\000','\000','\000','\000','\000','\000','\000') in
let n7 = mk_uint8 ('\255','\255','\255','\255','\255','\255','\255','\255') in
(int_of_uint8 n1 = 1) &&
(int_of_uint8 n2 = 0x01000000) &&
(overflow int_of_uint8 n3) &&
(overflow int_of_uint8 n4) &&
(overflow int_of_uint8 n5) &&
(overflow int_of_uint8 n6) &&
(overflow int_of_uint8 n7) &&
(int32_of_uint8 n1 = Int32.of_int 1) &&
(int32_of_uint8 n2 = Int32.of_int 0x01000000) &&
(int32_of_uint8 n3 = Int32.shift_left (Int32.of_int 0x20000000) 1) &&
(overflow int32_of_uint8 n4) &&
(overflow int32_of_uint8 n5) &&
(overflow int32_of_uint8 n6) &&
(overflow int32_of_uint8 n7) &&
(int64_of_uint8 n1 = Int64.of_int 1) &&
(int64_of_uint8 n2 = Int64.of_int 0x01000000) &&
(int64_of_uint8 n3 = Int64.shift_left (Int64.of_int 1) 30) &&
(int64_of_uint8 n4 = Int64.shift_left (Int64.of_int 1) 31) &&
(int64_of_uint8 n5 = Int64.shift_left (Int64.of_int 1) 56) &&
(overflow int64_of_uint8 n6) &&
(overflow int64_of_uint8 n7)
;;
let test_uint8_of_sth() =
let n1 = mk_uint8 ('\000','\000','\000','\000','\000','\000','\000','\001') in
let n2 = mk_uint8 ('\000','\000','\000','\000','\032','\000','\000','\000') in
let n3 = mk_uint8 ('\000','\000','\000','\000','\064','\000','\000','\000') in
let n4 = mk_uint8 ('\064','\000','\000','\000','\000','\000','\000','\000') in
let n5 = mk_uint8 ('\127','\255','\255','\255','\255','\255','\255','\255') in
(uint8_of_int 1 = n1) &&
(uint8_of_int 0x20000000 = n2) &&
(overflow uint8_of_int (-1)) &&
(uint8_of_int32 (Int32.of_string "1") = n1) &&
(uint8_of_int32 (Int32.of_string "0x20000000") = n2) &&
(uint8_of_int32 (Int32.of_string "0x40000000") = n3) &&
(overflow uint8_of_int32 (Int32.of_string "0x80000000")) &&
(overflow uint8_of_int32 (Int32.of_string "-1")) &&
(uint8_of_int64 (Int64.of_string "1") = n1) &&
(uint8_of_int64 (Int64.of_string "0x20000000") = n2) &&
(uint8_of_int64 (Int64.of_string "0x40000000") = n3) &&
(uint8_of_int64 (Int64.of_string "0x4000000000000000") = n4) &&
(uint8_of_int64 (Int64.of_string "0x7fffffffffffffff") = n5) &&
(overflow uint8_of_int64 (Int64.of_string "0x8000000000000000")) &&
(overflow uint8_of_int64 (Int64.of_string "-1"))
;;
(* TODO: fp4, fp8 testen *)
test "sth_of_int4" test_sth_of_int4;;
test "int4_of_sth" test_int4_of_sth;;
test "sth_of_uint4" test_sth_of_uint4;;
test "uint4_of_sth" test_uint4_of_sth;;
test "sth_of_int8" test_sth_of_int8;;
test "int8_of_sth" test_int8_of_sth;;
test "sth_of_uint8" test_sth_of_uint8;;
test "uint8_of_sth" test_uint8_of_sth;;
|