File: opal_value_array.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (120 lines) | stat: -rw-r--r-- 3,395 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2008-2014 Cisco Systems, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

/*
 * This test is intended to test the opal_value_array class
 */

#include "opal_config.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>

#include "support.h"
#include "opal/class/opal_value_array.h"
#include "opal/runtime/opal.h"

#define NUM_ITEMS 10


int main(int argc, char **argv)
{
    uint64_t i, val;
    uint64_t count;
    opal_value_array_t array;

    test_init("opal_value_array_t");

    i = opal_init_util(&argc, &argv);
    test_verify_int(OPAL_SUCCESS, i);
    if (OPAL_SUCCESS != i) {
        test_finalize();
        exit(1);
    }

    OBJ_CONSTRUCT(&array, opal_value_array_t);

    opal_value_array_init(&array, sizeof(uint64_t));
    test_verify_int(0, opal_value_array_get_size(&array));

    /* add several items to the array */
    for(i=0; i < NUM_ITEMS; i++) {
        opal_value_array_append_item(&array, &i);
    }
    test_verify_int(NUM_ITEMS, opal_value_array_get_size(&array));

    /* verify contents */
    for(i=0; i < NUM_ITEMS; i++) {
        val = OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i);
        if (val != i) {
            test_failure("Comparison failure");
            fprintf(stderr, " Expected result: %lld\n", (long long) i);
            fprintf(stderr, " Test result: %lld\n", (long long) val);
            fflush(stderr);
        }
    }

    /* re-init array with new type */
    opal_value_array_init(&array, sizeof(uint64_t));
    test_verify_int(0, opal_value_array_get_size(&array));

    /* set fixed size */
    opal_value_array_set_size(&array, NUM_ITEMS);

    /* initialize array */
    count = 0;
    for(i=0; i < NUM_ITEMS; i++) {
        OPAL_VALUE_ARRAY_SET_ITEM(&array, uint64_t, i, count++);
    }

    /* grow it */
    for(i=0; i < NUM_ITEMS; i++) {
        opal_value_array_append_item(&array, &count);
        count++;
    }
    /* check size */
    test_verify_int(count, opal_value_array_get_size(&array));

    /* validate contents */
    for(i=0; i < count; i++) {
        test_verify_int(i, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
    }

    /* remove an item */
    opal_value_array_remove_item(&array, NUM_ITEMS);

    /* check size */
    test_verify_int(count-1, opal_value_array_get_size(&array));

    /* validate contents */
    for(i=0; i < count-1; i++) {
        if(i >= NUM_ITEMS) {
            test_verify_int(i+1, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
        } else {
            test_verify_int(i, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
        }
    }

    OBJ_DESTRUCT(&array);

    opal_finalize_util ();

    return test_finalize();
}