git » libfiu » master » tree

[master] / tests / test-enable_stack.c

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include <fiu.h>
#include <fiu-control.h>

int __attribute__ ((noinline)) func1()
{
	/*
	int nptrs;
	void *buffer[100];
	nptrs = backtrace(buffer, 100);
	backtrace_symbols_fd(buffer, nptrs, 1);
	*/

	return fiu_fail("fp-1") != 0;
}

int __attribute__ ((noinline)) func2()
{
	return func1();
}


int main(void)
{
	int r;

	fiu_init(0);
	r = fiu_enable_stack("fp-1", 1, NULL, 0, (void *) &func2, -1);
	if (r != 0) {
		printf("NOTE: fiu_enable_stack() failed, skipping test\n");
		return 0;
	}

	assert(func1() == 0);
	assert(func2() == 1);

	fiu_disable("fp-1");

	assert(func1() == 0);
	assert(func2() == 0);

	return 0;
}