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

tester fixes (now exits with the error count)

parent fa8605ac
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,9 @@
* Initializes each test, calls their reader function for each output of mojitos, and then finalizes them and prints the given result.
*
* @param execution object that has the arguments for mojitos as well as the tests to be performed.
* @returns 0 if everything passed, number of failed tests otherwise.
*/
void execute_test(Execution *execution)
int execute_test(Execution *execution)
{
for (int i = 0; i < execution->nb_testers; i++) {
Tester *tester = execution->testers + i;
......@@ -51,12 +52,17 @@ void execute_test(Execution *execution)
}
};
int result = 0;
int current_res = 0;
printf("Execution results : \n");
for (int i = 0; i < execution->nb_testers; i++) {
Tester *tester = execution->testers + i;
current_res = tester->finalize(tester->state, execution->context);
printf("- %s\n", tester->name);
printf("-> %s\n", tester->finalize(tester->state, execution->context) ? "Failed" : "Passed");
printf("-> %s\n", current_res ? "Passed" : "Failed");
result += (current_res == 0);
}
close(upstream[0]);
return result;
}
......@@ -14,7 +14,7 @@ typedef struct {
void *context; //Pointer to an object containing the context for this run (we can modify its content and then reuse the same Execution to run multiple test runs with the same tests.)
} Execution;
void execute_test(Execution *execution);
int execute_test(Execution *execution);
#define PRINT(__fmt, ...) \
......
......@@ -18,7 +18,7 @@ void test_initialize(void **state, void *context)
void test_read(void *state, void *context, const char *buffer, int nread)
{
printf("Out : %s", buffer);
//printf("Out : %s", buffer);
if (nread < BUFFER_SIZE) {
((TestState *)state)->number += 1;
}
......
......@@ -57,7 +57,7 @@ void timing_reader(void* state, void* context, const char* buffer, int nread){
//buffer contains a line
tstate->count++;
}
printf("Out : %s", buffer);
//printf("Out : %s", buffer);
}
int timing_finalize(void* state, void* context){
......@@ -84,7 +84,7 @@ int calc_expected_result(TimingExecutionArgs* args){
/**
* @brief Performs all the timing related tests.
*/
void timing_test(){
int timing_test(){
Tester tester = {
.init = timing_init,
.read = timing_reader,
......@@ -103,11 +103,13 @@ void timing_test(){
.args = args,
};
int result = 0;
for (unsigned int i = 0; i < ARRAY_LENGTH(timingExecutionsArgs); i++){
TimingExecutionArgs current_values = timingExecutionsArgs[i];
args[2] = current_values.duration;
args[4] = current_values.frequency;
((TimingContext*)execution.context)->expected_result = calc_expected_result(&current_values);
execute_test(&execution);
result += execute_test(&execution);
}
return result;
}
\ No newline at end of file
#pragma once
void timing_test();
\ No newline at end of file
int timing_test();
\ No newline at end of file
......@@ -14,9 +14,9 @@ char path[] = "../bin/mojitos";
int main(int argc, char const *argv[])
{
int errors = 0;
//test_test();
errors += timing_test();
test_test();
timing_test();
return 0;
return errors;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment