Assign variables
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
var x;
|
||||
begin
|
||||
x := 5;
|
||||
! 5
|
||||
! x
|
||||
end.
|
||||
|
103
tests/tester.cpp
103
tests/tester.cpp
@ -1,9 +1,11 @@
|
||||
#include <boost/process.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "elna/tester.hpp"
|
||||
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/process.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace elna
|
||||
{
|
||||
std::uint32_t test_results::total() const noexcept
|
||||
@ -26,10 +28,10 @@ namespace elna
|
||||
return m_total == m_passed ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
void test_results::add_exit_code(const int exit_code) noexcept
|
||||
void test_results::add_exit_code(const test_status status) noexcept
|
||||
{
|
||||
++m_total;
|
||||
if (exit_code == 0)
|
||||
if (status == test_status::successful)
|
||||
{
|
||||
++m_passed;
|
||||
}
|
||||
@ -45,7 +47,7 @@ namespace elna
|
||||
return in_build_directory() / path;
|
||||
}
|
||||
|
||||
static int build_test(const std::filesystem::directory_entry& test_entry)
|
||||
static test_result build_test(const std::filesystem::directory_entry& test_entry)
|
||||
{
|
||||
const std::filesystem::path test_filename = test_entry.path().filename();
|
||||
|
||||
@ -61,7 +63,7 @@ namespace elna
|
||||
"-o", test_object.string(), test_entry.path().string());
|
||||
if (status != 0)
|
||||
{
|
||||
return status;
|
||||
return test_result{ test_status::compile_failed, status };
|
||||
}
|
||||
status = boost::process::system(
|
||||
"/opt/riscv/bin/riscv32-unknown-elf-ld",
|
||||
@ -74,37 +76,55 @@ namespace elna
|
||||
"--start-group", "-lgcc", "-lc", "-lgloss", "--end-group",
|
||||
"/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtend.o"
|
||||
);
|
||||
return status;
|
||||
return test_result{};
|
||||
}
|
||||
|
||||
static int run_test(const std::filesystem::directory_entry& test_entry)
|
||||
static test_result check_expectation(const std::filesystem::directory_entry& test_entry, const test_result& run)
|
||||
{
|
||||
const std::filesystem::path test_filename = test_entry.path().filename();
|
||||
|
||||
std::filesystem::path expectation_path = test_entry.path().parent_path() / "expectations" / test_filename;
|
||||
expectation_path.replace_extension(".txt");
|
||||
|
||||
boost::process::opstream pipe_stream;
|
||||
boost::process::child diff(
|
||||
boost::process::search_path("diff"), "-Nur", "--color",
|
||||
expectation_path.string(), "-",
|
||||
boost::process::std_in < pipe_stream
|
||||
);
|
||||
|
||||
pipe_stream << run.output;
|
||||
pipe_stream.flush();
|
||||
pipe_stream.pipe().close();
|
||||
diff.wait();
|
||||
|
||||
if (diff.exit_code() == 0)
|
||||
{
|
||||
return run;
|
||||
}
|
||||
return test_result{ test_status::expectation_failed, run.code, run.output };
|
||||
}
|
||||
|
||||
static test_result run_test(const std::filesystem::directory_entry& test_entry)
|
||||
{
|
||||
const std::filesystem::path test_filename = test_entry.path().filename();
|
||||
|
||||
std::filesystem::path test_binary = in_build_directory(test_filename);
|
||||
test_binary.replace_extension();
|
||||
|
||||
std::filesystem::path expectation_path = test_entry.path().parent_path() / "expectations" / test_filename;
|
||||
expectation_path.replace_extension(".txt");
|
||||
|
||||
std::cout << "Running " << test_binary << std::endl;
|
||||
|
||||
boost::process::pipe pipe_stream;
|
||||
boost::process::child vm(
|
||||
boost::asio::io_service io_service;
|
||||
std::future<std::string> buffer;
|
||||
boost::process::child spike(
|
||||
"/opt/riscv/bin/spike", "--isa=RV32IMAC",
|
||||
"/opt/riscv/riscv32-unknown-elf/bin/pk",
|
||||
test_binary.string(),
|
||||
boost::process::std_out > pipe_stream
|
||||
boost::process::std_out > buffer,
|
||||
boost::process::std_err > buffer,
|
||||
io_service
|
||||
);
|
||||
boost::process::child diff(
|
||||
"/usr/bin/diff", "-Nur", "--color",
|
||||
expectation_path.string(), "-",
|
||||
boost::process::std_in < pipe_stream
|
||||
);
|
||||
vm.wait();
|
||||
diff.wait();
|
||||
io_service.run();
|
||||
|
||||
return diff.exit_code();
|
||||
return test_result{ test_status::successful, spike.exit_code(), buffer.get() };
|
||||
}
|
||||
|
||||
static test_results run_in_path(const std::filesystem::path test_directory)
|
||||
@ -117,26 +137,37 @@ namespace elna
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int status{ 0 };
|
||||
test_result result;
|
||||
|
||||
std::cout << "Running " << test_entry << std::endl;
|
||||
try
|
||||
{
|
||||
status = build_test(test_entry);
|
||||
result = build_test(test_entry);
|
||||
if (result.status == test_status::successful)
|
||||
{
|
||||
result = run_test(test_entry);
|
||||
}
|
||||
result = check_expectation(test_entry, result);
|
||||
}
|
||||
catch (const boost::process::process_error& exception)
|
||||
{
|
||||
std::cout << exception.what() << std::endl;
|
||||
status = 3;
|
||||
continue;
|
||||
result.status = test_status::build_failed;
|
||||
result.output = exception.what();
|
||||
std::cout << result.output << std::endl;
|
||||
}
|
||||
if (status == 0)
|
||||
{
|
||||
status = run_test(test_entry);
|
||||
}
|
||||
results.add_exit_code(status);
|
||||
print_result(test_entry, result);
|
||||
results.add_exit_code(result.status);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
void print_result(const std::filesystem::directory_entry& test_entry, const test_result& result)
|
||||
{
|
||||
if (result.status != test_status::successful)
|
||||
{
|
||||
std::cout << test_entry << " failed." << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
|
Reference in New Issue
Block a user