Grow stack automatically
This commit is contained in:
1
tests/7_member_sum.eln
Normal file
1
tests/7_member_sum.eln
Normal file
@ -0,0 +1 @@
|
||||
! 3 + 4 + 5 + 1 + 2 + 4 + 3
|
1
tests/expectations/7_member_sum.txt
Normal file
1
tests/expectations/7_member_sum.txt
Normal file
@ -0,0 +1 @@
|
||||
22
|
1
tests/expectations/print_number.txt
Normal file
1
tests/expectations/print_number.txt
Normal file
@ -0,0 +1 @@
|
||||
3
|
2
tests/print_number.eln
Normal file
2
tests/print_number.eln
Normal file
@ -0,0 +1,2 @@
|
||||
! 3
|
||||
.
|
103
tests/runner.cpp
Executable file
103
tests/runner.cpp
Executable file
@ -0,0 +1,103 @@
|
||||
#include <boost/process.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
class test_results final
|
||||
{
|
||||
std::uint32_t m_total{ 0 };
|
||||
std::uint32_t m_passed{ 0 };
|
||||
|
||||
public:
|
||||
test_results() = default;
|
||||
|
||||
std::uint32_t total() const noexcept
|
||||
{
|
||||
return m_total;
|
||||
}
|
||||
|
||||
std::uint32_t passed() const noexcept
|
||||
{
|
||||
return m_passed;
|
||||
}
|
||||
|
||||
std::uint32_t failed() const noexcept
|
||||
{
|
||||
return m_total - m_passed;
|
||||
}
|
||||
|
||||
int exit_code() const noexcept
|
||||
{
|
||||
return m_total == m_passed ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
void add_exit_code(const int exit_code) noexcept
|
||||
{
|
||||
++m_total;
|
||||
if (exit_code == 0)
|
||||
{
|
||||
++m_passed;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int run_test(const std::filesystem::directory_entry& test_entry)
|
||||
{
|
||||
const std::filesystem::path test_filename = test_entry.path().filename();
|
||||
|
||||
std::filesystem::path test_binary = "build/riscv" / 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(
|
||||
"/opt/riscv/bin/spike", "--isa=RV32IMAC",
|
||||
"/opt/riscv/riscv32-unknown-elf/bin/pk",
|
||||
test_binary.string(),
|
||||
boost::process::std_out > pipe_stream
|
||||
);
|
||||
boost::process::child diff(
|
||||
"/usr/bin/diff", "-Nur", "--color",
|
||||
expectation_path.string(), "-",
|
||||
boost::process::std_in < pipe_stream
|
||||
);
|
||||
vm.wait();
|
||||
diff.wait();
|
||||
|
||||
return diff.exit_code();
|
||||
}
|
||||
|
||||
test_results run_in_path(const std::filesystem::path test_directory)
|
||||
{
|
||||
test_results results;
|
||||
|
||||
for (const auto& test_entry : std::filesystem::directory_iterator(test_directory))
|
||||
{
|
||||
if (test_entry.path().extension() != ".eln" || !test_entry.is_regular_file())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
results.add_exit_code(run_test(test_entry));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::process::system("rake");
|
||||
|
||||
std::cout << "Run all tests and check the results" << std::endl;
|
||||
std::filesystem::path test_directory{ "tests" };
|
||||
const auto results = run_in_path(test_directory);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << results.total() << " tests run, "
|
||||
<< results.passed() << " passed, "
|
||||
<< results.failed() << " failed." << std::endl;
|
||||
|
||||
return results.exit_code();
|
||||
}
|
Reference in New Issue
Block a user