/*
 * Copyright 2017, Data61
 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
 * ABN 41 687 119 230.
 *
 * This software may be distributed and modified according to the terms of
 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
 * See "LICENSE_BSD2.txt" for details.
 *
 * @TAG(DATA61_BSD)
 */

#pragma once

/* Include Kconfig variables. */
#include <autoconf.h>
#include <sel4test/gen_config.h>

#include <sel4/sel4.h>

#include <utils/attribute.h>
#include <sel4test/testutil.h>
#include <vka/vka.h>
#include <vspace/vspace.h>
#include <sel4platsupport/timer.h>
#include <sync/mutex.h>
#include <sel4utils/elf.h>
#include <sel4rpc/client.h>

#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

/* max test name size */
#define TEST_NAME_MAX (64 - 4 * sizeof(seL4_Word))

#define MAX_REGIONS 4

/* Contains information about the test environment for regular tests, bootstrap tests do
 * not use this environment */
struct env {
    /* An initialised vka that may be used by the test. */
    vka_t vka;
    /* virtual memory management interface */
    vspace_t vspace;
    /* abstract interface over application init */
    simple_t simple;
    /* notification for timer */
    vka_object_t timer_notification;
    /* RPC client for serial server resource allocation */
    sel4rpc_client_t rpc_client;

    /* caps for the current process */
    seL4_CPtr cspace_root;
    seL4_CPtr page_directory;
    seL4_CPtr endpoint;
    seL4_CPtr tcb;
    seL4_CPtr timer_untyped;
    seL4_CPtr asid_pool;
    seL4_CPtr asid_ctrl;
    seL4_CPtr sched_ctrl;
#ifdef CONFIG_IOMMU
    seL4_CPtr io_space;
#endif /* CONFIG_IOMMU */
#ifdef CONFIG_ARM_SMMU
    seL4_SlotRegion io_space_caps;
#endif
    seL4_Word cores;
    seL4_CPtr domain;
    seL4_CPtr device_frame;

    int priority;
    int cspace_size_bits;
    int num_regions;
    sel4utils_elf_region_t regions[MAX_REGIONS];
};
typedef struct env *env_t;

/* Prototype of a test function. Returns false on failure. */
typedef int (*test_fn)(uintptr_t environment);

/* Test type definitions. */
typedef enum test_type_name {BOOTSTRAP = 0, BASIC} test_type_name_t;
typedef struct testcase testcase_t; // Forward type declaration.
typedef struct test_type {
    /* Represents a single test type. See comment for `struct testcase` for info about ALIGN(32). */
    const char *name;
    test_type_name_t id;
    // Function called before and after all the tests for this test type have been run.
    void (*set_up_test_type)(uintptr_t e);
    void (*tear_down_test_type)(uintptr_t e);
    // Function called before and after each test for this test type.
    void (*set_up)(uintptr_t e);
    void (*tear_down)(uintptr_t e);
    // Run the test. Different tests take different environments
    test_result_t (*run_test)(struct testcase *test, uintptr_t e);
} ALIGN(32) test_type_t;

/* Declare a test type.
 * For now, we put the test types in a separate elf section. */
#define DEFINE_TEST_TYPE(_name, _id, _set_up_test_type, _tear_down_test_type, _set_up, _tear_down, _run_test) \
    __attribute__((used)) __attribute__((section("_test_type"))) struct test_type TEST_TYPE_ ##_name = { \
    .name = #_name, \
    .id = _id, \
    .set_up_test_type = _set_up_test_type, \
    .tear_down_test_type = _tear_down_test_type, \
    .set_up = _set_up, \
    .tear_down = _tear_down, \
    .run_test = _run_test, \
};

/* Represents a single testcase.
 * Because this struct is used to declare variables that get
 * placed into custom sections, that we later treat as an array,
 * we need to make sure the struct is aligned and filled to the
 * nearest power of two to avoid gcc placing arbitrary padding between them.
 *
 * The declaration below ensures that the actual size of
 * the objects in the section is the same as the size reported
 * by sizeof(struct testcase), allowing as to treat the items
 * in the section as an array */
struct testcase {
    char name[TEST_NAME_MAX];
    const char *description;
    test_fn function;
    seL4_Word test_type;
    seL4_Word enabled;
} PACKED;
typedef struct testcase ALIGN(sizeof(struct testcase)) testcase_t;

/* Declare a testcase.
 * Must be declared using C89 style (#_name, _desc, _func...) instead of
 * C99 style (name = _name, desc = _desc, func = _func...) to make sure
 * that it is accepted by C++ compilers.
 */
#define DEFINE_TEST_WITH_TYPE(_name, _description, _function, _test_type, _enabled) \
    __attribute__((used)) __attribute__((section("_test_case"))) struct testcase TEST_ ## _name = { \
    #_name, \
    _description, \
    (test_fn)_function, \
    _test_type, \
    _enabled, \
};

#define DEFINE_TEST(_name, _description, _function, _enabled) DEFINE_TEST_WITH_TYPE(_name, _description, _function, BASIC, _enabled)

#define DEFINE_TEST_BOOTSTRAP(_name, _description, _function, _enabled) DEFINE_TEST_WITH_TYPE(_name, _description, _function, BOOTSTRAP, _enabled)
/**/

/* Definitions so that we can find the test types */
extern struct test_type __start__test_type[];
extern struct test_type __stop__test_type[];

/* Definitions so that we can find the test cases */
extern testcase_t __start__test_case[];
extern testcase_t __stop__test_case[];

static inline int test_type_comparator(const void *a, const void *b)
{
    const struct test_type **ta = (const struct test_type **) a;
    const struct test_type **tb = (const struct test_type **) b;
    if ((*ta)->id > (*tb)->id) {
        return 1;
    } else if ((*ta)->id < (*tb)->id) {
        return -1;
    }

    return 0;
}

static inline int test_comparator(const void *a, const void *b)
{
    const struct testcase **ta = (const struct testcase **)a;
    const struct testcase **tb = (const struct testcase **)b;
    return strcmp((*ta)->name, (*tb)->name);
}

/* Fails a test case, stop running the rest of the test, but keep running other tests. */
static inline test_result_t _test_fail(const char *condition, const char *file, int line)
{
    _sel4test_failure(condition, file, line);
    return FAILURE;
}

/* Fails a test case, keep running the rest of the test, then keep running other tests. */
static inline void _test_error(const char *condition, const char *file, int line)
{

    _sel4test_report_error(condition, file, line);
}

/* Fails a test case, stop everything. */
static inline test_result_t _test_abort(const char *condition, const char *file, int line)
{
    _sel4test_failure(condition, file, line);
    return ABORT;
}

#define test_assert(e) if (!(e)) return _test_fail(#e, __FILE__, __LINE__)
#define test_check(e) if (!(e)) _test_error(#e, __FILE__, __LINE__)
#define test_assert_fatal(e) if (!(e)) return _test_abort(#e, __FILE__, __LINE__)

#define __TEST_BUFFER_SIZE 200
#define test_op_type(a, b, op, t, name_a, name_b, cast) \
    do {\
        if (!(a op b)) { \
            int len = snprintf(NULL, 0, "Check %s(" t ") %s %s(" t ") failed.",\
                               #name_a, (cast) a, #op, #name_b, (cast) b) + 1; \
            char buffer[len]; \
            snprintf(buffer, len, "Check %s(" t ") %s %s(" t ") failed.",\
                     #name_a, (cast) a, #op, #name_b, (cast) b); \
            _test_error(buffer, __FILE__, __LINE__); \
        }\
    } while (0)

#define test_op(a, b, op) \
    do { \
         typeof (a) _a = (a); \
         typeof (b) _b = (b); \
         if (sizeof(_a) != sizeof(_b)) { \
             int len = snprintf(NULL, 0, "%s (size %zu) != %s (size %zu), use of test_eq incorrect", #a,\
                     sizeof(_a), #b, sizeof(_b)) + 1;\
             char buffer[len];\
             snprintf(buffer, len, "%s (size %zu) != %s (size %zu), use of test_eq incorrect", #a, sizeof(_a),\
                     #b, sizeof(_b));\
             _test_error(buffer, __FILE__, __LINE__);\
         } else if (TYPES_COMPATIBLE(typeof(_a), int)) {\
             test_op_type(_a, _b, op, "%d", a, b, int); \
         } else if (TYPES_COMPATIBLE(typeof(_a), long)) {\
             test_op_type(_a, _b, op, "%ld", a, b, long); \
         } else if (TYPES_COMPATIBLE(typeof(_a), long long)) {\
             test_op_type(_a, _b, op, "%lld", a, b, long long); \
         } else if (TYPES_COMPATIBLE(typeof(_a), unsigned int)) {\
             test_op_type(_a, _b, op, "%u", a, b, unsigned int); \
         } else if (TYPES_COMPATIBLE(typeof(_a), unsigned long)) {\
             test_op_type(_a, _b, op, "%lu", a, b, unsigned long); \
         } else if (TYPES_COMPATIBLE(typeof(_a), unsigned long long)) {\
             test_op_type(_a, _b, op, "%llu", a, b, unsigned long long); \
         } else if (TYPES_COMPATIBLE(typeof(_a), char)) {\
             test_op_type(_a, _b, op, "%c", a, b, char); \
         } else if (TYPES_COMPATIBLE(typeof(_a), uintptr_t)) {\
             test_op_type(_a, _b, op, "0x%" PRIxPTR, a, b, uintptr_t);\
         } else { \
             _test_error("Cannot use test_op on this type", __FILE__, __LINE__);\
         }\
    } while (0)

/* Pretty printed test_check wrapper macros for basic comparisons on base types,
 * which output the values and variable names to aid debugging */
#define test_eq(a, b)  test_op(a, b, ==)
#define test_neq(a, b) test_op(a, b, !=)
#define test_gt(a, b)  test_op(a, b, >)
#define test_geq(a, b) test_op(a, b, >=)
#define test_lt(a, b)  test_op(a, b, <)
#define test_leq(a, b) test_op(a, b, <=)

#define __TEST_MAX_STRING 50
#define test_strop(a, b, op) \
     do {\
          if (strnlen(a, __TEST_MAX_STRING) == __TEST_MAX_STRING) {\
              _test_error("String " #a " too long for test_str* macros", __FILE__, __LINE__);\
          } else if (strnlen(b, __TEST_MAX_STRING) == __TEST_MAX_STRING) {\
              _test_error("String " #b " too long for test_str* macros", __FILE__, __LINE__);\
          } else if (!(strncmp(a, b, __TEST_MAX_STRING)) op 0) {\
              char buffer[__TEST_BUFFER_SIZE + 2 * __TEST_MAX_STRING];\
              snprintf(buffer, sizeof(buffer),\
                       "Check %s(%s) %s %s(%s) failed.", #a, a, #op, #b, b);\
              _test_error(buffer, __FILE__, __LINE__); \
          }\
    } while (0)

/* Pretty printed test_check wrapper macros for basic comparisons on c strings,
 * which output the values and variable names to aid debugging */
#define test_streq(a, b)  test_strop(a, b, ==)
#define test_strneq(a, b) test_strop(a, b, !=)
#define test_strge(a, b)  test_strop(a, b, >)
#define test_strgeq(a, b) test_strop(a, b, >=)
#define test_strle(a, b)  test_strop(a, b, <)
#define test_strleq(a, b) test_strop(a, b, <=)

env_t sel4test_get_env(void);

