Add ScopedTmpFile.

This replaces the existing AutoTestFile implementation with a simpler
implementation that uses O_TMPFILE to avoid having the temporary files
linked in the filesystem.

Refactor the existing tests to use the new ScopedTmpFile instead of
duplicating the same ScopedTestFile wrapper into each test.

Change-Id: Iee9416e52269eff271f748ec9d822aee6e28f59a
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3971917
Reviewed-by: Lei Zhang <thestig@chromium.org>
This commit is contained in:
Mark Brand 2023-01-30 11:19:45 +01:00 committed by Ivan Penkov
parent f617814017
commit 9a87ff661e
9 changed files with 388 additions and 223 deletions

View file

@ -222,7 +222,8 @@ check_PROGRAMS += \
src/processor/synth_minidump_unittest
if LINUX_HOST
check_PROGRAMS += \
src/processor/disassembler_objdump_unittest
src/processor/disassembler_objdump_unittest \
src/common/linux/scoped_tmpfile_unittest
endif LINUX_HOST
if SELFTEST
check_PROGRAMS += \
@ -529,7 +530,6 @@ src_client_linux_libbreakpad_client_a_SOURCES += \
endif
# Client tests
src_client_linux_linux_dumper_unittest_helper_SOURCES = \
src/client/linux/minidump_writer/linux_dumper_unittest_helper.cc
src_client_linux_linux_dumper_unittest_helper_LDFLAGS=$(PTHREAD_CFLAGS)
@ -558,7 +558,8 @@ src_client_linux_linux_client_unittest_shlib_SOURCES = \
src/client/linux/minidump_writer/proc_cpuinfo_reader_unittest.cc \
src/common/linux/elf_core_dump.cc \
src/common/linux/linux_libc_support_unittest.cc \
src/common/linux/tests/auto_testfile.h \
src/common/linux/scoped_tmpfile.h \
src/common/linux/scoped_tmpfile.cc \
src/common/linux/tests/crash_generator.cc \
src/common/memory_allocator_unittest.cc \
src/common/tests/auto_tempdir.h \
@ -957,6 +958,15 @@ src_processor_exploitability_unittest_LDADD += \
src/processor/disassembler_objdump.o
endif
src_common_linux_scoped_tmpfile_unittest_SOURCES = \
src/common/linux/scoped_tmpfile_unittest.cc
src_common_linux_scoped_tmpfile_unittest_CPPFLAGS = \
$(AM_CPPFLAGS) $(TEST_CFLAGS)
src_common_linux_scoped_tmpfile_unittest_LDADD = \
src/common/linux/scoped_tmpfile.o \
$(TEST_LIBS) \
$(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
src_processor_disassembler_objdump_unittest_SOURCES = \
src/processor/disassembler_objdump_unittest.cc
src_processor_disassembler_objdump_unittest_CPPFLAGS = \

View file

@ -193,7 +193,8 @@ EXTRA_PROGRAMS = $(am__EXEEXT_1)
@DISABLE_PROCESSOR_FALSE@ src/processor/synth_minidump_unittest
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@am__append_10 = \
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@ src/processor/disassembler_objdump_unittest
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@ src/processor/disassembler_objdump_unittest \
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@ src/common/linux/scoped_tmpfile_unittest
@DISABLE_PROCESSOR_FALSE@@SELFTEST_TRUE@am__append_11 = \
@DISABLE_PROCESSOR_FALSE@@SELFTEST_TRUE@ src/processor/stackwalker_selftest
@ -351,7 +352,8 @@ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libexecdir)" \
@DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_riscv64_unittest$(EXEEXT) \
@DISABLE_PROCESSOR_FALSE@ src/processor/stackwalker_x86_unittest$(EXEEXT) \
@DISABLE_PROCESSOR_FALSE@ src/processor/synth_minidump_unittest$(EXEEXT)
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@am__EXEEXT_6 = src/processor/disassembler_objdump_unittest$(EXEEXT)
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@am__EXEEXT_6 = src/processor/disassembler_objdump_unittest$(EXEEXT) \
@DISABLE_PROCESSOR_FALSE@@LINUX_HOST_TRUE@ src/common/linux/scoped_tmpfile_unittest$(EXEEXT)
@DISABLE_PROCESSOR_FALSE@@SELFTEST_TRUE@am__EXEEXT_7 = src/processor/stackwalker_selftest$(EXEEXT)
@LINUX_HOST_TRUE@am__EXEEXT_8 = src/client/linux/linux_client_unittest$(EXEEXT) \
@LINUX_HOST_TRUE@ src/common/linux/google_crashdump_uploader_test$(EXEEXT)
@ -672,7 +674,8 @@ am__src_client_linux_linux_client_unittest_shlib_SOURCES_DIST = \
src/client/linux/minidump_writer/proc_cpuinfo_reader_unittest.cc \
src/common/linux/elf_core_dump.cc \
src/common/linux/linux_libc_support_unittest.cc \
src/common/linux/tests/auto_testfile.h \
src/common/linux/scoped_tmpfile.h \
src/common/linux/scoped_tmpfile.cc \
src/common/linux/tests/crash_generator.cc \
src/common/memory_allocator_unittest.cc \
src/common/tests/auto_tempdir.h src/common/tests/file_utils.cc \
@ -706,6 +709,7 @@ am_src_client_linux_linux_client_unittest_shlib_OBJECTS = \
src/client/linux/minidump_writer/linux_client_unittest_shlib-proc_cpuinfo_reader_unittest.$(OBJEXT) \
src/common/linux/client_linux_linux_client_unittest_shlib-elf_core_dump.$(OBJEXT) \
src/common/linux/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.$(OBJEXT) \
src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.$(OBJEXT) \
src/common/linux/tests/client_linux_linux_client_unittest_shlib-crash_generator.$(OBJEXT) \
src/common/client_linux_linux_client_unittest_shlib-memory_allocator_unittest.$(OBJEXT) \
src/common/tests/client_linux_linux_client_unittest_shlib-file_utils.$(OBJEXT) \
@ -809,6 +813,12 @@ src_common_linux_google_crashdump_uploader_test_OBJECTS = \
src_common_linux_google_crashdump_uploader_test_DEPENDENCIES = \
$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
am_src_common_linux_scoped_tmpfile_unittest_OBJECTS = src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.$(OBJEXT)
src_common_linux_scoped_tmpfile_unittest_OBJECTS = \
$(am_src_common_linux_scoped_tmpfile_unittest_OBJECTS)
src_common_linux_scoped_tmpfile_unittest_DEPENDENCIES = \
src/common/linux/scoped_tmpfile.o $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_src_common_mac_macho_reader_unittest_OBJECTS = src/common/mac_macho_reader_unittest-dwarf_cfi_to_module.$(OBJEXT) \
src/common/mac_macho_reader_unittest-dwarf_cu_to_module.$(OBJEXT) \
src/common/mac_macho_reader_unittest-dwarf_line_to_module.$(OBJEXT) \
@ -1521,6 +1531,7 @@ am__depfiles_remade = src/client/$(DEPDIR)/minidump_file_writer.Po \
src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-breakpad_getcontext_unittest.Po \
src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-elf_core_dump.Po \
src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.Po \
src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Po \
src/common/linux/$(DEPDIR)/dumper_unittest-crc32.Po \
src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols.Po \
src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols_unittest.Po \
@ -1550,6 +1561,7 @@ am__depfiles_remade = src/client/$(DEPDIR)/minidump_file_writer.Po \
src/common/linux/$(DEPDIR)/linux_libc_support.Po \
src/common/linux/$(DEPDIR)/memory_mapped_file.Po \
src/common/linux/$(DEPDIR)/safe_readlink.Po \
src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Po \
src/common/linux/$(DEPDIR)/symbol_collector_client.Po \
src/common/linux/$(DEPDIR)/symbol_upload.Po \
src/common/linux/$(DEPDIR)/tools_linux_dump_syms_dump_syms-crc32.Po \
@ -1744,6 +1756,7 @@ SOURCES = $(src_client_linux_libbreakpad_client_a_SOURCES) \
$(src_common_dwarf_dwarf2reader_lineinfo_unittest_SOURCES) \
$(src_common_dwarf_dwarf2reader_splitfunctions_unittest_SOURCES) \
$(src_common_linux_google_crashdump_uploader_test_SOURCES) \
$(src_common_linux_scoped_tmpfile_unittest_SOURCES) \
$(src_common_mac_macho_reader_unittest_SOURCES) \
$(src_common_safe_math_unittest_SOURCES) \
$(src_common_test_assembler_unittest_SOURCES) \
@ -1804,6 +1817,7 @@ DIST_SOURCES = \
$(src_common_dwarf_dwarf2reader_lineinfo_unittest_SOURCES) \
$(src_common_dwarf_dwarf2reader_splitfunctions_unittest_SOURCES) \
$(src_common_linux_google_crashdump_uploader_test_SOURCES) \
$(src_common_linux_scoped_tmpfile_unittest_SOURCES) \
$(src_common_mac_macho_reader_unittest_SOURCES) \
$(src_common_safe_math_unittest_SOURCES) \
$(src_common_test_assembler_unittest_SOURCES) \
@ -2523,7 +2537,8 @@ src_client_linux_linux_client_unittest_shlib_SOURCES = \
src/client/linux/minidump_writer/proc_cpuinfo_reader_unittest.cc \
src/common/linux/elf_core_dump.cc \
src/common/linux/linux_libc_support_unittest.cc \
src/common/linux/tests/auto_testfile.h \
src/common/linux/scoped_tmpfile.h \
src/common/linux/scoped_tmpfile.cc \
src/common/linux/tests/crash_generator.cc \
src/common/memory_allocator_unittest.cc \
src/common/tests/auto_tempdir.h src/common/tests/file_utils.cc \
@ -2912,6 +2927,17 @@ src_processor_exploitability_unittest_LDADD = \
src/processor/tokenize.o src/third_party/libdisasm/libdisasm.a \
$(TEST_LIBS) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) \
$(am__append_27)
src_common_linux_scoped_tmpfile_unittest_SOURCES = \
src/common/linux/scoped_tmpfile_unittest.cc
src_common_linux_scoped_tmpfile_unittest_CPPFLAGS = \
$(AM_CPPFLAGS) $(TEST_CFLAGS)
src_common_linux_scoped_tmpfile_unittest_LDADD = \
src/common/linux/scoped_tmpfile.o \
$(TEST_LIBS) \
$(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
src_processor_disassembler_objdump_unittest_SOURCES = \
src/processor/disassembler_objdump_unittest.cc
@ -4293,6 +4319,9 @@ src/common/linux/client_linux_linux_client_unittest_shlib-elf_core_dump.$(OBJEXT
src/common/linux/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.$(OBJEXT): \
src/common/linux/$(am__dirstamp) \
src/common/linux/$(DEPDIR)/$(am__dirstamp)
src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.$(OBJEXT): \
src/common/linux/$(am__dirstamp) \
src/common/linux/$(DEPDIR)/$(am__dirstamp)
src/common/linux/tests/$(am__dirstamp):
@$(MKDIR_P) src/common/linux/tests
@: > src/common/linux/tests/$(am__dirstamp)
@ -4539,6 +4568,13 @@ src/common/linux/google_crashdump_uploader_test-libcurl_wrapper.$(OBJEXT): \
src/common/linux/google_crashdump_uploader_test$(EXEEXT): $(src_common_linux_google_crashdump_uploader_test_OBJECTS) $(src_common_linux_google_crashdump_uploader_test_DEPENDENCIES) $(EXTRA_src_common_linux_google_crashdump_uploader_test_DEPENDENCIES) src/common/linux/$(am__dirstamp)
@rm -f src/common/linux/google_crashdump_uploader_test$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(src_common_linux_google_crashdump_uploader_test_OBJECTS) $(src_common_linux_google_crashdump_uploader_test_LDADD) $(LIBS)
src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.$(OBJEXT): \
src/common/linux/$(am__dirstamp) \
src/common/linux/$(DEPDIR)/$(am__dirstamp)
src/common/linux/scoped_tmpfile_unittest$(EXEEXT): $(src_common_linux_scoped_tmpfile_unittest_OBJECTS) $(src_common_linux_scoped_tmpfile_unittest_DEPENDENCIES) $(EXTRA_src_common_linux_scoped_tmpfile_unittest_DEPENDENCIES) src/common/linux/$(am__dirstamp)
@rm -f src/common/linux/scoped_tmpfile_unittest$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(src_common_linux_scoped_tmpfile_unittest_OBJECTS) $(src_common_linux_scoped_tmpfile_unittest_LDADD) $(LIBS)
src/common/mac_macho_reader_unittest-dwarf_cfi_to_module.$(OBJEXT): \
src/common/$(am__dirstamp) \
src/common/$(DEPDIR)/$(am__dirstamp)
@ -5329,6 +5365,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-breakpad_getcontext_unittest.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-elf_core_dump.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/dumper_unittest-crc32.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols_unittest.Po@am__quote@ # am--include-marker
@ -5358,6 +5395,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/linux_libc_support.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/memory_mapped_file.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/safe_readlink.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/symbol_collector_client.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/symbol_upload.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@src/common/linux/$(DEPDIR)/tools_linux_dump_syms_dump_syms-crc32.Po@am__quote@ # am--include-marker
@ -5854,6 +5892,20 @@ src/common/linux/client_linux_linux_client_unittest_shlib-linux_libc_support_uni
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_client_linux_linux_client_unittest_shlib_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/linux/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.obj `if test -f 'src/common/linux/linux_libc_support_unittest.cc'; then $(CYGPATH_W) 'src/common/linux/linux_libc_support_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/linux/linux_libc_support_unittest.cc'; fi`
src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.o: src/common/linux/scoped_tmpfile.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_client_linux_linux_client_unittest_shlib_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.o -MD -MP -MF src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Tpo -c -o src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.o `test -f 'src/common/linux/scoped_tmpfile.cc' || echo '$(srcdir)/'`src/common/linux/scoped_tmpfile.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Tpo src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/common/linux/scoped_tmpfile.cc' object='src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_client_linux_linux_client_unittest_shlib_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.o `test -f 'src/common/linux/scoped_tmpfile.cc' || echo '$(srcdir)/'`src/common/linux/scoped_tmpfile.cc
src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.obj: src/common/linux/scoped_tmpfile.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_client_linux_linux_client_unittest_shlib_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.obj -MD -MP -MF src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Tpo -c -o src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.obj `if test -f 'src/common/linux/scoped_tmpfile.cc'; then $(CYGPATH_W) 'src/common/linux/scoped_tmpfile.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/linux/scoped_tmpfile.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Tpo src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/common/linux/scoped_tmpfile.cc' object='src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_client_linux_linux_client_unittest_shlib_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/linux/client_linux_linux_client_unittest_shlib-scoped_tmpfile.obj `if test -f 'src/common/linux/scoped_tmpfile.cc'; then $(CYGPATH_W) 'src/common/linux/scoped_tmpfile.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/linux/scoped_tmpfile.cc'; fi`
src/common/linux/tests/client_linux_linux_client_unittest_shlib-crash_generator.o: src/common/linux/tests/crash_generator.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_client_linux_linux_client_unittest_shlib_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/linux/tests/client_linux_linux_client_unittest_shlib-crash_generator.o -MD -MP -MF src/common/linux/tests/$(DEPDIR)/client_linux_linux_client_unittest_shlib-crash_generator.Tpo -c -o src/common/linux/tests/client_linux_linux_client_unittest_shlib-crash_generator.o `test -f 'src/common/linux/tests/crash_generator.cc' || echo '$(srcdir)/'`src/common/linux/tests/crash_generator.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/linux/tests/$(DEPDIR)/client_linux_linux_client_unittest_shlib-crash_generator.Tpo src/common/linux/tests/$(DEPDIR)/client_linux_linux_client_unittest_shlib-crash_generator.Po
@ -6792,6 +6844,20 @@ src/common/linux/google_crashdump_uploader_test-libcurl_wrapper.obj: src/common/
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_common_linux_google_crashdump_uploader_test_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/linux/google_crashdump_uploader_test-libcurl_wrapper.obj `if test -f 'src/common/linux/libcurl_wrapper.cc'; then $(CYGPATH_W) 'src/common/linux/libcurl_wrapper.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/linux/libcurl_wrapper.cc'; fi`
src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.o: src/common/linux/scoped_tmpfile_unittest.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_common_linux_scoped_tmpfile_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.o -MD -MP -MF src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Tpo -c -o src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.o `test -f 'src/common/linux/scoped_tmpfile_unittest.cc' || echo '$(srcdir)/'`src/common/linux/scoped_tmpfile_unittest.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Tpo src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/common/linux/scoped_tmpfile_unittest.cc' object='src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_common_linux_scoped_tmpfile_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.o `test -f 'src/common/linux/scoped_tmpfile_unittest.cc' || echo '$(srcdir)/'`src/common/linux/scoped_tmpfile_unittest.cc
src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.obj: src/common/linux/scoped_tmpfile_unittest.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_common_linux_scoped_tmpfile_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.obj -MD -MP -MF src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Tpo -c -o src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.obj `if test -f 'src/common/linux/scoped_tmpfile_unittest.cc'; then $(CYGPATH_W) 'src/common/linux/scoped_tmpfile_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/linux/scoped_tmpfile_unittest.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Tpo src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/common/linux/scoped_tmpfile_unittest.cc' object='src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_common_linux_scoped_tmpfile_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/common/linux/scoped_tmpfile_unittest-scoped_tmpfile_unittest.obj `if test -f 'src/common/linux/scoped_tmpfile_unittest.cc'; then $(CYGPATH_W) 'src/common/linux/scoped_tmpfile_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/src/common/linux/scoped_tmpfile_unittest.cc'; fi`
src/common/mac_macho_reader_unittest-dwarf_cfi_to_module.o: src/common/dwarf_cfi_to_module.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_common_mac_macho_reader_unittest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/common/mac_macho_reader_unittest-dwarf_cfi_to_module.o -MD -MP -MF src/common/$(DEPDIR)/mac_macho_reader_unittest-dwarf_cfi_to_module.Tpo -c -o src/common/mac_macho_reader_unittest-dwarf_cfi_to_module.o `test -f 'src/common/dwarf_cfi_to_module.cc' || echo '$(srcdir)/'`src/common/dwarf_cfi_to_module.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/common/$(DEPDIR)/mac_macho_reader_unittest-dwarf_cfi_to_module.Tpo src/common/$(DEPDIR)/mac_macho_reader_unittest-dwarf_cfi_to_module.Po
@ -9043,6 +9109,13 @@ src/processor/disassembler_objdump_unittest.log: src/processor/disassembler_objd
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
src/common/linux/scoped_tmpfile_unittest.log: src/common/linux/scoped_tmpfile_unittest$(EXEEXT)
@p='src/common/linux/scoped_tmpfile_unittest$(EXEEXT)'; \
b='src/common/linux/scoped_tmpfile_unittest'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
src/processor/stackwalker_selftest.log: src/processor/stackwalker_selftest$(EXEEXT)
@p='src/processor/stackwalker_selftest$(EXEEXT)'; \
b='src/processor/stackwalker_selftest'; \
@ -9535,6 +9608,7 @@ distclean: distclean-am
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-breakpad_getcontext_unittest.Po
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-elf_core_dump.Po
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.Po
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Po
-rm -f src/common/linux/$(DEPDIR)/dumper_unittest-crc32.Po
-rm -f src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols.Po
-rm -f src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols_unittest.Po
@ -9564,6 +9638,7 @@ distclean: distclean-am
-rm -f src/common/linux/$(DEPDIR)/linux_libc_support.Po
-rm -f src/common/linux/$(DEPDIR)/memory_mapped_file.Po
-rm -f src/common/linux/$(DEPDIR)/safe_readlink.Po
-rm -f src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Po
-rm -f src/common/linux/$(DEPDIR)/symbol_collector_client.Po
-rm -f src/common/linux/$(DEPDIR)/symbol_upload.Po
-rm -f src/common/linux/$(DEPDIR)/tools_linux_dump_syms_dump_syms-crc32.Po
@ -9889,6 +9964,7 @@ maintainer-clean: maintainer-clean-am
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-breakpad_getcontext_unittest.Po
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-elf_core_dump.Po
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-linux_libc_support_unittest.Po
-rm -f src/common/linux/$(DEPDIR)/client_linux_linux_client_unittest_shlib-scoped_tmpfile.Po
-rm -f src/common/linux/$(DEPDIR)/dumper_unittest-crc32.Po
-rm -f src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols.Po
-rm -f src/common/linux/$(DEPDIR)/dumper_unittest-dump_symbols_unittest.Po
@ -9918,6 +9994,7 @@ maintainer-clean: maintainer-clean-am
-rm -f src/common/linux/$(DEPDIR)/linux_libc_support.Po
-rm -f src/common/linux/$(DEPDIR)/memory_mapped_file.Po
-rm -f src/common/linux/$(DEPDIR)/safe_readlink.Po
-rm -f src/common/linux/$(DEPDIR)/scoped_tmpfile_unittest-scoped_tmpfile_unittest.Po
-rm -f src/common/linux/$(DEPDIR)/symbol_collector_client.Po
-rm -f src/common/linux/$(DEPDIR)/symbol_upload.Po
-rm -f src/common/linux/$(DEPDIR)/tools_linux_dump_syms_dump_syms-crc32.Po

View file

@ -35,7 +35,7 @@
#include "breakpad_googletest_includes.h"
#include "client/linux/minidump_writer/cpu_set.h"
#include "common/linux/tests/auto_testfile.h"
#include "common/linux/scoped_tmpfile.h"
using namespace google_breakpad;
@ -43,15 +43,6 @@ namespace {
typedef testing::Test CpuSetTest;
// Helper class to write test text file to a temporary file and return
// its file descriptor.
class ScopedTestFile : public AutoTestFile {
public:
explicit ScopedTestFile(const char* text)
: AutoTestFile("cpu_set", text) {
}
};
}
TEST(CpuSetTest, EmptyCount) {
@ -60,8 +51,8 @@ TEST(CpuSetTest, EmptyCount) {
}
TEST(CpuSetTest, OneCpu) {
ScopedTestFile file("10");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("10"));
CpuSet set;
ASSERT_TRUE(set.ParseSysFile(file.GetFd()));
@ -69,8 +60,8 @@ TEST(CpuSetTest, OneCpu) {
}
TEST(CpuSetTest, OneCpuTerminated) {
ScopedTestFile file("10\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("10\n"));
CpuSet set;
ASSERT_TRUE(set.ParseSysFile(file.GetFd()));
@ -78,8 +69,8 @@ TEST(CpuSetTest, OneCpuTerminated) {
}
TEST(CpuSetTest, TwoCpusWithComma) {
ScopedTestFile file("1,10");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("1,10"));
CpuSet set;
ASSERT_TRUE(set.ParseSysFile(file.GetFd()));
@ -87,8 +78,8 @@ TEST(CpuSetTest, TwoCpusWithComma) {
}
TEST(CpuSetTest, TwoCpusWithRange) {
ScopedTestFile file("1-2");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("1-2"));
CpuSet set;
ASSERT_TRUE(set.ParseSysFile(file.GetFd()));
@ -96,8 +87,8 @@ TEST(CpuSetTest, TwoCpusWithRange) {
}
TEST(CpuSetTest, TenCpusWithRange) {
ScopedTestFile file("9-18");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("9-18"));
CpuSet set;
ASSERT_TRUE(set.ParseSysFile(file.GetFd()));
@ -105,8 +96,8 @@ TEST(CpuSetTest, TenCpusWithRange) {
}
TEST(CpuSetTest, MultiItems) {
ScopedTestFile file("0, 2-4, 128");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("0, 2-4, 128"));
CpuSet set;
ASSERT_TRUE(set.ParseSysFile(file.GetFd()));
@ -114,14 +105,16 @@ TEST(CpuSetTest, MultiItems) {
}
TEST(CpuSetTest, IntersectWith) {
ScopedTestFile file1("9-19");
ASSERT_TRUE(file1.IsOk());
ScopedTmpFile file1;
ASSERT_TRUE(file1.InitString("9-19"));
CpuSet set1;
ASSERT_TRUE(set1.ParseSysFile(file1.GetFd()));
ASSERT_EQ(11, set1.GetCount());
ScopedTestFile file2("16-24");
ASSERT_TRUE(file2.IsOk());
ScopedTmpFile file2;
ASSERT_TRUE(file2.InitString("16-24"));
CpuSet set2;
ASSERT_TRUE(set2.ParseSysFile(file2.GetFd()));
ASSERT_EQ(9, set2.GetCount());
@ -132,8 +125,9 @@ TEST(CpuSetTest, IntersectWith) {
}
TEST(CpuSetTest, SelfIntersection) {
ScopedTestFile file1("9-19");
ASSERT_TRUE(file1.IsOk());
ScopedTmpFile file1;
ASSERT_TRUE(file1.InitString("9-19"));
CpuSet set1;
ASSERT_TRUE(set1.ParseSysFile(file1.GetFd()));
ASSERT_EQ(11, set1.GetCount());
@ -143,14 +137,16 @@ TEST(CpuSetTest, SelfIntersection) {
}
TEST(CpuSetTest, EmptyIntersection) {
ScopedTestFile file1("0-19");
ASSERT_TRUE(file1.IsOk());
ScopedTmpFile file1;
ASSERT_TRUE(file1.InitString("0-19"));
CpuSet set1;
ASSERT_TRUE(set1.ParseSysFile(file1.GetFd()));
ASSERT_EQ(20, set1.GetCount());
ScopedTestFile file2("20-39");
ASSERT_TRUE(file2.IsOk());
ScopedTmpFile file2;
ASSERT_TRUE(file2.InitString("20-39"));
CpuSet set2;
ASSERT_TRUE(set2.ParseSysFile(file2.GetFd()));
ASSERT_EQ(20, set2.GetCount());

View file

@ -32,7 +32,7 @@
#include "client/linux/minidump_writer/line_reader.h"
#include "breakpad_googletest_includes.h"
#include "common/linux/tests/auto_testfile.h"
#include "common/linux/scoped_tmpfile.h"
using namespace google_breakpad;
@ -40,22 +40,11 @@ namespace {
typedef testing::Test LineReaderTest;
class ScopedTestFile : public AutoTestFile {
public:
explicit ScopedTestFile(const char* text)
: AutoTestFile("line_reader", text) {
}
ScopedTestFile(const char* text, size_t text_len)
: AutoTestFile("line_reader", text, text_len) {
}
};
}
TEST(LineReaderTest, EmptyFile) {
ScopedTestFile file("");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString(""));
LineReader reader(file.GetFd());
const char* line;
@ -64,8 +53,8 @@ TEST(LineReaderTest, EmptyFile) {
}
TEST(LineReaderTest, OneLineTerminated) {
ScopedTestFile file("a\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("a\n"));
LineReader reader(file.GetFd());
const char* line;
@ -80,8 +69,8 @@ TEST(LineReaderTest, OneLineTerminated) {
}
TEST(LineReaderTest, OneLine) {
ScopedTestFile file("a");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("a"));
LineReader reader(file.GetFd());
const char* line;
@ -96,8 +85,8 @@ TEST(LineReaderTest, OneLine) {
}
TEST(LineReaderTest, TwoLinesTerminated) {
ScopedTestFile file("a\nb\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("a\nb\n"));
LineReader reader(file.GetFd());
const char* line;
@ -118,8 +107,8 @@ TEST(LineReaderTest, TwoLinesTerminated) {
}
TEST(LineReaderTest, TwoLines) {
ScopedTestFile file("a\nb");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("a\nb"));
LineReader reader(file.GetFd());
const char* line;
@ -142,8 +131,8 @@ TEST(LineReaderTest, TwoLines) {
TEST(LineReaderTest, MaxLength) {
char l[LineReader::kMaxLineLen-1];
memset(l, 'a', sizeof(l));
ScopedTestFile file(l, sizeof(l));
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitData(l, sizeof(l)));
LineReader reader(file.GetFd());
const char* line;
@ -158,8 +147,8 @@ TEST(LineReaderTest, TooLong) {
// Note: this writes kMaxLineLen 'a' chars in the test file.
char l[LineReader::kMaxLineLen];
memset(l, 'a', sizeof(l));
ScopedTestFile file(l, sizeof(l));
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitData(l, sizeof(l)));
LineReader reader(file.GetFd());
const char* line;

View file

@ -35,33 +35,19 @@
#include "client/linux/minidump_writer/proc_cpuinfo_reader.h"
#include "breakpad_googletest_includes.h"
#include "common/linux/tests/auto_testfile.h"
#include "common/linux/scoped_tmpfile.h"
using namespace google_breakpad;
#if !defined(__ANDROID__)
#define TEMPDIR "/tmp"
#else
#define TEMPDIR "/data/local/tmp"
#endif
namespace {
typedef testing::Test ProcCpuInfoReaderTest;
class ScopedTestFile : public AutoTestFile {
public:
explicit ScopedTestFile(const char* text)
: AutoTestFile("proc_cpuinfo_reader", text) {
}
};
}
TEST(ProcCpuInfoReaderTest, EmptyFile) {
ScopedTestFile file("");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString(""));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -69,8 +55,8 @@ TEST(ProcCpuInfoReaderTest, EmptyFile) {
}
TEST(ProcCpuInfoReaderTest, OneLineTerminated) {
ScopedTestFile file("foo : bar\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("foo : bar\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -82,8 +68,8 @@ TEST(ProcCpuInfoReaderTest, OneLineTerminated) {
}
TEST(ProcCpuInfoReaderTest, OneLine) {
ScopedTestFile file("foo : bar");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("foo : bar"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -97,8 +83,8 @@ TEST(ProcCpuInfoReaderTest, OneLine) {
}
TEST(ProcCpuInfoReaderTest, TwoLinesTerminated) {
ScopedTestFile file("foo : bar\nzoo : tut\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("foo : bar\nzoo : tut\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -114,8 +100,8 @@ TEST(ProcCpuInfoReaderTest, TwoLinesTerminated) {
}
TEST(ProcCpuInfoReaderTest, SkipMalformedLine) {
ScopedTestFile file("this line should have a column\nfoo : bar\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("this line should have a column\nfoo : bar\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -127,8 +113,8 @@ TEST(ProcCpuInfoReaderTest, SkipMalformedLine) {
}
TEST(ProcCpuInfoReaderTest, SkipOneEmptyLine) {
ScopedTestFile file("\n\nfoo : bar\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("\n\nfoo : bar\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -140,8 +126,8 @@ TEST(ProcCpuInfoReaderTest, SkipOneEmptyLine) {
}
TEST(ProcCpuInfoReaderTest, SkipEmptyField) {
ScopedTestFile file(" : bar\nzoo : tut\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString(" : bar\nzoo : tut\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -153,8 +139,8 @@ TEST(ProcCpuInfoReaderTest, SkipEmptyField) {
}
TEST(ProcCpuInfoReaderTest, SkipTwoEmptyLines) {
ScopedTestFile file("foo : bar\n\n\nfoo : bar\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("foo : bar\n\n\nfoo : bar\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -170,8 +156,8 @@ TEST(ProcCpuInfoReaderTest, SkipTwoEmptyLines) {
}
TEST(ProcCpuInfoReaderTest, FieldWithSpaces) {
ScopedTestFile file("foo bar : zoo\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("foo bar : zoo\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;
@ -183,8 +169,8 @@ TEST(ProcCpuInfoReaderTest, FieldWithSpaces) {
}
TEST(ProcCpuInfoReaderTest, EmptyValue) {
ScopedTestFile file("foo :\n");
ASSERT_TRUE(file.IsOk());
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("foo :\n"));
ProcCpuInfoReader reader(file.GetFd());
const char* field;

View file

@ -0,0 +1,99 @@
// Copyright 2022 Google LLC
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Utility class for creating a temporary file that is deleted in the
// destructor.
#include "common/linux/scoped_tmpfile.h"
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "common/linux/eintr_wrapper.h"
#if !defined(__ANDROID__)
#define TEMPDIR "/tmp"
#else
#define TEMPDIR "/data/local/tmp"
#endif
namespace google_breakpad {
ScopedTmpFile::ScopedTmpFile() = default;
ScopedTmpFile::~ScopedTmpFile() {
if (fd_ >= 0) {
close(fd_);
fd_ = -1;
}
}
bool ScopedTmpFile::InitEmpty() {
// Prevent calling Init when fd_ is already valid, leaking the file.
if (fd_ != -1) {
return false;
}
// Respect the TMPDIR environment variable.
const char* tempdir = getenv("TMPDIR");
if (!tempdir) {
tempdir = TEMPDIR;
}
// Create a temporary file that is not linked in to the filesystem, and that
// is only accessible by the current user.
fd_ = open(tempdir, O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);
return fd_ >= 0;
}
bool ScopedTmpFile::InitString(const char* text) {
return InitData(text, strlen(text));
}
bool ScopedTmpFile::InitData(const void* data, size_t data_len) {
if (!InitEmpty()) {
return false;
}
return SetContents(data, data_len);
}
bool ScopedTmpFile::SetContents(const void* data, size_t data_len) {
ssize_t r = HANDLE_EINTR(write(fd_, data, data_len));
if (r != static_cast<ssize_t>(data_len)) {
return false;
}
return 0 == lseek(fd_, 0, SEEK_SET);
}
} // namespace google_breakpad

View file

@ -0,0 +1,85 @@
// Copyright 2022 Google LLC
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Utility class for creating a temporary file for that is deleted in the
// destructor.
#ifndef COMMON_LINUX_SCOPED_TMPFILE_H_
#define COMMON_LINUX_SCOPED_TMPFILE_H_
#include <string>
namespace google_breakpad {
// Small RAII wrapper for temporary files.
//
// Example:
// ScopedTmpFile tmp;
// if (tmp.Init("Some file contents")) {
// ...
// }
class ScopedTmpFile {
public:
// Initialize the ScopedTmpFile object - this does not create the temporary
// file until Init is called.
ScopedTmpFile();
// Destroy temporary file on scope exit.
~ScopedTmpFile();
// Creates the empty temporary file - returns true iff the temporary file was
// created successfully. Should always be checked before using the file.
bool InitEmpty();
// Creates the temporary file with the provided C string. The terminating null
// is not written. Returns true iff the temporary file was created
// successfully and the contents were written successfully.
bool InitString(const char* text);
// Creates the temporary file with the provided data. Returns true iff the
// temporary file was created successfully and the contents were written
// successfully.
bool InitData(const void* data, size_t data_len);
// Returns the Posix file descriptor for the test file, or -1 if Init()
// returned false. Note: on Windows, this always returns -1.
int GetFd() const {
return fd_;
}
private:
// Set the contents of the temporary file, and seek back to the start of the
// file. On failure, returns false.
bool SetContents(const void* data, size_t data_len);
int fd_ = -1;
};
} // namespace google_breakpad
#endif // COMMON_LINUX_SCOPED_TMPFILE_H_

View file

@ -0,0 +1,46 @@
// Copyright 2022 Google LLC
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// scoped_tmpfile_unittest.cc: Unit tests for google_breakpad::ScopedTmpfile.
#include "common/linux/scoped_tmpfile.h"
#include <unistd.h>
#include "breakpad_googletest_includes.h"
using google_breakpad::ScopedTmpFile;
TEST(ScopedTmpFileTest, CheckContentsMatch) {
ScopedTmpFile file;
ASSERT_TRUE(file.InitString("Test"));
char file_contents[5] = {0};
ASSERT_EQ(4, read(file.GetFd(), file_contents, sizeof(file_contents)));
EXPECT_STREQ(file_contents, "Test");
}

View file

@ -1,123 +0,0 @@
// Copyright 2013 Google LLC
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Utility class for creating a temporary file for unit tests
// that is deleted in the destructor.
#ifndef GOOGLE_BREAKPAD_COMMON_LINUX_TESTS_AUTO_TESTFILE
#define GOOGLE_BREAKPAD_COMMON_LINUX_TESTS_AUTO_TESTFILE
#include <unistd.h>
#include <sys/types.h>
#include <string>
#include "breakpad_googletest_includes.h"
#include "common/linux/eintr_wrapper.h"
#include "common/tests/auto_tempdir.h"
namespace google_breakpad {
class AutoTestFile {
public:
// Create a new empty test file.
// test_prefix: (input) test-specific prefix, can't be NULL.
explicit AutoTestFile(const char* test_prefix) {
Init(test_prefix);
}
// Create a new test file, and fill it with initial data from a C string.
// The terminating zero is not written.
// test_prefix: (input) test-specific prefix, can't be NULL.
// text: (input) initial content.
AutoTestFile(const char* test_prefix, const char* text) {
Init(test_prefix);
if (fd_ >= 0)
WriteText(text, static_cast<size_t>(strlen(text)));
}
AutoTestFile(const char* test_prefix, const char* text, size_t text_len) {
Init(test_prefix);
if (fd_ >= 0)
WriteText(text, text_len);
}
// Destroy test file on scope exit.
~AutoTestFile() {
if (fd_ >= 0) {
close(fd_);
fd_ = -1;
}
}
// Returns true iff the test file could be created properly.
// Useful in tests inside EXPECT_TRUE(file.IsOk());
bool IsOk() {
return fd_ >= 0;
}
// Returns the Posix file descriptor for the test file, or -1
// If IsOk() returns false. Note: on Windows, this always returns -1.
int GetFd() {
return fd_;
}
private:
void Init(const char* test_prefix) {
fd_ = -1;
char path_templ[PATH_MAX];
int ret = snprintf(path_templ, sizeof(path_templ),
TEMPDIR "/%s-unittest.XXXXXX",
test_prefix);
if (ret >= static_cast<int>(sizeof(path_templ)))
return;
fd_ = mkstemp(path_templ);
if (fd_ < 0)
return;
unlink(path_templ);
}
void WriteText(const char* text, size_t text_len) {
ssize_t r = HANDLE_EINTR(write(fd_, text, text_len));
if (r != static_cast<ssize_t>(text_len)) {
close(fd_);
fd_ = -1;
return;
}
lseek(fd_, 0, SEEK_SET);
}
int fd_;
};
} // namespace google_breakpad
#endif // GOOGLE_BREAKPAD_COMMON_LINUX_TESTS_AUTO_TESTFILE