Skip to content
Snippets Groups Projects
Commit 31839efc authored by TwilCynder's avatar TwilCynder
Browse files

format

parent 51a13ed4
Branches
No related tags found
No related merge requests found
......@@ -4,9 +4,10 @@
#include <unistd.h>
#include <stdlib.h>
void execute_test(Execution* execution){
for (int i = 0; i < execution->nb_testers; i++){
Tester* tester = execution->testers + i;
void execute_test(Execution *execution)
{
for (int i = 0; i < execution->nb_testers; i++) {
Tester *tester = execution->testers + i;
tester->init(&tester->state, execution->context);
}
......@@ -17,15 +18,15 @@ void execute_test(Execution* execution){
pipe(upstream);
int res = fork();
if (res == 0){
// close and duplicate stdin/stdout from pipe
if (res == 0) {
// close and duplicate stdin/stdout from pipe
dup2(downstream[0], STDIN_FILENO);
dup2(upstream[1], STDOUT_FILENO);
if(execv(execution->args[0], execution->args)){
if(execv(execution->args[0], execution->args)) {
perror("Impossible de lancer le process mojitos");
}
} else if (res == -1){
} else if (res == -1) {
perror("Impossible d'initialiser le processus de lancement.");
exit(1);
}
......@@ -37,16 +38,16 @@ void execute_test(Execution* execution){
char buffer[BUFFER_SIZE];
int nread ;
while ( (nread=read(upstream[0], buffer, sizeof(buffer)-1)) > 0) {
buffer[nread] = 0 ;
for (int i = 0; i < execution->nb_testers; i++){
Tester* tester = execution->testers + i;
buffer[nread] = 0 ;
for (int i = 0; i < execution->nb_testers; i++) {
Tester *tester = execution->testers + i;
tester->read(tester->state, execution->context, buffer, nread);
}
};
printf("Execution results : \n");
for (int i = 0; i < execution->nb_testers; i++){
Tester* tester = execution->testers + i;
for (int i = 0; i < execution->nb_testers; i++) {
Tester *tester = execution->testers + i;
printf("- %s\n", tester->name);
printf("-> %s\n", tester->finalize(tester->state, execution->context) ? "Failed" : "Passed");
}
......
......@@ -5,15 +5,14 @@
extern char path[];
typedef struct {
char*const* args;
Tester* testers;
char *const *args;
Tester *testers;
int nb_testers;
void* context;
void *context;
} Execution;
void execute_test(Execution* execution);
void execute_test(Execution *execution);
#define PRINT(__fmt, ...) \
printf("-> "); \
printf(__fmt, ##__VA_ARGS__);
\ No newline at end of file
......@@ -9,27 +9,30 @@
#include "executions/timing.h"
char*const e1args[] = {path, "-f", "3", "-t", "3", 0};
char *const e1args[] = {path, "-f", "3", "-t", "3", 0};
typedef struct {
int number;
} TestState;
void test_initialize(void** state, void* context){
TestState* newtstate = (TestState*) malloc(sizeof(TestState));
void test_initialize(void **state, void *context)
{
TestState *newtstate = (TestState *) malloc(sizeof(TestState));
newtstate->number = 100;
*state = (void*) newtstate;
*state = (void *) newtstate;
}
void test_read(void* state, void* context, const char* buffer, int nread){
void test_read(void *state, void *context, const char *buffer, int nread)
{
printf("Out : %s", buffer);
if (nread < BUFFER_SIZE){
((TestState*)state)->number += 1;
if (nread < BUFFER_SIZE) {
((TestState *)state)->number += 1;
}
}
int test_finalize(void* state, void* context){
return ((TestState*)state)->number;
int test_finalize(void *state, void *context)
{
return ((TestState *)state)->number;
}
char path[] = "../bin/mojitos";
......
#pragma once
typedef void(*TesterInit)(void** state, void* context);
typedef void(*TesterReader)(void* state, void* context, const char* buffer, int read_size);
typedef int(*TesterFinalizer)(void* state, void* context);
typedef void(*TesterInit)(void **state, void *context);
typedef void(*TesterReader)(void *state, void *context, const char *buffer, int read_size);
typedef int(*TesterFinalizer)(void *state, void *context);
typedef struct {
TesterInit init;
TesterReader read;
TesterFinalizer finalize;
void* state;
const char* name;
void *state;
const char *name;
} Tester;
\ No newline at end of file
#pragma once
///
#define ARRAY_LENGTH(array) sizeof(array) / sizeof(*array)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment