Skip to content

Commit a76ca06

Browse files
committed
merge: solved conflict with div branches
1 parent bdfe350 commit a76ca06

6 files changed

Lines changed: 109 additions & 2 deletions

File tree

tests/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
enable_testing()
22

3+
4+
5+
If (JIT_PROVIDED)
6+
add_executable(
7+
${PROJECT_NAME}_tests
8+
main_test.cpp
9+
test_functions.cpp
10+
test_suites/ProjectIntegrationTestSuite.cpp
11+
test_suites/X64JitTestSuite.cpp
12+
test_suites/BytecodeLexerTestSuite.cpp
13+
test_suites/BytecodeParserTestSuite.cpp
14+
test_suites/BuiltinTestSuite.cpp
15+
bytecode_lexer_tests.cpp
16+
bytecode_parser_tests.cpp
17+
bytecode_commands_tests.cpp
18+
builtin_functions_tests.cpp
19+
jit_tests.cpp
20+
)
21+
else()
322
add_executable(
423
${PROJECT_NAME}_tests
524
main_test.cpp
@@ -15,6 +34,7 @@ add_executable(
1534
gc_tests.cpp
1635
test_suites/GcTestSuite.cpp
1736
)
37+
endif()
1838

1939
target_link_libraries(
2040
${PROJECT_NAME}_tests

tests/jit_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
#include <gtest/gtest.h>
3+
4+
#include "lib/vm_ui/vm_ui_functions.hpp"
5+
#include "test_functions.hpp"
6+
#include "test_suites/X64JitTestSuite.hpp"
7+
8+
TEST_F(X64JitTestSuite, Test1) {
9+
RunSingleTest(JitTestData{
10+
.test_name = "jit-float-test.oil",
11+
.arguments = "",
12+
.input = "",
13+
.expected_output = "",
14+
.expected_error = "",
15+
.expected_return_code = 0,
16+
.jit_action_bound = 1,
17+
});
18+
}

tests/test_data/examples

tests/test_suites/BytecodeParserTestSuite.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#include "lib/execution_tree/Block.hpp"
1515
#include "lib/execution_tree/FunctionRepository.hpp"
1616
#include "lib/execution_tree/IFunctionExecutable.hpp"
17-
#include "lib/executor/PlaceholderJitExecutorFactory.hpp"
1817
#include "lib/runtime/RuntimeMemory.hpp"
1918
#include "lib/runtime/VirtualTableRepository.hpp"
2019

20+
#include "lib/executor/PlaceholderJitExecutorFactory.hpp"
21+
2122
struct BytecodeParserTestSuite : public testing::Test {
2223
static constexpr size_t kJitBoundary = 10;
2324
void SetUp() override;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "X64JitTestSuite.hpp"
2+
3+
#include <filesystem>
4+
5+
#include "lib/vm_ui/vm_ui_functions.hpp"
6+
#include "tests/test_functions.hpp"
7+
8+
void X64JitTestSuite::SetUp() {
9+
std::filesystem::create_directories(kTemporaryDirectoryName);
10+
}
11+
12+
void X64JitTestSuite::TearDown() {
13+
std::filesystem::remove_all(kTemporaryDirectoryName);
14+
}
15+
16+
void X64JitTestSuite::RunSingleTest(const JitTestData& test_data) const {
17+
std::filesystem::path test_file = kTestDataDir;
18+
test_file /= "examples";
19+
test_file /= "compiled";
20+
test_file /= "jit";
21+
test_file /= test_data.test_name;
22+
std::string cmd = "ovum-vm -f \"";
23+
cmd += test_file.string();
24+
cmd += "\"";
25+
cmd += " -j ";
26+
cmd += std::to_string(test_data.jit_action_bound);
27+
28+
if (!test_data.arguments.empty()) {
29+
cmd += " -- ";
30+
cmd += test_data.arguments;
31+
}
32+
33+
std::istringstream in(test_data.input);
34+
std::ostringstream out;
35+
std::ostringstream err;
36+
ASSERT_EQ(StartVmConsoleUI(SplitString(cmd), std::cout, in, std::cout), test_data.expected_return_code);
37+
ASSERT_EQ(out.str(), test_data.expected_output);
38+
ASSERT_EQ(err.str(), test_data.expected_error);
39+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef X64JITTESTSUITE_HPP_
2+
#define X64JITTESTSUITE_HPP_
3+
4+
#include <string>
5+
6+
#include <gtest/gtest.h>
7+
8+
struct JitTestData {
9+
std::string test_name;
10+
std::string arguments;
11+
std::string input;
12+
std::string expected_output;
13+
std::string expected_error;
14+
int32_t expected_return_code = 0;
15+
uint64_t jit_action_bound = 0;
16+
};
17+
18+
struct X64JitTestSuite : public testing::Test { // special test structure
19+
const std::string kTemporaryDirectoryName = "./gtest_tmp";
20+
const std::string kTestDataDir = TEST_DATA_DIR;
21+
22+
void SetUp() override; // method that is called at the beginning of every test
23+
24+
void TearDown() override; // method that is called at the end of every test
25+
26+
void RunSingleTest(const JitTestData& test_data) const;
27+
};
28+
29+
#endif // X64JITTESTSUITE_HPP_

0 commit comments

Comments
 (0)