mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 19:00:06 +00:00
Merge remote-tracking branch 'upstream/master' into os2_linux
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
ODIN=../../odin
|
||||
PYTHON=$(shell which python3)
|
||||
|
||||
all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test os2_test
|
||||
|
||||
download_test_assets:
|
||||
$(PYTHON) download_assets.py
|
||||
|
||||
image_test:
|
||||
$(ODIN) run image/test_core_image.odin
|
||||
|
||||
compress_test:
|
||||
$(ODIN) run compress/test_core_compress.odin
|
||||
|
||||
strings_test:
|
||||
$(ODIN) run strings/test_core_strings.odin
|
||||
|
||||
hash_test:
|
||||
$(ODIN) run hash -out=test_hash -o:speed -no-bounds-check
|
||||
|
||||
crypto_test:
|
||||
$(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check
|
||||
|
||||
noise_test:
|
||||
$(ODIN) run math/noise -out=test_noise
|
||||
|
||||
os2_test:
|
||||
$(ODIN) run os2/test_os2.odin -out=test_os2
|
||||
@@ -35,7 +35,8 @@ echo ---
|
||||
echo ---
|
||||
echo Running core:encoding tests
|
||||
echo ---
|
||||
%PATH_TO_ODIN% run encoding %COMMON%
|
||||
%PATH_TO_ODIN% run encoding/json %COMMON%
|
||||
%PATH_TO_ODIN% run encoding/varint %COMMON%
|
||||
|
||||
echo ---
|
||||
echo Running core:math/noise tests
|
||||
|
||||
@@ -30,14 +30,12 @@ when ODIN_TEST {
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(message)
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
@@ -52,6 +50,9 @@ main :: proc() {
|
||||
gzip_test(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+21
-19
@@ -3,37 +3,39 @@ package test_core_json
|
||||
import "core:encoding/json"
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
|
||||
when ODIN_TEST {
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
t := testing.T{}
|
||||
|
||||
parse_json(&t)
|
||||
marshal_json(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
@@ -0,0 +1,156 @@
|
||||
package test_core_varint
|
||||
|
||||
import "core:encoding/varint"
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:slice"
|
||||
import "core:math/rand"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
|
||||
RANDOM_TESTS :: 100
|
||||
|
||||
when ODIN_TEST {
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
|
||||
test_leb128(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_leb128 :: proc(t: ^testing.T) {
|
||||
buf: [varint.LEB128_MAX_BYTES]u8
|
||||
|
||||
for vector in ULEB_Vectors {
|
||||
val, size, err := varint.decode_uleb128(vector.encoded)
|
||||
|
||||
msg := fmt.tprintf("Expected %02x to decode to %v consuming %v bytes, got %v and %v", vector.encoded, vector.value, vector.size, val, size)
|
||||
expect(t, size == vector.size && val == vector.value, msg)
|
||||
|
||||
msg = fmt.tprintf("Expected decoder to return error %v, got %v", vector.error, err)
|
||||
expect(t, err == vector.error, msg)
|
||||
|
||||
if err == .None { // Try to roundtrip
|
||||
size, err = varint.encode_uleb128(buf[:], vector.value)
|
||||
|
||||
msg = fmt.tprintf("Expected %v to encode to %02x, got %02x", vector.value, vector.encoded, buf[:size])
|
||||
expect(t, size == vector.size && slice.simple_equal(vector.encoded, buf[:size]), msg)
|
||||
}
|
||||
}
|
||||
|
||||
for vector in ILEB_Vectors {
|
||||
val, size, err := varint.decode_ileb128(vector.encoded)
|
||||
|
||||
msg := fmt.tprintf("Expected %02x to decode to %v consuming %v bytes, got %v and %v", vector.encoded, vector.value, vector.size, val, size)
|
||||
expect(t, size == vector.size && val == vector.value, msg)
|
||||
|
||||
msg = fmt.tprintf("Expected decoder to return error %v, got %v", vector.error, err)
|
||||
expect(t, err == vector.error, msg)
|
||||
|
||||
if err == .None { // Try to roundtrip
|
||||
size, err = varint.encode_ileb128(buf[:], vector.value)
|
||||
|
||||
msg = fmt.tprintf("Expected %v to encode to %02x, got %02x", vector.value, vector.encoded, buf[:size])
|
||||
expect(t, size == vector.size && slice.simple_equal(vector.encoded, buf[:size]), msg)
|
||||
}
|
||||
}
|
||||
|
||||
for num_bytes in 1..uint(16) {
|
||||
for _ in 0..RANDOM_TESTS {
|
||||
unsigned, signed := get_random(num_bytes)
|
||||
|
||||
{
|
||||
encode_size, encode_err := varint.encode_uleb128(buf[:], unsigned)
|
||||
msg := fmt.tprintf("%v failed to encode as an unsigned LEB128 value, got %v", unsigned, encode_err)
|
||||
expect(t, encode_err == .None, msg)
|
||||
|
||||
decoded, decode_size, decode_err := varint.decode_uleb128(buf[:])
|
||||
msg = fmt.tprintf("Expected %02x to decode as %v, got %v", buf[:encode_size], unsigned, decoded)
|
||||
expect(t, decode_err == .None && decode_size == encode_size && decoded == unsigned, msg)
|
||||
}
|
||||
|
||||
{
|
||||
encode_size, encode_err := varint.encode_ileb128(buf[:], signed)
|
||||
msg := fmt.tprintf("%v failed to encode as a signed LEB128 value, got %v", signed, encode_err)
|
||||
expect(t, encode_err == .None, msg)
|
||||
|
||||
decoded, decode_size, decode_err := varint.decode_ileb128(buf[:])
|
||||
msg = fmt.tprintf("Expected %02x to decode as %v, got %v, err: %v", buf[:encode_size], signed, decoded, decode_err)
|
||||
expect(t, decode_err == .None && decode_size == encode_size && decoded == signed, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get_random :: proc(byte_count: uint) -> (u: u128, i: i128) {
|
||||
assert(byte_count >= 0 && byte_count <= size_of(u128))
|
||||
|
||||
for _ in 1..byte_count {
|
||||
u <<= 8
|
||||
u |= u128(rand.uint32() & 0xff)
|
||||
}
|
||||
|
||||
bias := i128(1 << (byte_count * 7)) - 1
|
||||
i = i128(u) - bias
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ULEB_Test_Vector :: struct {
|
||||
encoded: []u8,
|
||||
value: u128,
|
||||
size: int,
|
||||
error: varint.Error,
|
||||
}
|
||||
|
||||
ULEB_Vectors :: []ULEB_Test_Vector{
|
||||
{ []u8{0x00}, 0, 1, .None },
|
||||
{ []u8{0x7f}, 127, 1, .None },
|
||||
{ []u8{0xE5, 0x8E, 0x26}, 624485, 3, .None },
|
||||
{ []u8{0x80}, 0, 0, .Buffer_Too_Small },
|
||||
{ []u8{}, 0, 0, .Buffer_Too_Small },
|
||||
|
||||
{ []u8{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03}, max(u128), 19, .None },
|
||||
}
|
||||
|
||||
ILEB_Test_Vector :: struct {
|
||||
encoded: []u8,
|
||||
value: i128,
|
||||
size: int,
|
||||
error: varint.Error,
|
||||
}
|
||||
|
||||
ILEB_Vectors :: []ILEB_Test_Vector{
|
||||
{ []u8{0x00}, 0, 1, .None },
|
||||
{ []u8{0x3f}, 63, 1, .None },
|
||||
{ []u8{0x40}, -64, 1, .None },
|
||||
{ []u8{0xC0, 0xBB, 0x78}, -123456, 3, .None },
|
||||
{ []u8{}, 0, 0, .Buffer_Too_Small },
|
||||
|
||||
{ []u8{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7e}, min(i128), 19, .None },
|
||||
{ []u8{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01}, max(i128), 19, .None },
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import "core:hash"
|
||||
import "core:time"
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
@@ -14,14 +15,12 @@ when ODIN_TEST {
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(" FAIL:", message)
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
@@ -35,6 +34,9 @@ main :: proc() {
|
||||
test_xxhash_vectors(&t)
|
||||
test_crc64_vectors(&t)
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -32,23 +32,21 @@ TEST_count := 0
|
||||
TEST_fail := 0
|
||||
|
||||
when ODIN_TEST {
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
}
|
||||
I_Error :: image.Error
|
||||
|
||||
@@ -57,6 +55,9 @@ main :: proc() {
|
||||
png_test(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
PNG_Test :: struct {
|
||||
|
||||
@@ -3,6 +3,7 @@ package test_core_math_noise
|
||||
import "core:testing"
|
||||
import "core:math/noise"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
@@ -12,29 +13,30 @@ V3 :: noise.Vec3
|
||||
V4 :: noise.Vec4
|
||||
|
||||
when ODIN_TEST {
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
noise_test(&t)
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Test_Vector :: struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package test_core_odin_parser
|
||||
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
|
||||
import "core:os"
|
||||
import "core:odin/parser"
|
||||
|
||||
|
||||
@@ -10,31 +10,31 @@ TEST_count := 0
|
||||
TEST_fail := 0
|
||||
|
||||
when ODIN_TEST {
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
test_parse_demo(&t)
|
||||
t := testing.T{}
|
||||
test_parse_demo(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,4 +47,4 @@ test_parse_demo :: proc(t: ^testing.T) {
|
||||
for key, value in pkg.files {
|
||||
expect(t, value.syntax_error_count == 0, fmt.tprintf("%v should contain zero errors", key))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,61 +3,63 @@ package test_core_image
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
|
||||
when ODIN_TEST {
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
expect :: testing.expect
|
||||
log :: testing.log
|
||||
} else {
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.println(message)
|
||||
return
|
||||
}
|
||||
fmt.println(" PASS")
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||
TEST_count += 1
|
||||
if !condition {
|
||||
TEST_fail += 1
|
||||
fmt.printf("[%v] %v\n", loc, message)
|
||||
return
|
||||
}
|
||||
}
|
||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||
fmt.printf("[%v] ", loc)
|
||||
fmt.printf("log: %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
t := testing.T{}
|
||||
test_index_any_small_string_not_found(&t)
|
||||
test_index_any_larger_string_not_found(&t)
|
||||
test_index_any_small_string_found(&t)
|
||||
test_index_any_larger_string_found(&t)
|
||||
t := testing.T{}
|
||||
test_index_any_small_string_not_found(&t)
|
||||
test_index_any_larger_string_not_found(&t)
|
||||
test_index_any_small_string_found(&t)
|
||||
test_index_any_larger_string_found(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_index_any_small_string_not_found :: proc(t: ^testing.T) {
|
||||
index := strings.index_any(".", "/:\"")
|
||||
log(t, index)
|
||||
expect(t, index == -1, "index_any should be negative")
|
||||
index := strings.index_any(".", "/:\"")
|
||||
log(t, index)
|
||||
expect(t, index == -1, "index_any should be negative")
|
||||
}
|
||||
|
||||
@test
|
||||
test_index_any_larger_string_not_found :: proc(t: ^testing.T) {
|
||||
index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"")
|
||||
expect(t, index == -1, "index_any should be negative")
|
||||
index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"")
|
||||
expect(t, index == -1, "index_any should be negative")
|
||||
}
|
||||
|
||||
@test
|
||||
test_index_any_small_string_found :: proc(t: ^testing.T) {
|
||||
index := strings.index_any(".", "/:.\"")
|
||||
expect(t, index == 0, "index_any should be 0")
|
||||
index := strings.index_any(".", "/:.\"")
|
||||
expect(t, index == 0, "index_any should be 0")
|
||||
}
|
||||
|
||||
@test
|
||||
test_index_any_larger_string_found :: proc(t: ^testing.T) {
|
||||
index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
|
||||
expect(t, index == 8, "index_any should be 8")
|
||||
index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
|
||||
expect(t, index == 8, "index_any should be 8")
|
||||
}
|
||||
|
||||
Vendored
+8
-1
@@ -1,6 +1,13 @@
|
||||
ODIN=../../odin
|
||||
ODINFLAGS=
|
||||
|
||||
OS=$(shell uname)
|
||||
|
||||
ifeq ($(OS), OpenBSD)
|
||||
ODINFLAGS:=$(ODINFLAGS) -extra-linker-flags:-L/usr/local/lib
|
||||
endif
|
||||
|
||||
all: botan_test
|
||||
|
||||
botan_test:
|
||||
$(ODIN) run botan -out=botan_hash -o:speed -no-bounds-check
|
||||
$(ODIN) run botan -out=botan_hash -o:speed -no-bounds-check $(ODINFLAGS)
|
||||
|
||||
+47
@@ -14,6 +14,7 @@ package test_vendor_botan
|
||||
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
|
||||
import "vendor:botan/md4"
|
||||
import "vendor:botan/md5"
|
||||
@@ -30,6 +31,7 @@ import "vendor:botan/gost"
|
||||
import "vendor:botan/streebog"
|
||||
import "vendor:botan/sm3"
|
||||
import "vendor:botan/skein512"
|
||||
import "vendor:botan/siphash"
|
||||
|
||||
TEST_count := 0
|
||||
TEST_fail := 0
|
||||
@@ -82,8 +84,12 @@ main :: proc() {
|
||||
test_sm3(&t)
|
||||
test_skein512_256(&t)
|
||||
test_skein512_512(&t)
|
||||
test_siphash_2_4(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
TestHash :: struct {
|
||||
@@ -575,3 +581,44 @@ test_skein512_512 :: proc(t: ^testing.T) {
|
||||
expect(t, computed_str == v.hash, fmt.tprintf("Expected: %s for input of %s, but got %s instead", v.hash, v.str, computed_str))
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_siphash_2_4 :: proc(t: ^testing.T) {
|
||||
// Test vectors from
|
||||
// https://github.com/veorq/SipHash/blob/master/vectors.h
|
||||
test_vectors := [?]u64 {
|
||||
0x726fdb47dd0e0e31, 0x74f839c593dc67fd, 0x0d6c8009d9a94f5a, 0x85676696d7fb7e2d,
|
||||
0xcf2794e0277187b7, 0x18765564cd99a68d, 0xcbc9466e58fee3ce, 0xab0200f58b01d137,
|
||||
0x93f5f5799a932462, 0x9e0082df0ba9e4b0, 0x7a5dbbc594ddb9f3, 0xf4b32f46226bada7,
|
||||
0x751e8fbc860ee5fb, 0x14ea5627c0843d90, 0xf723ca908e7af2ee, 0xa129ca6149be45e5,
|
||||
0x3f2acc7f57c29bdb, 0x699ae9f52cbe4794, 0x4bc1b3f0968dd39c, 0xbb6dc91da77961bd,
|
||||
0xbed65cf21aa2ee98, 0xd0f2cbb02e3b67c7, 0x93536795e3a33e88, 0xa80c038ccd5ccec8,
|
||||
0xb8ad50c6f649af94, 0xbce192de8a85b8ea, 0x17d835b85bbb15f3, 0x2f2e6163076bcfad,
|
||||
0xde4daaaca71dc9a5, 0xa6a2506687956571, 0xad87a3535c49ef28, 0x32d892fad841c342,
|
||||
0x7127512f72f27cce, 0xa7f32346f95978e3, 0x12e0b01abb051238, 0x15e034d40fa197ae,
|
||||
0x314dffbe0815a3b4, 0x027990f029623981, 0xcadcd4e59ef40c4d, 0x9abfd8766a33735c,
|
||||
0x0e3ea96b5304a7d0, 0xad0c42d6fc585992, 0x187306c89bc215a9, 0xd4a60abcf3792b95,
|
||||
0xf935451de4f21df2, 0xa9538f0419755787, 0xdb9acddff56ca510, 0xd06c98cd5c0975eb,
|
||||
0xe612a3cb9ecba951, 0xc766e62cfcadaf96, 0xee64435a9752fe72, 0xa192d576b245165a,
|
||||
0x0a8787bf8ecb74b2, 0x81b3e73d20b49b6f, 0x7fa8220ba3b2ecea, 0x245731c13ca42499,
|
||||
0xb78dbfaf3a8d83bd, 0xea1ad565322a1a0b, 0x60e61c23a3795013, 0x6606d7e446282b93,
|
||||
0x6ca4ecb15c5f91e1, 0x9f626da15c9625f3, 0xe51b38608ef25f57, 0x958a324ceb064572,
|
||||
}
|
||||
|
||||
key: [16]byte
|
||||
for i in 0..<16 {
|
||||
key[i] = byte(i)
|
||||
}
|
||||
|
||||
for i in 0..<len(test_vectors) {
|
||||
data := make([]byte, i)
|
||||
for j in 0..<i {
|
||||
data[j] = byte(j)
|
||||
}
|
||||
|
||||
vector := test_vectors[i]
|
||||
computed := siphash.sum_2_4(data[:], key[:])
|
||||
|
||||
expect(t, computed == vector, fmt.tprintf("Expected: 0x%x for input of %v, but got 0x%x instead", vector, data, computed))
|
||||
}
|
||||
}
|
||||
+4
@@ -3,6 +3,7 @@ package test_vendor_glfw
|
||||
import "core:testing"
|
||||
import "core:fmt"
|
||||
import "vendor:glfw"
|
||||
import "core:os"
|
||||
|
||||
GLFW_MAJOR :: 3
|
||||
GLFW_MINOR :: 3
|
||||
@@ -36,6 +37,9 @@ main :: proc() {
|
||||
test_glfw(&t)
|
||||
|
||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||
if TEST_fail > 0 {
|
||||
os.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
|
||||
Reference in New Issue
Block a user