2007-12-21 09:02:00 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
2004-02-11 00:22:43 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2007-12-21 09:02:00 +03:00
|
|
|
* Copyright (c) 2004-2007 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2010-07-28 18:20:58 +04:00
|
|
|
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-02-11 00:22:43 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-12-21 09:02:00 +03:00
|
|
|
* This test is intended to test the opal_pointer_array
|
2004-02-11 00:22:43 +03:00
|
|
|
* class
|
|
|
|
*/
|
|
|
|
|
2010-07-28 18:20:58 +04:00
|
|
|
#include "opal_config.h"
|
2004-02-11 00:22:43 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "support.h"
|
2007-12-22 08:32:40 +03:00
|
|
|
#include "opal/class/opal_pointer_array.h"
|
2004-02-11 00:22:43 +03:00
|
|
|
|
2005-04-06 00:34:56 +04:00
|
|
|
typedef union {
|
|
|
|
int ivalue;
|
|
|
|
char *cvalue;
|
|
|
|
} value_t;
|
|
|
|
|
2004-02-11 01:07:47 +03:00
|
|
|
static void test(bool thread_usage){
|
2004-02-11 00:22:43 +03:00
|
|
|
|
|
|
|
/* local variables */
|
2007-12-21 09:02:00 +03:00
|
|
|
opal_pointer_array_t *array;
|
2005-04-06 00:34:56 +04:00
|
|
|
value_t *test_data;
|
2005-04-01 17:35:57 +04:00
|
|
|
int len_test_data,i,test_len_in_array,error_cnt;
|
|
|
|
int ele_index;
|
2014-01-10 17:36:33 +04:00
|
|
|
int error_code;
|
2005-04-06 00:34:56 +04:00
|
|
|
value_t value;
|
2004-02-11 00:22:43 +03:00
|
|
|
|
|
|
|
/* initialize thread levels */
|
2014-01-10 17:36:33 +04:00
|
|
|
opal_set_using_threads(thread_usage);
|
2004-02-11 00:22:43 +03:00
|
|
|
|
2007-12-21 09:02:00 +03:00
|
|
|
array=OBJ_NEW(opal_pointer_array_t);
|
2004-02-11 00:22:43 +03:00
|
|
|
assert(array);
|
|
|
|
|
|
|
|
len_test_data=5;
|
2005-04-06 00:34:56 +04:00
|
|
|
test_data=malloc(sizeof(value_t)*len_test_data);
|
2004-02-11 00:22:43 +03:00
|
|
|
assert(test_data);
|
|
|
|
|
|
|
|
for(i=0 ; i < len_test_data ; i++ ) {
|
2005-04-06 00:34:56 +04:00
|
|
|
test_data[i].ivalue = (i+1);
|
2004-02-11 00:22:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add data to table */
|
|
|
|
test_len_in_array=3;
|
|
|
|
assert(len_test_data>=test_len_in_array);
|
|
|
|
for(i=0 ; i < test_len_in_array ; i++ ) {
|
2007-12-21 09:02:00 +03:00
|
|
|
opal_pointer_array_add(array,test_data[i].cvalue);
|
2004-02-11 00:22:43 +03:00
|
|
|
}
|
|
|
|
/* check to see that test_len_in_array are in array */
|
2005-04-06 00:34:56 +04:00
|
|
|
if( (array->size - array->number_free) == test_len_in_array) {
|
2004-02-11 00:22:43 +03:00
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("check on number of elments in array");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check order of data */
|
|
|
|
error_cnt=0;
|
|
|
|
for(i=0 ; i < test_len_in_array ; i++ ) {
|
2005-04-06 00:34:56 +04:00
|
|
|
value.cvalue = array->addr[i];
|
|
|
|
if( (i+1) != value.ivalue ) {
|
2004-02-11 00:22:43 +03:00
|
|
|
error_cnt++;
|
2005-04-06 00:34:56 +04:00
|
|
|
}
|
2004-02-11 00:22:43 +03:00
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" data check ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free 2nd element and make sure that value is reset correctly,
|
|
|
|
* and that the lowest_index is also reset correctly */
|
|
|
|
ele_index=1;
|
2007-12-21 09:02:00 +03:00
|
|
|
error_code=opal_pointer_array_set_item(array,ele_index,NULL);
|
2004-02-11 00:22:43 +03:00
|
|
|
if( 0 == error_code ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
2007-12-21 09:02:00 +03:00
|
|
|
test_failure(" opal_pointer_array_set_item ");
|
2004-02-11 00:22:43 +03:00
|
|
|
}
|
|
|
|
if( NULL == array->addr[ele_index]){
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" set pointer value");
|
|
|
|
}
|
|
|
|
if( ele_index == array->lowest_free ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" lowest free ");
|
|
|
|
}
|
|
|
|
|
2007-12-21 09:02:00 +03:00
|
|
|
/* test opal_pointer_array_get_item */
|
2004-02-11 00:22:43 +03:00
|
|
|
array->number_free=array->size;
|
|
|
|
array->lowest_free=0;
|
|
|
|
for(i=0 ; i < array->size ; i++ ) {
|
|
|
|
array->addr[i] = NULL;
|
|
|
|
}
|
|
|
|
error_cnt=0;
|
|
|
|
for(i=0 ; i < array->size ; i++ ) {
|
2005-04-06 00:34:56 +04:00
|
|
|
value.ivalue = i + 2;
|
2007-12-21 09:02:00 +03:00
|
|
|
ele_index=opal_pointer_array_add(array, value.cvalue);
|
2004-02-11 00:22:43 +03:00
|
|
|
if( i != ele_index ) {
|
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
2007-12-21 09:02:00 +03:00
|
|
|
test_failure(" opal_pointer_array_add 2nd ");
|
2004-02-11 00:22:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
error_cnt=0;
|
|
|
|
for(i=0 ; i < array->size ; i++ ) {
|
2007-12-21 09:02:00 +03:00
|
|
|
value.cvalue = opal_pointer_array_get_item(array,i);
|
2005-04-06 00:34:56 +04:00
|
|
|
if( (i+2) != value.ivalue ) {
|
2004-02-11 00:22:43 +03:00
|
|
|
error_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( 0 == error_cnt ) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure(" data check - 2nd ");
|
|
|
|
}
|
|
|
|
|
|
|
|
free (array);
|
|
|
|
free(test_data);
|
|
|
|
}
|
|
|
|
|
2005-04-06 00:34:56 +04:00
|
|
|
|
2004-02-11 00:22:43 +03:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2007-12-21 09:02:00 +03:00
|
|
|
test_init("opal_pointer_array");
|
2004-02-11 00:22:43 +03:00
|
|
|
|
|
|
|
/* run through tests with thread usage set to false */
|
|
|
|
test(false);
|
|
|
|
|
|
|
|
/* run through tests with thread usage set to true */
|
|
|
|
test(true);
|
|
|
|
|
2004-02-11 17:45:35 +03:00
|
|
|
return test_finalize();
|
2004-02-11 00:22:43 +03:00
|
|
|
}
|