Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
float_literals_tests.cpp File Reference
#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdlib>
#include <catch2/catch.hpp>
#include <utils.hpp>
#include <wasm_config.hpp>
#include <sysio/vm/backend.hpp>
Include dependency graph for float_literals_tests.cpp:

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <float_literals_0_wasm>", "[float_literals_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <float_literals_1_wasm>", "[float_literals_1_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/2]

BACKEND_TEST_CASE ( "Testing wasm <float_literals_0_wasm>" ,
"" [float_literals_0_wasm_tests] )

Definition at line 18 of file float_literals_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "float_literals.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "f32.nan")->to_ui32() == UINT32_C(2143289344));
24 CHECK(bkend.call_with_return("env", "f32.positive_nan")->to_ui32() == UINT32_C(2143289344));
25 CHECK(bkend.call_with_return("env", "f32.negative_nan")->to_ui32() == UINT32_C(4290772992));
26 CHECK(bkend.call_with_return("env", "f32.plain_nan")->to_ui32() == UINT32_C(2143289344));
27 CHECK(bkend.call_with_return("env", "f32.informally_known_as_plain_snan")->to_ui32() == UINT32_C(2141192192));
28 CHECK(bkend.call_with_return("env", "f32.all_ones_nan")->to_ui32() == UINT32_C(4294967295));
29 CHECK(bkend.call_with_return("env", "f32.misc_nan")->to_ui32() == UINT32_C(2139169605));
30 CHECK(bkend.call_with_return("env", "f32.misc_positive_nan")->to_ui32() == UINT32_C(2142257232));
31 CHECK(bkend.call_with_return("env", "f32.misc_negative_nan")->to_ui32() == UINT32_C(4289379550));
32 CHECK(bkend.call_with_return("env", "f32.infinity")->to_ui32() == UINT32_C(2139095040));
33 CHECK(bkend.call_with_return("env", "f32.positive_infinity")->to_ui32() == UINT32_C(2139095040));
34 CHECK(bkend.call_with_return("env", "f32.negative_infinity")->to_ui32() == UINT32_C(4286578688));
35 CHECK(bkend.call_with_return("env", "f32.zero")->to_ui32() == UINT32_C(0));
36 CHECK(bkend.call_with_return("env", "f32.positive_zero")->to_ui32() == UINT32_C(0));
37 CHECK(bkend.call_with_return("env", "f32.negative_zero")->to_ui32() == UINT32_C(2147483648));
38 CHECK(bkend.call_with_return("env", "f32.misc")->to_ui32() == UINT32_C(1086918619));
39 CHECK(bkend.call_with_return("env", "f32.min_positive")->to_ui32() == UINT32_C(1));
40 CHECK(bkend.call_with_return("env", "f32.min_normal")->to_ui32() == UINT32_C(8388608));
41 CHECK(bkend.call_with_return("env", "f32.max_subnormal")->to_ui32() == UINT32_C(8388607));
42 CHECK(bkend.call_with_return("env", "f32.max_finite")->to_ui32() == UINT32_C(2139095039));
43 CHECK(bkend.call_with_return("env", "f32.trailing_dot")->to_ui32() == UINT32_C(1149239296));
44 CHECK(bkend.call_with_return("env", "f32_dec.zero")->to_ui32() == UINT32_C(0));
45 CHECK(bkend.call_with_return("env", "f32_dec.positive_zero")->to_ui32() == UINT32_C(0));
46 CHECK(bkend.call_with_return("env", "f32_dec.negative_zero")->to_ui32() == UINT32_C(2147483648));
47 CHECK(bkend.call_with_return("env", "f32_dec.misc")->to_ui32() == UINT32_C(1086918619));
48 CHECK(bkend.call_with_return("env", "f32_dec.min_positive")->to_ui32() == UINT32_C(1));
49 CHECK(bkend.call_with_return("env", "f32_dec.min_normal")->to_ui32() == UINT32_C(8388608));
50 CHECK(bkend.call_with_return("env", "f32_dec.max_subnormal")->to_ui32() == UINT32_C(8388607));
51 CHECK(bkend.call_with_return("env", "f32_dec.max_finite")->to_ui32() == UINT32_C(2139095039));
52 CHECK(bkend.call_with_return("env", "f32_dec.trailing_dot")->to_ui32() == UINT32_C(1343554297));
53 CHECK(bkend.call_with_return("env", "f32_dec.root_beer_float")->to_ui32() == UINT32_C(1065353217));
54 CHECK(bkend.call_with_return("env", "f64.nan")->to_ui64() == UINT32_C(9221120237041090560));
55 CHECK(bkend.call_with_return("env", "f64.positive_nan")->to_ui64() == UINT32_C(9221120237041090560));
56 CHECK(bkend.call_with_return("env", "f64.negative_nan")->to_ui64() == UINT32_C(18444492273895866368));
57 CHECK(bkend.call_with_return("env", "f64.plain_nan")->to_ui64() == UINT32_C(9221120237041090560));
58 CHECK(bkend.call_with_return("env", "f64.informally_known_as_plain_snan")->to_ui64() == UINT32_C(9219994337134247936));
59 CHECK(bkend.call_with_return("env", "f64.all_ones_nan")->to_ui64() == UINT32_C(18446744073709551615));
60 CHECK(bkend.call_with_return("env", "f64.misc_nan")->to_ui64() == UINT32_C(9218888453225749180));
61 CHECK(bkend.call_with_return("env", "f64.misc_positive_nan")->to_ui64() == UINT32_C(9219717281780008969));
62 CHECK(bkend.call_with_return("env", "f64.misc_negative_nan")->to_ui64() == UINT32_C(18442992325002076997));
63 CHECK(bkend.call_with_return("env", "f64.infinity")->to_ui64() == UINT32_C(9218868437227405312));
64 CHECK(bkend.call_with_return("env", "f64.positive_infinity")->to_ui64() == UINT32_C(9218868437227405312));
65 CHECK(bkend.call_with_return("env", "f64.negative_infinity")->to_ui64() == UINT32_C(18442240474082181120));
66 CHECK(bkend.call_with_return("env", "f64.zero")->to_ui64() == UINT32_C(0));
67 CHECK(bkend.call_with_return("env", "f64.positive_zero")->to_ui64() == UINT32_C(0));
68 CHECK(bkend.call_with_return("env", "f64.negative_zero")->to_ui64() == UINT32_C(9223372036854775808));
69 CHECK(bkend.call_with_return("env", "f64.misc")->to_ui64() == UINT32_C(4618760256179416344));
70 CHECK(bkend.call_with_return("env", "f64.min_positive")->to_ui64() == UINT32_C(1));
71 CHECK(bkend.call_with_return("env", "f64.min_normal")->to_ui64() == UINT32_C(4503599627370496));
72 CHECK(bkend.call_with_return("env", "f64.max_subnormal")->to_ui64() == UINT32_C(4503599627370495));
73 CHECK(bkend.call_with_return("env", "f64.max_finite")->to_ui64() == UINT32_C(9218868437227405311));
74 CHECK(bkend.call_with_return("env", "f64.trailing_dot")->to_ui64() == UINT32_C(5057542381537067008));
75 CHECK(bkend.call_with_return("env", "f64_dec.zero")->to_ui64() == UINT32_C(0));
76 CHECK(bkend.call_with_return("env", "f64_dec.positive_zero")->to_ui64() == UINT32_C(0));
77 CHECK(bkend.call_with_return("env", "f64_dec.negative_zero")->to_ui64() == UINT32_C(9223372036854775808));
78 CHECK(bkend.call_with_return("env", "f64_dec.misc")->to_ui64() == UINT32_C(4618760256179416344));
79 CHECK(bkend.call_with_return("env", "f64_dec.min_positive")->to_ui64() == UINT32_C(1));
80 CHECK(bkend.call_with_return("env", "f64_dec.min_normal")->to_ui64() == UINT32_C(4503599627370496));
81 CHECK(bkend.call_with_return("env", "f64_dec.max_subnormal")->to_ui64() == UINT32_C(4503599627370495));
82 CHECK(bkend.call_with_return("env", "f64_dec.max_finite")->to_ui64() == UINT32_C(9218868437227405311));
83 CHECK(bkend.call_with_return("env", "f64_dec.trailing_dot")->to_ui64() == UINT32_C(6103021453049119613));
84 CHECK(bkend.call_with_return("env", "f64_dec.root_beer_float")->to_ui64() == UINT32_C(4607182419335945764));
85 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-dec-sep1")->to_f32()) == UINT32_C(1232348160));
86 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-dec-sep2")->to_f32()) == UINT32_C(1148846080));
87 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-dec-sep3")->to_f32()) == UINT32_C(1148897552));
88 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-dec-sep4")->to_f32()) == UINT32_C(1482758550));
89 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-dec-sep5")->to_f32()) == UINT32_C(1847438964));
90 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-hex-sep1")->to_f32()) == UINT32_C(1294004234));
91 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-hex-sep2")->to_f32()) == UINT32_C(1205143424));
92 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-hex-sep3")->to_f32()) == UINT32_C(1193345009));
93 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-hex-sep4")->to_f32()) == UINT32_C(1240465408));
94 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "f32-hex-sep5")->to_f32()) == UINT32_C(1437319208));
95 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-dec-sep1")->to_f64()) == UINT64_C(4696837146684686336));
96 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-dec-sep2")->to_f64()) == UINT64_C(4652007308841189376));
97 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-dec-sep3")->to_f64()) == UINT64_C(4652034942576659200));
98 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-dec-sep4")->to_f64()) == UINT64_C(2796837019126844485));
99 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-dec-sep5")->to_f64()) == UINT64_C(5027061507362119324));
100 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-hex-sep1")->to_f64()) == UINT64_C(4838519794133185330));
101 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-hex-sep2")->to_f64()) == UINT64_C(4682231715257647104));
102 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-hex-sep3")->to_f64()) == UINT64_C(4675897489574114112));
103 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-hex-sep4")->to_f64()) == UINT64_C(4701195061021376512));
104 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "f64-hex-sep5")->to_f64()) == UINT64_C(4806880140420149248));
105}
auto call_with_return(host_t &host, const std::string_view &mod, const std::string_view &func, Args... args)
Definition backend.hpp:178
#define CHECK(cond)
Definition util.h:80
wasm_allocator wa
Definition main.cpp:10
backend_t bkend(hello_wasm, ehm, &wa)
std::vector< uint8_t > read_wasm(const std::string &fname)
Definition utils.hpp:30
#define UINT32_C(val)
Definition stdint.h:283
#define UINT64_C(val)
Definition stdint.h:284
T bit_cast(const U &u)
Definition utils.hpp:35
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [2/2]

BACKEND_TEST_CASE ( "Testing wasm <float_literals_1_wasm>" ,
"" [float_literals_1_wasm_tests] )

Definition at line 107 of file float_literals_tests.cpp.

107 {
109 auto code = read_wasm( std::string(wasm_directory) + "float_literals.1.wasm");
110 backend_t bkend( code, &wa );
111
112 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "4294967249")->to_f64()) == UINT64_C(4751297606777307136));
113}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.