/*
 * libqos driver framework
 *
 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>
 */

#include "qemu/osdep.h"
#include "libqtest.h"
#include "libqos/qgraph.h"
#include "libqos/qgraph_internal.h"

#define MACHINE_PC "x86_64/pc"
#define MACHINE_RASPI2 "arm/raspi2"
#define I440FX "i440FX-pcihost"
#define PCIBUS_PC "pcibus-pc"
#define SDHCI "sdhci"
#define PCIBUS "pci-bus"
#define SDHCI_PCI "sdhci-pci"
#define SDHCI_MM "generic-sdhci"
#define REGISTER_TEST "register-test"

int npath;

static void *machinefunct(QTestState *qts)
{
    return NULL;
}

static void *driverfunct(void *obj, QGuestAllocator *machine, void *arg)
{
    return NULL;
}

static void testfunct(void *obj, void *arg, QGuestAllocator *alloc)
{
    return;
}

static void check_interface(const char *interface)
{
    g_assert_cmpint(qos_graph_has_machine(interface), ==, FALSE);
    g_assert_nonnull(qos_graph_get_node(interface));
    g_assert_cmpint(qos_graph_has_node(interface), ==, TRUE);
    g_assert_cmpint(qos_graph_get_node_type(interface), ==, QNODE_INTERFACE);
    qos_graph_node_set_availability(interface, TRUE);
    g_assert_cmpint(qos_graph_get_node_availability(interface), ==, TRUE);
}

static void check_machine(const char *machine)
{
    qos_node_create_machine(machine, machinefunct);
    g_assert_nonnull(qos_graph_get_machine(machine));
    g_assert_cmpint(qos_graph_has_machine(machine), ==, TRUE);
    g_assert_nonnull(qos_graph_get_node(machine));
    g_assert_cmpint(qos_graph_get_node_availability(machine), ==, FALSE);
    qos_graph_node_set_availability(machine, TRUE);
    g_assert_cmpint(qos_graph_get_node_availability(machine), ==, TRUE);
    g_assert_cmpint(qos_graph_has_node(machine), ==, TRUE);
    g_assert_cmpint(qos_graph_get_node_type(machine), ==, QNODE_MACHINE);
}

static void check_contains(const char *machine, const char *driver)
{
    QOSGraphEdge *edge;
    qos_node_contains(machine, driver, NULL);

    edge = qos_graph_get_edge(machine, driver);
    g_assert_nonnull(edge);
    g_assert_cmpint(qos_graph_edge_get_type(edge), ==, QEDGE_CONTAINS);
    g_assert_cmpint(qos_graph_has_edge(machine, driver), ==, TRUE);
}

static void check_produces(const char *machine, const char *interface)
{
    QOSGraphEdge *edge;

    qos_node_produces(machine, interface);
    check_interface(interface);
    edge = qos_graph_get_edge(machine, interface);
    g_assert_nonnull(edge);
    g_assert_cmpint(qos_graph_edge_get_type(edge), ==,
                    QEDGE_PRODUCES);
    g_assert_cmpint(qos_graph_has_edge(machine, interface), ==, TRUE);
}

static void check_consumes(const char *driver, const char *interface)
{
    QOSGraphEdge *edge;

    qos_node_consumes(driver, interface, NULL);
    check_interface(interface);
    edge = qos_graph_get_edge(interface, driver);
    g_assert_nonnull(edge);
    g_assert_cmpint(qos_graph_edge_get_type(edge), ==, QEDGE_CONSUMED_BY);
    g_assert_cmpint(qos_graph_has_edge(interface, driver), ==, TRUE);
}

static void check_driver(const char *driver)
{
    qos_node_create_driver(driver, driverfunct);
    g_assert_cmpint(qos_graph_has_machine(driver), ==, FALSE);
    g_assert_nonnull(qos_graph_get_node(driver));
    g_assert_cmpint(qos_graph_has_node(driver), ==, TRUE);
    g_assert_cmpint(qos_graph_get_node_type(driver), ==, QNODE_DRIVER);
    g_assert_cmpint(qos_graph_get_node_availability(driver), ==, FALSE);
    qos_graph_node_set_availability(driver, TRUE);
    g_assert_cmpint(qos_graph_get_node_availability(driver), ==, TRUE);
}

static void check_test(const char *test, const char *interface)
{
    QOSGraphEdge *edge;
    const char *full_name = g_strdup_printf("%s-tests/%s", interface, test);

    qos_add_test(test, interface, testfunct, NULL);
    g_assert_cmpint(qos_graph_has_machine(test), ==, FALSE);
    g_assert_cmpint(qos_graph_has_machine(full_name), ==, FALSE);
    g_assert_nonnull(qos_graph_get_node(full_name));
    g_assert_cmpint(qos_graph_has_node(full_name), ==, TRUE);
    g_assert_cmpint(qos_graph_get_node_type(full_name), ==, QNODE_TEST);
    edge = qos_graph_get_edge(interface, full_name);
    g_assert_nonnull(edge);
    g_assert_cmpint(qos_graph_edge_get_type(edge), ==,
                    QEDGE_CONSUMED_BY);
    g_assert_cmpint(qos_graph_has_edge(interface, full_name), ==, TRUE);
    g_assert_cmpint(qos_graph_get_node_availability(full_name), ==, TRUE);
    qos_graph_node_set_availability(full_name, FALSE);
    g_assert_cmpint(qos_graph_get_node_availability(full_name), ==, FALSE);
}

static void count_each_test(QOSGraphNode *path, int len)
{
    npath++;
}

static void check_leaf_discovered(int n)
{
    npath = 0;
    qos_graph_foreach_test_path(count_each_test);
    g_assert_cmpint(n, ==, npath);
}

/* G_Test functions */

static void init_nop(void)
{
    qos_graph_init();
    qos_graph_destroy();
}

static void test_machine(void)
{
    qos_graph_init();
    check_machine(MACHINE_PC);
    qos_graph_destroy();
}

static void test_contains(void)
{
    qos_graph_init();
    check_contains(MACHINE_PC, I440FX);
    g_assert_null(qos_graph_get_machine(MACHINE_PC));
    g_assert_null(qos_graph_get_machine(I440FX));
    g_assert_null(qos_graph_get_node(MACHINE_PC));
    g_assert_null(qos_graph_get_node(I440FX));
    qos_graph_destroy();
}

static void test_multiple_contains(void)
{
    qos_graph_init();
    check_contains(MACHINE_PC, I440FX);
    check_contains(MACHINE_PC, PCIBUS_PC);
    qos_graph_destroy();
}

static void test_produces(void)
{
    qos_graph_init();
    check_produces(MACHINE_PC, I440FX);
    g_assert_null(qos_graph_get_machine(MACHINE_PC));
    g_assert_null(qos_graph_get_machine(I440FX));
    g_assert_null(qos_graph_get_node(MACHINE_PC));
    g_assert_nonnull(qos_graph_get_node(I440FX));
    qos_graph_destroy();
}

static void test_multiple_produces(void)
{
    qos_graph_init();
    check_produces(MACHINE_PC, I440FX);
    check_produces(MACHINE_PC, PCIBUS_PC);
    qos_graph_destroy();
}

static void test_consumes(void)
{
    qos_graph_init();
    check_consumes(I440FX, SDHCI);
    g_assert_null(qos_graph_get_machine(I440FX));
    g_assert_null(qos_graph_get_machine(SDHCI));
    g_assert_null(qos_graph_get_node(I440FX));
    g_assert_nonnull(qos_graph_get_node(SDHCI));
    qos_graph_destroy();
}

static void test_multiple_consumes(void)
{
    qos_graph_init();
    check_consumes(I440FX, SDHCI);
    check_consumes(PCIBUS_PC, SDHCI);
    qos_graph_destroy();
}

static void test_driver(void)
{
    qos_graph_init();
    check_driver(I440FX);
    qos_graph_destroy();
}

static void test_test(void)
{
    qos_graph_init();
    check_test(REGISTER_TEST, SDHCI);
    qos_graph_destroy();
}

static void test_machine_contains_driver(void)
{
    qos_graph_init();
    check_machine(MACHINE_PC);
    check_driver(I440FX);
    check_contains(MACHINE_PC, I440FX);
    qos_graph_destroy();
}

static void test_driver_contains_driver(void)
{
    qos_graph_init();
    check_driver(PCIBUS_PC);
    check_driver(I440FX);
    check_contains(PCIBUS_PC, I440FX);
    qos_graph_destroy();
}

static void test_machine_produces_interface(void)
{
    qos_graph_init();
    check_machine(MACHINE_PC);
    check_produces(MACHINE_PC, SDHCI);
    qos_graph_destroy();
}

static void test_driver_produces_interface(void)
{
    qos_graph_init();
    check_driver(I440FX);
    check_produces(I440FX, SDHCI);
    qos_graph_destroy();
}

static void test_machine_consumes_interface(void)
{
    qos_graph_init();
    check_machine(MACHINE_PC);
    check_consumes(MACHINE_PC, SDHCI);
    qos_graph_destroy();
}

static void test_driver_consumes_interface(void)
{
    qos_graph_init();
    check_driver(I440FX);
    check_consumes(I440FX, SDHCI);
    qos_graph_destroy();
}

static void test_test_consumes_interface(void)
{
    qos_graph_init();
    check_test(REGISTER_TEST, SDHCI);
    qos_graph_destroy();
}

static void test_full_sample(void)
{
    qos_graph_init();
    check_machine(MACHINE_PC);
    check_contains(MACHINE_PC, I440FX);
    check_driver(I440FX);
    check_driver(PCIBUS_PC);
    check_contains(I440FX, PCIBUS_PC);
    check_produces(PCIBUS_PC, PCIBUS);
    check_driver(SDHCI_PCI);
    qos_node_consumes(SDHCI_PCI, PCIBUS, NULL);
    check_produces(SDHCI_PCI, SDHCI);
    check_driver(SDHCI_MM);
    check_produces(SDHCI_MM, SDHCI);
    qos_add_test(REGISTER_TEST, SDHCI, testfunct, NULL);
    check_leaf_discovered(1);
    qos_print_graph();
    qos_graph_destroy();
}

static void test_full_sample_raspi(void)
{
    qos_graph_init();
    check_machine(MACHINE_PC);
    check_contains(MACHINE_PC, I440FX);
    check_driver(I440FX);
    check_driver(PCIBUS_PC);
    check_contains(I440FX, PCIBUS_PC);
    check_produces(PCIBUS_PC, PCIBUS);
    check_driver(SDHCI_PCI);
    qos_node_consumes(SDHCI_PCI, PCIBUS, NULL);
    check_produces(SDHCI_PCI, SDHCI);
    check_machine(MACHINE_RASPI2);
    check_contains(MACHINE_RASPI2, SDHCI_MM);
    check_driver(SDHCI_MM);
    check_produces(SDHCI_MM, SDHCI);
    qos_add_test(REGISTER_TEST, SDHCI, testfunct, NULL);
    qos_print_graph();
    check_leaf_discovered(2);
    qos_graph_destroy();
}

static void test_cycle(void)
{
    qos_graph_init();
    check_machine(MACHINE_RASPI2);
    check_driver("B");
    check_driver("C");
    check_driver("D");
    check_contains(MACHINE_RASPI2, "B");
    check_contains("B", "C");
    check_contains("C", "D");
    check_contains("D", MACHINE_RASPI2);
    check_leaf_discovered(0);
    qos_print_graph();
    qos_graph_destroy();
}

static void test_two_test_same_interface(void)
{
    qos_graph_init();
    check_machine(MACHINE_RASPI2);
    check_produces(MACHINE_RASPI2, "B");
    qos_add_test("C", "B", testfunct, NULL);
    qos_add_test("D", "B", testfunct, NULL);
    check_contains(MACHINE_RASPI2, "B");
    check_leaf_discovered(4);
    qos_print_graph();
    qos_graph_destroy();
}

static void test_test_in_path(void)
{
    qos_graph_init();
    check_machine(MACHINE_RASPI2);
    check_produces(MACHINE_RASPI2, "B");
    qos_add_test("C", "B", testfunct, NULL);
    check_driver("D");
    check_consumes("D", "B");
    check_produces("D", "E");
    qos_add_test("F", "E", testfunct, NULL);
    check_leaf_discovered(2);
    qos_print_graph();
    qos_graph_destroy();
}

static void test_double_edge(void)
{
    qos_graph_init();
    check_machine(MACHINE_RASPI2);
    check_produces("B", "C");
    qos_node_consumes("C", "B", NULL);
    qos_add_test("D", "C", testfunct, NULL);
    check_contains(MACHINE_RASPI2, "B");
    qos_print_graph();
    qos_graph_destroy();
}

int main(int argc, char **argv)
{
    g_test_init(&argc, &argv, NULL);
    g_test_add_func("/qgraph/init_nop", init_nop);
    g_test_add_func("/qgraph/test_machine", test_machine);
    g_test_add_func("/qgraph/test_contains", test_contains);
    g_test_add_func("/qgraph/test_multiple_contains", test_multiple_contains);
    g_test_add_func("/qgraph/test_produces", test_produces);
    g_test_add_func("/qgraph/test_multiple_produces", test_multiple_produces);
    g_test_add_func("/qgraph/test_consumes", test_consumes);
    g_test_add_func("/qgraph/test_multiple_consumes",
                    test_multiple_consumes);
    g_test_add_func("/qgraph/test_driver", test_driver);
    g_test_add_func("/qgraph/test_test", test_test);
    g_test_add_func("/qgraph/test_machine_contains_driver",
                    test_machine_contains_driver);
    g_test_add_func("/qgraph/test_driver_contains_driver",
                    test_driver_contains_driver);
    g_test_add_func("/qgraph/test_machine_produces_interface",
                    test_machine_produces_interface);
    g_test_add_func("/qgraph/test_driver_produces_interface",
                    test_driver_produces_interface);
    g_test_add_func("/qgraph/test_machine_consumes_interface",
                    test_machine_consumes_interface);
    g_test_add_func("/qgraph/test_driver_consumes_interface",
                    test_driver_consumes_interface);
    g_test_add_func("/qgraph/test_test_consumes_interface",
                    test_test_consumes_interface);
    g_test_add_func("/qgraph/test_full_sample", test_full_sample);
    g_test_add_func("/qgraph/test_full_sample_raspi", test_full_sample_raspi);
    g_test_add_func("/qgraph/test_cycle", test_cycle);
    g_test_add_func("/qgraph/test_two_test_same_interface",
                    test_two_test_same_interface);
    g_test_add_func("/qgraph/test_test_in_path", test_test_in_path);
    g_test_add_func("/qgraph/test_double_edge", test_double_edge);

    g_test_run();
    return 0;
}
