<commit_before>/**
 * @file io_src_msg_test.c
 * @date 22 oct. 2012
 * @author <EMAIL>
 * @brief Unit tests for fixed length message sources
 *
 * Copyright (C) 2012 Parrot S.A.
 */

#include <unistd.h>
#include <fcntl.h>

#include <limits.h>
#include <stdbool.h>
#include <signal.h>
#include <stddef.h>

#include <CUnit/Basic.h>

#include <io_mon.h>
#include <io_src_msg.h>

#include <fautes.h>
#include <fautes_utils.h>

static void reached_state(int *glob_state, int state)
{
	*glob_state |= state;
}

struct msg {
	char a;
	int b;
	double c;
};

struct my_msg_src {
	struct msg msg;
	struct io_src_msg msg_src;
	int pipefds[2];
};

#define to_src_my_msg_src(p) container_of(p, struct my_msg_src, msg_src)

static void my_msg_src_clean(struct io_src_msg *msg)
{
	struct my_msg_src *my_src;

	my_src = to_src_my_msg_src(msg);

	/*
	 * don't close the source fd, it has been closed by the underlying
	 * source's clean callback
	 */
	if (!(msg->src.type & IO_IN))
		close(my_src->pipefds[0]);
	if (!(msg->src.type & IO_OUT))
		close(my_src->pipefds[1]);

	memset(&(my_src->msg), 0, sizeof(struct msg));
	my_src->pipefds[0] = my_src->pipefds[1] = -1;
}

static const struct msg MSG1 = {11, 11111, 11.111};
static const struct msg MSG2 = {22, 22222, 22.222};
static const struct msg MSG3 = {33, 33333, 33.333};
static const struct msg MSG4 = {44, 44444, 44.444};

#define STATE_START 0
#define STATE_MSG1_RECEIVED 1
#define STATE_MSG2_RECEIVED 2
#define STATE_MSG3_RECEIVED 4
#define STATE_MSG4_RECEIVED 8
#define STATE_ALL_DONE 15
int state;

/*<commit_msg>[DEVMINOR][src_msg_test] Set state static<commit_after>/**
 * @file io_src_msg_test.c
 * @date 22 oct. 2012
 * @author <EMAIL>
 * @brief Unit tests for fixed length message sources
 *
 * Copyright (C) 2012 Parrot S.A.
 */

#include <unistd.h>
#include <fcntl.h>

#include <limits.h>
#include <stdbool.h>
#include <signal.h>
#include <stddef.h>

#include <CUnit/Basic.h>

#include <io_mon.h>
#include <io_src_msg.h>

#include <fautes.h>
#include <fautes_utils.h>

static void reached_state(int *glob_state, int state)
{
	*glob_state |= state;
}

struct msg {
	char a;
	int b;
	double c;
};

struct my_msg_src {
	struct msg msg;
	struct io_src_msg msg_src;
	int pipefds[2];
};

#define to_src_my_msg_src(p) container_of(p, struct my_msg_src, msg_src)

static void my_msg_src_clean(struct io_src_msg *msg)
{
	struct my_msg_src *my_src;

	my_src = to_src_my_msg_src(msg);

	/*
	 * don't close the source fd, it has been closed by the underlying
	 * source's clean callback
	 */
	if (!(msg->src.type & IO_IN))
		close(my_src->pipefds[0]);
	if (!(msg->src.type & IO_OUT))
		close(my_src->pipefds[1]);

	memset(&(my_src->msg), 0, sizeof(struct msg));
	my_src->pipefds[0] = my_src->pipefds[1] = -1;
}

static const struct msg MSG1 = {11, 11111, 11.111};
static const struct msg MSG2 = {22, 22222, 22.222};
static const struct msg MSG3 = {33, 33333, 33.333};
static const struct msg MSG4 = {44, 44444, 44.444};

#define STATE_START 0
#define STATE_MSG1_RECEIVED 1
#define STATE_MSG2_RECEIVED 2
#define STATE_MSG3_RECEIVED 4
#define STATE_MSG4_RECEIVED 8
#define STATE_ALL_DONE 15
static int state;

/*
{'fraction_non_alphanumeric': 0.13782153064464908, 'fraction_numerical': 0.05080978088281994, 'mean_word_length': 4.595026642984014, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626815', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1300, 'n_words': 340}