Exemple #1
0
static int64_t get_alloc_bandwidth (struct resource *r)
{
    int64_t alloc_bw;
    if (rdl_resource_get_int (r, "alloc_bw", &alloc_bw) == 0) {
        return alloc_bw;
    } else {  // something got messed up, set it to zero and return zero
        rdl_resource_set_int (r, "alloc_bw", 0);
        return 0;
    }
}
Exemple #2
0
int main (int argc, char *argv[])
{
    struct rdllib *l;
    struct rdl *rdl1, *rdl2;
    struct rdl_accumulator *a;
    struct resource *r, *c;
    int64_t val;
    const char *h = NULL;

    const char *filename = argv[1];

    log_init (basename (argv[0]));
    rdllib_set_default_errf (NULL, &perr);

    if (!(l = rdllib_open ()))
        log_err_exit ("rdllib_open");

    if (filename == NULL || *filename == '\0')
        filename = getenv ("TESTRDL_INPUT_FILE");

    if (!(rdl1 = rdl_loadfile (l, filename)))
        log_err_exit ("loadfile: %s", filename);

    while ((h = rdl_next_hierarchy (rdl1, h)))
        fprintf (stderr, "%s\n", h);

    if (!(rdl2 = rdl_copy (rdl1)))
        log_err_exit ("copy");

    r = rdl_resource_get (rdl1, "default");
    if (rdl_resource_set_int (r, "test-tag", 5959) < 0)
        exit (1);
    rdl_resource_get_int (r, "test-tag", &val);
    if (val != 5959)
        exit (1);
     rdl_resource_delete_tag (r, "test-tag");

    c = rdl_resource_next_child (r);

    a = rdl_accumulator_create (rdl1);
    if (rdl_accumulator_add (a, c) < 0)
        exit (1);

    rdl2 = rdl_accumulator_copy (a);
    rdl_accumulator_destroy (a);

    print_resource (rdl_resource_get (rdl2, "default"), 0);

    /*
     *  Test find
     */
    json_t *args = Jnew ();
    Jadd_str (args, "type", "node");
    Jadd_int (args, "id", 300);
    rdl2 = rdl_find (rdl1, args);
    if (rdl2 == NULL)
        log_err_exit ("rdl_find");
    json_decref (args);
    r = rdl_resource_get (rdl2, "default");
    if (r == NULL)
        exit (1);

    c = rdl_resource_next_child (r);
    printf ("found %s\n", rdl_resource_name (c));

    rdl_resource_destroy (r);
    rdl_destroy (rdl2);

    r = rdl_resource_get (rdl1, "default:/hype/hype300/socket0/memory");
    if (r == NULL)
        exit (1);

    print_resource (r, 0);
    rdl_resource_alloc (r, 1024);
    printf ("After alloc:\n");
    print_resource (r, 0);
    rdl_resource_free (r, 1024);
    printf ("After free:\n");
    print_resource (r, 0);

    rdllib_close (l);

    log_fini ();

    return 0;
}