Blame tests/hello/hello.c

Packit c04fcb
/*
Packit c04fcb
 * Copyright (C) 2009  Pierre-Marc Fournier
Packit c04fcb
 * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Packit c04fcb
 *
Packit c04fcb
 * This library is free software; you can redistribute it and/or
Packit c04fcb
 * modify it under the terms of the GNU Lesser General Public
Packit c04fcb
 * License as published by the Free Software Foundation; version 2.1 of
Packit c04fcb
 * the License.
Packit c04fcb
 *
Packit c04fcb
 * This library is distributed in the hope that it will be useful,
Packit c04fcb
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c04fcb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit c04fcb
 * Lesser General Public License for more details.
Packit c04fcb
 *
Packit c04fcb
 * You should have received a copy of the GNU Lesser General Public
Packit c04fcb
 * License along with this library; if not, write to the Free Software
Packit c04fcb
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
Packit c04fcb
 */
Packit c04fcb
Packit c04fcb
#include <stdio.h>
Packit c04fcb
#include <unistd.h>
Packit c04fcb
#include <sys/mman.h>
Packit c04fcb
#include <stdarg.h>
Packit c04fcb
#include <sys/types.h>
Packit c04fcb
#include <sys/stat.h>
Packit c04fcb
#include <fcntl.h>
Packit c04fcb
#include <signal.h>
Packit c04fcb
#include <string.h>
Packit c04fcb
/*
Packit c04fcb
 * Work-around inet.h missing struct mmsghdr forward declaration, with
Packit c04fcb
 * triggers a warning when system files warnings are enabled.
Packit c04fcb
 */
Packit c04fcb
struct mmsghdr;
Packit c04fcb
#include <arpa/inet.h>
Packit c04fcb
#include <stdlib.h>
Packit c04fcb
#include <stdbool.h>
Packit c04fcb
Packit c04fcb
#define TRACEPOINT_DEFINE
Packit c04fcb
#include "ust_tests_hello.h"
Packit c04fcb
Packit c04fcb
void inthandler(int sig)
Packit c04fcb
{
Packit c04fcb
	printf("in SIGUSR1 handler\n");
Packit c04fcb
	tracepoint(ust_tests_hello, tptest_sighandler);
Packit c04fcb
}
Packit c04fcb
Packit c04fcb
int init_int_handler(void)
Packit c04fcb
{
Packit c04fcb
	int result;
Packit c04fcb
	struct sigaction act;
Packit c04fcb
Packit c04fcb
	memset(&act, 0, sizeof(act));
Packit c04fcb
	result = sigemptyset(&act.sa_mask);
Packit c04fcb
	if (result == -1) {
Packit c04fcb
		perror("sigemptyset");
Packit c04fcb
		return -1;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	act.sa_handler = inthandler;
Packit c04fcb
	act.sa_flags = SA_RESTART;
Packit c04fcb
Packit c04fcb
	/* Only defer ourselves. Also, try to restart interrupted
Packit c04fcb
	 * syscalls to disturb the traced program as little as possible.
Packit c04fcb
	 */
Packit c04fcb
	result = sigaction(SIGUSR1, &act, NULL);
Packit c04fcb
	if (result == -1) {
Packit c04fcb
		perror("sigaction");
Packit c04fcb
		return -1;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	return 0;
Packit c04fcb
}
Packit c04fcb
Packit c04fcb
void test_inc_count(void);
Packit c04fcb
Packit c04fcb
int main(int argc, char **argv)
Packit c04fcb
{
Packit c04fcb
	int i, netint;
Packit c04fcb
	long values[] = { 1, 2, 3 };
Packit c04fcb
	char text[10] = "test";
Packit c04fcb
	double dbl = 2.0;
Packit c04fcb
	float flt = 2222.0;
Packit c04fcb
	int delay = 0;
Packit c04fcb
	bool mybool = 123;	/* should print "1" */
Packit c04fcb
Packit c04fcb
	init_int_handler();
Packit c04fcb
Packit c04fcb
	if (argc == 2)
Packit c04fcb
		delay = atoi(argv[1]);
Packit c04fcb
Packit c04fcb
	fprintf(stderr, "Hello, World!\n");
Packit c04fcb
Packit c04fcb
	sleep(delay);
Packit c04fcb
Packit c04fcb
	fprintf(stderr, "Tracing... ");
Packit c04fcb
	for (i = 0; i < 1000000; i++) {
Packit c04fcb
		netint = htonl(i);
Packit c04fcb
		tracepoint(ust_tests_hello, tptest, i, netint, values,
Packit c04fcb
			   text, strlen(text), dbl, flt, mybool);
Packit c04fcb
		//usleep(100000);
Packit c04fcb
	}
Packit c04fcb
	fprintf(stderr, " done.\n");
Packit c04fcb
	return 0;
Packit c04fcb
}