/*
 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <autoconf.h>
#include <sel4test/gen_config.h>

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <sel4test/test.h>
#include <sel4test/testutil.h>

#include <utils/util.h>

/* buffer for test stdout size */
#define STDOUT_CACHE 50000


/* buffer stdout here during a test if we're outputting xml */
static char current_stdout_bank[STDOUT_CACHE];
/* index we are up to in the buffer */
static int buf_index = 0;
/* is the buffer currently enabled? otherwise just printf */
static bool do_buffer_printf = false;

/* global to track if the current test has passed */
static test_result_t current_test_result = SUCCESS;

#undef printf
void sel4test_printf(const char *string)
{
    if (!do_buffer_printf) {
        printf("%s", string);
    } else if (buf_index < STDOUT_CACHE && buf_index >= 0) {
        size_t len = STDOUT_CACHE - buf_index;
        snprintf(current_stdout_bank + buf_index, len, "%s", string);
        /* NULL terminate the destination in case 'string' was too long. */
        current_stdout_bank[STDOUT_CACHE - 1] = '\0';
        buf_index += strlen(string);
    }
}

void sel4test_start_printf_buffer(void)
{
    /* only enable the printf buffer if we are buffering output */
    if (config_set(CONFIG_PRINT_XML)) {
        buf_index = 0;
        do_buffer_printf = true;
    }
}

void sel4test_end_printf_buffer(void)
{
    do_buffer_printf = false;
    if (buf_index != 0) {
        printf("\t\t<system-out>%s</system-out>\n", current_stdout_bank);
        buf_index = 0;
    }

}

void _sel4test_report_error(const char *error, const char *file, int line)
{
    if (config_set(CONFIG_PRINT_XML)) {
        printf("\t\t<error>%s at line %d of file %s</error>\n", error, line, file);
    } else {
        printf("\tError: %s at line %d of file %s\n", error, line, file);
    }
    current_test_result = FAILURE;
}

void _sel4test_failure(const char *failure, const char *file, int line)
{
    if (config_set(CONFIG_PRINT_XML)) {
        printf("\t\t<failure type=\"failure\">%s at line %d of file %s</failure>\n", failure, line, file);
    } else {
        printf("\tFailure: %s at line %d of file %s\n", failure, line, file);
    }
    current_test_result = FAILURE;
}

void _sel4test_abort(const char *failure, const char *file, int line)
{
    if (config_set(CONFIG_PRINT_XML)) {
        printf("\t\t<failure type=\"failure\">%s at line %d of file %s</failure>\n", failure, line, file);
    } else {
        printf("\tFailure: %s at line %d of file %s\n", failure, line, file);
    }
    current_test_result = ABORT;
}

void sel4test_reset(void)
{
    current_test_result = SUCCESS;

#ifdef CONFIG_ENABLE_BENCHMARKS
    seL4_BenchmarkResetLog();
#endif /* CONFIG_ENABLE_BENCHMARKS */
}

test_result_t sel4test_get_result(void)
{
    return current_test_result;
}
