Skip to content

Commit

Permalink
Put build artifacts in temporary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfixes committed Apr 5, 2021
1 parent 32196ac commit 1ee342c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Update .gitattributes so we have consistent line endings
- Test runner detects console width if possible, allowing variable width from 80-132 chars
- Unit test executables are now built as tempfiles

### Deprecated

Expand Down
4 changes: 3 additions & 1 deletion exe/arduino_ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ def perform_unit_tests(cpp_library, config)
puts cpp_library.last_err
next false
end
cpp_library.run_test_file(exe)
cpp_library.run_test_file(Pathname.new(exe.path))
ensure
exe&.unlink
end
end
end
Expand Down
23 changes: 11 additions & 12 deletions lib/arduino_ci/cpp_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class CppLibrary
# @return [ArduinoBackend] The backend support for this library
attr_reader :backend

# @return [Array<Pathname>] The set of artifacts created by this class (note: incomplete!)
attr_reader :artifacts

# @return [Array<Pathname>] The set of directories that should be excluded from compilation
attr_reader :exclude_dirs

Expand All @@ -50,7 +47,6 @@ def initialize(friendly_name, backend)
@name = friendly_name
@backend = backend
@info_cache = nil
@artifacts = []
@last_err = ""
@last_out = ""
@last_msg = ""
Expand Down Expand Up @@ -491,13 +487,13 @@ def test_args(aux_libraries, ci_gcc_config)
# @param test_file [Pathname] The path to the file containing the unit tests
# @param aux_libraries [Array<Pathname>] The external Arduino libraries required by this project
# @param ci_gcc_config [Hash] The GCC config object
# @return [Pathname] path to the compiled test executable
# @return [Tempfile] the compiled test executable
def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_gcc_config)
base = test_file.basename
executable = Pathname.new("unittest_#{base}.bin").expand_path
File.delete(executable) if File.exist?(executable)
executable = Tempfile.new("unittest_#{base}.bin")
executable.close
arg_sets = []
arg_sets << ["-std=c++0x", "-o", executable.to_s, "-DARDUINO=100"]
arg_sets << ["-std=c++0x", "-o", executable.path, "-DARDUINO=100"]
if libasan?(gcc_binary)
arg_sets << [ # Stuff to help with dynamic memory mishandling
"-g", "-O1",
Expand All @@ -514,17 +510,20 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g
arg_sets << cpp_files_libraries(full_dependencies).map(&:to_s)
arg_sets << [test_file.to_s]
args = arg_sets.flatten(1)
return nil unless run_gcc(gcc_binary, *args)
unless run_gcc(gcc_binary, *args)
executable.unlink
return nil
end

artifacts << executable
executable
end

# print any found stack dumps
# @param executable [Pathname] the path to the test file
# @param executable [Tempfile] the path to the test file
def print_stack_dump(executable)
path = Pathname.new(executable.path)
possible_dumpfiles = [
executable.sub_ext("#{executable.extname}.stackdump")
path.sub_ext("#{path.extname}.stackdump")
]
possible_dumpfiles.select(&:exist?).each do |dump|
puts "========== Stack dump from #{dump}:"
Expand Down
2 changes: 1 addition & 1 deletion spec/cpp_library_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def verified_install(backend, path)
it "tests #{File.basename(path)} with #{compiler} expecting #{expected}" do
exe = @cpp_library.build_for_test_with_configuration(path, [], compiler, config.gcc_config("uno"))
expect(exe).not_to be nil
expect(@cpp_library.run_test_file(exe)).to eq(expected)
expect(@cpp_library.run_test_file(Pathname.new(exe.path))).to eq(expected)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/testsomething_unittests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

it "#{tfn} builds successfully and passes tests" do
expect(@exe).not_to be nil
expect(@cpp_library.run_test_file(@exe)).to_not be_falsey
expect(@cpp_library.run_test_file(Pathname.new(@exe.path))).to_not be_falsey
end
end
end
Expand Down

0 comments on commit 1ee342c

Please sign in to comment.