2022-06-05 15:16:04 +02:00
|
|
|
require 'pathname'
|
|
|
|
require 'rake/clean'
|
|
|
|
require 'open3'
|
|
|
|
|
|
|
|
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
|
|
|
|
BINARY = 'build/bin/elna'
|
2022-06-11 00:38:03 +02:00
|
|
|
TESTS = FileList['tests/*.eln'].flat_map do |test|
|
2022-06-05 23:43:45 +02:00
|
|
|
build = Pathname.new 'build'
|
2022-06-11 00:38:03 +02:00
|
|
|
test_basename = Pathname.new(test).basename('')
|
2022-06-05 23:43:45 +02:00
|
|
|
|
2022-06-11 00:38:03 +02:00
|
|
|
[build + 'riscv' + test_basename].map { |path| path.sub_ext('').to_path }
|
2022-06-05 23:43:45 +02:00
|
|
|
end
|
2022-06-11 00:38:03 +02:00
|
|
|
|
2022-06-05 15:16:04 +02:00
|
|
|
SOURCES = FileList['source/**/*.d']
|
|
|
|
|
|
|
|
directory 'build'
|
|
|
|
|
|
|
|
CLEAN.include 'build'
|
|
|
|
CLEAN.include '.dub'
|
|
|
|
|
2022-06-11 00:38:03 +02:00
|
|
|
rule(/build\/riscv\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
|
|
|
|
sh '/opt/riscv/bin/riscv32-unknown-elf-ld',
|
2022-06-08 08:34:44 +02:00
|
|
|
'-o', t.name,
|
2022-06-11 00:38:03 +02:00
|
|
|
'-L/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0',
|
|
|
|
'-L/opt/riscv/riscv32-unknown-elf/lib',
|
|
|
|
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
|
|
|
|
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtbegin.o',
|
|
|
|
t.source,
|
2022-06-11 22:52:13 +02:00
|
|
|
'--start-group', '-lgcc', '-lc', '-lgloss', '--end-group',
|
2022-06-11 00:38:03 +02:00
|
|
|
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtend.o'
|
2022-06-05 23:43:45 +02:00
|
|
|
end
|
|
|
|
|
2022-06-11 00:38:03 +02:00
|
|
|
rule(/build\/riscv\/.+\.o$/ => ->(file) { test_for_object(file, '.eln') }) do |t|
|
2022-06-05 15:16:04 +02:00
|
|
|
Pathname.new(t.name).dirname.mkpath
|
2022-06-08 08:34:44 +02:00
|
|
|
sh BINARY, '-o', t.name, t.source
|
|
|
|
end
|
|
|
|
|
2022-06-05 15:16:04 +02:00
|
|
|
file BINARY => SOURCES do |t|
|
|
|
|
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc-12')
|
|
|
|
end
|
|
|
|
|
|
|
|
task default: BINARY
|
|
|
|
|
|
|
|
desc 'Run all tests and check the results'
|
|
|
|
task test: TESTS
|
|
|
|
task test: BINARY do
|
|
|
|
TESTS.each do |test|
|
|
|
|
expected = Pathname
|
|
|
|
.new(test)
|
|
|
|
.sub_ext('.txt')
|
2022-06-05 23:43:45 +02:00
|
|
|
.sub(/^build\/[[:alpha:]]+\//, 'tests/expectations/')
|
2022-06-12 23:48:50 +02:00
|
|
|
.to_path
|
2022-06-05 15:16:04 +02:00
|
|
|
|
|
|
|
puts "Running #{test}"
|
2022-06-11 00:38:03 +02:00
|
|
|
if test.include? '/riscv/'
|
2022-06-12 23:48:50 +02:00
|
|
|
spike = [
|
|
|
|
'/opt/riscv/bin/spike',
|
|
|
|
'/opt/riscv/riscv32-unknown-elf/bin/pk',
|
|
|
|
test
|
|
|
|
]
|
|
|
|
diff = ['diff', '-Nur', '--color', expected, '-']
|
|
|
|
tail = ['tail', '-n', '1']
|
|
|
|
|
|
|
|
last_stdout, wait_threads = Open3.pipeline_r spike, tail, diff
|
2022-06-11 00:38:03 +02:00
|
|
|
else
|
|
|
|
raise 'Unsupported test platform'
|
|
|
|
end
|
2022-06-12 23:48:50 +02:00
|
|
|
print last_stdout.read
|
|
|
|
last_stdout.close
|
2022-06-05 15:16:04 +02:00
|
|
|
|
2022-06-12 23:48:50 +02:00
|
|
|
fail unless wait_threads.last.value.exitstatus.zero?
|
2022-06-05 15:16:04 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Run unittest blocks'
|
|
|
|
task unittest: SOURCES do |t|
|
|
|
|
sh('dub', 'test', '--compiler=gdc-12')
|
|
|
|
end
|
|
|
|
|
2022-06-11 00:38:03 +02:00
|
|
|
def test_for_object(out_file, extension)
|
2022-06-05 15:16:04 +02:00
|
|
|
test_source = Pathname
|
|
|
|
.new(out_file)
|
2022-06-11 00:38:03 +02:00
|
|
|
.sub_ext(extension)
|
2022-06-05 23:43:45 +02:00
|
|
|
.sub(/^build\/[[:alpha:]]+\//, 'tests/')
|
2022-06-05 15:16:04 +02:00
|
|
|
.to_path
|
|
|
|
[test_source, BINARY]
|
|
|
|
end
|
2022-06-05 23:43:45 +02:00
|
|
|
|
2022-06-08 08:34:44 +02:00
|
|
|
def test_for_out(out_file, extension)
|
2022-06-05 23:43:45 +02:00
|
|
|
Pathname
|
|
|
|
.new(out_file)
|
2022-06-08 08:34:44 +02:00
|
|
|
.sub_ext(extension)
|
2022-06-05 23:43:45 +02:00
|
|
|
.to_path
|
|
|
|
end
|