Add unit test binaries, and move Apple's tests to a 'regression' subdirectory.
This commit is contained in:
Родитель
0545e62f6d
Коммит
697d8e9529
|
@ -0,0 +1,57 @@
|
|||
DEVELOPER?= $(shell xcode-select -print-path)
|
||||
PLATFORMS?= $(DEVELOPER)/Platforms/
|
||||
CFLAGS?= -Os -std=c99
|
||||
LDFLAGS?= -dynamiclib
|
||||
|
||||
DEVICE_SDK?= iPhoneOS6.1
|
||||
DEVICE_PLATFORM?= $(PLATFORMS)/iPhoneOS.platform
|
||||
DEVICE_ROOT?= $(DEVICE_PLATFORM)/Developer/SDKs/$(DEVICE_SDK).sdk
|
||||
DEVICE_CC?= $(shell xcrun -sdk `echo ${DEVICE_SDK} | tr '[A-Z]' '[a-z]'` -f clang)
|
||||
DEVICE_CFLAGS?= -arch armv7 -arch armv7s -isysroot "$(DEVICE_ROOT)" -gdwarf-2 -miphoneos-version-min=3.0 $(CFLAGS)
|
||||
|
||||
SIM_SDK?= iPhoneSimulator6.1
|
||||
SIM_PLATFORM?= $(PLATFORMS)/iPhoneSimulator.platform
|
||||
SIM_ROOT?= $(SIM_PLATFORM)/Developer/SDKs/$(SIM_SDK).sdk
|
||||
SIM_CC?= $(shell xcrun -sdk `echo ${SIM_SDK} | tr '[A-Z]' '[a-z]'` -f clang)
|
||||
SIM_CFLAGS?= -arch i386 -isysroot "$(SIM_ROOT)" -mmacosx-version-min=10.6 -gdwarf-2 $(CFLAGS)
|
||||
|
||||
MAC_SDK?= MacOSX10.8
|
||||
MAC_PLATFORM?= $(PLATFORMS)/MacOSX.platform
|
||||
MAC_ROOT?= $(MAC_PLATFORM)/Developer/SDKs/$(MAC_SDK).sdk
|
||||
MAC_CC?= $(shell xcrun -sdk `echo ${MAC_SDK} | tr '[A-Z]' '[a-z]'` -f clang)
|
||||
MAC_CFLAGS?= -arch x86_64 -arch i386 -isysroot "$(MAC_ROOT)" -mmacosx-version-min=10.6 -gdwarf-2 $(CFLAGS)
|
||||
|
||||
IOS_OBJS= test-ios.o
|
||||
SIM_OBJS= test-sim.o
|
||||
MAC_OBJS= test-macosx.o
|
||||
|
||||
PRODUCTS= $(IOS_PRODUCT) $(MAC_PRODUCT) $(SIM_PRODUCT)
|
||||
IOS_PRODUCT= test.ios
|
||||
SIM_PRODUCT= test.sim
|
||||
MAC_PRODUCT= test.macosx
|
||||
|
||||
all: $(PRODUCTS)
|
||||
|
||||
test-sim.o: test.c
|
||||
$(SIM_CC) $(SIM_CFLAGS) -c $< -o $@
|
||||
|
||||
test-ios.o: test.c
|
||||
$(DEVICE_CC) $(DEVICE_CFLAGS) -c $< -o $@
|
||||
|
||||
test-macosx.o: test.c
|
||||
$(MAC_CC) $(MAC_CFLAGS) -c $< -o $@
|
||||
|
||||
$(MAC_PRODUCT): $(MAC_OBJS)
|
||||
$(MAC_CC) $(LDFLAGS) $(MAC_CFLAGS) $+ -o $@
|
||||
|
||||
$(IOS_PRODUCT): $(IOS_OBJS)
|
||||
$(DEVICE_CC) $(LDFLAGS) $(DEVICE_CFLAGS) $+ -o $@
|
||||
|
||||
$(SIM_PRODUCT): $(SIM_OBJS)
|
||||
$(SIM_CC) $(LDFLAGS) $(SIM_CFLAGS) $+ -o $@
|
||||
|
||||
clean-objs:
|
||||
rm -f $(IOS_OBJS) $(MAC_OBJS) $(SIM_OBJS)
|
||||
|
||||
clean: clean-objs
|
||||
rm -f $(PRODUCTS)
|
|
@ -1,7 +1,8 @@
|
|||
These test cases where extracted from Apple's libunwind-35.1, where they
|
||||
The regression test cases were extracted from Apple's libunwind-35.1, where they
|
||||
are used to validate Apple's compact frame and dwarf unwinding implementation.
|
||||
|
||||
A custom build script (build.sh) may be used to regenerate the test binaries.
|
||||
A custom build script (build-regression-tests.sh) may be used to regenerate
|
||||
the test binaries.
|
||||
|
||||
The test cases themselves are licensed under libunwind's license:
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ process() {
|
|||
local opts=`echo $2`
|
||||
local count=$3
|
||||
|
||||
eval cc -o bins/tbin.$file.${count} ${file} ${opts}
|
||||
eval cc -o regression-bins/tbin.$file.${count} ${file} ${opts}
|
||||
}
|
||||
|
||||
main() {
|
||||
|
@ -41,7 +41,7 @@ main() {
|
|||
|
||||
IFS=$ifs_nl
|
||||
local count="1"
|
||||
for opt in `grep -H "TEST-OPTIONS:" *.s`; do
|
||||
for opt in `grep -H "TEST-OPTIONS:" regression/*.s`; do
|
||||
IFS=$ifs_back
|
||||
local fname=`echo "${opt}" | awk -F : '{print $1}'`
|
||||
local opts=`echo "${opt}" | cut -d ' ' -f 3-`
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdint.h>
|
||||
|
||||
// TODO
|
||||
uint32_t ef __attribute__((section("__PL_DWARF,__eh_frame"))) = {
|
||||
0
|
||||
};
|
||||
|
||||
uint32_t df __attribute__((section("__PL_DWARF,__debug_frame"))) = {
|
||||
0
|
||||
};
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -26,4 +26,53 @@
|
|||
|
||||
#include "PLCrashAsyncDwarfEncoding.h"
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @ingroup plcrash_async
|
||||
* @defgroup plcrash_async_dwarf DWARF
|
||||
*
|
||||
* Implements async-safe parsing of DWARF encodings.
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Initialize a new DWARF frame reader using the provided memory object. Any resources held by a successfully initialized
|
||||
* instance must be freed via plcrash_async_dwarf_frame_reader_free();
|
||||
*
|
||||
* @param reader The reader instance to initialize.
|
||||
* @param mobj The memory object containing frame data (eh_frame or debug_frame) at the start address. This instance must
|
||||
* survive for the lifetime of the reader.
|
||||
* @param cpu_type The target architecture of the CFE data, encoded as a Mach-O CPU type. Interpreting CFE data is
|
||||
* architecture-specific, and Apple has not defined encodings for all supported architectures.
|
||||
*/
|
||||
plcrash_error_t plcrash_async_dwarf_frame_reader_init (plcrash_async_dwarf_frame_reader_t *reader, plcrash_async_mobject_t *mobj, cpu_type_t cputype) {
|
||||
// TODO
|
||||
return PLCRASH_EUNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate the frame descriptor entry for @a pc, if available.
|
||||
*
|
||||
* @param reader The initialized frame reader which will be searched for the entry.
|
||||
* @param pc The PC value to search for within the frame data. Note that this value must be relative to
|
||||
* the target Mach-O image's __TEXT vmaddr.
|
||||
*
|
||||
* @return Returns PLFRAME_ESUCCCESS on success, or one of the remaining error codes if a DWARF parsing error occurs. If
|
||||
* the entry can not be found, PLFRAME_ENOTFOUND will be returned.
|
||||
*/
|
||||
plcrash_error_t plcrash_async_dwarf_frame_reader_find_fde (plcrash_async_dwarf_frame_reader_t *reader, pl_vm_address_t pc) {
|
||||
// TODO
|
||||
return PLCRASH_EUNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free all resources associated with @a reader.
|
||||
*/
|
||||
void plcrash_async_dwarf_frame_reader_free (plcrash_async_dwarf_frame_reader_t *reader) {
|
||||
// noop
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -31,5 +31,43 @@
|
|||
#include "PLCrashAsyncImageList.h"
|
||||
#include "PLCrashAsyncThread.h"
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @ingroup plcrash_async_dwarf
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* A DWARF frame reader instance. Performs DWARF eh_frame/debug_frame parsing from a backing memory object.
|
||||
*/
|
||||
typedef struct plcrash_async_dwarf_frame_reader {
|
||||
/** A memory object containing the DWARF data at the starting address. */
|
||||
plcrash_async_mobject_t *mobj;
|
||||
|
||||
/** The target CPU type. */
|
||||
cpu_type_t cpu_type;
|
||||
|
||||
/** The byte order of the encoded data. */
|
||||
const plcrash_async_byteorder_t *byteorder;
|
||||
} plcrash_async_dwarf_frame_reader_t;
|
||||
|
||||
|
||||
/**
|
||||
* DWARF Frame Descriptor Entry.
|
||||
*/
|
||||
typedef struct plcrash_async_dwarf_fde {
|
||||
} plcrash_async_dwarf_fde_t;
|
||||
|
||||
|
||||
plcrash_error_t plcrash_async_dwarf_frame_reader_init (plcrash_async_dwarf_frame_reader_t *reader, plcrash_async_mobject_t *mobj, cpu_type_t cputype);
|
||||
|
||||
plcrash_error_t plcrash_async_dwarf_frame_reader_find_fde (plcrash_async_dwarf_frame_reader_t *reader, pl_vm_address_t pc);
|
||||
|
||||
void plcrash_async_dwarf_frame_reader_free (plcrash_async_dwarf_frame_reader_t *reader);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* PLCRASH_ASYNC_DWARF_ENCODING_H */
|
|
@ -30,22 +30,61 @@
|
|||
|
||||
#include "PLCrashAsyncDwarfEncoding.h"
|
||||
|
||||
#if TARGET_OS_MAC && (!TARGET_OS_IPHONE)
|
||||
# define TEST_BINARY @"test.macosx"
|
||||
#elif TARGET_IPHONE_SIMULATOR
|
||||
# define TEST_BINARY @"test.sim"
|
||||
#elif TARGET_OS_IPHONE
|
||||
# define TEST_BINARY @"test.ios"
|
||||
#else
|
||||
# error Unsupported target
|
||||
#endif
|
||||
|
||||
@interface PLCrashAsyncDwarfEncodingTests : PLCrashTestCase {
|
||||
plcrash_async_macho_t _image;
|
||||
plcrash_async_mobject_t _eh_frame;
|
||||
plcrash_async_mobject_t _debug_frame;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation PLCrashAsyncDwarfEncodingTests
|
||||
|
||||
- (void) setUp {
|
||||
|
||||
NSError *error;
|
||||
plcrash_error_t err;
|
||||
|
||||
/* Map and load the binary */
|
||||
NSData *mappedImage = [self nativeBinaryFromTestResource: TEST_BINARY];
|
||||
STAssertNotNil(mappedImage, @"Failed to map image: %@", error);
|
||||
|
||||
err = plcrash_nasync_macho_init(&_image, mach_task_self(), [TEST_BINARY UTF8String], [mappedImage bytes]);
|
||||
STAssertEquals(err, PLCRASH_ESUCCESS, @"Failed to initialize Mach-O parser");
|
||||
|
||||
/* Map the eh/debug frame sections. We use our own fake __PL_DWARF segment to avoid toolchain interference with our test data. */
|
||||
err = plcrash_async_macho_map_section(&_image, "__PL_DWARF", "__eh_frame", &_eh_frame);
|
||||
STAssertEquals(err, PLCRASH_ESUCCESS, @"Failed to map __eh_frame section");
|
||||
|
||||
err = plcrash_async_macho_map_section(&_image, "__PL_DWARF", "__debug_frame", &_debug_frame);
|
||||
STAssertEquals(err, PLCRASH_ESUCCESS, @"Failed to map __debug_frame section");
|
||||
}
|
||||
|
||||
- (void) tearDown {
|
||||
|
||||
plcrash_async_mobject_free(&_eh_frame);
|
||||
plcrash_async_mobject_free(&_debug_frame);
|
||||
plcrash_nasync_macho_free(&_image);
|
||||
}
|
||||
|
||||
- (void) testSomething {
|
||||
- (void) testFindFrameDescriptorEntry {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the Apple unwind regression tests.
|
||||
*/
|
||||
- (void) testRegression {
|
||||
// TODO;
|
||||
return;
|
||||
|
||||
NSError *error;
|
||||
plcrash_error_t err;
|
||||
|
||||
|
@ -82,7 +121,19 @@
|
|||
STAssertEquals(err, PLCRASH_ESUCCESS, @"Failed to map __debug_frame section for %@", tcase);
|
||||
has_debug_frame = YES;
|
||||
}
|
||||
|
||||
/* Smoke test the FDE parser */
|
||||
cpu_type_t cpu_type = plcrash_async_macho_cpu_type(&image);
|
||||
// TODO
|
||||
if (has_eh_frame) {
|
||||
plcrash_async_dwarf_frame_reader_t reader;
|
||||
plcrash_async_dwarf_frame_reader_init(&reader, &eh_frame, cpu_type);
|
||||
}
|
||||
|
||||
if (has_debug_frame) {
|
||||
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
if (has_eh_frame)
|
||||
plcrash_async_mobject_free(&eh_frame);
|
||||
|
|
Загрузка…
Ссылка в новой задаче