Skip to content
Snippets Groups Projects
Commit 6759b0ae authored by TwilCynder's avatar TwilCynder
Browse files

test architecture wip

parent ab5ef5f1
Branches
Tags
No related merge requests found
#include "execution.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#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;
tester->init(&tester->state);
}
#define BUFFER_SIZE 100
int main(int argc, char const *argv[])
{
int downstream[2];
int upstream[2];
pipe(downstream);
pipe(upstream);
if (fork() == 0){
//child
close(upstream[0]);
close(downstream[1]);
int res = fork();
if (res == 0){
// close and duplicate stdin/stdout from pipe
dup2(downstream[0], STDIN_FILENO);
dup2(upstream[1], STDOUT_FILENO);
char *args[] = {"../bin/mojitos/", "-t", "3", "-f", "10", "-u", NULL};
printf("Executing %s\n", args[0]);
printf("Executing %s\n", execution->args[0]);
execv(args[0], args);
exit(0);
if(execv(execution->args[0], execution->args)){
perror("Impossible de lancer le process mojitos");
}
} else if (res == -1){
perror("Impossible d'initialiser le processus de lancement.");
exit(1);
}
close(upstream[1]);
......@@ -38,10 +39,16 @@ int main(int argc, char const *argv[])
char buffer[BUFFER_SIZE];
int nread ;
while ( (nread=read(upstream[0], buffer, sizeof(buffer)-1)) > 0) {
buffer[nread] = 0 ; // NUL terminator.
printf("Out : %s\n", buffer);
} ;
exit(0);
return 0;
}
buffer[nread] = 0 ;
for (int i = 0; i < execution->nb_testers; i++){
Tester* tester = execution->testers + i;
tester->read(tester->state, buffer, nread);
}
};
printf("Execution results : ");
for (int i = 0; i < execution->nb_testers; i++){
Tester* tester = execution->testers + i;
printf("| %s : %d\n", tester->name, tester->finalize(tester->state));
}
}
\ No newline at end of file
#include "tester.h"
#define BUFFER_SIZE 128
extern char path[];
typedef struct {
char*const* args;
Tester* testers;
int nb_testers;
} Execution;
void execute_test(Execution* execution);
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include "tester.h"
#include "execution.h"
char*const e1args[] = {path, "-f", "3", "-t", "3", 0};
typedef struct {
int number;
} TestState;
void test_initialize(void** state){
TestState* newtstate = (TestState*) malloc(sizeof(TestState));
newtstate->number = 100;
*state = (void*) newtstate;
}
void test_read(void* state, const char* buffer, int nread){
printf("Out : %s", buffer);
if (nread < BUFFER_SIZE){
((TestState*)state)->number += 1;
}
}
int test_finalize(void* state){
printf("N : %d", ((TestState*)state)->number);
return 0;
}
char path[] = "../bin/mojitos";
int main(int argc, char const *argv[])
{
Tester test_tester = {
.init = test_initialize,
.read = test_read,
.finalize = test_finalize,
.name = "Test"
};
Execution e1 = {
.args = e1args,
.testers = &test_tester,
.nb_testers = 1
};
execute_test(&e1);
return 0;
}
#pragma once
typedef void(*TesterInit)(void** state);
typedef void(*TesterReader)(void* state, const char* buffer, int read_size);
typedef int(*TesterFinalizer)(void* state);
typedef struct {
TesterInit init;
TesterReader read;
TesterFinalizer finalize;
void* state;
const char* name;
} Tester;
\ 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