authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-12 17:27:55+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-14 17:53:26+02:00
logebf97627fd4e1ee46c1b446108e4b4e3bf4b5769
tree249b2694ff550955753023d30b9ddc727d1b585e
parent1fada3746606b3a83d4c56213de93a1017753c96

build: Test the c.zig file too

* Add some more tests for the sqrt/sqrtf implementations. The idea is to cross-check the software impl with the HW one whenever possible. * Fix a broken test, oops.

2 files changed, 38 insertions(+), 23 deletions(-)

build.zig+1
......@@ -259,6 +259,7 @@ pub fn build(b: *Builder) !void {
259259 test_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/std.zig", "std", "Run the standard library tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));
260260
261261 test_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));
262 test_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/special/c.zig", "minilibc", "Run the mini libc tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));
262263
263264 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
264265 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
lib/std/special/c.zig+37-23
......@@ -85,7 +85,7 @@ test "strncpy" {
8585 var s1: [9:0]u8 = undefined;
8686
8787 s1[0] = 0;
88 _ = strncpy(&s1, "foobarbaz", 9);
88 _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));
8989 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
9090}
9191
......@@ -993,17 +993,24 @@ export fn sqrt(x: f64) f64 {
993993}
994994
995995test "sqrt" {
996 const epsilon = 0.000001;
997
998 std.testing.expect(sqrt(0.0) == 0.0);
999 std.testing.expect(std.math.approxEqAbs(f64, sqrt(2.0), 1.414214, epsilon));
1000 std.testing.expect(std.math.approxEqAbs(f64, sqrt(3.6), 1.897367, epsilon));
1001 std.testing.expect(sqrt(4.0) == 2.0);
1002 std.testing.expect(std.math.approxEqAbs(f64, sqrt(7.539840), 2.745877, epsilon));
1003 std.testing.expect(std.math.approxEqAbs(f64, sqrt(19.230934), 4.385309, epsilon));
1004 std.testing.expect(sqrt(64.0) == 8.0);
1005 std.testing.expect(std.math.approxEqAbs(f64, sqrt(64.1), 8.006248, epsilon));
1006 std.testing.expect(std.math.approxEqAbs(f64, sqrt(8942.230469), 94.563367, epsilon));
996 const V = [_]f64{
997 0.0,
998 4.089288054930154,
999 7.538757127071935,
1000 8.97780793672623,
1001 5.304443821913729,
1002 5.682408965311888,
1003 0.5846878579110049,
1004 3.650338664297043,
1005 0.3178091951800732,
1006 7.1505232436382835,
1007 3.6589165881946464,
1008 };
1009
1010 // Note that @sqrt will either generate the sqrt opcode (if supported by the
1011 // target ISA) or a call to `sqrtf` otherwise.
1012 for (V) |val|
1013 std.testing.expectEqual(@sqrt(val), sqrt(val));
10071014}
10081015
10091016test "sqrt special" {
......@@ -1091,17 +1098,24 @@ export fn sqrtf(x: f32) f32 {
10911098}
10921099
10931100test "sqrtf" {
1094 const epsilon = 0.000001;
1095
1096 std.testing.expect(sqrtf(0.0) == 0.0);
1097 std.testing.expect(std.math.approxEqAbs(f32, sqrtf(2.0), 1.414214, epsilon));
1098 std.testing.expect(std.math.approxEqAbs(f32, sqrtf(3.6), 1.897367, epsilon));
1099 std.testing.expect(sqrtf(4.0) == 2.0);
1100 std.testing.expect(std.math.approxEqAbs(f32, sqrtf(7.539840), 2.745877, epsilon));
1101 std.testing.expect(std.math.approxEqAbs(f32, sqrtf(19.230934), 4.385309, epsilon));
1102 std.testing.expect(sqrtf(64.0) == 8.0);
1103 std.testing.expect(std.math.approxEqAbs(f32, sqrtf(64.1), 8.006248, epsilon));
1104 std.testing.expect(std.math.approxEqAbs(f32, sqrtf(8942.230469), 94.563370, epsilon));
1101 const V = [_]f32{
1102 0.0,
1103 4.089288054930154,
1104 7.538757127071935,
1105 8.97780793672623,
1106 5.304443821913729,
1107 5.682408965311888,
1108 0.5846878579110049,
1109 3.650338664297043,
1110 0.3178091951800732,
1111 7.1505232436382835,
1112 3.6589165881946464,
1113 };
1114
1115 // Note that @sqrt will either generate the sqrt opcode (if supported by the
1116 // target ISA) or a call to `sqrtf` otherwise.
1117 for (V) |val|
1118 std.testing.expectEqual(@sqrt(val), sqrtf(val));
11051119}
11061120
11071121test "sqrtf special" {