1 #include <glib.h>
2
3 extern "C" {
4 #include "compiler_tests.h"
5 #include <glib/gprintf.h>
6 }
7 #include "gtest/gtest.h"
8 #include <inttypes.h>
9 #include <cstdint>
10 #include <string_view> // Make sure we can use C++17 std::string_view
11 #include <optional>
12
TEST(CompilerTest,stringview)13 TEST(CompilerTest, stringview) {
14 std::string_view hello("Hello");
15 EXPECT_STREQ("Hello", hello.data());
16 }
17
TEST(CompilerTest,optional)18 TEST(CompilerTest, optional) {
19 auto godzilla = std::optional<std::string>{"Godzilla"};
20 EXPECT_TRUE(godzilla.has_value());
21 }
22
23 // This test makes sure that the definitions in tcg are correct.
24 // Note, calling gtest from C doesn't work well, and using qemu from C++ doesn't
25 // work well either, so we have the test part that interacts with qemu in a .c file.
TEST(CompilerTest,LargeEnumInBitThing)26 TEST(CompilerTest, LargeEnumInBitThing) {
27 EXPECT_TRUE(test_enum_equal());
28 }
29
TEST(CompilerTest,long_jump_stack_test)30 TEST(CompilerTest, long_jump_stack_test) {
31 // This test is to guarantee that the stack frame is set properly.
32 // a broken stack frame will result in an exception/termination.
33 EXPECT_TRUE(long_jump_stack_test());
34 }
35
TEST(CompilerTest,long_jump_double_call)36 TEST(CompilerTest, long_jump_double_call) {
37 EXPECT_TRUE(long_jump_double_call());
38 }
39
TEST(CompilerTest,long_jump_ret_value)40 TEST(CompilerTest, long_jump_ret_value) {
41 EXPECT_TRUE(long_jump_ret_value());
42 }
43
TEST(CompilerTest,long_jump_preserve_int_params)44 TEST(CompilerTest, long_jump_preserve_int_params) {
45 // This test is to guarantee that the parameters are still available
46 // parameters (on windows) can be passed in as registers.
47 // Note, the bitmask should help you identify which parameter is missing. bit 0/4/8/12 etc = param1, 1/5/9/13 = param2 etc.
48 EXPECT_EQ(long_jump_preserve_int_params(PARAM1, PARAM2, PARAM3, PARAM4), PARAM1 + PARAM2 + PARAM3 + PARAM4);
49 }
50
TEST(CompilerTest,long_jump_preserve_float_params)51 TEST(CompilerTest, long_jump_preserve_float_params) {
52 // This test is to guarantee that the parameters are still available
53 // parameters (on windows) can be passed in as registers.
54 // Note, the bitmask should help you identify which parameter is missing. bit 0/4/8/12 etc = param1, 1/5/9/13 = param2 etc.
55 EXPECT_TRUE(long_jump_preserve_float_params(1.123, 2.123, 3.123, 4.123));
56 }
57
58
TEST(CompilerTest,setjmp_sets_fields)59 TEST(CompilerTest, setjmp_sets_fields) {
60 EXPECT_TRUE(setjmp_sets_fields());
61 }
62
TEST(CompilerTest,g_strdup_printf_incorrect_b129781540)63 TEST(CompilerTest, g_strdup_printf_incorrect_b129781540) {
64 int64_t val = 6442450944;
65 char* str = g_strdup_printf("%" PRId64, val);
66 EXPECT_STREQ("6442450944", str);
67 free(str);
68 }
69